Code example for Preference

Methods: getContextgetSharedPreferencessetOnPreferenceChangeListener

0
    if (!(preference instanceof KeyboardLayoutPreference)) {
      return; 
    } 
 
    // Initialize the value based on the current orientation. 
    SharedPreferences sharedPreferences = preference.getSharedPreferences();
    boolean isLandscapeKeyboardSettingActive = isLandscapeKeyboardSettingActive(
        sharedPreferences, preference.getContext().getResources().getConfiguration());
    KeyboardLayoutPreference.class.cast(preference).setValue(
        getKeyboardLayout(sharedPreferences,
                          isLandscapeKeyboardSettingActive
                              ? PREF_LANDSCAPE_KEYBOARD_LAYOUT_KEY
                              : PREF_PORTRAIT_KEYBOARD_LAYOUT_KEY));
    preference.setOnPreferenceChangeListener(CURRENT_KEYBOARD_LAYOUT_PREFERENCE_CHANGE_LISTENER);
  } 
 
  /** 
   * Returns parsed {@link KeyboardLayout} instance, or TWELVE_KEYS if any error is found. 
   */ 
  private static KeyboardLayout getKeyboardLayout(SharedPreferences sharedPreferences, String key) {
    if (sharedPreferences == null || key == null) {