本文整理汇总了Java中android.preference.TwoStatePreference类的典型用法代码示例。如果您正苦于以下问题:Java TwoStatePreference类的具体用法?Java TwoStatePreference怎么用?Java TwoStatePreference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TwoStatePreference类属于android.preference包,在下文中一共展示了TwoStatePreference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initIncreasingRing
import android.preference.TwoStatePreference; //导入依赖的package包/类
private void initIncreasingRing(PreferenceCategory root) {
mIncreasingRing = (TwoStatePreference)
root.findPreference(CMSettings.System.INCREASING_RING);
mIncreasingRingVolume = (IncreasingRingVolumePreference)
root.findPreference(KEY_INCREASING_RING_VOLUME);
if (!mVoiceCapable) {
if (mIncreasingRing != null) {
root.removePreference(mIncreasingRing);
mIncreasingRing = null;
}
if (mIncreasingRingVolume != null) {
root.removePreference(mIncreasingRingVolume);
mIncreasingRingVolume = null;
}
} else {
if (mIncreasingRingVolume != null) {
mIncreasingRingVolume.setCallback(mIncreasingRingVolumeCallback);
}
}
}
示例2: initVibrateWhenRinging
import android.preference.TwoStatePreference; //导入依赖的package包/类
private void initVibrateWhenRinging(PreferenceCategory root) {
mVibrateWhenRinging = (TwoStatePreference) root.findPreference(KEY_VIBRATE_WHEN_RINGING);
if (mVibrateWhenRinging == null) {
Log.i(TAG, "Preference not found: " + KEY_VIBRATE_WHEN_RINGING);
return;
}
if (!mVoiceCapable || !Utils.isUserOwner()) {
root.removePreference(mVibrateWhenRinging);
mVibrateWhenRinging = null;
return;
}
mVibrateWhenRinging.setPersistent(false);
updateVibrateWhenRinging();
mVibrateWhenRinging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean val = (Boolean) newValue;
return Settings.System.putInt(getContentResolver(),
Settings.System.VIBRATE_WHEN_RINGING,
val ? 1 : 0);
}
});
}
示例3: onSharedPreferenceChanged
import android.preference.TwoStatePreference; //导入依赖的package包/类
@Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
if (TextUtils.equals(key, PREF_ACCOUNT_NAME)) {
refreshSyncSettingsUI();
} else if (TextUtils.equals(key, PREF_ENABLE_CLOUD_SYNC)) {
mEnableSyncPreference = (TwoStatePreference) findPreference(PREF_ENABLE_SYNC_NOW);
final boolean syncEnabled = prefs.getBoolean(PREF_ENABLE_CLOUD_SYNC, false);
if (isSyncEnabled()) {
mEnableSyncPreference.setSummary(getString(R.string.cloud_sync_summary));
} else {
mEnableSyncPreference.setSummary(getString(R.string.cloud_sync_summary_disabled));
}
AccountStateChangedListener.onSyncPreferenceChanged(getSignedInAccountName(),
syncEnabled);
}
}
示例4: purchaseCompleted
import android.preference.TwoStatePreference; //导入依赖的package包/类
@Override
public void purchaseCompleted(final boolean success, final String sku) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (getString(R.string.sku_tasker).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_purchased_tasker)).setChecked(success);
} else if (getString(R.string.sku_tesla_unread).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_tesla_unread_enabled)).setChecked(success);
} else if (getString(R.string.sku_dashclock).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_purchased_dashclock)).setChecked(success);
} else if (getString(R.string.sku_themes).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_purchased_themes)).setChecked(success);
} else {
Timber.d("Unhandled sku: %s", sku);
}
}
});
}
示例5: onCreate
import android.preference.TwoStatePreference; //导入依赖的package包/类
@DexAppend
@Override
public void onCreate(Bundle icicle) {
try {
PreferenceGroup pg = (PreferenceGroup) findPreference(
FakeSignatureGlobalUI.DEBUG_APPLICATIONS_CATEGORY_KEY);
if (pg != null) {
TwoStatePreference p = createTwoStatePreference(pg.getContext());
p.setKey(FakeSignatureGlobalUI.SETTING_SECURE_KEY);
p.setTitle(FakeSignatureGlobalUI.SETTING_TITLE);
p.setSummary(FakeSignatureGlobalUI.SETTING_SUMMARY);
p.setPersistent(false);
mResetTwoStatePrefsAdd(p);
mAllPrefs.add(p);
//pg.setOrderingAsAdded(true);
pg.addPreference(p);
mAllowFakeSignatureGlobal = p;
} else {
Log.e("DevelopmentSettings_FakeSignatureGlobalUI", "cannot find 'applications' preference category");
}
} catch (Throwable t) {
Log.e("DevelopmentSettings_FakeSignatureGlobalUI", "onCreate exception", t);
}
}
示例6: updatePreference
import android.preference.TwoStatePreference; //导入依赖的package包/类
/**
* Update monitoring preference.
*
* @param preference preference to update.
* @param value new value.
*/
private void updatePreference(Preference preference, Object value) {
// Get value if not passed
Object newVal;
if (value == null) {
if (preference instanceof VNTNumberPickerPreference) {
newVal = PreferenceManager.getDefaultSharedPreferences(preference.getContext())
.getInt(preference.getKey(), Integer.parseInt(preference.getSummary().toString()));
} else if (preference instanceof TwoStatePreference) {
newVal = PreferenceManager.getDefaultSharedPreferences(preference.getContext())
.getBoolean(preference.getKey(), true);
} else {
newVal = PreferenceManager.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), "");
}
} else {
newVal = value;
}
// Update preference
updateAlgorithm(preference, newVal);
updateSummary(preference, newVal);
}
示例7: updateTalkBackShortcutStatus
import android.preference.TwoStatePreference; //导入依赖的package包/类
private void updateTalkBackShortcutStatus() {
final TwoStatePreference preference = (TwoStatePreference) findPreferenceByResId(
R.string.pref_two_volume_long_press_key);
if (preference == null) {
return;
}
if (Build.VERSION.SDK_INT >= ProcessorVolumeStream.MIN_API_LEVEL) {
preference.setEnabled(
TalkBackService.getInstance() != null || preference.isChecked());
} else {
final PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
R.string.pref_category_miscellaneous_key);
if (category == null) {
return;
}
category.removePreference(preference);
}
}
示例8: checkVibrationSupport
import android.preference.TwoStatePreference; //导入依赖的package包/类
/**
* Ensure that the vibration setting does not appear on devices without a
* vibrator.
*/
private void checkVibrationSupport() {
Activity activity = getActivity();
if (activity == null) {
return;
}
final Vibrator vibrator = (Vibrator) activity.getSystemService(VIBRATOR_SERVICE);
if (vibrator != null && vibrator.hasVibrator()) {
return;
}
final PreferenceGroup category =
(PreferenceGroup) findPreferenceByResId(R.string.pref_category_feedback_key);
final TwoStatePreference prefVibration =
(TwoStatePreference) findPreferenceByResId(R.string.pref_vibration_key);
if (prefVibration != null) {
prefVibration.setChecked(false);
category.removePreference(prefVibration);
}
}
示例9: checkProximitySupport
import android.preference.TwoStatePreference; //导入依赖的package包/类
/**
* Ensure that the proximity sensor setting does not appear on devices
* without a proximity sensor.
*/
private void checkProximitySupport() {
Activity activity = getActivity();
if (activity == null) {
return;
}
final SensorManager manager = (SensorManager) activity.getSystemService(SENSOR_SERVICE);
final Sensor proximity = manager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
if (proximity != null) {
return;
}
final PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
R.string.pref_category_when_to_speak_key);
final TwoStatePreference prefProximity =
(TwoStatePreference) findPreferenceByResId(R.string.pref_proximity_key);
if (prefProximity != null) {
prefProximity.setChecked(false);
category.removePreference(prefProximity);
}
}
示例10: onCreate
import android.preference.TwoStatePreference; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Accountant.getInstance(getActivity());
getActivity().setTitle(getString(R.string.labs_title));
addPreferencesFromResource(R.xml.lab_preferences);
// Set whether the preference should be checked or not.
Preference pref = findPreference("MediaControllerService");
// For builds other than KitKat, hide RemoteController API.
if (null != pref) pref.setOnPreferenceChangeListener(this);
// Add out listeners and state change stuff.
if (pref instanceof TwoStatePreference) {
notifPref = (TwoStatePreference) pref;
updateNotifPref();
}
}
示例11: checkPermissions
import android.preference.TwoStatePreference; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private boolean checkPermissions(String name) {
PreferenceScreen screen = getPreferenceScreen();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// Check if permission was revoked
if ((name == null || "disable_on_call".equals(name)) && prefs.getBoolean("disable_on_call", false))
if (!Util.hasPhoneStatePermission(this)) {
prefs.edit().putBoolean("disable_on_call", false).apply();
((TwoStatePreference) screen.findPreference("disable_on_call")).setChecked(false);
requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_CALL);
if (name != null)
return false;
}
return true;
}
示例12: refresh
import android.preference.TwoStatePreference; //导入依赖的package包/类
@Override
protected void refresh() {
super.refresh();
final ListPreference transmitPref;
final EditTextPreference gpggaLatPref, gpggaLonPref;
transmitPref = (ListPreference) findPreference(KEY_TRANSMIT_GPGGA_TO_BASE);
gpggaLatPref = (EditTextPreference) findPreference(KEY_TRANSMIT_GPGGA_LAT);
gpggaLonPref = (EditTextPreference) findPreference(KEY_TRANSMIT_GPGGA_LON);
final boolean enabled = ((TwoStatePreference)findPreference(KEY_ENABLE)).isChecked();
final boolean transmitLatLon = TextUtils.equals("1", transmitPref.getValue());
gpggaLatPref.setEnabled(transmitLatLon && enabled);
gpggaLonPref.setEnabled(transmitLatLon && enabled);
transmitPref.setSummary(transmitPref.getEntry());
gpggaLatPref.setSummary(gpggaLatPref.getText());
gpggaLonPref.setSummary(gpggaLonPref.getText());
}
示例13: onRequestPermissionsResult
import android.preference.TwoStatePreference; //导入依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
for (int i = 0; i < permissions.length; i++)
{
if (permissions[i].equals(Manifest.permission.ACCESS_COARSE_LOCATION) && grantResults[i] == PackageManager.PERMISSION_GRANTED)
{
ListPreference backlightPreference = (ListPreference) findPreference(PebbleNotificationCenter.LIGHT_SCREEN_ON_NOTIFICATIONS);
backlightPreference.setValue("3");
}
else if (permissions[i].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE) && grantResults[i] == PackageManager.PERMISSION_GRANTED)
{
TwoStatePreference logWriterPreference = (TwoStatePreference) findPreference(LogWriter.SETTING_ENABLE_LOG_WRITING);
logWriterPreference.setChecked(true);
}
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
示例14: onRequestPermissionsResult
import android.preference.TwoStatePreference; //导入依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
PreferenceScreen screen = getPreferenceScreen();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean granted = (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED);
if (requestCode == REQUEST_METERED2) {
prefs.edit().putBoolean("unmetered_2g", granted).apply();
((TwoStatePreference) screen.findPreference("unmetered_2g")).setChecked(granted);
} else if (requestCode == REQUEST_METERED3) {
prefs.edit().putBoolean("unmetered_3g", granted).apply();
((TwoStatePreference) screen.findPreference("unmetered_3g")).setChecked(granted);
} else if (requestCode == REQUEST_METERED4) {
prefs.edit().putBoolean("unmetered_4g", granted).apply();
((TwoStatePreference) screen.findPreference("unmetered_4g")).setChecked(granted);
} else if (requestCode == REQUEST_ROAMING_EU) {
prefs.edit().putBoolean("eu_roaming", granted).apply();
((TwoStatePreference) screen.findPreference("eu_roaming")).setChecked(granted);
} else if (requestCode == REQUEST_ROAMING_NATIONAL) {
prefs.edit().putBoolean("national_roaming", granted).apply();
((TwoStatePreference) screen.findPreference("national_roaming")).setChecked(granted);
} else if (requestCode == REQUEST_ROAMING_INTERNATIONAL) {
prefs.edit().putBoolean("whitelist_roaming", granted).apply();
((TwoStatePreference) screen.findPreference("whitelist_roaming")).setChecked(granted);
}
if (granted)
ServiceSinkhole.reload("permission granted", this);
}
示例15: onCreate
import android.preference.TwoStatePreference; //导入依赖的package包/类
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_accounts);
mAccountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
mEnableSyncPreference = (TwoStatePreference) findPreference(PREF_ENABLE_SYNC_NOW);
mSyncNowPreference = findPreference(PREF_SYNC_NOW);
mClearSyncDataPreference = findPreference(PREF_CLEAR_SYNC_DATA);
if (ProductionFlags.IS_METRICS_LOGGING_SUPPORTED) {
final Preference enableMetricsLogging =
findPreference(Settings.PREF_ENABLE_METRICS_LOGGING);
final Resources res = getResources();
if (enableMetricsLogging != null) {
final String enableMetricsLoggingTitle = res.getString(
R.string.enable_metrics_logging, getApplicationName());
enableMetricsLogging.setTitle(enableMetricsLoggingTitle);
}
} else {
removePreference(Settings.PREF_ENABLE_METRICS_LOGGING);
}
if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
removeSyncPreferences();
} else {
// Disable by default till we are sure we can enable this.
disableSyncPreferences();
new ManagedProfileCheckerTask(this).execute();
}
}