Java Code Examples for android.preference.Preference

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/Preferences/.

Source file: BalancePreferencesActivity.java

  18 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.preferences);
  Preference usernamePref=findPreference("username");
  usernamePref.setOnPreferenceChangeListener(this);
  Preference passwordPref=findPreference("password");
  passwordPref.setOnPreferenceClickListener(this);
  passwordPref.setOnPreferenceChangeListener(this);
  Preference freshTimePref=findPreference("freshTime");
  freshTimePref.setOnPreferenceChangeListener(numberCheckListener);
}
 

Example 2

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/activity/.

Source file: SettingsActivity.java

  18 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.preferences);
  sharedPreferences.registerOnSharedPreferenceChangeListener(this);
  offset60DbInputListener=new Offset60DbInputListener();
  final Preference offsetPreference=getPreferenceScreen().findPreference(SettingsHelper.OFFSET_60_DB);
  offsetPreference.setOnPreferenceChangeListener(offset60DbInputListener);
}
 

Example 3

From project Airports, under directory /src/com/nadmm/airports/.

Source file: PreferencesActivity.java

  18 
vote

@SuppressWarnings("deprecation") @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key){
  Preference pref=findPreference(key);
  if (key.equals(KEY_LOCATION_NEARBY_RADIUS)) {
    String radius=mSharedPrefs.getString(key,"20");
    pref.setSummary("Using " + radius + " NM radius");
  }
}
 

Example 4

From project andlytics, under directory /src/com/github/andlyticsproject/.

Source file: PreferenceActivity.java

  18 
vote

private void buildAccountsList(){
  final AccountManager manager=AccountManager.get(this);
  Account[] accounts=manager.getAccountsByType(Constants.ACCOUNT_TYPE_GOOGLE);
  accountsList=new ArrayList<String>();
  for (  Account account : accounts) {
    if (!Preferences.getIsHiddenAccount(this,account.name)) {
      accountsList.add(account.name);
      Preference pref=new Preference(this);
      pref.setTitle(account.name);
      pref.setOnPreferenceClickListener(accountPrefrenceClickedListener);
      accountListPrefCat.addPreference(pref);
    }
  }
}
 

Example 5

From project android-context, under directory /defunct/shared/.

Source file: PrefsActivity.java

  18 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.preferences);
  Preference helpPref=(Preference)findPreference("helpPreference");
  helpPref.setIntent(new Intent(this,edu.fsu.cs.contextprovider.shared.HelpActivity.class));
  Preference changelogPref=(Preference)findPreference("changelogPreference");
  changelogPref.setOnPreferenceClickListener(this);
  Preference contactDeveloperPref=(Preference)findPreference("contactDeveloperPreference");
  contactDeveloperPref.setOnPreferenceClickListener(this);
  Preference aboutPref=(Preference)findPreference("aboutPreference");
  aboutPref.setIntent(new Intent(this,edu.fsu.cs.contextprovider.shared.AboutActivity.class));
}
 

Example 6

From project android-vpn-settings, under directory /src/com/android/settings/vpn/.

Source file: L2tpEditor.java

  18 
vote

private Preference createSecretStringPreference(Context c){
  SecretHandler sHandler=mSecretHandler=new SecretHandler(c,R.string.vpn_l2tp_secret_string_title,R.string.vpn_l2tp_secret){
    @Override protected String getSecretFromProfile(){
      return ((L2tpProfile)getProfile()).getSecretString();
    }
    @Override protected void saveSecretToProfile(    String secret){
      ((L2tpProfile)getProfile()).setSecretString(secret);
    }
  }
;
  Preference pref=sHandler.getPreference();
  pref.setEnabled(mSecret.isChecked());
  return pref;
}
 

Example 7

From project android-xbmcremote, under directory /src/org/xbmc/android/remote/presentation/controller/.

Source file: SettingsController.java

  18 
vote

