use of org.chromium.chrome.browser.preferences.ChromeSwitchPreference in project AndroidChromium by JackyAndroid.
the class ContextualSearchPreferenceFragment method initContextualSearchSwitch.
private void initContextualSearchSwitch() {
ChromeSwitchPreference contextualSearchSwitch = (ChromeSwitchPreference) findPreference(PREF_CONTEXTUAL_SEARCH_SWITCH);
boolean isContextualSearchEnabled = !PrefServiceBridge.getInstance().isContextualSearchDisabled();
contextualSearchSwitch.setChecked(isContextualSearchEnabled);
contextualSearchSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PrefServiceBridge.getInstance().setContextualSearchState((boolean) newValue);
ContextualSearchUma.logPreferenceChange((boolean) newValue);
return true;
}
});
contextualSearchSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {
@Override
public boolean isPreferenceControlledByPolicy(Preference preference) {
return PrefServiceBridge.getInstance().isContextualSearchDisabledByPolicy();
}
});
}
use of org.chromium.chrome.browser.preferences.ChromeSwitchPreference in project AndroidChromium by JackyAndroid.
the class SingleCategoryPreferences method configureGlobalToggles.
private void configureGlobalToggles() {
// Only some have a global toggle at the top.
ChromeSwitchPreference globalToggle = (ChromeSwitchPreference) getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY);
// Configure/hide the third-party cookie toggle, as needed.
Preference thirdPartyCookies = getPreferenceScreen().findPreference(THIRD_PARTY_COOKIES_TOGGLE_KEY);
if (mCategory.showCookiesSites()) {
thirdPartyCookies.setOnPreferenceChangeListener(this);
updateThirdPartyCookiesCheckBox();
} else {
getPreferenceScreen().removePreference(thirdPartyCookies);
}
// Configure/hide the notifications vibrate toggle, as needed.
Preference notificationsVibrate = getPreferenceScreen().findPreference(NOTIFICATIONS_VIBRATE_TOGGLE_KEY);
if (mCategory.showNotificationsSites()) {
notificationsVibrate.setOnPreferenceChangeListener(this);
updateNotificationsVibrateCheckBox();
} else {
getPreferenceScreen().removePreference(notificationsVibrate);
}
// Show/hide the link that explains protected media settings, as needed.
if (!mCategory.showProtectedMediaSites()) {
getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(EXPLAIN_PROTECTED_MEDIA_KEY));
}
if (mCategory.showAllSites() || mCategory.showStorageSites()) {
getPreferenceScreen().removePreference(globalToggle);
getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(ALLOWED_GROUP));
getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(BLOCKED_GROUP));
} else {
// When this menu opens, make sure the Blocked list is collapsed.
if (!mGroupByAllowBlock) {
mBlockListExpanded = false;
mAllowListExpanded = true;
}
mGroupByAllowBlock = true;
PreferenceGroup allowedGroup = (PreferenceGroup) getPreferenceScreen().findPreference(ALLOWED_GROUP);
PreferenceGroup blockedGroup = (PreferenceGroup) getPreferenceScreen().findPreference(BLOCKED_GROUP);
if (mCategory.showPermissionBlockedMessage(getActivity())) {
getPreferenceScreen().removePreference(globalToggle);
getPreferenceScreen().removePreference(allowedGroup);
getPreferenceScreen().removePreference(blockedGroup);
// Show the link to system settings since permission is disabled.
ChromeBasePreference osWarning = new ChromeBasePreference(getActivity(), null);
ChromeBasePreference osWarningExtra = new ChromeBasePreference(getActivity(), null);
mCategory.configurePermissionIsOffPreferences(osWarning, osWarningExtra, getActivity(), true);
if (osWarning.getTitle() != null) {
getPreferenceScreen().addPreference(osWarning);
}
if (osWarningExtra.getTitle() != null) {
getPreferenceScreen().addPreference(osWarningExtra);
}
} else {
allowedGroup.setOnPreferenceClickListener(this);
blockedGroup.setOnPreferenceClickListener(this);
// Determine what toggle to use and what it should display.
int contentType = mCategory.toContentSettingsType();
globalToggle.setOnPreferenceChangeListener(this);
globalToggle.setTitle(ContentSettingsResources.getTitle(contentType));
if (mCategory.showGeolocationSites() && PrefServiceBridge.getInstance().isLocationAllowedByPolicy()) {
globalToggle.setSummaryOn(ContentSettingsResources.getGeolocationAllowedSummary());
} else {
globalToggle.setSummaryOn(ContentSettingsResources.getEnabledSummary(contentType));
}
globalToggle.setSummaryOff(ContentSettingsResources.getDisabledSummary(contentType));
if (mCategory.isManaged() && !mCategory.isManagedByCustodian()) {
globalToggle.setIcon(R.drawable.controlled_setting_mandatory);
}
if (mCategory.showAutoplaySites()) {
globalToggle.setChecked(PrefServiceBridge.getInstance().isAutoplayEnabled());
} else if (mCategory.showBackgroundSyncSites()) {
globalToggle.setChecked(PrefServiceBridge.getInstance().isBackgroundSyncAllowed());
} else if (mCategory.showCameraSites()) {
globalToggle.setChecked(PrefServiceBridge.getInstance().isCameraEnabled());
} else if (mCategory.showCookiesSites()) {
globalToggle.setChecked(PrefServiceBridge.getInstance().isAcceptCookiesEnabled());
} else if (mCategory.showFullscreenSites()) {
globalToggle.setChecked(PrefServiceBridge.getInstance().isFullscreenAllowed());
// The fullscreen global toggle cannot be disabled.
// TODO(mgiuca): Remove this setting entirely (requires deleting all the data;
// see https://crbug.com/591896).
globalToggle.setEnabled(false);
} else if (mCategory.showGeolocationSites()) {
globalToggle.setChecked(LocationSettings.getInstance().isChromeLocationSettingEnabled());
} else if (mCategory.showJavaScriptSites()) {
globalToggle.setChecked(PrefServiceBridge.getInstance().javaScriptEnabled());
} else if (mCategory.showMicrophoneSites()) {
globalToggle.setChecked(PrefServiceBridge.getInstance().isMicEnabled());
} else if (mCategory.showNotificationsSites()) {
globalToggle.setChecked(PrefServiceBridge.getInstance().isNotificationsEnabled());
} else if (mCategory.showPopupSites()) {
globalToggle.setChecked(PrefServiceBridge.getInstance().popupsEnabled());
} else if (mCategory.showProtectedMediaSites()) {
globalToggle.setChecked(PrefServiceBridge.getInstance().isProtectedMediaIdentifierEnabled());
}
}
}
}
Aggregations