use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by omnirom.
the class CurrentDreamPreferenceControllerTest method gearHidesIfActiveDreamInfoHasNoOptions.
@Test
public void gearHidesIfActiveDreamInfoHasNoOptions() {
mDreamInfo.settingsComponentName = null;
mDreamInfo.isActive = true;
when(mBackend.getDreamInfos()).thenReturn(new ArrayList<>(Arrays.asList(mDreamInfo)));
GearPreference mockPref = mock(GearPreference.class);
ArgumentCaptor<GearPreference.OnGearClickListener> captor = ArgumentCaptor.forClass(GearPreference.OnGearClickListener.class);
// setting a null onGearClickListener removes the gear from view
mController.updateState(mockPref);
verify(mockPref).setOnGearClickListener(captor.capture());
captor.getAllValues().forEach(listener -> assertThat(listener).isNull());
}
use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by omnirom.
the class SecuritySettings method createPreferenceHierarchy.
/**
* Important!
*
* Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
* logic or adding/removing preferences here.
*/
private PreferenceScreen createPreferenceHierarchy() {
PreferenceScreen root = getPreferenceScreen();
if (root != null) {
root.removeAll();
}
addPreferencesFromResource(R.xml.security_settings);
root = getPreferenceScreen();
// Add category for security status
addPreferencesFromResource(R.xml.security_settings_status);
// Add options for lock/unlock screen
final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, mManagedPasswordProvider, MY_USER_ID);
addPreferencesFromResource(resid);
// DO or PO installed in the user may disallow to change password.
disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, MY_USER_ID);
mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID);
if (mProfileChallengeUserId != UserHandle.USER_NULL && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
addPreferencesFromResource(R.xml.security_settings_profile);
addPreferencesFromResource(R.xml.security_settings_unification);
final int profileResid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, mManagedPasswordProvider, mProfileChallengeUserId);
addPreferencesFromResource(profileResid);
maybeAddFingerprintPreference(root, mProfileChallengeUserId);
if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
final Preference lockPreference = root.findPreference(KEY_UNLOCK_SET_OR_CHANGE_PROFILE);
final String summary = getContext().getString(R.string.lock_settings_profile_unified_summary);
lockPreference.setSummary(summary);
lockPreference.setEnabled(false);
// PO may disallow to change password for the profile, but screen lock and managed
// profile's lock is the same. Disable main "Screen lock" menu.
disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, mProfileChallengeUserId);
} else {
// PO may disallow to change profile password, and the profile's password is
// separated from screen lock password. Disable profile specific "Screen lock" menu.
disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE_PROFILE, mProfileChallengeUserId);
}
}
Preference unlockSetOrChange = findPreference(KEY_UNLOCK_SET_OR_CHANGE);
if (unlockSetOrChange instanceof GearPreference) {
((GearPreference) unlockSetOrChange).setOnGearClickListener(this);
}
mIsAdmin = mUm.isAdminUser();
// Fingerprint and trust agents
int numberOfTrustAgent = 0;
PreferenceGroup securityCategory = (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
if (securityCategory != null) {
maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
numberOfTrustAgent = addTrustAgentSettings(securityCategory);
setLockscreenPreferencesSummary(securityCategory);
}
mVisiblePatternProfile = (SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN_PROFILE);
mUnifyProfile = (SwitchPreference) root.findPreference(KEY_UNIFICATION);
// Append the rest of the settings
addPreferencesFromResource(R.xml.security_settings_misc);
// Do not display SIM lock for devices without an Icc card
TelephonyManager tm = TelephonyManager.getDefault();
CarrierConfigManager cfgMgr = (CarrierConfigManager) getActivity().getSystemService(Context.CARRIER_CONFIG_SERVICE);
PersistableBundle b = cfgMgr.getConfig();
if (!mIsAdmin || !isSimIccReady() || b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
root.removePreference(root.findPreference(KEY_SIM_LOCK));
} else {
// Disable SIM lock if there is no ready SIM card.
root.findPreference(KEY_SIM_LOCK).setEnabled(isSimReady());
}
if (Settings.System.getInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
root.findPreference(KEY_SCREEN_PINNING).setSummary(getResources().getString(R.string.switch_on_text));
}
// Encryption status of device
if (LockPatternUtils.isDeviceEncryptionEnabled()) {
root.findPreference(KEY_ENCRYPTION_AND_CREDENTIALS).setSummary(R.string.encryption_and_credential_settings_summary);
} else {
root.findPreference(KEY_ENCRYPTION_AND_CREDENTIALS).setSummary(R.string.summary_placeholder);
}
// Show password
mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD);
// Credential storage
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
// Advanced Security features
initTrustAgentPreference(root, numberOfTrustAgent);
// The above preferences come and go based on security state, so we need to update
// the index. This call is expected to be fairly cheap, but we may want to do something
// smarter in the future.
final Activity activity = getActivity();
FeatureFactory.getFactory(activity).getSearchFeatureProvider().getIndexingManager(activity).updateFromClassNameResource(SecuritySettings.class.getName(), true);
PreferenceGroup securityStatusPreferenceGroup = (PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(getActivity(), getPrefContext(), getMetricsCategory(), CategoryKey.CATEGORY_SECURITY);
int numSecurityStatusPrefs = 0;
if (tilePrefs != null && !tilePrefs.isEmpty()) {
for (Preference preference : tilePrefs) {
if (!TextUtils.isEmpty(preference.getKey()) && preference.getKey().startsWith(SECURITY_STATUS_KEY_PREFIX)) {
// category.
if (preference.getKey().equals("security_status_security_patch_level")) {
continue;
}
securityStatusPreferenceGroup.addPreference(preference);
numSecurityStatusPrefs++;
} else {
// Other injected settings are placed under the Security preference screen.
root.addPreference(preference);
}
}
}
if (numSecurityStatusPrefs == 0) {
root.removePreference(securityStatusPreferenceGroup);
} else if (numSecurityStatusPrefs > 0) {
// Update preference data with tile data. Security feature provider only updates the
// data if it actually needs to be changed.
mSecurityFeatureProvider.updatePreferences(getActivity(), root, mDashboardFeatureProvider.getTilesForCategory(CategoryKey.CATEGORY_SECURITY));
}
for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]);
if (pref != null)
pref.setOnPreferenceChangeListener(this);
}
mLocationcontroller.displayPreference(root);
mManageDeviceAdminPreferenceController.updateState(root.findPreference(KEY_MANAGE_DEVICE_ADMIN));
mEnterprisePrivacyPreferenceController.displayPreference(root);
mEnterprisePrivacyPreferenceController.onResume();
final Preference encryptioncredential = root.findPreference(KEY_ENCRYPTION_AND_CREDENTIALS);
if (LockPatternUtils.isDeviceEncryptionEnabled()) {
final String summaryencrypt = getContext().getString(R.string.custom_encryption_and_credential_settings_summary_on);
encryptioncredential.setSummary(summaryencrypt);
} else {
final String summarydecrypt = getContext().getString(R.string.custom_encryption_and_credential_settings_summary_off);
encryptioncredential.setSummary(summarydecrypt);
}
return root;
}
use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by DirtyUnicorns.
the class CurrentDreamPreferenceControllerTest method gearShowsIfActiveDreamInfoHasOptions.
@Test
public void gearShowsIfActiveDreamInfoHasOptions() {
mDreamInfo.settingsComponentName = mock(ComponentName.class);
mDreamInfo.isActive = true;
when(mBackend.getDreamInfos()).thenReturn(new ArrayList<>(Arrays.asList(mDreamInfo)));
GearPreference mockPref = mock(GearPreference.class);
ArgumentCaptor<GearPreference.OnGearClickListener> captor = ArgumentCaptor.forClass(GearPreference.OnGearClickListener.class);
// verify that updateState sets a non-null gear click listener
mController.updateState(mockPref);
verify(mockPref).setOnGearClickListener(captor.capture());
captor.getAllValues().forEach(listener -> assertThat(listener).isNotNull());
}
use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by DirtyUnicorns.
the class CurrentDreamPreferenceControllerTest method gearHidesIfActiveDreamInfoHasNoOptions.
@Test
public void gearHidesIfActiveDreamInfoHasNoOptions() {
mDreamInfo.settingsComponentName = null;
mDreamInfo.isActive = true;
when(mBackend.getDreamInfos()).thenReturn(new ArrayList<>(Arrays.asList(mDreamInfo)));
GearPreference mockPref = mock(GearPreference.class);
ArgumentCaptor<GearPreference.OnGearClickListener> captor = ArgumentCaptor.forClass(GearPreference.OnGearClickListener.class);
// setting a null onGearClickListener removes the gear from view
mController.updateState(mockPref);
verify(mockPref).setOnGearClickListener(captor.capture());
captor.getAllValues().forEach(listener -> assertThat(listener).isNull());
}
use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by DirtyUnicorns.
the class TextToSpeechSettings method initSettings.
private void initSettings() {
final ContentResolver resolver = getContentResolver();
// Set up the default rate and pitch.
mDefaultRate = android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_RATE, TextToSpeech.Engine.DEFAULT_RATE);
mDefaultPitch = android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH);
mDefaultRatePref.setProgress(getSeekBarProgressFromValue(KEY_DEFAULT_RATE, mDefaultRate));
mDefaultRatePref.setOnPreferenceChangeListener(this);
mDefaultRatePref.setMax(getSeekBarProgressFromValue(KEY_DEFAULT_RATE, MAX_SPEECH_RATE));
mDefaultPitchPref.setProgress(getSeekBarProgressFromValue(KEY_DEFAULT_PITCH, mDefaultPitch));
mDefaultPitchPref.setOnPreferenceChangeListener(this);
mDefaultPitchPref.setMax(getSeekBarProgressFromValue(KEY_DEFAULT_PITCH, MAX_SPEECH_PITCH));
if (mTts != null) {
mCurrentEngine = mTts.getCurrentEngine();
mTts.setSpeechRate(mDefaultRate / 100.0f);
mTts.setPitch(mDefaultPitch / 100.0f);
}
SettingsActivity activity = null;
if (getActivity() instanceof SettingsActivity) {
activity = (SettingsActivity) getActivity();
} else {
throw new IllegalStateException("TextToSpeechSettings used outside a " + "Settings");
}
if (mCurrentEngine != null) {
EngineInfo info = mEnginesHelper.getEngineInfo(mCurrentEngine);
Preference mEnginePreference = findPreference(KEY_TTS_ENGINE_PREFERENCE);
((GearPreference) mEnginePreference).setOnGearClickListener(this);
mEnginePreference.setSummary(info.label);
}
checkVoiceData(mCurrentEngine);
}
Aggregations