Search in sources :

Example 6 with ManagedPreferenceDelegate

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;
        }
    });
}
Also used : Context(android.content.Context) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ButtonPreference(org.chromium.chrome.browser.preferences.ButtonPreference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) ButtonPreference(org.chromium.chrome.browser.preferences.ButtonPreference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 7 with ManagedPreferenceDelegate

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());
}
Also used : ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) ChromeBasePreference(org.chromium.chrome.browser.preferences.ChromeBasePreference) ChromeBaseCheckBoxPreference(org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference) Preference(android.preference.Preference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 8 with ManagedPreferenceDelegate

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();
        }
    });
}
Also used : ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 9 with ManagedPreferenceDelegate

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();
        }
    });
}
Also used : ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Aggregations

Preference (android.preference.Preference)9 ManagedPreferenceDelegate (org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate)9 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)7 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)6 ChromeBaseCheckBoxPreference (org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference)4 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)4 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)2 Context (android.content.Context)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 ButtonPreference (org.chromium.chrome.browser.preferences.ButtonPreference)1 PrefServiceBridge (org.chromium.chrome.browser.preferences.PrefServiceBridge)1 SyncPreference (org.chromium.chrome.browser.preferences.SyncPreference)1