org.chromium.chrome.browser.preferences.ChromeSwitchPreference Java Examples

The following examples show how to use org.chromium.chrome.browser.preferences.ChromeSwitchPreference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DoNotTrackPreference.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.do_not_track_preferences);
    getActivity().setTitle(R.string.do_not_track_title);

    ChromeSwitchPreference doNotTrackSwitch =
            (ChromeSwitchPreference) findPreference(PREF_DO_NOT_TRACK_SWITCH);

    boolean isDoNotTrackEnabled = PrefServiceBridge.getInstance().isDoNotTrackEnabled();
    doNotTrackSwitch.setChecked(isDoNotTrackEnabled);

    doNotTrackSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PrefServiceBridge.getInstance().setDoNotTrackEnabled((boolean) newValue);
            return true;
        }
    });
}
 
Example #2
Source File: AutofillAndPaymentsPreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceUtils.addPreferencesFromResource(this, R.xml.autofill_and_payments_preferences);
    getActivity().setTitle(R.string.prefs_autofill_and_payments);

    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PersonalDataManager.setAutofillEnabled((boolean) newValue);
            return true;
        }
    });

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS)) {
        Preference pref = new Preference(getActivity());
        pref.setTitle(getActivity().getString(R.string.payment_apps_title));
        pref.setFragment(AndroidPaymentAppsFragment.class.getCanonicalName());
        pref.setShouldDisableView(true);
        pref.setKey(PREF_ANDROID_PAYMENT_APPS);
        getPreferenceScreen().addPreference(pref);
    }
}
 
Example #3
Source File: PhysicalWebPreferenceFragment.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void initPhysicalWebSwitch() {
    ChromeSwitchPreference physicalWebSwitch =
            (ChromeSwitchPreference) findPreference(PREF_PHYSICAL_WEB_SWITCH);

    physicalWebSwitch.setChecked(
            PrivacyPreferencesManager.getInstance().isPhysicalWebEnabled());

    physicalWebSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean enabled = (boolean) newValue;
            if (enabled) {
                PhysicalWebUma.onPrefsFeatureEnabled();
                ensureLocationPermission();
            } else {
                PhysicalWebUma.onPrefsFeatureDisabled();
            }
            PrivacyPreferencesManager.getInstance().setPhysicalWebEnabled(enabled);
            return true;
        }
    });
}
 
Example #4
Source File: DoNotTrackPreference.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.do_not_track_preferences);
    getActivity().setTitle(R.string.do_not_track_title);

    ChromeSwitchPreference doNotTrackSwitch =
            (ChromeSwitchPreference) findPreference(PREF_DO_NOT_TRACK_SWITCH);

    boolean isDoNotTrackEnabled = PrefServiceBridge.getInstance().isDoNotTrackEnabled();
    doNotTrackSwitch.setChecked(isDoNotTrackEnabled);

    doNotTrackSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PrefServiceBridge.getInstance().setDoNotTrackEnabled((boolean) newValue);
            return true;
        }
    });
}
 
Example #5
Source File: AutofillPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.autofill_preferences);
    getActivity().setTitle(R.string.prefs_autofill);

    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PersonalDataManager.setAutofillEnabled((boolean) newValue);
            return true;
        }
    });

    setPreferenceCategoryIcons();
}
 
Example #6
Source File: PhysicalWebPreferenceFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void initPhysicalWebSwitch() {
    ChromeSwitchPreference physicalWebSwitch =
            (ChromeSwitchPreference) findPreference(PREF_PHYSICAL_WEB_SWITCH);

    physicalWebSwitch.setChecked(
            PrivacyPreferencesManager.getInstance().isPhysicalWebEnabled());

    physicalWebSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean enabled = (boolean) newValue;
            if (enabled) {
                PhysicalWebUma.onPrefsFeatureEnabled(getActivity());
                ensureLocationPermission();
            } else {
                PhysicalWebUma.onPrefsFeatureDisabled(getActivity());
            }
            PrivacyPreferencesManager.getInstance().setPhysicalWebEnabled(enabled);
            return true;
        }
    });
}
 
Example #7
Source File: DoNotTrackPreference.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.do_not_track_preferences);
    getActivity().setTitle(R.string.do_not_track_title);

    ChromeSwitchPreference doNotTrackSwitch =
            (ChromeSwitchPreference) findPreference(PREF_DO_NOT_TRACK_SWITCH);

    boolean isDoNotTrackEnabled = PrefServiceBridge.getInstance().isDoNotTrackEnabled();
    doNotTrackSwitch.setChecked(isDoNotTrackEnabled);

    doNotTrackSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PrefServiceBridge.getInstance().setDoNotTrackEnabled((boolean) newValue);
            return true;
        }
    });
}
 
