use of org.chromium.chrome.browser.preferences.ChromeSwitchPreference in project AndroidChromium by JackyAndroid.
the class SingleCategoryPreferences method onPreferenceChange.
// OnPreferenceChangeListener:
@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;
}
use of org.chromium.chrome.browser.preferences.ChromeSwitchPreference in project AndroidChromium by JackyAndroid.
the class DoNotTrackPreference method onCreate.
@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;
}
});
}
use of org.chromium.chrome.browser.preferences.ChromeSwitchPreference in project AndroidChromium by JackyAndroid.
the class DataReductionPreferences method createDataReductionSwitch.
private void createDataReductionSwitch(boolean isEnabled) {
final ChromeSwitchPreference dataReductionSwitch = new ChromeSwitchPreference(getActivity(), null);
dataReductionSwitch.setKey(PREF_DATA_REDUCTION_SWITCH);
dataReductionSwitch.setSummaryOn(R.string.text_on);
dataReductionSwitch.setSummaryOff(R.string.text_off);
dataReductionSwitch.setDrawDivider(true);
dataReductionSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(dataReductionSwitch.getContext(), (boolean) newValue);
DataReductionPreferences.this.updatePreferences((boolean) newValue);
return true;
}
});
dataReductionSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {
@Override
public boolean isPreferenceControlledByPolicy(Preference preference) {
return CommandLine.getInstance().hasSwitch(ENABLE_DATA_REDUCTION_PROXY) || DataReductionProxySettings.getInstance().isDataReductionProxyManaged();
}
});
getPreferenceScreen().addPreference(dataReductionSwitch);
// 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 data reduction is really turned off), so
// .setChecked() should be called after .addPreference()
dataReductionSwitch.setChecked(isEnabled);
}
use of org.chromium.chrome.browser.preferences.ChromeSwitchPreference in project AndroidChromium by JackyAndroid.
the class SyncCustomizationFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mProfileSyncService = ProfileSyncService.get();
assert mProfileSyncService != null;
mIsBackendInitialized = mProfileSyncService.isBackendInitialized();
mIsPassphraseRequired = mIsBackendInitialized && mProfileSyncService.isPassphraseRequiredForDecryption();
getActivity().setTitle(R.string.sign_in_sync);
View view = super.onCreateView(inflater, container, savedInstanceState);
addPreferencesFromResource(R.xml.sync_customization_preferences);
mSyncEverything = (SwitchPreference) findPreference(PREFERENCE_SYNC_EVERYTHING);
mSyncAutofill = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_AUTOFILL);
mSyncBookmarks = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_BOOKMARKS);
mSyncOmnibox = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_OMNIBOX);
mSyncPasswords = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_PASSWORDS);
mSyncRecentTabs = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_RECENT_TABS);
mSyncSettings = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_SETTINGS);
mPaymentsIntegration = (CheckBoxPreference) findPreference(PREFERENCE_PAYMENTS_INTEGRATION);
mSyncEncryption = findPreference(PREFERENCE_ENCRYPTION);
mSyncEncryption.setOnPreferenceClickListener(this);
mManageSyncData = findPreference(PREFERENCE_SYNC_MANAGE_DATA);
mManageSyncData.setOnPreferenceClickListener(this);
mSyncErrorCard = findPreference(PREFERENCE_SYNC_ERROR_CARD);
mSyncErrorCard.setOnPreferenceClickListener(this);
mAllTypes = new CheckBoxPreference[] { mSyncAutofill, mSyncBookmarks, mSyncOmnibox, mSyncPasswords, mSyncRecentTabs, mSyncSettings, mPaymentsIntegration };
mSyncEverything.setOnPreferenceChangeListener(this);
for (CheckBoxPreference type : mAllTypes) {
type.setOnPreferenceChangeListener(this);
}
mSyncSwitchPreference = (ChromeSwitchPreference) findPreference(PREF_SYNC_SWITCH);
mSyncSwitchPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
assert canDisableSync();
if ((boolean) newValue) {
mProfileSyncService.requestStart();
} else {
stopSync();
}
// Must be done asynchronously because the switch state isn't updated
// until after this function exits.
new Handler().post(new Runnable() {
@Override
public void run() {
updateSyncStateFromSwitch();
}
});
return true;
}
});
mSyncedAccountPreference = (SyncedAccountPreference) findPreference(PREFERENCE_SYNC_ACCOUNT_LIST);
mSyncedAccountPreference.setOnPreferenceChangeListener(new SyncAccountSwitcher(getActivity(), mSyncedAccountPreference));
return view;
}
use of org.chromium.chrome.browser.preferences.ChromeSwitchPreference in project AndroidChromium by JackyAndroid.
the class AutofillPreferences method onCreate.
@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();
}
Aggregations