Search in sources :

Example 1 with SpinnerPreference

use of org.chromium.chrome.browser.preferences.SpinnerPreference in project AndroidChromium by JackyAndroid.

the class ClearBrowsingDataPreferences method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecordUserAction.record("ClearBrowsingData_DialogCreated");
    mMaxImportantSites = PrefServiceBridge.getMaxImportantSites();
    PrefServiceBridge.getInstance().requestInfoAboutOtherFormsOfBrowsingHistory(this);
    getActivity().setTitle(R.string.clear_browsing_data_title);
    addPreferencesFromResource(R.xml.clear_browsing_data_preferences);
    DialogOption[] options = getDialogOptions();
    mItems = new Item[options.length];
    for (int i = 0; i < options.length; i++) {
        boolean enabled = true;
        // It is possible to disable the deletion of browsing history.
        if (options[i] == DialogOption.CLEAR_HISTORY && !PrefServiceBridge.getInstance().canDeleteBrowsingHistory()) {
            enabled = false;
            PrefServiceBridge.getInstance().setBrowsingDataDeletionPreference(DialogOption.CLEAR_HISTORY.getDataType(), false);
        }
        mItems[i] = new Item(this, options[i], (ClearBrowsingDataCheckBoxPreference) findPreference(options[i].getPreferenceKey()), isOptionSelectedByDefault(options[i]), enabled);
    }
    // Not all checkboxes defined in the layout are necessarily handled by this class
    // or a particular subclass. Hide those that are not.
    EnumSet<DialogOption> unboundOptions = EnumSet.allOf(DialogOption.class);
    unboundOptions.removeAll(Arrays.asList(getDialogOptions()));
    for (DialogOption option : unboundOptions) {
        getPreferenceScreen().removePreference(findPreference(option.getPreferenceKey()));
    }
    // The time range selection spinner.
    SpinnerPreference spinner = (SpinnerPreference) findPreference(PREF_TIME_RANGE);
    spinner.setOnPreferenceChangeListener(this);
    TimePeriodSpinnerOption[] spinnerOptions = getTimePeriodSpinnerOptions();
    int selectedTimePeriod = PrefServiceBridge.getInstance().getBrowsingDataDeletionTimePeriod();
    int spinnerOptionIndex = -1;
    for (int i = 0; i < spinnerOptions.length; ++i) {
        if (spinnerOptions[i].getTimePeriod() == selectedTimePeriod) {
            spinnerOptionIndex = i;
            break;
        }
    }
    assert spinnerOptionIndex != -1;
    spinner.setOptions(spinnerOptions, spinnerOptionIndex);
    // The "Clear" button.
    ButtonPreference clearButton = (ButtonPreference) findPreference(PREF_CLEAR_BUTTON);
    clearButton.setOnPreferenceClickListener(this);
    clearButton.setShouldDisableView(true);
    // The general information footnote informs users about data that will not be deleted.
    // If the user is signed in, it also informs users about the behavior of synced deletions.
    // and we show an additional Google-specific footnote. This footnote informs users that they
    // will not be signed out of their Google account, and if the web history service indicates
    // that they have other forms of browsing history, then also about that.
    TextMessageWithLinkAndIconPreference google_summary = (TextMessageWithLinkAndIconPreference) findPreference(PREF_GOOGLE_SUMMARY);
    TextMessageWithLinkAndIconPreference general_summary = (TextMessageWithLinkAndIconPreference) findPreference(PREF_GENERAL_SUMMARY);
    google_summary.setLinkClickDelegate(new Runnable() {

        @Override
        public void run() {
            new TabDelegate(false).launchUrl(WEB_HISTORY_URL, TabLaunchType.FROM_CHROME_UI);
        }
    });
    general_summary.setLinkClickDelegate(new Runnable() {

        @Override
        public void run() {
            HelpAndFeedback.getInstance(getActivity()).show(getActivity(), getResources().getString(R.string.help_context_clear_browsing_data), Profile.getLastUsedProfile(), null);
        }
    });
    if (ChromeSigninController.get(getActivity()).isSignedIn()) {
        general_summary.setSummary(R.string.clear_browsing_data_footnote_sync_and_site_settings);
    } else {
        getPreferenceScreen().removePreference(google_summary);
        general_summary.setSummary(R.string.clear_browsing_data_footnote_site_settings);
    }
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.IMPORTANT_SITES_IN_CBD)) {
        PrefServiceBridge.fetchImportantSites(this);
    }
}
Also used : SpinnerPreference(org.chromium.chrome.browser.preferences.SpinnerPreference) TextMessageWithLinkAndIconPreference(org.chromium.chrome.browser.preferences.TextMessageWithLinkAndIconPreference) ButtonPreference(org.chromium.chrome.browser.preferences.ButtonPreference) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate) ClearBrowsingDataCheckBoxPreference(org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference)

Aggregations

ButtonPreference (org.chromium.chrome.browser.preferences.ButtonPreference)1 ClearBrowsingDataCheckBoxPreference (org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference)1 SpinnerPreference (org.chromium.chrome.browser.preferences.SpinnerPreference)1 TextMessageWithLinkAndIconPreference (org.chromium.chrome.browser.preferences.TextMessageWithLinkAndIconPreference)1 TabDelegate (org.chromium.chrome.browser.tabmodel.document.TabDelegate)1