Example #8
Source File: AutofillPreferences.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.autofill_preferences);
    getActivity().setTitle(R.string.prefs_autofill);

    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PersonalDataManager.setAutofillEnabled((boolean) newValue);
            return true;
        }
    });

    setPreferenceCategoryIcons();
}
 
Example #9
Source File: PhysicalWebPreferenceFragment.java    From delion with Apache License 2.0 6 votes vote down vote up
private void initPhysicalWebSwitch() {
    ChromeSwitchPreference physicalWebSwitch =
            (ChromeSwitchPreference) findPreference(PREF_PHYSICAL_WEB_SWITCH);

    physicalWebSwitch.setChecked(
            PrivacyPreferencesManager.getInstance().isPhysicalWebEnabled());

    physicalWebSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean enabled = (boolean) newValue;
            if (enabled) {
                PhysicalWebUma.onPrefsFeatureEnabled(getActivity());
                ensureLocationPermission();
            } else {
                PhysicalWebUma.onPrefsFeatureDisabled(getActivity());
            }
            PrivacyPreferencesManager.getInstance().setPhysicalWebEnabled(enabled);
            return true;
        }
    });
}
 
Example #10
Source File: AutofillAndPaymentsPreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    ((ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH))
            .setChecked(PersonalDataManager.isAutofillEnabled());
    refreshPaymentAppsPref();
}
 
Example #11
Source File: SingleCategoryPreferences.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (READ_WRITE_TOGGLE_KEY.equals(preference.getKey())) {
        if (mCategory.isManaged()) return false;

        if (mCategory.showAutoplaySites()) {
            PrefServiceBridge.getInstance().setAutoplayEnabled((boolean) newValue);
        } else if (mCategory.showBackgroundSyncSites()) {
            PrefServiceBridge.getInstance().setBackgroundSyncEnabled((boolean) newValue);
        } else if (mCategory.showCameraSites()) {
            PrefServiceBridge.getInstance().setCameraEnabled((boolean) newValue);
        } else if (mCategory.showCookiesSites()) {
            PrefServiceBridge.getInstance().setAllowCookiesEnabled((boolean) newValue);
            updateThirdPartyCookiesCheckBox();
        } else if (mCategory.showGeolocationSites()) {
            PrefServiceBridge.getInstance().setAllowLocationEnabled((boolean) newValue);
        } else if (mCategory.showJavaScriptSites()) {
            PrefServiceBridge.getInstance().setJavaScriptEnabled((boolean) newValue);
        } else if (mCategory.showMicrophoneSites()) {
            PrefServiceBridge.getInstance().setMicEnabled((boolean) newValue);
        } else if (mCategory.showNotificationsSites()) {
            PrefServiceBridge.getInstance().setNotificationsEnabled((boolean) newValue);
            updateNotificationsVibrateCheckBox();
        } else if (mCategory.showPopupSites()) {
            PrefServiceBridge.getInstance().setAllowPopupsEnabled((boolean) newValue);
        } else if (mCategory.showProtectedMediaSites()) {
            PrefServiceBridge.getInstance().setProtectedMediaIdentifierEnabled(
                    (boolean) newValue);
        }

        // Categories that support adding exceptions also manage the 'Add site' preference.
        if (mCategory.showAutoplaySites() || mCategory.showBackgroundSyncSites()
                || mCategory.showJavaScriptSites()) {
            if ((boolean) newValue) {
                Preference addException = getPreferenceScreen().findPreference(
                        ADD_EXCEPTION_KEY);
                if (addException != null) {  // Can be null in testing.
                    getPreferenceScreen().removePreference(addException);
                }
            } else {
                getPreferenceScreen().addPreference(
                        new AddExceptionPreference(getActivity(), ADD_EXCEPTION_KEY,
                                getAddExceptionDialogMessage(), this));
            }
        }

        ChromeSwitchPreference globalToggle = (ChromeSwitchPreference)
                getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY);
        updateAllowedHeader(mAllowedSiteCount, !globalToggle.isChecked());

        getInfoForOrigins();
    } else if (THIRD_PARTY_COOKIES_TOGGLE_KEY.equals(preference.getKey())) {
        PrefServiceBridge.getInstance().setBlockThirdPartyCookiesEnabled(!((boolean) newValue));
    } else if (NOTIFICATIONS_VIBRATE_TOGGLE_KEY.equals(preference.getKey())) {
        PrefServiceBridge.getInstance().setNotificationsVibrateEnabled((boolean) newValue);
    }
    return true;
}
 
