use of android.preference.CheckBoxPreference in project MaxLock by Maxr1998.
the class MaxLockPreferenceFragment method onCreate.
@SuppressLint("WorldReadableFiles")
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
if (getArguments() != null) {
screen = Screen.valueOf(getArguments().getString(Screen.KEY, Screen.MAIN.toString()));
} else {
screen = Screen.MAIN;
}
prefs = MLPreferences.getPreferences(getActivity());
setTitle();
if (screen == Screen.IMOD) {
getPreferenceManager().setSharedPreferencesName(Common.PREFS_APPS);
}
if (SDK_INT < Build.VERSION_CODES.N)
getPreferenceManager().setSharedPreferencesMode(Context.MODE_WORLD_READABLE);
addPreferencesFromResource(screen.preferenceXML);
switch(screen) {
case MAIN:
updateImplementationStatus();
PreferenceCategory catAppUI = (PreferenceCategory) findPreference(Common.CATEGORY_APPLICATION_UI);
CheckBoxPreference useDark = (CheckBoxPreference) findPreference(Common.USE_DARK_STYLE);
if (!useDark.isChecked()) {
catAppUI.removePreference(findPreference(Common.USE_AMOLED_BLACK));
}
if (SDK_INT >= Build.VERSION_CODES.O) {
catAppUI.removePreference(findPreference(Common.NEW_APP_NOTIFICATION));
}
break;
case TYPE:
FingerprintManagerCompat fpm = FingerprintManagerCompat.from(getActivity());
if (!fpm.isHardwareDetected()) {
getPreferenceScreen().removePreference(findPreference(Common.SHADOW_FINGERPRINT));
getPreferenceScreen().removePreference(findPreference(Common.CATEGORY_FINGERPRINT));
} else {
CheckBoxPreference disableFP = (CheckBoxPreference) findPreference(Common.DISABLE_FINGERPRINT);
if (!fpm.hasEnrolledFingerprints() && !disableFP.isChecked()) {
disableFP.setSummary(disableFP.getSummary() + getResources().getString(R.string.pref_fingerprint_summary_non_enrolled));
}
}
break;
case UI:
ListPreference lp = (ListPreference) findPreference(Common.BACKGROUND);
findPreference(Common.BACKGROUND_COLOR).setEnabled(lp.getValue().equals("color"));
lp.setOnPreferenceChangeListener((preference, newValue) -> {
if (preference.getKey().equals(Common.BACKGROUND)) {
if (newValue.toString().equals("custom")) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, WALLPAPER_REQUEST_CODE);
} else {
FileUtils.deleteQuietly(new File(getActivity().getFilesDir(), "background"));
}
findPreference(Common.BACKGROUND_COLOR).setEnabled(newValue.toString().equals("color"));
}
return true;
});
break;
case OPTIONS:
Preference el = findPreference(Common.ENABLE_LOGGING);
el.setEnabled(prefs.getBoolean(Common.ENABLE_PRO, false));
if (!prefs.getBoolean(Common.ENABLE_PRO, false)) {
el.setSummary(R.string.toast_pro_required);
}
if (MLImplementation.getImplementation(prefs) != MLImplementation.DEFAULT) {
PreferenceCategory catOther = (PreferenceCategory) findPreference(Common.CATEGORY_OTHER);
catOther.removePreference(findPreference(Common.HIDE_RECENTS_THUMBNAILS));
}
break;
case IMOD:
// Intika I.Mod - Pro setup
Preference iModDelayGlobal = findPreference(Common.ENABLE_IMOD_DELAY_GLOBAL);
Preference iModDelayPerApp = findPreference(Common.ENABLE_IMOD_DELAY_APP);
iModDelayGlobal.setEnabled(prefs.getBoolean(Common.ENABLE_PRO, false));
iModDelayPerApp.setEnabled(prefs.getBoolean(Common.ENABLE_PRO, false));
if (!prefs.getBoolean(Common.ENABLE_PRO, false)) {
iModDelayGlobal.setTitle(R.string.pref_delay_needpro);
iModDelayPerApp.setTitle(R.string.pref_delay_needpro);
}
break;
}
}
use of android.preference.CheckBoxPreference in project android_packages_apps_Dialer by MoKee.
the class SoundSettingsFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.sound_settings);
Context context = getActivity();
mRingtonePreference = findPreference(context.getString(R.string.ringtone_preference_key));
mVibrateWhenRinging = (CheckBoxPreference) findPreference(context.getString(R.string.vibrate_on_preference_key));
mPlayDtmfTone = (CheckBoxPreference) findPreference(context.getString(R.string.play_dtmf_preference_key));
mDtmfToneLength = (ListPreference) findPreference(context.getString(R.string.dtmf_tone_length_preference_key));
if (hasVibrator()) {
mVibrateWhenRinging.setOnPreferenceChangeListener(this);
} else {
PreferenceScreen ps = getPreferenceScreen();
Preference inCallVibration = findPreference(context.getString(R.string.incall_vibration_category_key));
ps.removePreference(mVibrateWhenRinging);
ps.removePreference(inCallVibration);
mVibrateWhenRinging = null;
}
mPlayDtmfTone.setOnPreferenceChangeListener(this);
mPlayDtmfTone.setChecked(shouldPlayDtmfTone());
TelephonyManager telephonyManager = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) >= Build.VERSION_CODES.M && telephonyManager.canChangeDtmfToneLength() && (telephonyManager.isWorldPhone() || !shouldHideCarrierSettings())) {
mDtmfToneLength.setOnPreferenceChangeListener(this);
mDtmfToneLength.setValueIndex(Settings.System.getInt(context.getContentResolver(), Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, DTMF_TONE_TYPE_NORMAL));
} else {
getPreferenceScreen().removePreference(mDtmfToneLength);
mDtmfToneLength = null;
}
if (!CallRecorderService.isEnabled(getActivity())) {
getPreferenceScreen().removePreference(findPreference(context.getString(R.string.call_recording_category_key)));
}
}
use of android.preference.CheckBoxPreference in project fdroidclient by f-droid.
the class PreferencesFragment method checkSummary.
private void checkSummary(String key, int resId) {
CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
pref.setSummary(resId);
}
use of android.preference.CheckBoxPreference in project android_packages_apps_Settings by LineageOS.
the class SecuritySettings method createPreferenceHierarchy.
private PreferenceScreen createPreferenceHierarchy() {
PreferenceScreen root = this.getPreferenceScreen();
if (root != null) {
root.removeAll();
}
addPreferencesFromResource(R.xml.security_settings);
root = this.getPreferenceScreen();
mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK);
mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS);
mAssistedGps = (CheckBoxPreference) getPreferenceScreen().findPreference(ASSISTED_GPS);
PreferenceManager pm = getPreferenceManager();
// Lock screen
if (!mLockPatternUtils.isSecure()) {
addPreferencesFromResource(R.xml.security_settings_chooser);
} else {
switch(mLockPatternUtils.getKeyguardStoredPasswordQuality()) {
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
addPreferencesFromResource(R.xml.security_settings_pattern);
break;
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
addPreferencesFromResource(R.xml.security_settings_pin);
break;
case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
addPreferencesFromResource(R.xml.security_settings_password);
break;
}
}
// set or change current. Should be common to all unlock preference screens
// mSetOrChange = (PreferenceScreen) pm.findPreference(KEY_UNLOCK_SET_OR_CHANGE);
// visible pattern
mVisiblePattern = (CheckBoxPreference) pm.findPreference(KEY_VISIBLE_PATTERN);
// tactile feedback. Should be common to all unlock preference screens.
mTactileFeedback = (CheckBoxPreference) pm.findPreference(KEY_TACTILE_FEEDBACK_ENABLED);
mVisibleDots = (CheckBoxPreference) pm.findPreference(KEY_VISIBLE_DOTS);
mShowErrorPath = (CheckBoxPreference) pm.findPreference(KEY_SHOW_ERROR_PATH);
mShowCustomMsg = (CheckBoxPreference) pm.findPreference(KEY_SHOW_CUSTOM_MSG);
mCustomMsg = (EditTextPreference) pm.findPreference(KEY_CUSTOM_MSG);
mCustomMsgColor = pm.findPreference(KEY_CUSTOM_MSG_COLOR);
mShowUnlockMsg = (CheckBoxPreference) pm.findPreference(KEY_SHOW_UNLOCK_MSG);
mShowUnlockErrMsg = (CheckBoxPreference) pm.findPreference(KEY_SHOW_UNLOCK_ERR_MSG);
mIncorrectDelay = (ListPreference) pm.findPreference(KEY_INCORRECT_DELAY);
int activePhoneType = TelephonyManager.getDefault().getPhoneType();
// do not display SIM lock for CDMA phone
if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) {
PreferenceScreen simLockPreferences = getPreferenceManager().createPreferenceScreen(this);
simLockPreferences.setTitle(R.string.sim_lock_settings_category);
// Intent to launch SIM lock settings
simLockPreferences.setIntent(new Intent().setClassName(PACKAGE, ICC_LOCK_SETTINGS));
PreferenceCategory simLockCat = new PreferenceCategory(this);
simLockCat.setTitle(R.string.sim_lock_settings_title);
root.addPreference(simLockCat);
simLockCat.addPreference(simLockPreferences);
}
// Passwords
PreferenceCategory passwordsCat = new PreferenceCategory(this);
passwordsCat.setTitle(R.string.security_passwords_title);
root.addPreference(passwordsCat);
CheckBoxPreference showPassword = mShowPassword = new CheckBoxPreference(this);
showPassword.setKey("show_password");
showPassword.setTitle(R.string.show_password);
showPassword.setSummary(R.string.show_password_summary);
showPassword.setPersistent(false);
passwordsCat.addPreference(showPassword);
// Device policies
PreferenceCategory devicePoliciesCat = new PreferenceCategory(this);
devicePoliciesCat.setTitle(R.string.device_admin_title);
root.addPreference(devicePoliciesCat);
Preference deviceAdminButton = new Preference(this);
deviceAdminButton.setTitle(R.string.manage_device_admin);
deviceAdminButton.setSummary(R.string.manage_device_admin_summary);
Intent deviceAdminIntent = new Intent();
deviceAdminIntent.setClass(this, DeviceAdminSettings.class);
deviceAdminButton.setIntent(deviceAdminIntent);
devicePoliciesCat.addPreference(deviceAdminButton);
// Credential storage
PreferenceCategory credentialsCat = new PreferenceCategory(this);
credentialsCat.setTitle(R.string.credentials_category);
root.addPreference(credentialsCat);
mCredentialStorage.createPreferences(credentialsCat, CredentialStorage.TYPE_KEYSTORE);
return root;
}
use of android.preference.CheckBoxPreference in project android_packages_apps_Settings by LineageOS.
the class LanguageSettings method onPreferenceTreeClick.
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
// Input Method stuff
if (Utils.isMonkeyRunning()) {
return false;
}
if (preference instanceof CheckBoxPreference) {
final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
final String id = getInputMethodIdFromKey(chkPref.getKey());
if (chkPref.isChecked()) {
InputMethodInfo selImi = null;
final int N = mInputMethodProperties.size();
for (int i = 0; i < N; i++) {
InputMethodInfo imi = mInputMethodProperties.get(i);
if (id.equals(imi.getId())) {
selImi = imi;
if (isSystemIme(imi)) {
// This is a built-in IME, so no need to warn.
mLastTickedInputMethodId = id;
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
}
}
chkPref.setChecked(false);
if (selImi == null) {
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
if (mDialog == null) {
mDialog = (new AlertDialog.Builder(this)).setTitle(android.R.string.dialog_alert_title).setIcon(android.R.drawable.ic_dialog_alert).setCancelable(true).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
chkPref.setChecked(true);
mLastTickedInputMethodId = id;
}
}).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).create();
} else {
if (mDialog.isShowing()) {
mDialog.dismiss();
}
}
mDialog.setMessage(getString(R.string.ime_security_warning, selImi.getServiceInfo().applicationInfo.loadLabel(getPackageManager())));
mDialog.show();
} else if (id.equals(mLastTickedInputMethodId)) {
mLastTickedInputMethodId = null;
}
} else if (preference instanceof PreferenceScreen) {
if (preference.getIntent() == null) {
PreferenceScreen pref = (PreferenceScreen) preference;
String activityName = pref.getKey();
String packageName = activityName.substring(0, activityName.lastIndexOf("."));
int slash = activityName.indexOf("/");
if (slash > 0) {
packageName = activityName.substring(0, slash);
activityName = activityName.substring(slash + 1);
}
if (activityName.length() > 0) {
Intent i = new Intent(Intent.ACTION_MAIN);
i.setClassName(packageName, activityName);
startActivity(i);
}
}
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
Aggregations