android.preference.TwoStatePreference Java Examples
The following examples show how to use
android.preference.TwoStatePreference.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActivitySettings.java From tracker-control-android with GNU General Public License v3.0 | 6 votes |
@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; }
Example #2
Source File: AccountsSettingsFragment.java From Android-Keyboard with Apache License 2.0 | 6 votes |
@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); } }
Example #3
Source File: AccountsSettingsFragment.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
@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); } }
Example #4
Source File: ConfigurationActivity.java From Noyze with Apache License 2.0 | 6 votes |
@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(); } }
Example #5
Source File: AccountsSettingsFragment.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
@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); } }
Example #6
Source File: ActivitySettings.java From NetGuard with GNU General Public License v3.0 | 6 votes |
@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; }
Example #7
Source File: ConfigurationActivity.java From Noyze with Apache License 2.0 | 6 votes |
@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(); } }
Example #8
Source File: MonitoringSettingsFragment.java From go-bees with GNU General Public License v3.0 | 6 votes |
/** * 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); }
Example #9
Source File: SettingsFragment.java From always-on-amoled with GNU General Public License v3.0 | 5 votes |
private void updateSpecialPreferences() { if (shouldEnableNotificationsAlerts && checkNotificationsPermission(context, false)) { ((TwoStatePreference) findPreference("notifications_alerts")).setChecked(true); } if (((MaterialListPreference) findPreference("stop_delay")).getValue().equals("0")) findPreference("stop_delay").setSummary(R.string.settings_stop_delay_desc); else findPreference("stop_delay").setSummary("%s"); findPreference("watchface_clock").setSummary(context.getResources().getStringArray(R.array.customize_clock)[prefs.clockStyle]); findPreference("watchface_date").setSummary(context.getResources().getStringArray(R.array.customize_date)[prefs.dateStyle]); findPreference("greenify_enabled").setSummary(isPackageInstalled("com.oasisfeng.greenify") ? context.getString(R.string.settings_greenify_integration_desc) : context.getString(R.string.settings_greenify_integration_desc_not_found)); if (!isPackageInstalled("com.oasisfeng.greenify")) { ((SwitchPreference) findPreference("greenify_enabled")).setChecked(false); } }
Example #10
Source File: DebugSettingsFragment.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); addPreferencesFromResource(R.xml.prefs_screen_debug); if (!Settings.SHOULD_SHOW_LXX_SUGGESTION_UI) { removePreference(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI); } final PreferenceGroup dictDumpPreferenceGroup = (PreferenceGroup)findPreference(PREF_KEY_DUMP_DICTS); for (final String dictName : DictionaryFacilitatorImpl.DICT_TYPE_TO_CLASS.keySet()) { final Preference pref = new DictDumpPreference(getActivity(), dictName); pref.setOnPreferenceClickListener(this); dictDumpPreferenceGroup.addPreference(pref); } final Resources res = getResources(); setupKeyPreviewAnimationDuration(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION, res.getInteger(R.integer.config_key_preview_show_up_duration)); setupKeyPreviewAnimationDuration(DebugSettings.PREF_KEY_PREVIEW_DISMISS_DURATION, res.getInteger(R.integer.config_key_preview_dismiss_duration)); final float defaultKeyPreviewShowUpStartScale = ResourceUtils.getFloatFromFraction( res, R.fraction.config_key_preview_show_up_start_scale); final float defaultKeyPreviewDismissEndScale = ResourceUtils.getFloatFromFraction( res, R.fraction.config_key_preview_dismiss_end_scale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE, defaultKeyPreviewShowUpStartScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_Y_SCALE, defaultKeyPreviewShowUpStartScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_X_SCALE, defaultKeyPreviewDismissEndScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE, defaultKeyPreviewDismissEndScale); mServiceNeedsRestart = false; mDebugMode = (TwoStatePreference) findPreference(DebugSettings.PREF_DEBUG_MODE); updateDebugMode(); }
Example #11
Source File: AccountsSettingsFragment.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
@Override public boolean onPreferenceClick(final Preference preference) { final TwoStatePreference syncPreference = (TwoStatePreference) preference; if (syncPreference.isChecked()) { // Uncheck for now. syncPreference.setChecked(false); // Show opt-in. final AlertDialog optInDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.cloud_sync_title) .setMessage(R.string.cloud_sync_opt_in_text) .setPositiveButton(R.string.account_select_ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { if (which == DialogInterface.BUTTON_POSITIVE) { final Context context = getActivity(); final String[] accountsForLogin = LoginAccountUtils.getAccountsForLogin(context); createAccountPicker(accountsForLogin, getSignedInAccountName(), new AccountChangedListener(syncPreference)) .show(); } } }) .setNegativeButton(R.string.cloud_sync_cancel, null) .create(); optInDialog.setOnShowListener(this); optInDialog.show(); } return true; }
Example #12
Source File: AccountsSettingsFragment.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
@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(); } }
Example #13
Source File: PreferenceFragment.java From AcDisplay with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void setValue(@NonNull Preference preference, @NonNull ConfigBase.Option option, @NonNull Object value) { TwoStatePreference cbp = (TwoStatePreference) preference; cbp.setChecked((Boolean) value); }
Example #14
Source File: BasePreferenceFragment.java From Dashchan with Apache License 2.0 | 5 votes |
@Override public boolean checkDependency(Preference dependencyPreference) { if (dependencyPreference instanceof TwoStatePreference) { return ((TwoStatePreference) dependencyPreference).isChecked() == positive; } return false; }
Example #15
Source File: ActivitySettings.java From NetGuard with GNU General Public License v3.0 | 5 votes |
@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_CALL) { prefs.edit().putBoolean("disable_on_call", granted).apply(); ((TwoStatePreference) screen.findPreference("disable_on_call")).setChecked(granted); } if (granted) ServiceSinkhole.reload("permission granted", this, false); }
Example #16
Source File: SettingsActivity.java From island with Apache License 2.0 | 5 votes |
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final TwoStatePreference pref_show_admin_message = (TwoStatePreference) findPreference(getString(R.string.key_show_admin_message)); final DevicePolicies policies; if (SDK_INT >= N && (policies = new DevicePolicies(getActivity())).isActiveDeviceOwner()) { pref_show_admin_message.setChecked(policies.invoke(DevicePolicyManager::getShortSupportMessage) != null); pref_show_admin_message.setOnPreferenceChangeListener((pref, value) -> { final boolean enabled = value == Boolean.TRUE; policies.execute(DevicePolicyManager::setShortSupportMessage, enabled ? getText(R.string.device_admin_support_message_short) : null); policies.execute(DevicePolicyManager::setLongSupportMessage, enabled ? getText(R.string.device_admin_support_message_long) : null); return true; }); } else if (pref_show_admin_message != null) removeLeafPreference(getPreferenceScreen(), pref_show_admin_message); }
Example #17
Source File: SettingsFragment.java From More-For-GO with GNU General Public License v3.0 | 5 votes |
private void updatePermissionsBasedPreferences() { if (!hasDrawingPermission()) ((TwoStatePreference) findPreference("overlay")).setChecked(false); else if (shouldAllowOverlay) ((TwoStatePreference) findPreference("overlay")).setChecked(true); if (!hasModifySettingsPermission()) ((TwoStatePreference) findPreference("dim")).setChecked(false); else if (shouldAllowDim) ((TwoStatePreference) findPreference("dim")).setChecked(true); if (!hasDrawingPermission()) ((TwoStatePreference) findPreference("show_fab")).setChecked(false); else if (shouldAllowFab) ((TwoStatePreference) findPreference("show_fab")).setChecked(true); if (!hasModifySettingsPermission()) ((TwoStatePreference) findPreference("maximize_brightness")).setChecked(false); else if (shouldAllowMaximizeBrightness) ((TwoStatePreference) findPreference("maximize_brightness")).setChecked(true); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { findPreference("screen_of_proximity").setEnabled(false); ((TwoStatePreference) findPreference("screen_of_proximity")).setChecked(false); } if (!hasModifySecurePermission()) ((TwoStatePreference) findPreference("extreme_battery_saver")).setChecked(false); }
Example #18
Source File: DebugSettingsFragment.java From openboard with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); addPreferencesFromResource(R.xml.prefs_screen_debug); if (!Settings.SHOULD_SHOW_LXX_SUGGESTION_UI) { removePreference(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI); } final PreferenceGroup dictDumpPreferenceGroup = (PreferenceGroup)findPreference(PREF_KEY_DUMP_DICTS); for (final String dictName : DictionaryFacilitatorImpl.DICT_TYPE_TO_CLASS.keySet()) { final Preference pref = new DictDumpPreference(getActivity(), dictName); pref.setOnPreferenceClickListener(this); dictDumpPreferenceGroup.addPreference(pref); } final Resources res = getResources(); setupKeyPreviewAnimationDuration(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION, res.getInteger(R.integer.config_key_preview_show_up_duration)); setupKeyPreviewAnimationDuration(DebugSettings.PREF_KEY_PREVIEW_DISMISS_DURATION, res.getInteger(R.integer.config_key_preview_dismiss_duration)); final float defaultKeyPreviewShowUpStartScale = ResourceUtils.getFloatFromFraction( res, R.fraction.config_key_preview_show_up_start_scale); final float defaultKeyPreviewDismissEndScale = ResourceUtils.getFloatFromFraction( res, R.fraction.config_key_preview_dismiss_end_scale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE, defaultKeyPreviewShowUpStartScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_Y_SCALE, defaultKeyPreviewShowUpStartScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_X_SCALE, defaultKeyPreviewDismissEndScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE, defaultKeyPreviewDismissEndScale); setupKeyboardHeight( DebugSettings.PREF_KEYBOARD_HEIGHT_SCALE, SettingsValues.DEFAULT_SIZE_SCALE); mServiceNeedsRestart = false; mDebugMode = (TwoStatePreference) findPreference(DebugSettings.PREF_DEBUG_MODE); updateDebugMode(); }
Example #19
Source File: DebugSettingsFragment.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); addPreferencesFromResource(R.xml.prefs_screen_debug); if (!Settings.SHOULD_SHOW_LXX_SUGGESTION_UI) { removePreference(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI); } final PreferenceGroup dictDumpPreferenceGroup = (PreferenceGroup)findPreference(PREF_KEY_DUMP_DICTS); for (final String dictName : DictionaryFacilitatorImpl.DICT_TYPE_TO_CLASS.keySet()) { final Preference pref = new DictDumpPreference(getActivity(), dictName); pref.setOnPreferenceClickListener(this); dictDumpPreferenceGroup.addPreference(pref); } final Resources res = getResources(); setupKeyPreviewAnimationDuration(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION, res.getInteger(R.integer.config_key_preview_show_up_duration)); setupKeyPreviewAnimationDuration(DebugSettings.PREF_KEY_PREVIEW_DISMISS_DURATION, res.getInteger(R.integer.config_key_preview_dismiss_duration)); final float defaultKeyPreviewShowUpStartScale = ResourceUtils.getFloatFromFraction( res, R.fraction.config_key_preview_show_up_start_scale); final float defaultKeyPreviewDismissEndScale = ResourceUtils.getFloatFromFraction( res, R.fraction.config_key_preview_dismiss_end_scale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE, defaultKeyPreviewShowUpStartScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_Y_SCALE, defaultKeyPreviewShowUpStartScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_X_SCALE, defaultKeyPreviewDismissEndScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE, defaultKeyPreviewDismissEndScale); setupKeyboardHeight( DebugSettings.PREF_KEYBOARD_HEIGHT_SCALE, SettingsValues.DEFAULT_SIZE_SCALE); mServiceNeedsRestart = false; mDebugMode = (TwoStatePreference) findPreference(DebugSettings.PREF_DEBUG_MODE); updateDebugMode(); }
Example #20
Source File: AccountsSettingsFragment.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
@Override public boolean onPreferenceClick(final Preference preference) { final TwoStatePreference syncPreference = (TwoStatePreference) preference; if (syncPreference.isChecked()) { // Uncheck for now. syncPreference.setChecked(false); // Show opt-in. final AlertDialog optInDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.cloud_sync_title) .setMessage(R.string.cloud_sync_opt_in_text) .setPositiveButton(R.string.account_select_ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { if (which == DialogInterface.BUTTON_POSITIVE) { final Context context = getActivity(); final String[] accountsForLogin = LoginAccountUtils.getAccountsForLogin(context); createAccountPicker(accountsForLogin, getSignedInAccountName(), new AccountChangedListener(syncPreference)) .show(); } } }) .setNegativeButton(R.string.cloud_sync_cancel, null) .create(); optInDialog.setOnShowListener(this); optInDialog.show(); } return true; }
Example #21
Source File: AccountsSettingsFragment.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
@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(); } }
Example #22
Source File: DebugSettingsFragment.java From Android-Keyboard with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); addPreferencesFromResource(R.xml.prefs_screen_debug); if (!Settings.SHOULD_SHOW_LXX_SUGGESTION_UI) { removePreference(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI); } final PreferenceGroup dictDumpPreferenceGroup = (PreferenceGroup)findPreference(PREF_KEY_DUMP_DICTS); for (final String dictName : DictionaryFacilitatorImpl.DICT_TYPE_TO_CLASS.keySet()) { final Preference pref = new DictDumpPreference(getActivity(), dictName); pref.setOnPreferenceClickListener(this); dictDumpPreferenceGroup.addPreference(pref); } final Resources res = getResources(); setupKeyPreviewAnimationDuration(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION, res.getInteger(R.integer.config_key_preview_show_up_duration)); setupKeyPreviewAnimationDuration(DebugSettings.PREF_KEY_PREVIEW_DISMISS_DURATION, res.getInteger(R.integer.config_key_preview_dismiss_duration)); final float defaultKeyPreviewShowUpStartScale = ResourceUtils.getFloatFromFraction( res, R.fraction.config_key_preview_show_up_start_scale); final float defaultKeyPreviewDismissEndScale = ResourceUtils.getFloatFromFraction( res, R.fraction.config_key_preview_dismiss_end_scale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE, defaultKeyPreviewShowUpStartScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_Y_SCALE, defaultKeyPreviewShowUpStartScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_X_SCALE, defaultKeyPreviewDismissEndScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE, defaultKeyPreviewDismissEndScale); setupKeyboardHeight( DebugSettings.PREF_KEYBOARD_HEIGHT_SCALE, SettingsValues.DEFAULT_SIZE_SCALE); mServiceNeedsRestart = false; mDebugMode = (TwoStatePreference) findPreference(DebugSettings.PREF_DEBUG_MODE); updateDebugMode(); }
Example #23
Source File: AccountsSettingsFragment.java From Android-Keyboard with Apache License 2.0 | 5 votes |
@Override public boolean onPreferenceClick(final Preference preference) { final TwoStatePreference syncPreference = (TwoStatePreference) preference; if (syncPreference.isChecked()) { // Uncheck for now. syncPreference.setChecked(false); // Show opt-in. final AlertDialog optInDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.cloud_sync_title) .setMessage(R.string.cloud_sync_opt_in_text) .setPositiveButton(R.string.account_select_ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { if (which == DialogInterface.BUTTON_POSITIVE) { final Context context = getActivity(); final String[] accountsForLogin = LoginAccountUtils.getAccountsForLogin(context); createAccountPicker(accountsForLogin, getSignedInAccountName(), new AccountChangedListener(syncPreference)) .show(); } } }) .setNegativeButton(R.string.cloud_sync_cancel, null) .create(); optInDialog.setOnShowListener(this); optInDialog.show(); } return true; }
Example #24
Source File: AccountsSettingsFragment.java From Android-Keyboard with Apache License 2.0 | 5 votes |
@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(); } }
Example #25
Source File: ActivitySettings.java From tracker-control-android with GNU General Public License v3.0 | 5 votes |
@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_CALL) { prefs.edit().putBoolean("disable_on_call", granted).apply(); ((TwoStatePreference) screen.findPreference("disable_on_call")).setChecked(granted); } if (granted) ServiceSinkhole.reload("permission granted", this, false); }
Example #26
Source File: SettingsFragment.java From always-on-amoled with GNU General Public License v3.0 | 4 votes |
@Override public boolean onPreferenceChange(final Preference preference, Object o) { prefs.apply(); Utils.logDebug("Preference change", preference.getKey() + " Value:" + o.toString()); if (preference.getKey().equals("notifications_alerts")) { if ((boolean) o) return checkNotificationsPermission(context, true); return true; } if (preference.getKey().equals("raise_to_wake")) { if (!Utils.hasFingerprintSensor(context)) askDeviceAdmin(R.string.settings_raise_to_wake_device_admin); restartService(); } if (preference.getKey().equals("stop_delay")) if (!Utils.hasFingerprintSensor(context)) askDeviceAdmin(R.string.settings_raise_to_wake_device_admin); if (preference.getKey().equals("persistent_notification") && !(boolean) o) { Snackbar.make(rootView, R.string.warning_1_harm_performance, 10000).setAction(R.string.action_revert, v -> { ((CheckBoxPreference) preference).setChecked(true); restartService(); }).show(); restartService(); } if (preference.getKey().equals("enabled")) { context.sendBroadcast(new Intent(TOGGLED)); restartService(); } if (preference.getKey().equals("proximity_to_lock")) { if (Shell.SU.available() || (Utils.isAndroidNewerThanL() && !Build.MANUFACTURER.equalsIgnoreCase("samsung"))) return true; else { DevicePolicyManager mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); if ((mDPM != null && mDPM.isAdminActive(mAdminName))) { return true; } new AlertDialog.Builder(getActivity()).setTitle(getString(android.R.string.dialog_alert_title) + "!") .setMessage(getString(R.string.warning_7_disable_fingerprint)) .setPositiveButton(getString(android.R.string.yes), (dialogInterface, i) -> { askDeviceAdmin(R.string.settings_raise_to_wake_device_admin); }) .setNegativeButton(getString(android.R.string.no), (dialogInterface, i) -> { dialogInterface.dismiss(); }) .show(); return false; } } if (preference.getKey().equals("startafterlock") && !(boolean) o) Snackbar.make(rootView, R.string.warning_4_device_not_secured, 10000).setAction(R.string.action_revert, v -> ((CheckBoxPreference) preference).setChecked(true)).show(); if (preference.getKey().equals("doze_mode") && (boolean) o) { if (Shell.SU.available()) { if (!DozeManager.isDumpPermissionGranted(context)) DozeManager.grantPermission(context, "android.permission.DUMP"); if (!DozeManager.isDevicePowerPermissionGranted(context)) DozeManager.grantPermission(context, "android.permission.DEVICE_POWER"); return true; } Snackbar.make(rootView, R.string.warning_11_no_root, Snackbar.LENGTH_LONG).show(); return false; } if (preference.getKey().equals("greenify_enabled") && (boolean) o) { if (!isPackageInstalled("com.oasisfeng.greenify")) { openPlayStoreUrl("com.oasisfeng.greenify", context); return false; } } if (preference.getKey().equals("camera_shortcut") || preference.getKey().equals("google_now_shortcut")) { try { if (!hasUsageAccess()) { Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS); PackageManager packageManager = getActivity().getPackageManager(); if (intent.resolveActivity(packageManager) != null) { startActivity(intent); } else { Toast.makeText(context, "Please grant usage access permission manually for the app, your device can't do it automatically.", Toast.LENGTH_LONG).show(); } return false; } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } if (preference.getKey().equals("battery_saver")) if ((boolean) o) { ((TwoStatePreference) findPreference("doze_mode")).setChecked(true); setUpBatterySaverPermission(); } return true; }
Example #27
Source File: ManageSpaceActivity.java From MiPushFramework with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.fragmented_preferences); Context context = getActivity(); //Too bad in ui thread //TODO: Three messages seem to be too much, and need separate strings for toast. getPreferenceScreen().findPreference("clear_history").setOnPreferenceClickListener(preference -> { Toast.makeText(context, getString(R.string.settings_clear_history) + getString(R.string.start), Toast.LENGTH_SHORT).show(); EventDb.deleteHistory(context, null); Toast.makeText(context, getString(R.string.settings_clear_history) + getString(R.string.end), Toast.LENGTH_SHORT).show(); return true; }); getPreferenceScreen().findPreference("clear_log").setOnPreferenceClickListener(preference -> { Toast.makeText(context, getString(R.string.settings_clear_log) + getString(R.string.start), Toast.LENGTH_SHORT).show(); LogUtils.clearLog(context); Toast.makeText(context, getString(R.string.settings_clear_log) + getString(R.string.end), Toast.LENGTH_SHORT).show(); return true; }); getPreferenceScreen().findPreference("mock_notification").setOnPreferenceClickListener(preference -> { String packageName = Constants.MANAGER_APP_NAME; Date date = new Date(); String title = context.getString(R.string.debug_test_title); String description = context.getString(R.string.debug_test_content) + date.toString(); NotificationController.test(context, packageName, title, description); return true; }); PackageManager pm = context.getPackageManager(); ComponentName componentName = new ComponentName(Constants.SERVICE_APP_NAME, EmptyActivity.OnePlus.class.getName()); boolean disabled = pm.getComponentEnabledSetting(componentName) == COMPONENT_ENABLED_STATE_DISABLED; TwoStatePreference preferencePushIcon = (TwoStatePreference) getPreferenceScreen().findPreference("activity_push_icon"); preferencePushIcon.setChecked(!disabled); preferencePushIcon.setOnPreferenceClickListener(preference -> { TwoStatePreference switchPreference = (TwoStatePreference) preference; boolean enableLauncher = switchPreference.isChecked(); pm.setComponentEnabledSetting(componentName, enableLauncher ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); return true; }); Preference iceboxSupported = getPreferenceScreen().findPreference("IceboxSupported"); if (!Utils.isAppInstalled(IceBox.PACKAGE_NAME)) { iceboxSupported.setEnabled(false); iceboxSupported.setTitle(R.string.settings_icebox_not_installed); } else { iceboxSupported.setOnPreferenceChangeListener((preference, newValue) -> { Boolean value = (Boolean) newValue; if (value) { if (ContextCompat.checkSelfPermission(getActivity(), IceBox.SDK_PERMISSION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(getActivity(), new String[]{IceBox.SDK_PERMISSION}, 0x233); } else { Toast.makeText(context, getString(R.string.icebox_permission_granted), Toast.LENGTH_SHORT).show(); } } return true; }); } }
Example #28
Source File: AccountsSettingsFragment.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 4 votes |
AccountChangedListener(final TwoStatePreference dependentPreference) { mDependentPreference = dependentPreference; }
Example #29
Source File: AccountsSettingsFragment.java From Android-Keyboard with Apache License 2.0 | 4 votes |
AccountChangedListener(final TwoStatePreference dependentPreference) { mDependentPreference = dependentPreference; }
Example #30
Source File: AccountsSettingsFragment.java From Indic-Keyboard with Apache License 2.0 | 4 votes |
AccountChangedListener(final TwoStatePreference dependentPreference) { mDependentPreference = dependentPreference; }