/** 
 * Used in SettingsActivity in order to update the %value% placeholder in  the summaries.
 * @param activity Reference to activity
 */
public void registerOnSharedPreferenceChangeListener(PreferenceActivity activity){
  activity.getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
  PreferenceScreen ps=activity.getPreferenceScreen();
  mSummaries.clear();
  for (  String key : ps.getSharedPreferences().getAll().keySet()) {
    Preference pref=ps.findPreference(key);
    if (pref != null && pref.getSummary() != null) {
      mSummaries.put(key,pref.getSummary().toString());
    }
  }
  updateSummaries();
}
 

Example 8

From project androidpn, under directory /androidpn-client/src/org/androidpn/client/.

Source file: NotificationSettingsActivity.java

  18 
vote

private void setPreferenceDependencies(){
  Preference soundPref=getPreferenceManager().findPreference(Constants.SETTINGS_SOUND_ENABLED);
  if (soundPref != null) {
    soundPref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED);
  }
  Preference vibratePref=getPreferenceManager().findPreference(Constants.SETTINGS_VIBRATE_ENABLED);
  if (vibratePref != null) {
    vibratePref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED);
  }
}
 

Example 9

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/.

Source file: AccessibilitySettings.java

  18 
vote

/** 
 * Sets the state of the preferences for enabling/disabling AccessibilityServices.
 * @param isEnabled If to enable or disable the preferences.
 */
private void setAccessibilityServicePreferencesState(boolean isEnabled){
  if (mAccessibilityServicesCategory == null) {
    return;
  }
  int count=mAccessibilityServicesCategory.getPreferenceCount();
  for (int i=0; i < count; i++) {
    Preference pref=mAccessibilityServicesCategory.getPreference(i);
    pref.setEnabled(isEnabled);
  }
}
 

Example 10

From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/activities/led/.

Source file: NotificationActivity.java

  18 
vote

private void createEditCategorySettings(PreferenceScreen cat){
  Preference editCat=getPreferenceManager().createPreferenceScreen(this);
  editCat.setKey("cat_" + cat.getKey().substring("applications_".length()));
  editCat.setTitle(R.string.trackball_category_edit_title);
  editCat.setSummary(R.string.trackball_category_edit_summary);
  cat.addPreference(editCat);
}
 

Example 11

From project aksunai, under directory /src/org/androidnerds/app/aksunai/preferences/.

Source file: Preferences.java

  17 
vote

@Override public void onCreate(Bundle icicle){
  super.onCreate(icicle);
  PreferenceManager manager=getPreferenceManager();
  manager.setSharedPreferencesName("aksunai-prefs");
  manager.setSharedPreferencesMode(MODE_WORLD_WRITEABLE);
  this.addPreferencesFromResource(resourceId());
  Preference p=findPreference("pref_large_font_label");
  if (p != null) {
    p.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener(){
      public boolean onPreferenceChange(      Preference p,      Object newObjValue){
        Boolean newValue=(Boolean)newObjValue;
        if (newValue == null) {
          return false;
        }
        return true;
      }
    }
);
  }
}
 

Example 12

From project and-bible, under directory /AndBible/src/net/bible/android/view/activity/settings/.

Source file: SettingsActivity.java

  17 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  UiUtils.applyTheme(this);
  super.onCreate(savedInstanceState);
  CurrentActivityHolder.getInstance().setCurrentActivity(this);
  try {
    addPreferencesFromResource(R.xml.settings);
    Preference unusedNightModePreference=getPreferenceScreen().findPreference(ScreenSettings.getUnusedNightModePreferenceKey());
    getPreferenceScreen().removePreference(unusedNightModePreference);
    if (!ControlFactory.getInstance().getPageTiltScrollControl().isTiltSensingPossible()) {
      Preference tiltToScrollPreferenceKey=getPreferenceScreen().findPreference(PageTiltScrollControl.TILT_TO_SCROLL_PREFERENCE_KEY);
      getPreferenceScreen().removePreference(tiltToScrollPreferenceKey);
    }
  }
 catch (  Exception e) {
    Log.e(TAG,"Error preparing preference screen",e);
    Dialogs.getInstance().showErrorMsg(R.string.error_occurred);
  }
}
 

