Example usage for android.preference PreferenceGroup setOnPreferenceClickListener

List of usage examples for android.preference PreferenceGroup setOnPreferenceClickListener

Introduction

In this page you can find the example usage for android.preference PreferenceGroup setOnPreferenceClickListener.

Prototype

public void setOnPreferenceClickListener(OnPreferenceClickListener onPreferenceClickListener) 

Source Link

Document

Sets the callback to be invoked when this Preference is clicked.

Usage

From source file:org.chromium.chrome.browser.preferences.website.WebsitePreferences.java

private void configureGlobalToggles() {
    // Only some have a global toggle at the top.
    ChromeSwitchPreference globalToggle = (ChromeSwitchPreference) getPreferenceScreen()
            .findPreference(READ_WRITE_TOGGLE_KEY);

    Preference thirdPartyCookies = getPreferenceScreen().findPreference(THIRD_PARTY_COOKIES_TOGGLE_KEY);

    if (mFilter.showCookiesSites(mCategoryFilter)) {
        thirdPartyCookies.setOnPreferenceChangeListener(this);
        updateThirdPartyCookiesCheckBox();
    } else {/*  w  w  w .  ja  va  2 s .com*/
        getPreferenceScreen().removePreference(thirdPartyCookies);
    }

    if (mFilter.showAllSites(mCategoryFilter) || mFilter.showStorageSites(mCategoryFilter)) {
        getPreferenceScreen().removePreference(globalToggle);
        getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(ALLOWED_GROUP));
        getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(BLOCKED_GROUP));
    } else {
        // When this menu opens, make sure the Blocked list is collapsed.
        if (!mGroupByAllowBlock) {
            mBlockListExpanded = false;
            mAllowListExpanded = true;
        }
        mGroupByAllowBlock = true;
        PreferenceGroup allowedGroup = (PreferenceGroup) getPreferenceScreen().findPreference(ALLOWED_GROUP);
        PreferenceGroup blockedGroup = (PreferenceGroup) getPreferenceScreen().findPreference(BLOCKED_GROUP);
        allowedGroup.setOnPreferenceClickListener(this);
        blockedGroup.setOnPreferenceClickListener(this);

        // Determine what toggle to use and what it should display.
        int type = mFilter.toContentSettingsType(mCategoryFilter);
        Website.PermissionDataEntry entry = Website.PermissionDataEntry.getPermissionDataEntry(type);
        if (mFilter.showGeolocationSites(mCategoryFilter) && !isCategoryManaged()
                && !LocationSettings.getInstance().isSystemLocationSettingEnabled()) {
            getPreferenceScreen().removePreference(globalToggle);

            // Show the link to system settings since system location is disabled.
            ChromeBasePreference locationMessage = new ChromeBasePreference(getActivity(), null);
            int color = getResources().getColor(R.color.pref_accent_color);
            ForegroundColorSpan linkSpan = new ForegroundColorSpan(color);
            final String message = getString(R.string.android_location_off);
            final SpannableString messageWithLink = SpanApplier.applySpans(message,
                    new SpanInfo("<link>", "</link>", linkSpan));
            locationMessage.setTitle(messageWithLink);
            locationMessage.setIntent(LocationSettings.getInstance().getSystemLocationSettingsIntent());
            getPreferenceScreen().addPreference(locationMessage);
        } else {
            globalToggle.setOnPreferenceChangeListener(this);
            globalToggle.setTitle(entry.titleResourceId);
            globalToggle.setSummaryOn(entry.getEnabledSummaryResourceId());
            globalToggle.setSummaryOff(entry.getDisabledSummaryResourceId());
            if (isCategoryManaged() && !isCategoryManagedByCustodian()) {
                globalToggle.setIcon(R.drawable.controlled_setting_mandatory);
            }
            if (mFilter.showGeolocationSites(mCategoryFilter)) {
                globalToggle.setChecked(LocationSettings.getInstance().isChromeLocationSettingEnabled());
            } else if (mFilter.showCameraMicSites(mCategoryFilter)) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isCameraMicEnabled());
            } else if (mFilter.showPopupSites(mCategoryFilter)) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().popupsEnabled());
            } else if (mFilter.showPushNotificationsSites(mCategoryFilter)) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isPushNotificationsEnabled());
            } else if (mFilter.showCookiesSites(mCategoryFilter)) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isAcceptCookiesEnabled());
            }
        }
    }
}

From source file:org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences.java

