本文整理汇总了Java中android.preference.CheckBoxPreference.setDefaultValue方法的典型用法代码示例。如果您正苦于以下问题:Java CheckBoxPreference.setDefaultValue方法的具体用法?Java CheckBoxPreference.setDefaultValue怎么用?Java CheckBoxPreference.setDefaultValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.CheckBoxPreference
的用法示例。
在下文中一共展示了CheckBoxPreference.setDefaultValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addCheckBox
import android.preference.CheckBoxPreference; //导入方法依赖的package包/类
private CheckBoxPreference addCheckBox(String title, PreferenceCategory category, String key, Drawable icon, String onText, String offText, boolean defaultValue, Context context) {
CheckBoxPreference c = new CheckBoxPreference(context);
c.setTitle(title);
c.setKey(key);
if (null != icon) c.setIcon(icon);
if (offText.equals(null) || onText.equals(null)) {
if (offText.equals(null)) {
c.setSummary(onText);
} else if (onText.equals(null)) {
c.setSummary(offText);
}
} else {
c.setSummaryOn(onText);
c.setSummaryOff(offText);
}
c.setDefaultValue(defaultValue);
c.setChecked(KRFAM.sharedPreferences.getBoolean(key, defaultValue));
category.addPreference(c);
return c;
}
示例2: createCheckBoxPreference
import android.preference.CheckBoxPreference; //导入方法依赖的package包/类
/**
* Create a SwitchPreference for the specified preference
* @param titleResId resource ID to use for the title
* @param summaryResId resource ID to use for the summary
* @param key preference key
* @return newly created preference
*/
private CheckBoxPreference createCheckBoxPreference(@StringRes int titleResId, @StringRes int summaryResId, Settings.Key key) {
final CheckBoxPreference checkBoxPreference = new CheckBoxPreference(getActivity());
checkBoxPreference.setDefaultValue(mSettings.getDefault(key));
checkBoxPreference.setKey(key.name());
checkBoxPreference.setSummary(summaryResId);
checkBoxPreference.setTitle(titleResId);
checkBoxPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
checkBoxPreference.setChecked((boolean) newValue);
return true;
}
});
return checkBoxPreference;
}
示例3: onCreate
import android.preference.CheckBoxPreference; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(this);
PreferenceCategory category = new PreferenceCategory(this);
category.setTitle(R.string.filter_pokemons);
screen.addPreference(category);
try {
JSONArray pokemonList = new JSONArray(Utils.loadJSONFromFile(this, "pokemon.json"));
for (int i = 0; i < pokemonList.length(); i++){
JSONObject pokemon = pokemonList.getJSONObject(i);
CheckBoxPreference checkBox = new CheckBoxPreference(this);
checkBox.setTitle(pokemon.getString("Name"));
checkBox.setIcon(new BitmapDrawable(getResources(), Utils.bitmapForPokemon(this, Integer.parseInt(pokemon.getString("Number")))));
checkBox.setDefaultValue(true);
checkBox.setSummary(String.format(getString(R.string.setting_filter_pokemon_summary), pokemon.getString("Name")));
checkBox.setKey("pref_key_show_pokemon_" + Integer.parseInt(pokemon.getString("Number")));
category.addPreference(checkBox);
}
} catch (JSONException e) {
e.printStackTrace();
}
setPreferenceScreen(screen);
}
示例4: initPrivilegedInstallerPreference
import android.preference.CheckBoxPreference; //导入方法依赖的package包/类
/**
* Initializes SystemInstaller preference, which can only be enabled when F-Droid is installed as a system-app
*/
private void initPrivilegedInstallerPreference() {
final CheckBoxPreference pref = (CheckBoxPreference) findPreference(Preferences.PREF_PRIVILEGED_INSTALLER);
// This code will be run each time the activity is resumed, and so we may have already removed
// this preference.
if (pref == null) {
return;
}
Preferences p = Preferences.get();
boolean enabled = p.isPrivilegedInstallerEnabled();
boolean installed = PrivilegedInstaller.isExtensionInstalledCorrectly(getActivity())
== PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES;
// On later versions of Android the privileged installer needs to be installed
// via flashing an update.zip or building into a rom. As such, if it isn't installed
// by the time the user boots, opens F-Droid, and views this settings page, then there
// is no benefit showing it to them (it will only be disabled and we can't offer any
// way to easily install from here.
if (Build.VERSION.SDK_INT > 19 && !installed) {
PreferenceCategory other = (PreferenceCategory) findPreference("pref_category_other");
if (pref != null) {
other.removePreference(pref);
}
} else {
pref.setEnabled(installed);
pref.setDefaultValue(installed);
pref.setChecked(enabled && installed);
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
if (pref.isChecked()) {
editor.remove(Preferences.PREF_PRIVILEGED_INSTALLER);
} else {
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false);
}
editor.apply();
return true;
}
});
}
}
示例5: createPreferenceScreen
import android.preference.CheckBoxPreference; //导入方法依赖的package包/类
private PreferenceScreen createPreferenceScreen() {
// Root
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
// Units preference
CheckBoxPreference isMetric = new CheckBoxPreference(this);
isMetric.setDefaultValue(PreferenceStore.isMetricLocale());
isMetric.setKey(PreferenceStore.PREFS_METRIC);
isMetric.setTitle(R.string.metric_title);
isMetric.setSummaryOff(R.string.metric_use_english);
isMetric.setSummaryOn(R.string.metric_use_metric);
root.addPreference(isMetric);
// Multitouch preference, aka "pinch zoom"
if (InertiaScroller.isMultitouchAvailable()) {
CheckBoxPreference useMultitouch = new CheckBoxPreference(this);
useMultitouch.setDefaultValue(Boolean.TRUE);
useMultitouch.setKey(PreferenceStore.PREFS_MULTITOUCH);
useMultitouch.setTitle(R.string.multitouch_title);
useMultitouch.setSummaryOff(R.string.multitouch_disable_pinch);
useMultitouch.setSummaryOn(R.string.multitouch_enable_pinch);
root.addPreference(useMultitouch);
}
// Display distance to center of screen
CheckBoxPreference distanceDisplay = new CheckBoxPreference(this);
distanceDisplay.setDefaultValue(false);
distanceDisplay.setKey(PreferenceStore.PREFS_SHOW_DISTANCE);
distanceDisplay.setTitle(R.string.distance_title);
distanceDisplay.setSummaryOn(R.string.distance_show);
distanceDisplay.setSummaryOff(R.string.distance_hide);
root.addPreference(distanceDisplay);
CheckBoxPreference headingDisplay = new CheckBoxPreference(this);
headingDisplay.setDefaultValue(false);
headingDisplay.setKey(PreferenceStore.PREFS_SHOW_HEADING);
headingDisplay.setTitle(R.string.heading_title);
headingDisplay.setSummaryOn(R.string.heading_show);
headingDisplay.setSummaryOff(R.string.heading_hide);
root.addPreference(headingDisplay);
// Display safety reminder when map is changed preference
CheckBoxPreference safetyReminder = new CheckBoxPreference(this);
safetyReminder.setDefaultValue(true);
safetyReminder.setKey(PreferenceStore.PREFS_SHOW_REMINDER);
safetyReminder.setTitle(R.string.safety_reminder_title);
safetyReminder.setSummaryOn(R.string.safety_reminder_show);
safetyReminder.setSummaryOff(R.string.safety_reminder_hide);
root.addPreference(safetyReminder);
// Display language selection option
Preference language = createLanguagePreference();
root.addPreference(language);
// About dialog
Preference about = createAboutPreference();
if (about != null) {
root.addPreference(about);
}
// Maximum image size info
Preference imageSizeInfo = createImageSizeInfo();
if (imageSizeInfo != null) {
root.addPreference(imageSizeInfo);
}
return root;
}