Example 13

From project androidZenWriter, under directory /src/com/javaposse/android/zenwriter/.

Source file: PrefsActivity.java

  17 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.zenpreferences);
  Preference backgroundPref=this.findPreference("backgroundpref");
  final PrefsActivity THIS=this;
  backgroundPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){
    @Override public boolean onPreferenceClick(    Preference preference){
      return THIS.selectBackgroundImage(preference);
    }
  }
);
  SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  if (prefs.getString("backgroundpref","").length() > 0) {
    backgroundPref.setSummary(new File(prefs.getString("backgroundpref","")).getName());
  }
}
 

Example 14

From project android-thaiime, under directory /inputmethodcommon/src/com/android/inputmethodcommon/.

Source file: InputMethodSettingsImpl.java

  16 
vote

/** 
 * Initialize internal states of this object.
 * @param context the context for this application.
 * @param prefScreen a PreferenceScreen of PreferenceActivity or PreferenceFragment.
 * @return true if this application is an IME and has two or more subtypes, false otherwise.
 */
public boolean init(final Context context,final PreferenceScreen prefScreen){
  mContext=context;
  mImm=(InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
  mImi=getMyImi(context,mImm);
  if (mImi == null || mImi.getSubtypeCount() <= 1) {
    return false;
  }
  mSubtypeEnablerPreference=new Preference(context);
  mSubtypeEnablerPreference.setOnPreferenceClickListener(new OnPreferenceClickListener(){
    @Override public boolean onPreferenceClick(    Preference preference){
      final CharSequence title=getSubtypeEnablerTitle(context);
      final Intent intent=new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
      intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID,mImi.getId());
      if (!TextUtils.isEmpty(title)) {
        intent.putExtra(Intent.EXTRA_TITLE,title);
      }
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
      context.startActivity(intent);
      return true;
    }
  }
);
  prefScreen.addPreference(mSubtypeEnablerPreference);
  updateSubtypeEnabler();
  return true;
}
 

Example 15

From project 4308Cirrus, under directory /tendril-cirrus/src/main/java/edu/colorado/cs/cirrus/cirrus/.

Source file: CirrusPreferenceActivity.java

  15 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.preferences);
  myPreferenceClickListener=new simplePreferenceClickListener();
  setHomeLocPref=(Preference)findPreference("setHomeLocPref");
  gpsFreqPref=(Preference)findPreference("gpsFrequency");
  smartHeatPref=(Preference)findPreference("smartHeat");
  homeTempPref=(EditTextPreference)findPreference("homeTemp");
  awayTempPref=(EditTextPreference)findPreference("awayTemp");
  radiusPref=(EditTextPreference)findPreference("gpsRadius");
  logoutPref=(Preference)findPreference("logout");
  setHomeLocPref.setOnPreferenceClickListener(myPreferenceClickListener);
  gpsFreqPref.setOnPreferenceClickListener(myPreferenceClickListener);
  smartHeatPref.setOnPreferenceClickListener(myPreferenceClickListener);
  homeTempPref.setOnPreferenceClickListener(myPreferenceClickListener);
  awayTempPref.setOnPreferenceClickListener(myPreferenceClickListener);
  logoutPref.setOnPreferenceClickListener(myPreferenceClickListener);
  radiusPref.setOnPreferenceClickListener(myPreferenceClickListener);
  EditText homeTempEditText=(EditText)homeTempPref.getEditText();
  homeTempEditText.setKeyListener(DigitsKeyListener.getInstance(false,true));
  EditText awayTempEditText=(EditText)awayTempPref.getEditText();
  awayTempEditText.setKeyListener(DigitsKeyListener.getInstance(false,true));
  EditText radiusEditText=(EditText)radiusPref.getEditText();
  radiusEditText.setKeyListener(DigitsKeyListener.getInstance(false,true));
  cirrusPrefs=new PreferenceUtils(this);
  startLocationStuff();
}
 

