Esempio n. 1
0
 /**
  * Merges set values with those coming from another source, keeping the existing value if one
  * already exists
  */
 public synchronized void mergeWithoutReplacement(ContentValues other) {
   if (setValues == null) {
     setValues = new ContentValues();
   }
   for (Entry<String, Object> item : other.valueSet()) {
     if (setValues.containsKey(item.getKey())) {
       continue;
     }
     AndroidUtilities.putInto(setValues, item.getKey(), item.getValue());
   }
 }
Esempio n. 2
0
  private void launchTaskList() {
    Intent intent = getIntent();

    Bundle extras = intent.getExtras();

    Intent taskListIntent = new Intent(this, TaskListActivity.class);
    taskListIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    if (extras != null && extras.containsKey(TOKEN_CUSTOM_CLASS)) {
      taskListIntent.putExtras(intent.getExtras());
    }

    if (extras != null && extras.containsKey(TOKEN_FILTER_SQL)) {
      // launched from desktop shortcut, must create a fake filter
      String title = extras.getString(TOKEN_FILTER_TITLE);
      String sql = extras.getString(TOKEN_FILTER_SQL);
      sql = sql.replace("tasks.userId=0", "1"); // TODO: replace dirty hack for missing column
      ContentValues values = new ContentValues();
      for (String key : extras.keySet()) {
        if (!key.startsWith(TOKEN_FILTER_VALUES_ITEM)) {
          continue;
        }

        Object value = extras.get(key);
        key = key.substring(TOKEN_FILTER_VALUES_ITEM.length());

        // assume one of the big 4...
        if (value instanceof String) {
          values.put(key, (String) value);
        } else if (value instanceof Integer) {
          values.put(key, (Integer) value);
        } else if (value instanceof Double) {
          values.put(key, (Double) value);
        } else if (value instanceof Long) {
          values.put(key, (Long) value);
        } else {
          throw new IllegalStateException(
              "Unsupported bundle type " + value.getClass()); // $NON-NLS-1$
        }
      }

      Filter filter;
      if (extras.containsKey(TOKEN_CUSTOM_CLASS)) {
        filter = new FilterWithCustomIntent(title, sql, values);
        Bundle customExtras = new Bundle();
        Set<String> keys = extras.keySet();
        for (String key : keys) {
          if (AndroidUtilities.indexOf(CUSTOM_EXTRAS, key) < 0) {
            AndroidUtilities.putInto(customExtras, key, extras.get(key));
          }
        }

        ((FilterWithCustomIntent) filter).customExtras = customExtras; // Something
        ((FilterWithCustomIntent) filter).customTaskList =
            ComponentName.unflattenFromString(extras.getString(TOKEN_CUSTOM_CLASS));
      } else {
        filter = new Filter(title, sql, values);
      }
      taskListIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter);
    }

    startActivity(taskListIntent);
    finish();
  }