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);
}
use of android.preference.Preference in project AndroidChromium by JackyAndroid.
the class AutofillPreferences method rebuildProfileList.
// Always clears the list before building/rebuilding.
private void rebuildProfileList() {
// Add an edit preference for each current Chrome profile.
PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
profileCategory.removeAll();
for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
// Add an item on the current page...
Preference pref = new Preference(getActivity());
pref.setTitle(profile.getFullName());
pref.setSummary(profile.getLabel());
if (profile.getIsLocal()) {
pref.setFragment(AutofillProfileEditor.class.getName());
} else {
pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
pref.setFragment(AutofillServerProfilePreferences.class.getName());
}
Bundle args = pref.getExtras();
args.putString(AUTOFILL_GUID, profile.getGUID());
profileCategory.addPreference(pref);
}
}
use of android.preference.Preference in project AndroidChromium by JackyAndroid.
the class AutofillPreferences method rebuildCreditCardList.
private void rebuildCreditCardList() {
PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_CREDIT_CARDS);
profileCategory.removeAll();
for (CreditCard card : PersonalDataManager.getInstance().getCreditCardsForSettings()) {
// Add an item on the current page...
Preference pref = new Preference(getActivity());
pref.setTitle(card.getObfuscatedNumber());
pref.setSummary(card.getFormattedExpirationDate(getActivity()));
if (card.getIsLocal()) {
pref.setFragment(AutofillLocalCardEditor.class.getName());
} else {
pref.setFragment(AutofillServerCardEditor.class.getName());
pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
}
Bundle args = pref.getExtras();
args.putString(AUTOFILL_GUID, card.getGUID());
profileCategory.addPreference(pref);
}
}
use of android.preference.Preference in project AndroidChromium by JackyAndroid.
the class SignInPreference method update.
/**
* Updates the title, summary, and image based on the current sign-in state.
*/
private void update() {
String title;
String summary;
String fragment;
Account account = ChromeSigninController.get(getContext()).getSignedInUser();
if (account == null) {
title = getContext().getString(R.string.sign_in_to_chrome);
summary = getContext().getString(R.string.sign_in_to_chrome_summary);
fragment = null;
} else {
summary = SyncPreference.getSyncStatusSummary(getContext());
fragment = AccountManagementFragment.class.getName();
title = AccountManagementFragment.getCachedUserName(account.name);
if (title == null) {
final Profile profile = Profile.getLastUsedProfile();
String cachedName = ProfileDownloader.getCachedFullName(profile);
Bitmap cachedBitmap = ProfileDownloader.getCachedAvatar(profile);
if (TextUtils.isEmpty(cachedName) || cachedBitmap == null) {
AccountManagementFragment.startFetchingAccountInformation(getContext(), profile, account.name);
}
title = TextUtils.isEmpty(cachedName) ? account.name : cachedName;
}
}
setTitle(title);
setSummary(summary);
setFragment(fragment);
updateSyncStatusIcon();
ChromeSigninController signinController = ChromeSigninController.get(getContext());
boolean enabled = signinController.isSignedIn() || SigninManager.get(getContext()).isSignInAllowed();
if (mViewEnabled != enabled) {
mViewEnabled = enabled;
notifyChanged();
}
if (!enabled)
setFragment(null);
if (SigninManager.get(getContext()).isSigninDisabledByPolicy()) {
setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());
} else {
Resources resources = getContext().getResources();
Bitmap bitmap = AccountManagementFragment.getUserPicture(signinController.getSignedInAccountName(), resources);
setIcon(new BitmapDrawable(resources, bitmap));
}
setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (!AccountSigninActivity.startIfAllowed(getContext(), SigninAccessPoint.SETTINGS)) {
return false;
}
setEnabled(false);
return true;
}
});
if (account == null && enabled) {
RecordUserAction.record("Signin_Impression_FromSettings");
}
}
Aggregations