Example 16

From project android-bankdroid, under directory /src/com/liato/bankdroid/.

Source file: SettingsActivity.java

  15 
vote

@Override public boolean onPreferenceChange(Preference pref,Object newValue){
  final String prefKey=pref.getKey();
  if ("notify_min_delta".equals(prefKey)) {
    Integer val;
    try {
      val=Integer.valueOf((String)newValue);
    }
 catch (    NumberFormatException e) {
      val=null;
    }
    if (val != null && val >= 0) {
      return true;
    }
 else {
      Toast.makeText(pref.getContext(),String.format(pref.getContext().getString(R.string.invalid_integer),newValue),Toast.LENGTH_LONG).show();
    }
    return false;
  }
  return false;
}
 

Example 17

From project Android-Battery-Widget, under directory /src/com/em/batterywidget/.

Source file: OptionsManager.java

  15 
vote

@SuppressWarnings("deprecation") @Override protected void onCreate(Bundle bundle){
  super.onCreate(bundle);
  addPreferencesFromResource(R.xml.options);
  mVibrationCB=(CheckBoxPreference)getPreferenceScreen().findPreference(Constants.VIBRATION_CHECKBOX_KEY);
  mSoundCB=(CheckBoxPreference)getPreferenceScreen().findPreference(Constants.SOUND_CHECKBOX_KEY);
  mNotifyCB=(CheckBoxPreference)getPreferenceScreen().findPreference(Constants.NOTIFY_ICON_CHECKBOX_KEY);
  mThemeList=(ListPreference)getPreferenceScreen().findPreference(Constants.WIDGET_THEME_KEY);
  mColourList=(ListPreference)getPreferenceScreen().findPreference(Constants.TEXT_COLOUR_KEY);
  mTempList=(ListPreference)getPreferenceScreen().findPreference(Constants.TEMPERATURE_TYPE_KEY);
  mAboutPref=(Preference)getPreferenceScreen().findPreference(Constants.ABOUT_PREF_KEY);
  mPrefSettings=new Preferences(Constants.BATTERY_SETTINGS,this);
}
 

Example 18

From project android-voip-service, under directory /src/main/java/org/linphone/.

Source file: LinphonePreferencesActivity.java

  15 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.linphone_preferences);
  addTransportChecboxesListener();
  ecPref=(CheckBoxPreference)findPreference(pref_echo_canceller_calibration_key);
  ecPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){
    public boolean onPreferenceClick(    Preference preference){
      startEcCalibration();
      return false;
    }
  }
);
  boolean fastCpu=Version.isArmv7();
  if (fastCpu) {
    detectAudioCodec(pref_codec_ilbc_key,"iLBC",8000);
    findPreference(pref_codec_speex16_key).setEnabled(true);
  }
  detectAudioCodec(pref_codec_amr_key,"AMR",8000);
  if (!Version.isVideoCapable()) {
    uncheckAndDisableCheckbox(pref_video_enable_key);
  }
 else   if (!AndroidCameraRecordManager.getInstance().hasFrontCamera()) {
    uncheckDisableAndHideCheckbox(R.string.pref_video_use_front_camera_key);
  }
  if (prefs().getBoolean(LinphoneActivity.PREF_FIRST_LAUNCH,true)) {
    if (fastCpu) {
      Toast.makeText(this,getString(ec_calibration_launch_message),Toast.LENGTH_LONG).show();
      startEcCalibration();
    }
    prefs().edit().putBoolean(LinphoneActivity.PREF_FIRST_LAUNCH,false).commit();
  }
  detectVideoCodec(R.string.pref_video_codec_h264_key,"H264");
  if (Hacks.needSoftvolume())   checkAndDisableCheckbox(R.string.pref_audio_soft_volume_key);
}
 