Example #12
Source File: AutofillPreferences.java    From delion with Apache License 2.0 4 votes vote down vote up
private void updateSummaries() {
    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setChecked(PersonalDataManager.isAutofillEnabled());
}
 
Example #13
Source File: AutofillPreferences.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void updateSummaries() {
    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setChecked(PersonalDataManager.isAutofillEnabled());
}
 
Example #14
Source File: SingleCategoryPreferences.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (READ_WRITE_TOGGLE_KEY.equals(preference.getKey())) {
        if (mCategory.isManaged()) return false;

        if (mCategory.showAutoplaySites()) {
            PrefServiceBridge.getInstance().setAutoplayEnabled((boolean) newValue);
        } else if (mCategory.showBackgroundSyncSites()) {
            PrefServiceBridge.getInstance().setBackgroundSyncEnabled((boolean) newValue);
        } else if (mCategory.showCameraSites()) {
            PrefServiceBridge.getInstance().setCameraEnabled((boolean) newValue);
        } else if (mCategory.showCookiesSites()) {
            PrefServiceBridge.getInstance().setAllowCookiesEnabled((boolean) newValue);
            updateThirdPartyCookiesCheckBox();
        } else if (mCategory.showFullscreenSites()) {
            PrefServiceBridge.getInstance().setFullscreenAllowed((boolean) newValue);
        } else if (mCategory.showGeolocationSites()) {
            PrefServiceBridge.getInstance().setAllowLocationEnabled((boolean) newValue);
        } else if (mCategory.showJavaScriptSites()) {
            PrefServiceBridge.getInstance().setJavaScriptEnabled((boolean) newValue);
        } else if (mCategory.showMicrophoneSites()) {
            PrefServiceBridge.getInstance().setMicEnabled((boolean) newValue);
        } else if (mCategory.showNotificationsSites()) {
            PrefServiceBridge.getInstance().setNotificationsEnabled((boolean) newValue);
            updateNotificationsVibrateCheckBox();
        } else if (mCategory.showPopupSites()) {
            PrefServiceBridge.getInstance().setAllowPopupsEnabled((boolean) newValue);
        } else if (mCategory.showProtectedMediaSites()) {
            PrefServiceBridge.getInstance().setProtectedMediaIdentifierEnabled(
                    (boolean) newValue);
        }

        // Categories that support adding exceptions also manage the 'Add site' preference.
        if (mCategory.showAutoplaySites() || mCategory.showBackgroundSyncSites()
                || mCategory.showJavaScriptSites()) {
            if ((boolean) newValue) {
                Preference addException = getPreferenceScreen().findPreference(
                        ADD_EXCEPTION_KEY);
                if (addException != null) {  // Can be null in testing.
                    getPreferenceScreen().removePreference(addException);
                }
            } else {
                getPreferenceScreen().addPreference(
                        new AddExceptionPreference(getActivity(), ADD_EXCEPTION_KEY,
                                getAddExceptionDialogMessage(), this));
            }
        }

        ChromeSwitchPreference globalToggle = (ChromeSwitchPreference)
                getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY);
        updateAllowedHeader(mAllowedSiteCount, !globalToggle.isChecked());

        getInfoForOrigins();
    } else if (THIRD_PARTY_COOKIES_TOGGLE_KEY.equals(preference.getKey())) {
        PrefServiceBridge.getInstance().setBlockThirdPartyCookiesEnabled(!((boolean) newValue));
    } else if (NOTIFICATIONS_VIBRATE_TOGGLE_KEY.equals(preference.getKey())) {
        PrefServiceBridge.getInstance().setNotificationsVibrateEnabled((boolean) newValue);
    }
    return true;
}
 
Example #15
Source File: SyncCustomizationFragment.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the sync action bar switch to enable/disable sync.
 *
 * @return the mActionBarSwitch
 */
@VisibleForTesting
public ChromeSwitchPreference getSyncSwitchPreference() {
    return mSyncSwitchPreference;
}
 
Example #16
Source File: SyncCustomizationFragment.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the sync action bar switch to enable/disable sync.
 *
 * @return the mActionBarSwitch
 */
@VisibleForTesting
public ChromeSwitchPreference getSyncSwitchPreference() {
    return mSyncSwitchPreference;
}
 
Example #17
Source File: SyncCustomizationFragment.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the sync action bar switch to enable/disable sync.
 *
 * @return the mActionBarSwitch
 */
@VisibleForTesting
public ChromeSwitchPreference getSyncSwitchPreference() {
    return mSyncSwitchPreference;
}