示例#1
0
  private void saveConfiguration(FilterListItem filterListItem) {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    String sql = null, contentValuesString = null, title = null;

    if (filterListItem != null && filterListItem instanceof Filter) {
      sql = ((Filter) filterListItem).getSqlQuery();
      ContentValues values = ((Filter) filterListItem).valuesForNewTasks;
      if (values != null)
        contentValuesString = AndroidUtilities.contentValuesToSerializedString(values);
      title = ((Filter) filterListItem).title;
    }

    Preferences.setString(WidgetConfigActivity.PREF_TITLE + mAppWidgetId, title);
    Preferences.setString(WidgetConfigActivity.PREF_SQL + mAppWidgetId, sql);
    Preferences.setString(WidgetConfigActivity.PREF_VALUES + mAppWidgetId, contentValuesString);

    if (filterListItem instanceof FilterWithCustomIntent) {
      String flattenedName =
          ((FilterWithCustomIntent) filterListItem).customTaskList.flattenToString();
      Preferences.setString(WidgetConfigActivity.PREF_CUSTOM_INTENT + mAppWidgetId, flattenedName);
      String flattenedExtras =
          AndroidUtilities.bundleToSerializedString(
              ((FilterWithCustomIntent) filterListItem).customExtras);
      if (flattenedExtras != null)
        Preferences.setString(
            WidgetConfigActivity.PREF_CUSTOM_EXTRAS + mAppWidgetId, flattenedExtras);
    }
  }
示例#2
0
  /**
   * Perform upgrade from one version to the next. Needs to be called on the UI thread so it can
   * display a progress bar and then show users a change log.
   *
   * @param from
   * @param to
   */
  public void performUpgrade(final Context context, final int from) {
    if (from == 135) AddOnService.recordOem();

    if (from > 0 && from < V3_8_2) {
      if (Preferences.getBoolean(R.string.p_transparent_deprecated, false))
        Preferences.setString(R.string.p_theme, "transparent"); // $NON-NLS-1$
      else Preferences.setString(R.string.p_theme, "black"); // $NON-NLS-1$
    }

    if (from <= V3_9_1_1) {
      actFmPreferenceService.clearLastSyncDate();
    }

    // long running tasks: pop up a progress dialog
    final ProgressDialog dialog;
    if (from < V4_0_6 && context instanceof Activity)
      dialog = DialogUtilities.progressDialog(context, context.getString(R.string.DLG_upgrading));
    else dialog = null;

    final String lastSetVersionName = AstridPreferences.getCurrentVersionName();

    Preferences.setInt(AstridPreferences.P_UPGRADE_FROM, from);

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  // NOTE: This line should be uncommented whenever any new version requires a data
                  // migration
                  // TasksXmlExporter.exportTasks(context,
                  // TasksXmlExporter.ExportType.EXPORT_TYPE_ON_UPGRADE, null, null,
                  // lastSetVersionName);

                  if (from < V3_0_0) new Astrid2To3UpgradeHelper().upgrade2To3(context, from);

                  if (from < V3_1_0) new Astrid2To3UpgradeHelper().upgrade3To3_1(context, from);

                  if (from < V3_8_3_1) new TagCaseMigrator().performTagCaseMigration(context);

                  if (from < V3_8_4 && Preferences.getBoolean(R.string.p_showNotes, false))
                    taskService.clearDetails(Task.NOTES.neq("")); // $NON-NLS-1$

                  if (from < V4_0_6) new DueDateTimeMigrator().migrateDueTimes();

                } finally {
                  DialogUtilities.dismissDialog((Activity) context, dialog);
                  context.sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH));
                }
              }
            })
        .start();
  }
示例#3
0
 @Override
 public void signOut() {
   gtasksPreferenceService.clearLastSyncDate();
   gtasksPreferenceService.setToken(null);
   Preferences.setString(GtasksPreferenceService.PREF_USER_NAME, null);
   gtasksMetadataService.clearMetadata();
 }
