use of org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate in project AndroidChromium by JackyAndroid.
the class TranslatePreferences method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.translate_preferences);
getActivity().setTitle(R.string.google_translate);
setHasOptionsMenu(true);
final Context context = getActivity();
if (context == null)
return;
ChromeSwitchPreference translateSwitch = (ChromeSwitchPreference) findPreference(PREF_TRANSLATE_SWITCH);
boolean isTranslateEnabled = PrefServiceBridge.getInstance().isTranslateEnabled();
translateSwitch.setChecked(isTranslateEnabled);
translateSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PrefServiceBridge.getInstance().setTranslateEnabled((boolean) newValue);
return true;
}
});
translateSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {
@Override
public boolean isPreferenceControlledByPolicy(Preference preference) {
return PrefServiceBridge.getInstance().isTranslateManaged();
}
});
ButtonPreference resetTranslateButton = (ButtonPreference) findPreference(PREF_RESET_TRANSLATE_BUTTON);
resetTranslateButton.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
PrefServiceBridge.getInstance().resetTranslateDefaults();
Toast.makeText(getActivity(), getString(R.string.translate_prefs_toast_description), Toast.LENGTH_SHORT).show();
return true;
}
});
}
use of org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate in project AndroidChromium by JackyAndroid.
the class SavePasswordsPreferences method createSavePasswordsSwitch.
private void createSavePasswordsSwitch() {
mSavePasswordsSwitch = new ChromeSwitchPreference(getActivity(), null);
mSavePasswordsSwitch.setKey(PREF_SAVE_PASSWORDS_SWITCH);
mSavePasswordsSwitch.setTitle(R.string.prefs_saved_passwords);
mSavePasswordsSwitch.setOrder(ORDER_SWITCH);
mSavePasswordsSwitch.setSummaryOn(R.string.text_on);
mSavePasswordsSwitch.setSummaryOff(R.string.text_off);
mSavePasswordsSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PrefServiceBridge.getInstance().setRememberPasswordsEnabled((boolean) newValue);
return true;
}
});
mSavePasswordsSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {
@Override
public boolean isPreferenceControlledByPolicy(Preference preference) {
return PrefServiceBridge.getInstance().isRememberPasswordsManaged();
}
});
getPreferenceScreen().addPreference(mSavePasswordsSwitch);
// Note: setting the switch state before the preference is added to the screen results in
// some odd behavior where the switch state doesn't always match the internal enabled state
// (e.g. the switch will say "On" when save passwords is really turned off), so
// .setChecked() should be called after .addPreference()
mSavePasswordsSwitch.setChecked(PrefServiceBridge.getInstance().isRememberPasswordsEnabled());
}
use of org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate 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.ManagedPreferenceDelegate in project AndroidChromium by JackyAndroid.
the class UsageAndCrashReportsPreferenceFragment method initUsageAndCrashReportsSwitch.
private void initUsageAndCrashReportsSwitch() {
ChromeSwitchPreference usageAndCrashReportsSwitch = (ChromeSwitchPreference) findPreference(PREF_USAGE_AND_CRASH_REPORTS_SWITCH);
boolean enabled = PrivacyPreferencesManager.getInstance().isUsageAndCrashReportingPermittedByUser();
usageAndCrashReportsSwitch.setChecked(enabled);
usageAndCrashReportsSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
UmaSessionStats.changeMetricsReportingConsent((boolean) newValue);
return true;
}
});
usageAndCrashReportsSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {
@Override
public boolean isPreferenceControlledByPolicy(Preference preference) {
return PrefServiceBridge.getInstance().isMetricsReportingManaged();
}
});
}
Aggregations