// code which handles the action for each menu item
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.settings:
        {
          Intent preferences_intent = new Intent();
          preferences_intent.setComponent(
              new ComponentName(download_photos.this, preferences.class));
          preferences_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          getApplicationContext().startActivity(preferences_intent);

          return true;
        }
      case R.id.logout:
        {
          try {
            download_photos.this.facebook.logout(getApplicationContext());
          } catch (IOException e) {
            e.printStackTrace();
          }

          mPrefs = getSharedPreferences("COMMON", MODE_PRIVATE);

          SharedPreferences.Editor editor = mPrefs.edit();
          editor.putString("access_token", null);
          editor.putLong("access_expires", 0);
          editor.putBoolean("logout", true);
          editor.commit();
          finish();
          return true;
        }
      case R.id.about:
        {
          // shows our customized about dialog
          AboutDialog about = new AboutDialog(this);

          about.show();
          return true;
        }
        // lets deal with default case
      default:
        return super.onOptionsItemSelected(item);
    }
  }
Example #2
0
 public void save() {
   if (rs.isChecked() == true) {
     edit.putBoolean("silent", true);
     edit.commit();
   } else {
     edit.putBoolean("silent", false);
     edit.commit();
   }
   if (nc.isChecked() == true) {
     edit.putBoolean("nightmode", true);
     edit.commit();
   } else {
     edit.putBoolean("nightmode", false);
     edit.commit();
   }
   Toast.makeText(getApplicationContext(), "保存成功!", Toast.LENGTH_SHORT).show();
 }