本文整理汇总了Java中android.preference.SwitchPreference.setEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchPreference.setEnabled方法的具体用法?Java SwitchPreference.setEnabled怎么用?Java SwitchPreference.setEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.SwitchPreference
的用法示例。
在下文中一共展示了SwitchPreference.setEnabled方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSwitchPreferenceBasedOnCheckBoxPreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox,
final PreferenceGroup group) {
final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext());
switchPref.setTitle(checkBox.getTitle());
switchPref.setKey(checkBox.getKey());
switchPref.setOrder(checkBox.getOrder());
switchPref.setPersistent(checkBox.isPersistent());
switchPref.setEnabled(checkBox.isEnabled());
switchPref.setChecked(checkBox.isChecked());
switchPref.setSummary(checkBox.getSummary());
switchPref.setSummaryOn(checkBox.getSummaryOn());
switchPref.setSummaryOff(checkBox.getSummaryOff());
switchPref.setSwitchTextOn(EMPTY_TEXT);
switchPref.setSwitchTextOff(EMPTY_TEXT);
group.addPreference(switchPref);
switchPref.setDependency(checkBox.getDependency());
}
示例2: updatePreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void updatePreference(int i) {
AppServiceManager appServiceManager= (AppServiceManager) ModelManager.getInstance(getActivity()).getModel(ModelFactory.MODEL_APP_SERVICE);
SwitchPreference switchPreference = (SwitchPreference) findPreference(String.valueOf(i));
Status status = appServiceManager.appServiceList.get(i).getStatus();
if(status.getStatus()== Status.APP_NOT_INSTALLED) {
switchPreference.setEnabled(false);
switchPreference.setChecked(false);
switchPreference.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_error_red_50dp));
switchPreference.setSummary(status.getMessage());
}else if(status.getStatus()== Status.APP_NOT_RUNNING) {
switchPreference.setEnabled(true);
switchPreference.setChecked(false);
switchPreference.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_error_red_50dp));
switchPreference.setSummary(status.getMessage());
}else{
switchPreference.setEnabled(true);
switchPreference.setChecked(true);
switchPreference.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_ok_teal_50dp));
switchPreference.setSummary(status.getMessage());
}
}
示例3: createSwitchPreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private SwitchPreference createSwitchPreference(String dataSourceType) {
SwitchPreference switchPreference = new SwitchPreference(getActivity());
switchPreference.setKey(dataSourceType);
String title = dataSourceType;
title = title.replace("_", " ");
title = title.substring(0, 1).toUpperCase() + title.substring(1).toLowerCase();
switchPreference.setTitle(title);
switchPreference.setOnPreferenceChangeListener(onPreferenceChangeListener);
switchPreference.setEnabled(isSensorSupported(dataSourceType));
switch (dataSourceType) {
case (DataSourceType.ACCELEROMETER):
switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Accelerometer.frequencyOptions));
break;
case (DataSourceType.GYROSCOPE):
switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Gyroscope.frequencyOptions));
break;
case (DataSourceType.AMBIENT_TEMPERATURE):
// switchPreference.setOnPreferenceClickListener(alertDialogFrequency(AmbientTemperature.frequencyOptions));
break;
case (DataSourceType.COMPASS):
switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Compass.frequencyOptions));
break;
case (DataSourceType.AMBIENT_LIGHT):
switchPreference.setOnPreferenceClickListener(alertDialogFrequency(AmbientLight.frequencyOptions));
break;
case (DataSourceType.PRESSURE):
// switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Pressure.frequencyOptions));
break;
case (DataSourceType.PROXIMITY):
// switchPreference.setOnPreferenceClickListener(alertDialogFrequency(Proximity.frequencyOptions));
break;
}
return switchPreference;
}
示例4: setupPreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void setupPreference() {
SwitchPreference calendarSyncState = (SwitchPreference) findPreference("calendar_sync_state");
PreferenceCategory calendarCategory = (PreferenceCategory) findPreference("calendar_category");
if (!SupporterHelper.isSupporter()) {
calendarSyncState.setChecked(false);
calendarSyncState.setEnabled(false);
calendarCategory.setTitle(calendarCategory.getTitle() + " (Supporter Feature)");
} else {
if (calendarSyncState.isChecked() && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED) {
setCalendarPreference();
} else if (calendarSyncState.isChecked() && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(context, "Calendar permission denied, try re-selecting or go to Android Settings -> Apps to enable.", Toast.LENGTH_LONG).show();
}
}
}
示例5: refreshFingerprintPreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void refreshFingerprintPreference() {
final SwitchPreference fingerprintPreference = (SwitchPreference) findPreference(PreferenceKeys.FINGERPRINT_ENABLED.key());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && new FingerprintHelper(this).canUseFingerPrint()) {
fingerprintPreference.setChecked(PreferenceUtils.getBoolean(PreferenceKeys.FINGERPRINT_ENABLED, false));
if (PINManager.isPINSet()) {
fingerprintPreference.setEnabled(true);
} else {
fingerprintPreference.setEnabled(false);
}
} else {
final PreferenceCategory privacy = (PreferenceCategory) findPreference(PreferenceKeys.PRIVACY.key());
privacy.removePreference(fingerprintPreference);
}
}
示例6: initBluetoothPrefs
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void initBluetoothPrefs() {
SwitchPreference useBluetoothSwitch = (SwitchPreference) this
.findPreference(SettingKeys.USE_BLUETOOTH);
if (bluetoothIsSupported()) {
useBluetoothSwitch.setEnabled(true);
initBluetoothDeviceList();
} else {
useBluetoothSwitch.setEnabled(false);
useBluetoothSwitch.setChecked(false);
String msg = getString(R.string.summary_bluetooth_not_supported);
useBluetoothSwitch.setSummary(msg);
}
}
示例7: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
getPreferenceManager().setStorageDeviceProtected();
}
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.settings);
PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceDonation = (SwitchPreference) preferenceScreen.findPreference(SHOW_DONATION);
preferenceStandbyTimeout = preferenceScreen
.findPreference(BreventConfiguration.BREVENT_STANDBY_TIMEOUT);
preferenceScreen.findPreference("brevent_language")
.setOnPreferenceChangeListener(this);
BreventApplication application = (BreventApplication) getActivity().getApplication();
if (!application.supportStandby()) {
((PreferenceCategory) preferenceScreen.findPreference("brevent_list"))
.removePreference(preferenceStandbyTimeout);
}
if (!application.supportUpgrade()) {
SwitchPreference preferenceAutoUpdate = (SwitchPreference) preferenceScreen
.findPreference(BreventConfiguration.BREVENT_AUTO_UPDATE);
preferenceAutoUpdate.setEnabled(false);
}
if (!BuildConfig.RELEASE) {
preferenceScreen.removePreference(preferenceScreen.findPreference("brevent"));
}
if (!application.supportAppops()) {
((PreferenceCategory) preferenceScreen.findPreference("brevent"))
.removePreference(preferenceScreen.findPreference(BREVENT_APPOPS));
}
if (BuildConfig.RELEASE) {
preferenceScreen.findPreference("brevent_about_version")
.setOnPreferenceClickListener(this);
updateDonation();
}
onUpdateBreventMethod();
}
示例8: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
addPreferencesFromResource(R.xml.pref_main);
mSets = Settings.getInstance(getActivity().getApplicationContext());
getActivity().setTitle(R.string.title_settings);
pref_version = findPreference("application_version");
pref_weibo = findPreference("sina_weibo");
pref_os_license = findPreference("open_source_license");
pref_api_provider = findPreference("api_provider");
pref_github = findPreference("github_repo");
pref_token_choose = (MaterialListPreference) findPreference("api_token_choose");
pref_token_custom = findPreference("api_token_custom");
pref_swipe_back = (SwitchPreference) findPreference("swipe_back");
pref_notification_interval = (MaterialListPreference) findPreference("notification_interval");
pref_do_not_disturb = (SwitchPreference) findPreference("do_not_disturb");
pref_disable_animation = (SwitchPreference) findPreference("disable_animation");
pref_navigation_tint = (SwitchPreference) findPreference("navigation_tint");
String version = "Unknown";
try {
version = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName;
version += " (" + getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionCode + ")";
} catch (Exception e) {
// Keep the default value
}
pref_version.setSummary(version);
pref_swipe_back.setChecked(mSets.getBoolean(Settings.KEY_SWIPE_BACK, true));
pref_token_custom.setDefaultValue(mSets.getInt(Settings.KEY_TOKEN_CHOOSE, 0));
pref_token_custom.setEnabled(mSets.getInt(Settings.KEY_TOKEN_CHOOSE, 0) == 2);
pref_do_not_disturb.setChecked(mSets.getBoolean(Settings.KEY_NOTIFICATION_DO_NOT_DISTURB, true));
pref_disable_animation.setChecked(mSets.getBoolean(Settings.KEY_DISABLE_ANIMATION, false));
if (Build.VERSION.SDK_INT < 21) {
pref_navigation_tint.setEnabled(false);
pref_navigation_tint.setChecked(false);
} else {
pref_navigation_tint.setChecked(mSets.getBoolean(Settings.KEY_NAVIGATION_TINT, true));
}
String[] values = getResources().getStringArray(R.array.item_token_list_values);
int index, target = mSets.getInt(Settings.KEY_TOKEN_CHOOSE, 0);
for (index = 0; index < values.length; index++) {
if (values[index].equals(String.valueOf(target))) break;
}
pref_token_choose.setSummary(
getResources().getStringArray(R.array.item_token_list)
[index]
);
String[] values1 = getResources().getStringArray(R.array.notification_interval_item);
int index1, target1 = mSets.getInt(Settings.KEY_NOTIFICATION_INTERVAL, 0);
for (index1 = 0; index1 < values.length; index1++) {
if (values1[index1].equals(String.valueOf(target1))) break;
}
pref_notification_interval.setSummary(
getResources().getStringArray(R.array.notification_interval)
[index1]
);
pref_weibo.setOnPreferenceClickListener(this);
pref_os_license.setOnPreferenceClickListener(this);
pref_api_provider.setOnPreferenceClickListener(this);
pref_github.setOnPreferenceClickListener(this);
pref_token_custom.setOnPreferenceClickListener(this);
pref_token_choose.setOnPreferenceChangeListener(this);
pref_swipe_back.setOnPreferenceChangeListener(this);
pref_notification_interval.setOnPreferenceChangeListener(this);
pref_do_not_disturb.setOnPreferenceChangeListener(this);
pref_disable_animation.setOnPreferenceChangeListener(this);
pref_navigation_tint.setOnPreferenceChangeListener(this);
}
示例9: setupPreferences
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void setupPreferences() {
widgetPresets = findPreference("widget_presets");
widgetBackgroundColor = (ColorPreference) findPreference("widget_background_color");
widgetTextColor = (ColorPreference) findPreference("widget_text_color");
widgetSecondaryTextColor = (ColorPreference) findPreference("widget_secondary_text_color");
widgetIconColor = (ColorPreference) findPreference("widget_icon_color");
widgetRoundCorners = (SwitchPreference) findPreference("widget_theme_round_corner");
widgetAccentColor = (ColorPreference) findPreference("widget_list_accent_color");
widgetTitleColor = (ColorPreference) findPreference("widget_title_text_color");
widgetHideSettings = (SwitchPreference) findPreference("widget_refresh_enabled");
if (!SupporterHelper.isSupporter()) {
Preference weather = findPreference("weather");
weather.setEnabled(false);
weather.setSelectable(false);
PreferenceCategory prefCatWeather = (PreferenceCategory) findPreference("weather_category");
prefCatWeather.setTitle(prefCatWeather.getTitle() + " (Supporter Feature)");
Preference measurement = findPreference("weather_US_SI");
measurement.setEnabled(false);
measurement.setSelectable(false);
PreferenceCategory prefCatWidget = (PreferenceCategory) findPreference("widget_category");
prefCatWidget.setTitle(prefCatWidget.getTitle() + " (Supporter Feature)");
widgetPresets.setEnabled(false);
widgetPresets.setSelectable(false);
widgetBackgroundColor.setEnabled(false);
widgetBackgroundColor.setSelectable(false);
widgetTextColor.setEnabled(false);
widgetTextColor.setSelectable(false);
widgetSecondaryTextColor.setEnabled(false);
widgetSecondaryTextColor.setSelectable(false);
widgetIconColor.setEnabled(false);
widgetIconColor.setSelectable(false);
widgetRoundCorners.setEnabled(false);
widgetRoundCorners.setSelectable(false);
widgetAccentColor.setEnabled(false);
widgetAccentColor.setSelectable(false);
widgetTitleColor.setEnabled(false);
widgetTitleColor.setSelectable(false);
widgetHideSettings.setEnabled(false);
widgetHideSettings.setSelectable(false);
}
Preference localTime = findPreference("local_time");
localTime.setOnPreferenceChangeListener(createLocalTimeListener());
}
示例10: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.internal_sensor__confix);
enabledSensorNr = 0;
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
String[] internalSensorArrayList = getResources().getStringArray(
R.array.internal_sensor_config);
for (String s : internalSensorArrayList) {
final SwitchPreference swp = (SwitchPreference) getPreferenceManager()
.findPreference(s);
if (swp.isChecked())
enabledSensorNr++;
if (!availableSensor(swp.getKey())) {
swp.setSummary("not available");
swp.setEnabled(false);
} else {
swp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(
Preference preference, Object newValue) {
if ((Boolean) newValue) {
if (enabledSensorNr >= 2) {
openPopupDialog("Warning",
"More than 2 sensors can't be enabled at once!");
return false;
} else {
enabledSensorNr++;
return true;
}
} else {
enabledSensorNr--;
return true;
}
}
});
}
}
}