Exemple #1
0
  /** Called when this application is started up */
  public synchronized void onStartupApplication(final Activity context) {
    if (hasStartedUp || context == null) {
      return;
    }

    // sets up context manager
    ContextManager.setContext(context);

    try {
      database.openForWriting();
      checkForMissingColumns();
    } catch (SQLiteException e) {
      handleSQLiteError(context, e);
      return;
    }

    // show notification if reminders are silenced
    if (context instanceof Activity) {
      AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
      if (!Preferences.getBoolean(R.string.p_rmd_enabled, true)) {
        Toast.makeText(context, R.string.TLA_notification_disabled, Toast.LENGTH_LONG).show();
      } else if (audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION) == 0) {
        Toast.makeText(context, R.string.TLA_notification_volume_low, Toast.LENGTH_LONG).show();
      }
    }

    // read current version
    int latestSetVersion = 0;
    try {
      latestSetVersion = AstridPreferences.getCurrentVersion();
    } catch (Exception e) {
      exceptionService.reportError("astrid-startup-version-read", e); // $NON-NLS-1$
    }

    if (latestSetVersion == 0) {
      if (Preferences.getLong(AstridPreferences.P_FIRST_LAUNCH, -1) < 0) {
        Preferences.setLong(AstridPreferences.P_FIRST_LAUNCH, DateUtilities.now());
      }
    }

    BeastModePreferences.assertHideUntilSectionExists(context, latestSetVersion);

    int version = 0;
    String versionName = "0"; // $NON-NLS-1$
    try {
      PackageManager pm = context.getPackageManager();
      PackageInfo pi = pm.getPackageInfo(Constants.PACKAGE, PackageManager.GET_META_DATA);
      version = pi.versionCode;
      versionName = pi.versionName;
    } catch (Exception e) {
      exceptionService.reportError("astrid-startup-package-read", e); // $NON-NLS-1$
    }

    Log.i(
        "astrid",
        "Astrid Startup. "
            + latestSetVersion
            + //$NON-NLS-1$ //$NON-NLS-2$
            " => "
            + version); //$NON-NLS-1$

    databaseRestoreIfEmpty(context);

    // invoke upgrade service
    boolean justUpgraded = latestSetVersion != version;
    if (justUpgraded && version > 0) {
      if (latestSetVersion > 0) {
        upgradeService.performUpgrade(context, latestSetVersion);
      }
      AstridPreferences.setCurrentVersion(version);
      AstridPreferences.setCurrentVersionName(versionName);
    }

    final int finalLatestVersion = latestSetVersion;

    initializeDatabaseListeners();

    // perform startup activities in a background thread
    new Thread(
            new Runnable() {
              @Override
              public void run() {
                taskService.cleanup();

                // if sync ongoing flag was set, clear it
                gtasksPreferenceService.stopOngoing();

                // perform initialization
                ReminderStartupReceiver.startReminderSchedulingService(context);
                BackupService.scheduleService(context);

                gtasksSyncService.initialize();

                // get and display update messages
                if (finalLatestVersion != 0) {
                  //                    new UpdateMessageService(context).processUpdates();
                }
              }
            })
        .start();

    AstridPreferences.setPreferenceDefaults();
    CalendarStartupReceiver.scheduleCalendarAlarms(
        context,
        false); // This needs to be after set preference defaults for the purposes of ab testing

    showTaskKillerHelp(context);

    hasStartedUp = true;
  }
  private static void setLitePreferenceDefaults() {
    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, 4);
    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_default_reminders_mode_key, 16);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_default_random_hours, 0);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_fontSize, 18);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_showNotes, false);

    Preferences.setIfUnset(prefs, editor, r, R.string.p_use_contact_picker, false);
    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, false);
    Preferences.setIfUnset(prefs, editor, r, R.string.p_autoIdea, false);

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

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

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

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

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

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

    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);
    }

    BeastModePreferences.setDefaultLiteModeOrder(context);

    Preferences.setIfUnset(prefs, editor, r, R.string.p_theme, ThemeService.THEME_WHITE_RED);

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

    setShowFriendsView();

    setShowFeaturedLists();

    editor.commit();
  }