Example #1
0
 public static ORecordValues valuesToData(OModel model, OValues value) {
   ORecordValues data = new ORecordValues();
   data.put("name", value.get("name"));
   data.put("db_datas", value.getString("datas"));
   data.put("datas_fname", value.get("name"));
   data.put("file_size", value.get("file_size"));
   data.put("res_model", false);
   data.put("res_id", false);
   data.put("file_type", value.get("file_type"));
   data.put("company_id", model.getUser().getCompanyId());
   return data;
 }
Example #2
0
 public static JSONObject valuesToData(OModel model, OValues value) {
   JSONObject data = new JSONObject();
   try {
     data.put("name", value.get("name"));
     data.put("db_datas", value.getString("datas"));
     data.put("datas_fname", value.get("name"));
     data.put("file_size", value.get("file_size"));
     data.put("file_type", value.get("file_type"));
     data.put("company_id", model.getUser().getCompany_id());
     if (value.contains("res_id")) data.put("res_id", value.getInt("res_id"));
     else data.put("res_id", false);
     if (value.contains("res_model")) data.put("res_model", value.getString("res_model"));
     else data.put("res_model", false);
     return data;
   } catch (JSONException e) {
     e.printStackTrace();
   }
   return null;
 }
Example #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.base_control_searchable_layout);
    setResult(RESULT_CANCELED);
    edt_searchable_input = (EditText) findViewById(R.id.edt_searchable_input);
    edt_searchable_input.addTextChangedListener(this);
    Bundle extra = getIntent().getExtras();
    if (extra != null) {
      if (extra.containsKey("resource_id")) {
        resource_array_id = extra.getInt("resource_id");
      }
      if (extra.containsKey(OColumn.ROW_ID)) {
        mRowId = extra.getInt(OColumn.ROW_ID);
      }
      if (extra.containsKey("model")) {
        mModel = OModel.get(this, extra.getString("model"), null);
      }
      if (extra.containsKey("live_search")) {
        mLiveSearch = extra.getBoolean("live_search");
      }
      if (extra.containsKey("selected_position")) {
        selected_position = extra.getInt("selected_position");
      }
      if (extra.containsKey("search_hint")) {
        edt_searchable_input.setHint("Search " + extra.getString("search_hint"));
      }
      if (resource_array_id != -1) {
        String[] arrays = getResources().getStringArray(resource_array_id);
        for (int i = 0; i < arrays.length; i++) {
          ODataRow row = new ODataRow();
          row.put(OColumn.ROW_ID, i);
          row.put(mRelModel.getDefaultNameColumn(), arrays[i]);
          objects.add(row);
        }
      } else {
        if (extra.containsKey("column_name")) {
          mCol = mModel.getColumn(extra.getString("column_name"));
          mRelModel = mModel.createInstance(mCol.getType());
          objects.addAll(OSelectionField.getRecordItems(mRelModel, mCol));
        }
      }

      mList = (ListView) findViewById(R.id.searchable_items);
      mList.setOnItemClickListener(this);
      mAdapter =
          new OListAdapter(this, android.R.layout.simple_expandable_list_item_1, objects) {
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
              View v = convertView;
              if (v == null) v = getLayoutInflater().inflate(getResource(), parent, false);
              ODataRow row = (ODataRow) objects.get(position);
              OControls.setText(
                  v, android.R.id.text1, row.getString(mRelModel.getDefaultNameColumn()));
              if (row.contains(OColumn.ROW_ID) && selected_position == row.getInt(OColumn.ROW_ID)) {
                v.setBackgroundColor(getResources().getColor(R.color.control_pressed));
              } else {
                v.setBackgroundColor(Color.TRANSPARENT);
              }
              return v;
            }
          };
      if (mLiveSearch) {
        mAdapter.setOnSearchChange(this);
      }
      mList.setAdapter(mAdapter);
    } else {
      finish();
    }
  }