Java Code Examples for android.preference.PreferenceScreen#onItemClick()

The following examples show how to use android.preference.PreferenceScreen#onItemClick() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupPreferenceFragment.java    From tickmate with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.group_preferences);

    group_id = getArguments().getInt("group_id");
    mOpenTrackList = getArguments().getBoolean("openTrackList");
    group = DataSource.getInstance().getGroup(group_id);
    loadGroup();
    // openTrackList indicates that this preference was created for the purpose of immediately
    //   opening up the track multi-select list
    if (mOpenTrackList) {
        PreferenceScreen screen = (PreferenceScreen) findPreference("group_preference_screen");
        int tracksPrefPosition = findPreference("tracks").getOrder();
        // make the tracks multi-select preference open up
        screen.onItemClick( null, null, tracksPrefPosition, 0 );
    }
}
 
Example 2
Source File: XmlSettingsActivity.java    From WhereYouGo with GNU General Public License v3.0 4 votes vote down vote up
@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setTitle(R.string.settings);

      needRestart = false;

/* workaround: I don't really know why I cannot call CustomActivity.customOnCreate(this); - OMG! */
      switch (Preferences.APPEARANCE_FONT_SIZE) {
          case PreferenceValues.VALUE_FONT_SIZE_SMALL:
              this.setTheme(R.style.FontSizeSmall);
              break;
          case PreferenceValues.VALUE_FONT_SIZE_MEDIUM:
              this.setTheme(R.style.FontSizeMedium);
              break;
          case PreferenceValues.VALUE_FONT_SIZE_LARGE:
              this.setTheme(R.style.FontSizeLarge);
              break;
      }

/*
       *
 */
      addPreferencesFromResource(R.xml.whereyougo_preferences);
      PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);

/*
 * Remove internal preferences
 */
      Preference somePreference = findPreference(R.string.pref_KEY_X_HIDDEN_PREFERENCES);
      PreferenceScreen preferenceScreen = getPreferenceScreen();
      preferenceScreen.removePreference(somePreference);

/*
       * Register OnClick handler
 */
      Preference preferenceRoot = findPreference(R.string.pref_KEY_S_ROOT);
      preferenceRoot.setOnPreferenceClickListener(this);

      Preference preferenceAbout = findPreference(R.string.pref_KEY_X_ABOUT);
      if (preferenceAbout != null) {
          preferenceAbout.setOnPreferenceClickListener(this);

      }

/*
       * Workaround: Update/set value preview
 */
      // String dir = Preferences.getStringPreference( R.string.pref_KEY_S_ROOT );
      // x.setSummary( "(" + dir + ") " + Locale.getString( R.string.pref_root_desc ) ); // TODO make it better :-(

/* TODO - check this code */
      if (!Utils.isAndroid201OrMore()) {
          Preference prefSensorFilter = findPreference(R.string.pref_KEY_S_SENSORS_ORIENT_FILTER);
          if (prefSensorFilter != null) {
              prefSensorFilter.setEnabled(false);
          }
      }

      if (getIntent() != null && getIntent().hasExtra(getString(R.string.pref_KEY_X_LOGIN_PREFERENCES))) {
          Preference preferenceLogin = findPreference(R.string.pref_KEY_X_LOGIN_PREFERENCES);
          if (preferenceLogin != null) {
              PreferenceScreen screen = getPreferenceScreen();
              for (int i = 0; i < screen.getPreferenceCount(); ++i) {
                  if (screen.getPreference(i) == preferenceLogin) {
                      getIntent().putExtra(getString(R.string.pref_KEY_X_LOGIN_PREFERENCES), false);
                      screen.onItemClick(null, null, i, 0);
                      break;
                  }
              }
          }
      }

      /*
       * Enable/disable status bar propertie
       */
      if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
          CheckBoxPreference status_bar = (CheckBoxPreference) findPreference(R.string.pref_KEY_B_STATUSBAR);
          CheckBoxPreference gps_hide = (CheckBoxPreference) findPreference(R.string.pref_KEY_B_GPS_DISABLE_WHEN_HIDE);
          CheckBoxPreference gps_guiding = (CheckBoxPreference) findPreference(R.string.pref_KEY_B_GUIDING_GPS_REQUIRED);
          if (gps_hide.isChecked()) {
              status_bar.setEnabled(!gps_guiding.isChecked());
          } else {
              status_bar.setEnabled(false);
          }
      }
  }