Example 19

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/activity/.

Source file: SettingsActivity.java

  15 
vote

private void setBookStorePreferenceSummary(Preference preference,String storeName){
  BooksStore booksStore;
  if (storeName == null) {
    booksStore=BookStoreFactory.get(this);
  }
 else {
    booksStore=BookStoreFactory.get(this,storeName);
  }
  preference.setSummary(getString(R.string.preferences_bookstore_summary,booksStore.getLabel()));
}
 

Example 20

From project android_device_samsung_galaxys2, under directory /DeviceSettings/src/com/cyanogenmod/settings/device/.

Source file: RadioFragmentActivity.java

  15 
vote

@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,Preference preference){
  String boxValue;
  String key=preference.getKey();
  Log.w(TAG,"key: " + key);
  return true;
}
 

Example 21

From project android_device_samsung_galaxys2_1, under directory /DeviceSettings/src/com/cyanogenmod/settings/device/.

Source file: RadioFragmentActivity.java

  15 
vote

@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,Preference preference){
  String boxValue;
  String key=preference.getKey();
  Log.w(TAG,"key: " + key);
  return true;
}
 

Example 22

From project android_device_samsung_i777, under directory /DeviceSettings/src/com/cyanogenmod/settings/device/.

Source file: RadioFragmentActivity.java

  15 
vote

@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,Preference preference){
  String boxValue;
  String key=preference.getKey();
  Log.w(TAG,"key: " + key);
  return true;
}
 

Example 23

From project android_packages_apps_CMSettings, under directory /src/com/cyanogenmod/settings/activities/.

Source file: Backlight.java

  15 
vote

public boolean onPreferenceChange(Preference preference,Object newValue){
  boolean handled=false;
  if (preference == mFilterEnabled) {
    Settings.System.putInt(getContentResolver(),Settings.System.LIGHT_FILTER,getBoolean(newValue) ? 1 : 0);
    handled=true;
  }
 else   if (preference == mFilterWindow) {
    Settings.System.putInt(getContentResolver(),Settings.System.LIGHT_FILTER_WINDOW,getInt(newValue));
    handled=true;
  }
 else   if (preference == mFilterReset) {
    Settings.System.putInt(getContentResolver(),Settings.System.LIGHT_FILTER_RESET,getInt(newValue));
    handled=true;
  }
 else   if (preference == mFilterInterval) {
    Settings.System.putInt(getContentResolver(),Settings.System.LIGHT_FILTER_INTERVAL,getInt(newValue));
    handled=true;
  }
 else   if (preference == mScreenDim) {
    Settings.System.putInt(getContentResolver(),Settings.System.LIGHT_SCREEN_DIM,getInt(newValue));
    handled=true;
  }
 else   if (preference == mLevelsEnabled) {
    Settings.System.putInt(getContentResolver(),Settings.System.LIGHT_SENSOR_CUSTOM,getBoolean(newValue) ? 1 : 0);
    handled=true;
  }
 else   if (preference == mDecreaseEnabled) {
    Settings.System.putInt(getContentResolver(),Settings.System.LIGHT_DECREASE,getBoolean(newValue) ? 1 : 0);
    handled=true;
  }
 else   if (preference == mDecreaseHysteresis) {
    Settings.System.putInt(getContentResolver(),Settings.System.LIGHT_HYSTERESIS,getInt(newValue));
    handled=true;
  }
  if (handled) {
    long tag=Settings.System.getLong(getContentResolver(),Settings.System.LIGHTS_CHANGED,0) + 1;
    Settings.System.putLong(getContentResolver(),Settings.System.LIGHTS_CHANGED,tag);
  }
  return handled;
}