Beispiel #1
0
 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
   try {
     Log.d("syncPrefs", "onChanged");
     if (activity.isFinishing()) {
       // Setting the summary now would crash it with
       // IllegalStateException since we are not attached to a view
     } else {
       if (KEY_SYNC_ENABLE.equals(key)) {
         toggleSync(prefs);
       } else if (KEY_BACKGROUND_SYNC.equals(key)) {
         setSyncInterval(activity, prefs);
       } else if (KEY_ACCOUNT.equals(key)) {
         Log.d("syncPrefs", "account");
         prefAccount.setTitle(prefs.getString(KEY_ACCOUNT, ""));
       } else if (KEY_SD_ENABLE.equals(key)) {
         // Restart the sync service
         OrgSyncService.stop(getActivity());
       } else if (KEY_SD_DIR.equals(key)) {
         setSdDirSummary(prefs);
       } else if (KEY_DROPBOX_ENABLE.equals(key)) {
         // TODO
         if (mDropboxHelper == null) {
           mDropboxHelper = new DropboxSyncHelper(getActivity());
         }
         if (prefs.getBoolean(key, false)) {
           // authorize the user
           mDropboxHelper.linkAccount();
           //                        DropboxSynchronizer.linkAccount(this,
           //                                DROPBOX_LINK_CODE);
         } else {
           mDropboxHelper.unlinkAccount();
           //                        DropboxSynchronizer.unlink(getActivity());
         }
         // Restart sync service
         OrgSyncService.stop(getActivity());
       } else if (KEY_DROPBOX_DIR.equals(key)) {
         setDropboxDirSummary(prefs);
       }
     }
   } catch (IllegalStateException e) {
     // This is just in case the "isFinishing" wouldn't be enough
     // The isFinishing will try to prevent us from doing something
     // stupid
     // This catch prevents the app from crashing if we do something
     // stupid
   }
 }
Beispiel #2
0
  @Override
  public void onResume() {
    super.onResume();

    if (mDropboxHelper != null) {
      if (mDropboxHelper.handleLinkResult()) {
        // Success
      } else {
        // Link failed or was cancelled by the user.
        PreferenceManager.getDefaultSharedPreferences(getActivity())
            .edit()
            .putBoolean(KEY_DROPBOX_ENABLE, false)
            .commit();
      }
    }
  }