示例#4
0
  /**
   * Migration for existing users to assert that the "hide always" section divider exists in the
   * preferences. Knowing that this section will always be in the constructed list of controls
   * simplifies the logic a bit.
   *
   * @param c
   */
  public static void assertHideUntilSectionExists(Context c, long latestSetVersion) {
    if (latestSetVersion == 0) Preferences.setBoolean(BEAST_MODE_ASSERTED_HIDE_ALWAYS, true);

    if (Preferences.getBoolean(BEAST_MODE_ASSERTED_HIDE_ALWAYS, false)) return;

    String order = Preferences.getStringValue(BEAST_MODE_ORDER_PREF);
    String hideSectionPref = c.getString(R.string.TEA_ctrl_hide_section_pref);
    if (TextUtils.isEmpty(order)) {
      // create preference and stick hide always at the end of it
      String[] items = c.getResources().getStringArray(R.array.TEA_control_sets_prefs);
      StringBuilder builder = new StringBuilder();
      for (String item : items) {
        if (item.equals(hideSectionPref)) continue;
        builder.append(item);
        builder.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
      }

      builder.append(hideSectionPref);
      builder.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
      order = builder.toString();
    } else if (!order.contains(hideSectionPref)) {
      order += (hideSectionPref + BEAST_MODE_PREF_ITEM_SEPARATOR);
    }
    Preferences.setString(BEAST_MODE_ORDER_PREF, order);

    Preferences.setBoolean(BEAST_MODE_ASSERTED_HIDE_ALWAYS, true);
  }
示例#5
0
 @Override
 public void finish() {
   StringBuilder newSetting = new StringBuilder(30);
   for (int i = 0; i < adapter.getCount(); i++) {
     newSetting.append(adapter.getItem(i));
     newSetting.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
   }
   Preferences.setString(BEAST_MODE_ORDER_PREF, newSetting.toString());
   super.finish();
 }
