public void onResume() { // if the SyncService was stopped because Android killed it, we should not show the progress // dialog any more if (SyncManager.getInstance().getCurrentService().activity == null) { TLog.i( TAG, "Android killed the SyncService while in background. We will remove the dialog now."); removeDialog(DIALOG_SYNC); } super.onResume(); Intent intent = this.getIntent(); SyncService currentService = SyncManager.getInstance().getCurrentService(); if (currentService.needsAuth() && intent != null) { Uri uri = intent.getData(); if (uri != null && uri.getScheme().equals("tomdroid")) { TLog.i(TAG, "Got url : {0}", uri.toString()); showDialog(DIALOG_AUTH_PROGRESS); Handler handler = new Handler() { @Override public void handleMessage(Message msg) { if (authProgressDialog != null) authProgressDialog.dismiss(); if (msg.what == SyncService.AUTH_COMPLETE) startSyncing(true); } }; ((ServiceAuth) currentService).remoteAuthComplete(uri, handler); } } SyncManager.setActivity(this); SyncManager.setHandler(this.syncMessageHandler); // tablet refresh if (rightPane != null) { updateTextAttributes(); if (!creating) showNoteInPane(lastIndex); } else updateNotesList(query, lastIndex); // set the view shown when the list is empty updateEmptyList(query); creating = false; }
@SuppressWarnings("deprecation") private void startSyncing(boolean push) { String serverUri = Preferences.getString(Preferences.Key.SYNC_SERVER); SyncService currentService = SyncManager.getInstance().getCurrentService(); if (currentService.needsAuth()) { // service needs authentication TLog.i(TAG, "Creating dialog"); showDialog(DIALOG_AUTH_PROGRESS); Handler handler = new Handler() { @Override public void handleMessage(Message msg) { Uri authorizationUri = (Uri) msg.obj; if (authorizationUri != null) { resetSyncValues(); Intent i = new Intent(Intent.ACTION_VIEW, authorizationUri); startActivity(i); } else { // Auth failed, don't update the value showDialog(DIALOG_CONNECT_FAILED); } if (authProgressDialog != null) authProgressDialog.dismiss(); } }; ((ServiceAuth) currentService).getAuthUri(serverUri, handler); } else { syncProcessedNotes = 0; syncTotalNotes = 0; dialogString = getString(R.string.syncing_connect); showDialog(DIALOG_SYNC); SyncManager.getInstance().startSynchronization(push); // push by default } }
/** Called when the activity is created. */ @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Preferences.init(this, CLEAR_PREFERENCES); context = this; SyncManager.setActivity(this); SyncManager.setHandler(this.syncMessageHandler); main = View.inflate(this, R.layout.main, null); setContentView(main); // get the Path to the notes-folder from Preferences if (Preferences.getString(Preferences.Key.SD_LOCATION).startsWith("/")) { NOTES_PATH = Preferences.getString(Preferences.Key.SD_LOCATION); } else { NOTES_PATH = Environment.getExternalStorageDirectory() + "/" + Preferences.getString(Preferences.Key.SD_LOCATION) + "/"; } // generate the http header we want to send on syncing getPackageManager(); try { PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA); HTTP_HEADER = String.format( "%1$s v%2$s, build %3$s, Android v%4$s, %5$s/%6$s", pi.packageName, pi.versionName, pi.versionCode, Build.VERSION.RELEASE, Build.MANUFACTURER, Build.MODEL); } catch (NameNotFoundException e) { e.printStackTrace(); HTTP_HEADER = "Tomdroid vunknown, build unknown, Android unknown, unknown/unknown"; } TLog.v(TAG, "Generated http-header: {0}: {1}", "X-Tomboy-Client", Tomdroid.HTTP_HEADER); // did we already show the warning and got destroyed by android's activity killer? if (Preferences.getBoolean(Preferences.Key.FIRST_RUN)) { TLog.i(TAG, "Tomdroid is first run."); // add a first explanatory note NoteManager.putNote(this, FirstNote.createFirstNote(this)); // Warn that this is a "will eat your babies" release showDialog(DIALOG_FIRST_RUN); } this.intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { this.setTitle(getString(R.string.app_name) + " - " + getString(R.string.SearchResultTitle)); query = intent.getStringExtra(SearchManager.QUERY); // adds query to search history suggestions SearchRecentSuggestions suggestions = new SearchRecentSuggestions( this, SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE); suggestions.saveRecentQuery(query, null); } else { // if main view -> disable the tomdroid icon home button setHomeButtonEnabled(false); } String defaultSortOrder = Preferences.getString(Preferences.Key.SORT_ORDER); NoteManager.setSortOrder(defaultSortOrder); // set list adapter updateNotesList(query, -1); // add note to pane for tablet rightPane = (LinearLayout) findViewById(R.id.right_pane); registerForContextMenu(findViewById(android.R.id.list)); // check if receiving note if (getIntent().hasExtra("view_note")) { uri = getIntent().getData(); getIntent().setData(null); Intent i = new Intent(Intent.ACTION_VIEW, uri, this, ViewNote.class); startActivity(i); } if (rightPane != null) { content = (TextView) findViewById(R.id.content); title = (TextView) findViewById(R.id.title); // this we will call on resume as well. updateTextAttributes(); showNoteInPane(0); } // set the view shown when the list is empty updateEmptyList(query); // Syncing if SyncOnStart (pref) set AND onCreate_SyncOnStart set false for syncing only on // startup if (Preferences.getBoolean(Preferences.Key.SYNC_ON_START) && first_onCreate_run) { startSyncing(true); TLog.i(TAG, "SyncOnStart activated"); } // we already run onCreate now! first_onCreate_run = false; }