use of android.preference.Preference in project AndroidChromium by JackyAndroid.
the class UsbDevicePreferences method resetList.
private void resetList() {
getPreferenceScreen().removeAll();
addPreferencesFromResource(R.xml.usb_device_preferences);
PreferenceScreen preferenceScreen = getPreferenceScreen();
Preference header = preferenceScreen.findPreference(PREF_OBJECT_NAME);
header.setTitle(mUsbInfo.getName());
header.setOnPreferenceClickListener(this);
for (int i = 0; i < mSites.size(); ++i) {
Website site = mSites.get(i);
Preference preference = new WebsitePreference(getActivity(), site, mCategory);
preference.getExtras().putSerializable(SingleWebsitePreferences.EXTRA_SITE, site);
preference.setFragment(SingleWebsitePreferences.class.getCanonicalName());
preferenceScreen.addPreference(preference);
}
// Force this list to be reloaded if the activity is resumed.
mSites = null;
}
use of android.preference.Preference in project AndroidChromium by JackyAndroid.
the class SingleWebsitePreferences method resetSite.
/**
* Resets the current site, clearing all permissions and storage used (inc. cookies).
*/
@VisibleForTesting
protected void resetSite() {
if (getActivity() == null)
return;
// Clear the screen.
// TODO(mvanouwerkerk): Refactor this class so that it does not depend on the screen state
// for its logic. This class should maintain its own data model, and only update the screen
// after a change is made.
PreferenceScreen screen = getPreferenceScreen();
for (String key : PERMISSION_PREFERENCE_KEYS) {
Preference preference = screen.findPreference(key);
if (preference != null)
screen.removePreference(preference);
}
// Clear the permissions.
mSite.setAutoplayPermission(ContentSetting.DEFAULT);
mSite.setBackgroundSyncPermission(ContentSetting.DEFAULT);
mSite.setCameraPermission(ContentSetting.DEFAULT);
mSite.setCookiePermission(ContentSetting.DEFAULT);
WebsitePreferenceBridge.nativeClearCookieData(mSite.getAddress().getTitle());
mSite.setFullscreenPermission(ContentSetting.DEFAULT);
mSite.setGeolocationPermission(ContentSetting.DEFAULT);
mSite.setJavaScriptPermission(ContentSetting.DEFAULT);
mSite.setKeygenPermission(ContentSetting.DEFAULT);
mSite.setMicrophonePermission(ContentSetting.DEFAULT);
mSite.setMidiPermission(ContentSetting.DEFAULT);
mSite.setNotificationPermission(ContentSetting.DEFAULT);
mSite.setPopupPermission(ContentSetting.DEFAULT);
mSite.setProtectedMediaIdentifierPermission(ContentSetting.DEFAULT);
for (UsbInfo info : mSite.getUsbInfo()) info.revoke();
// Clear the storage and finish the activity if necessary.
if (mSite.getTotalUsage() > 0) {
clearStoredData();
} else {
// Clearing stored data implies popping back to parent menu if there
// is nothing left to show. Therefore, we only need to explicitly
// close the activity if there's no stored data to begin with.
getActivity().finish();
}
}
use of android.preference.Preference in project AndroidChromium by JackyAndroid.
the class SiteSettingsPreferences method updatePreferenceStates.
private void updatePreferenceStates() {
PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance();
// Translate preference.
Preference translatePref = findPreference(TRANSLATE_KEY);
if (translatePref != null) {
setTranslateStateSummary(translatePref);
}
// Preferences that navigate to Website Settings.
List<String> websitePrefs = new ArrayList<String>();
if (mMediaSubMenu) {
websitePrefs.add(PROTECTED_CONTENT_KEY);
websitePrefs.add(AUTOPLAY_KEY);
} else {
// When showing the main menu, only one of these two will be visible, at most.
if (mProtectedContentMenuAvailable && !mAutoplayMenuAvailable) {
websitePrefs.add(PROTECTED_CONTENT_KEY);
} else if (mAutoplayMenuAvailable && !mProtectedContentMenuAvailable) {
websitePrefs.add(AUTOPLAY_KEY);
}
websitePrefs.add(BACKGROUND_SYNC_KEY);
websitePrefs.add(CAMERA_KEY);
websitePrefs.add(COOKIES_KEY);
websitePrefs.add(FULLSCREEN_KEY);
websitePrefs.add(JAVASCRIPT_KEY);
websitePrefs.add(LOCATION_KEY);
websitePrefs.add(MICROPHONE_KEY);
websitePrefs.add(NOTIFICATIONS_KEY);
websitePrefs.add(POPUPS_KEY);
}
// associated content settings entry.
for (String prefName : websitePrefs) {
Preference p = findPreference(prefName);
boolean checked = false;
if (AUTOPLAY_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isAutoplayEnabled();
} else if (BACKGROUND_SYNC_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isBackgroundSyncAllowed();
} else if (CAMERA_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isCameraEnabled();
} else if (COOKIES_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isAcceptCookiesEnabled();
} else if (FULLSCREEN_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isFullscreenAllowed();
} else if (JAVASCRIPT_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().javaScriptEnabled();
} else if (LOCATION_KEY.equals(prefName)) {
checked = LocationSettings.getInstance().areAllLocationSettingsEnabled();
} else if (MICROPHONE_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isMicEnabled();
} else if (NOTIFICATIONS_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isNotificationsEnabled();
} else if (POPUPS_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().popupsEnabled();
} else if (PROTECTED_CONTENT_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isProtectedMediaIdentifierEnabled();
}
int contentType = keyToContentSettingsType(prefName);
p.setTitle(ContentSettingsResources.getTitle(contentType));
p.setOnPreferenceClickListener(this);
// Disable autoplay preference if Data Saver is ON.
if (AUTOPLAY_KEY.equals(prefName) && DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) {
p.setSummary(ContentSettingsResources.getAutoplayDisabledByDataSaverSummary());
p.setEnabled(false);
} else if (COOKIES_KEY.equals(prefName) && checked && prefServiceBridge.isBlockThirdPartyCookiesEnabled()) {
p.setSummary(ContentSettingsResources.getCookieAllowedExceptThirdPartySummary());
} else if (LOCATION_KEY.equals(prefName) && checked && prefServiceBridge.isLocationAllowedByPolicy()) {
p.setSummary(ContentSettingsResources.getGeolocationAllowedSummary());
} else {
p.setSummary(ContentSettingsResources.getCategorySummary(contentType, checked));
}
if (p.isEnabled()) {
p.setIcon(ContentSettingsResources.getIcon(contentType));
} else {
p.setIcon(ContentSettingsResources.getDisabledIcon(contentType, getResources()));
}
}
Preference p = findPreference(ALL_SITES_KEY);
if (p != null)
p.setOnPreferenceClickListener(this);
p = findPreference(MEDIA_KEY);
if (p != null)
p.setOnPreferenceClickListener(this);
// TODO(finnur): Re-move this for Storage once it can be moved to the 'Usage' menu.
p = findPreference(STORAGE_KEY);
if (p != null)
p.setOnPreferenceClickListener(this);
p = findPreference(USB_KEY);
if (p != null)
p.setOnPreferenceClickListener(this);
}
use of android.preference.Preference in project AndroidChromium by JackyAndroid.
the class AutofillServerProfilePreferences method onCreate.
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
addPreferencesFromResource(R.xml.autofill_server_profile_preferences);
getActivity().setTitle(R.string.autofill_edit_profile);
// We know which card to display based on the GUID stuffed in
// our extras by AutofillPreferences.
Bundle extras = getArguments();
if (extras != null) {
mGUID = extras.getString(AutofillPreferences.AUTOFILL_GUID);
}
assert mGUID != null;
AutofillProfile profile = PersonalDataManager.getInstance().getProfile(mGUID);
if (profile == null) {
getActivity().finish();
return;
}
assert !profile.getIsLocal();
Preference profileDescription = findPreference(PREF_SERVER_PROFILE_DESCRIPTION);
profileDescription.setTitle(profile.getFullName());
profileDescription.setSummary(profile.getStreetAddress());
findPreference(PREF_SERVER_PROFILE_EDIT_LINK).setOnPreferenceClickListener(this);
}
use of android.preference.Preference 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);
}
Aggregations