@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // We have a menu item to show in action bar. setHasOptionsMenu(true); syncActionHelper = new SyncActionHelper(getActivity(), this); setUpUiComponents(); initializeData(); setupQuickAddBar(); Fragment filterlistFrame = getFragmentManager().findFragmentByTag(FilterListFragment.TAG_FILTERLIST_FRAGMENT); mDualFragments = (filterlistFrame != null) && filterlistFrame.isInLayout(); if (mDualFragments) { // In dual-pane mode, the list view highlights the selected item. getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); getListView().setItemsCanFocus(false); } if (Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1) > -1) upgradeService.showChangeLog( getActivity(), Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1)); getActivity() .runOnUiThread( new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MAX_PRIORITY); } }); getListView() .setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TodorooCursor<Task> cursor = (TodorooCursor<Task>) taskAdapter.getItem(position); Task task = new Task(cursor); if (task.isDeleted()) return; if (task.isEditable()) { onTaskListItemClicked(id); } } }); }
/** 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; }