Search in sources :

Example 61 with Preference

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);
}
Also used : Preference(android.preference.Preference) Bundle(android.os.Bundle) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)

Example 62 with Preference

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);
}
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 63 with Preference

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);
    }
}
Also used : ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) Bundle(android.os.Bundle) PreferenceGroup(android.preference.PreferenceGroup) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)

Example 64 with Preference

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);
    }
}
Also used : ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) Bundle(android.os.Bundle) PreferenceGroup(android.preference.PreferenceGroup) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Example 65 with Preference

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");
    }
}
Also used : Account(android.accounts.Account) Bitmap(android.graphics.Bitmap) ChromeSigninController(org.chromium.components.signin.ChromeSigninController) Preference(android.preference.Preference) AccountManagementFragment(org.chromium.chrome.browser.signin.AccountManagementFragment) Resources(android.content.res.Resources) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Profile(org.chromium.chrome.browser.profiles.Profile)

Aggregations

Preference (android.preference.Preference)183 CheckBoxPreference (android.preference.CheckBoxPreference)54 ListPreference (android.preference.ListPreference)54 PreferenceScreen (android.preference.PreferenceScreen)37 Intent (android.content.Intent)33 EditTextPreference (android.preference.EditTextPreference)29 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)23 PreferenceCategory (android.preference.PreferenceCategory)23 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)21 SharedPreferences (android.content.SharedPreferences)19 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)16 PreferenceGroup (android.preference.PreferenceGroup)15 Test (org.junit.Test)15 Uri (android.net.Uri)12 Bundle (android.os.Bundle)12 ArrayList (java.util.ArrayList)11 Resources (android.content.res.Resources)10 SwitchPreference (android.preference.SwitchPreference)10 View (android.view.View)10 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)10