示例#6
0
  /** Synchronize with server when data changes */
  public void pushTaskOnSave(Task task, ContentValues values, GtasksInvoker invoker, boolean sleep)
      throws IOException {
    if (sleep) AndroidUtilities.sleepDeep(1000L); // Wait for metadata to be saved

    Metadata gtasksMetadata = gtasksMetadataService.getTaskMetadata(task.getId());
    com.google.api.services.tasks.model.Task remoteModel = null;
    boolean newlyCreated = false;

    String remoteId = null;
    String listId = Preferences.getStringValue(GtasksPreferenceService.PREF_DEFAULT_LIST);
    if (listId == null) {
      com.google.api.services.tasks.model.TaskList defaultList = invoker.getGtaskList(DEFAULT_LIST);
      if (defaultList != null) {
        listId = defaultList.getId();
        Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, listId);
      } else {
        listId = DEFAULT_LIST;
      }
    }

    if (gtasksMetadata == null
        || !gtasksMetadata.containsNonNullValue(GtasksMetadata.ID)
        || TextUtils.isEmpty(gtasksMetadata.getValue(GtasksMetadata.ID))) { // Create case
      if (gtasksMetadata == null) {
        gtasksMetadata = GtasksMetadata.createEmptyMetadata(task.getId());
      }
      if (gtasksMetadata.containsNonNullValue(GtasksMetadata.LIST_ID)) {
        listId = gtasksMetadata.getValue(GtasksMetadata.LIST_ID);
      }

      remoteModel = new com.google.api.services.tasks.model.Task();
      newlyCreated = true;
    } else { // update case
      remoteId = gtasksMetadata.getValue(GtasksMetadata.ID);
      listId = gtasksMetadata.getValue(GtasksMetadata.LIST_ID);
      remoteModel = new com.google.api.services.tasks.model.Task();
      remoteModel.setId(remoteId);
    }

    // If task was newly created but without a title, don't sync--we're in the middle of
    // creating a task which may end up being cancelled
    if (newlyCreated
        && (!values.containsKey(Task.TITLE.name) || TextUtils.isEmpty(task.getValue(Task.TITLE)))) {
      return;
    }

    // Update the remote model's changed properties
    if (values.containsKey(Task.DELETION_DATE.name) && task.isDeleted()) {
      remoteModel.setDeleted(true);
    }

    if (values.containsKey(Task.TITLE.name)) {
      remoteModel.setTitle(task.getValue(Task.TITLE));
    }
    if (values.containsKey(Task.NOTES.name)) {
      remoteModel.setNotes(task.getValue(Task.NOTES));
    }
    if (values.containsKey(Task.DUE_DATE.name) && task.hasDueDate()) {
      remoteModel.setDue(GtasksApiUtilities.unixTimeToGtasksDueDate(task.getValue(Task.DUE_DATE)));
    }
    if (values.containsKey(Task.COMPLETION_DATE.name)) {
      if (task.isCompleted()) {
        remoteModel.setCompleted(
            GtasksApiUtilities.unixTimeToGtasksCompletionTime(task.getValue(Task.COMPLETION_DATE)));
        remoteModel.setStatus("completed"); // $NON-NLS-1$
      } else {
        remoteModel.setCompleted(null);
        remoteModel.setStatus("needsAction"); // $NON-NLS-1$
      }
    }

    if (!newlyCreated) {
      invoker.updateGtask(listId, remoteModel);
    } else {
      String parent = gtasksMetadataService.getRemoteParentId(gtasksMetadata);
      String priorSibling = gtasksMetadataService.getRemoteSiblingId(listId, gtasksMetadata);

      CreateRequest create = new CreateRequest(invoker, listId, remoteModel, parent, priorSibling);
      com.google.api.services.tasks.model.Task created = create.executePush();

      if (created != null) {
        // Update the metadata for the newly created task
        gtasksMetadata.setValue(GtasksMetadata.ID, created.getId());
        gtasksMetadata.setValue(GtasksMetadata.LIST_ID, listId);
      } else return;
    }

    task.setValue(Task.MODIFICATION_DATE, DateUtilities.now());
    gtasksMetadata.setValue(GtasksMetadata.LAST_SYNC, DateUtilities.now() + 1000L);
    metadataService.save(gtasksMetadata);
    task.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
    taskDao.saveExistingWithSqlConstraintCheck(task);
  }
  @Override
  public void onReceive(final Context context, Intent intent) {
    if (!Preferences.getBoolean(R.string.p_field_missed_calls, false)) {
      Preferences.clear(PREF_LAST_INCOMING_NUMBER);
      return;
    }

    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

    if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
      String number = digitsOnly(intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER));
      if (TextUtils.isEmpty(number)) return;

      Preferences.setString(PREF_LAST_INCOMING_NUMBER, number);
    } else if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) {
      final String lastNumber = Preferences.getStringValue(PREF_LAST_INCOMING_NUMBER);
      if (TextUtils.isEmpty(lastNumber)) {
        return;
      }

      Preferences.clear(PREF_LAST_INCOMING_NUMBER);

      new Thread() {
        @Override
        public void run() {
          AndroidUtilities.sleepDeep(WAIT_BEFORE_READ_LOG);
          Cursor calls =
              context
                  .getContentResolver()
                  .query(
                      Calls.CONTENT_URI,
                      new String[] {Calls.NUMBER, Calls.DATE, Calls.CACHED_NAME},
                      Calls.TYPE + " = ? AND " + Calls.NEW + " = ?",
                      new String[] {Integer.toString(Calls.MISSED_TYPE), "1"},
                      Calls.DATE + " DESC");
          try {
            if (calls == null) return;
            if (calls.moveToFirst()) {
              int numberIndex = calls.getColumnIndex(Calls.NUMBER);
              String number = calls.getString(numberIndex);

              // Sanity check for phone number match
              // in case the phone logs haven't updated for some reaosn
              if (!lastNumber.equals(digitsOnly(number))) {
                return;
              }

              // If a lot of time has passed since the most recent missed call, ignore
              // It could be the same person calling you back before you call them back,
              // but if you answer this time, the missed call will still be in the database
              // and will be processed again.
              int dateIndex = calls.getColumnIndex(Calls.DATE);
              long date = calls.getLong(dateIndex);
              if (DateUtilities.now() - date > 2 * DateUtilities.ONE_MINUTE) {
                return;
              }

              int nameIndex = calls.getColumnIndex(Calls.CACHED_NAME);
              String name = calls.getString(nameIndex);

              String timeString = DateUtilities.getTimeString(context, new Date(date));

              long contactId = getContactIdFromNumber(context, number);

              Intent missedCallIntent = new Intent(context, MissedCallActivity.class);
              missedCallIntent.putExtra(MissedCallActivity.EXTRA_NUMBER, number);
              missedCallIntent.putExtra(MissedCallActivity.EXTRA_NAME, name);
              missedCallIntent.putExtra(MissedCallActivity.EXTRA_TIME, timeString);
              missedCallIntent.putExtra(MissedCallActivity.EXTRA_CONTACT_ID, contactId);
              missedCallIntent.setFlags(
                  Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
              context.startActivity(missedCallIntent);
            }
          } finally {
            if (calls != null) calls.close();
          }
        }
      }.start();
    }
  }