private void configureGlobalToggles() {
    // Only some have a global toggle at the top.
    ChromeSwitchPreference globalToggle = (ChromeSwitchPreference) getPreferenceScreen()
            .findPreference(READ_WRITE_TOGGLE_KEY);

    // Configure/hide the third-party cookie toggle, as needed.
    Preference thirdPartyCookies = getPreferenceScreen().findPreference(THIRD_PARTY_COOKIES_TOGGLE_KEY);
    if (mCategory.showCookiesSites()) {
        thirdPartyCookies.setOnPreferenceChangeListener(this);
        updateThirdPartyCookiesCheckBox();
    } else {/*from w ww .j  a va2s  .  c  o  m*/
        getPreferenceScreen().removePreference(thirdPartyCookies);
    }

    // Configure/hide the notifications vibrate toggle, as needed.
    Preference notificationsVibrate = getPreferenceScreen().findPreference(NOTIFICATIONS_VIBRATE_TOGGLE_KEY);
    if (mCategory.showNotificationsSites()) {
        notificationsVibrate.setOnPreferenceChangeListener(this);
        updateNotificationsVibrateCheckBox();
    } else {
        getPreferenceScreen().removePreference(notificationsVibrate);
    }

    // Show/hide the link that explains protected media settings, as needed.
    if (!mCategory.showProtectedMediaSites()) {
        getPreferenceScreen()
                .removePreference(getPreferenceScreen().findPreference(EXPLAIN_PROTECTED_MEDIA_KEY));
    }

    if (mCategory.showAllSites() || mCategory.showStorageSites()) {
        getPreferenceScreen().removePreference(globalToggle);
        getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(ALLOWED_GROUP));
        getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(BLOCKED_GROUP));
    } else {
        // When this menu opens, make sure the Blocked list is collapsed.
        if (!mGroupByAllowBlock) {
            mBlockListExpanded = false;
            mAllowListExpanded = true;
        }
        mGroupByAllowBlock = true;
        PreferenceGroup allowedGroup = (PreferenceGroup) getPreferenceScreen().findPreference(ALLOWED_GROUP);
        PreferenceGroup blockedGroup = (PreferenceGroup) getPreferenceScreen().findPreference(BLOCKED_GROUP);

        if (mCategory.showPermissionBlockedMessage(getActivity())) {
            getPreferenceScreen().removePreference(globalToggle);
            getPreferenceScreen().removePreference(allowedGroup);
            getPreferenceScreen().removePreference(blockedGroup);

            // Show the link to system settings since permission is disabled.
            ChromeBasePreference osWarning = new ChromeBasePreference(getActivity(), null);
            ChromeBasePreference osWarningExtra = new ChromeBasePreference(getActivity(), null);
            mCategory.configurePermissionIsOffPreferences(osWarning, osWarningExtra, getActivity(), true);
            if (osWarning.getTitle() != null) {
                getPreferenceScreen().addPreference(osWarning);
            }
            if (osWarningExtra.getTitle() != null) {
                getPreferenceScreen().addPreference(osWarningExtra);
            }
        } else {
            allowedGroup.setOnPreferenceClickListener(this);
            blockedGroup.setOnPreferenceClickListener(this);

            // Determine what toggle to use and what it should display.
            int contentType = mCategory.toContentSettingsType();
            globalToggle.setOnPreferenceChangeListener(this);
            globalToggle.setTitle(ContentSettingsResources.getTitle(contentType));
            if (mCategory.showGeolocationSites()
                    && PrefServiceBridge.getInstance().isLocationAllowedByPolicy()) {
                globalToggle.setSummaryOn(ContentSettingsResources.getGeolocationAllowedSummary());
            } else {
                globalToggle.setSummaryOn(ContentSettingsResources.getEnabledSummary(contentType));
            }
            globalToggle.setSummaryOff(ContentSettingsResources.getDisabledSummary(contentType));
            if (mCategory.isManaged() && !mCategory.isManagedByCustodian()) {
                globalToggle.setIcon(R.drawable.controlled_setting_mandatory);
            }
            if (mCategory.showAutoplaySites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isAutoplayEnabled());
            } else if (mCategory.showBackgroundSyncSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isBackgroundSyncAllowed());
            } else if (mCategory.showCameraSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isCameraEnabled());
            } else if (mCategory.showCookiesSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isAcceptCookiesEnabled());
            } else if (mCategory.showFullscreenSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isFullscreenAllowed());
                // The fullscreen global toggle cannot be disabled.
                // TODO(mgiuca): Remove this setting entirely (requires deleting all the data;
                // see https://crbug.com/591896).
                globalToggle.setEnabled(false);
            } else if (mCategory.showGeolocationSites()) {
                globalToggle.setChecked(LocationSettings.getInstance().isChromeLocationSettingEnabled());
            } else if (mCategory.showJavaScriptSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().javaScriptEnabled());
            } else if (mCategory.showMicrophoneSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isMicEnabled());
            } else if (mCategory.showNotificationsSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isNotificationsEnabled());
            } else if (mCategory.showPopupSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().popupsEnabled());
            } else if (mCategory.showProtectedMediaSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isProtectedMediaIdentifierEnabled());
            }
        }
    }
}