示例#8
0
  public void checkAndMigrateLegacy() throws IOException {
    if (!gtasksPreferenceService.migrationHasOccurred()) {

      // Fetch all tasks that have associated gtask metadata
      String defaultListTitle =
          gtasksListService.getListName(
              Preferences.getStringValue(GtasksPreferenceService.PREF_DEFAULT_LIST));
      String defaultListId = null;

      TodorooCursor<Task> allTasksWithGtaskData =
          taskService.query(
              Query.select(Task.PROPERTIES)
                  .where(
                      Task.ID.in(
                          Query.select(Metadata.TASK)
                              .from(Metadata.TABLE)
                              .where(Metadata.KEY.eq(GtasksMetadata.METADATA_KEY)))));

      try {
        if (allTasksWithGtaskData.getCount() > 0) {
          // Fetch all remote tasks from all remote lists (this may be an expensive operation)
          // and map their titles to their real remote ids
          HashMap<String, String> taskAndListTitlesToRemoteTaskIds = new HashMap<String, String>();

          List<TaskList> items = allLists.getItems();
          for (TaskList list : items) {
            if (list.getTitle().equals(defaultListTitle)) {
              defaultListId = list.getId();
            }

            Tasks allTasks = gtasksService.getAllGtasksFromListId(list.getId(), false, false, 0);

            List<com.google.api.services.tasks.model.Task> tasksItems = allTasks.getItems();
            if (tasksItems != null) {
              for (com.google.api.services.tasks.model.Task t : tasksItems) {
                String key = constructKeyFromTitles(t.getTitle(), list.getTitle());
                taskAndListTitlesToRemoteTaskIds.put(key, t.getId());
              }
            }
          }

          if (defaultListId == null) {
            com.google.api.services.tasks.model.TaskList defaultList =
                gtasksService.getGtaskList("@default"); // $NON-NLS-1$
            defaultListId = defaultList.getId();
          }
          Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, defaultListId);

          // For each local task, check to see if its title paired with any list title has a match
          // in the map
          for (allTasksWithGtaskData.moveToFirst();
              !allTasksWithGtaskData.isAfterLast();
              allTasksWithGtaskData.moveToNext()) {
            GtasksTaskContainer container =
                gtasksMetadataService.readTaskAndMetadata(allTasksWithGtaskData);
            // memorize the original listname for the case that the task is not matched,
            // then it should at least be recreated in the correct list
            String originalListName =
                gtasksListService.getListName(
                    container.gtaskMetadata.getValue(GtasksMetadata.LIST_ID));
            String originalListId = null;

            // Search through lists to see if one of them has match
            String taskTitle = container.task.getValue(Task.TITLE);
            boolean foundMatch = false;
            items = allLists.getItems();
            for (TaskList list : items) {
              String expectedKey = constructKeyFromTitles(taskTitle, list.getTitle());

              // save the new id of the current list
              // if it matches the listname of the current task
              if (list.getTitle() != null && list.getTitle().equals(originalListName)) {
                originalListId = list.getId();
              }

              if (taskAndListTitlesToRemoteTaskIds.containsKey(expectedKey)) {
                foundMatch = true;
                String newRemoteTaskId = taskAndListTitlesToRemoteTaskIds.get(expectedKey);
                String newRemoteListId = list.getId();

                container.gtaskMetadata.setValue(GtasksMetadata.ID, newRemoteTaskId);
                container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, newRemoteListId);
                gtasksMetadataService.saveTaskAndMetadata(container);
                break;
              }
            }

            if (!foundMatch) {
              // For non-matches, make the task look newly created
              container.gtaskMetadata = GtasksMetadata.createEmptyMetadata(container.task.getId());
              container.gtaskMetadata.setValue(GtasksMetadata.ID, ""); // $NON-NLS-1$
              if (originalListId != null) {
                // set the list-id based on the original listname, saved above during for-loop
                container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, originalListId);
              } else {
                // remote list or local list was renamed, so put this unmatched task in the default
                // list
                container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, defaultListId);
              }
              gtasksMetadataService.saveTaskAndMetadata(container);
              break;
            }
          }
        }

        // migrate the list-id's afterwards, so that we can put the non-matched tasks in their
        // original lists
        // if the listnames didnt change before migration (defaultlist otherwise)
        listService.migrateListIds(allLists);

      } finally {
        allTasksWithGtaskData.close();
      }
      Preferences.setBoolean(
          GtasksPreferenceService.PREF_MIGRATION_HAS_OCCURRED, true); // Record successful migration
    }
  }
  private static void setNormalPreferenceDefaults() {
    Context context = ContextManager.getContext();
    SharedPreferences prefs = Preferences.getPrefs(context);
    Editor editor = prefs.edit();
    Resources r = context.getResources();

    Preferences.setIfUnset(prefs, editor, r, R.string.p_default_urgency_key, 0);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_default_importance_key, 2);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_default_hideUntil_key, 0);
    Preferences.setIfUnset(
        prefs,
        editor,
        r,
        R.string.p_default_reminders_key,
        Task.NOTIFY_AT_DEADLINE | Task.NOTIFY_AFTER_DEADLINE);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_default_random_hours, 0);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_fontSize, 16);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_showNotes, false);

    Preferences.setIfUnset(prefs, editor, r, R.string.p_use_contact_picker, true);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_field_missed_calls, true);

    Preferences.setIfUnset(prefs, editor, r, R.string.p_third_party_addons, false);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_end_at_deadline, true);

    Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_persistent, true);

    Preferences.setIfUnset(prefs, editor, r, R.string.p_ideas_tab_enabled, true);

    Preferences.setIfUnset(prefs, editor, r, R.string.p_show_featured_lists, true);

    Preferences.setIfUnset(prefs, editor, r, R.string.p_taskRowStyle, false);

    Preferences.setIfUnset(prefs, editor, r, R.string.p_calendar_reminders, true);

    String dragDropTestInitialized = "android_drag_drop_initialized"; // $NON-NLS-1$
    if (!Preferences.getBoolean(dragDropTestInitialized, false)) {
      SharedPreferences publicPrefs = getPublicPrefs(context);
      if (publicPrefs != null) {
        Editor edit = publicPrefs.edit();
        if (edit != null) {
          edit.putInt(SortHelper.PREF_SORT_FLAGS, SortHelper.FLAG_DRAG_DROP);
          edit.putInt(SortHelper.PREF_SORT_SORT, SortHelper.SORT_AUTO);
          edit.commit();
          Preferences.setInt(P_SUBTASKS_HELP, 1);
        }
      }
      Preferences.setBoolean(dragDropTestInitialized, true);
    }

    if ("white-blue"
        .equals(
            Preferences.getStringValue(
                R.string.p_theme))) { // $NON-NLS-1$ migrate from when white-blue wasn't the default
      Preferences.setString(R.string.p_theme, ThemeService.THEME_WHITE);
    }

    if (Constants.MARKET_STRATEGY.defaultPhoneLayout()) {
      Preferences.setIfUnset(prefs, editor, r, R.string.p_force_phone_layout, true);
    }

    setShowFriendsView();

    setShowFeaturedLists();

    editor.commit();
  }
示例#10
0
 public static void setCurrentVersionName(String versionName) {
   Preferences.setString(P_CURRENT_VERSION_NAME, versionName);
 }