Search in sources :

Example 36 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.

the class AccessibilitySettings method updateCategoryOrderFromArray.

/**
 * Update the order of preferences in the category by matching their preference
 * key with the string array of preference order which is defined in the xml.
 *
 * @param categoryKey The key of the category need to update the order
 * @param key         The key of the string array which defines the order of category
 */
private void updateCategoryOrderFromArray(String categoryKey, int key) {
    String[] services = getResources().getStringArray(key);
    PreferenceCategory category = mCategoryToPrefCategoryMap.get(categoryKey);
    int preferenceCount = category.getPreferenceCount();
    int serviceLength = services.length;
    for (int preferenceIndex = 0; preferenceIndex < preferenceCount; preferenceIndex++) {
        for (int serviceIndex = 0; serviceIndex < serviceLength; serviceIndex++) {
            if (category.getPreference(preferenceIndex).getKey().equals(services[serviceIndex])) {
                category.getPreference(preferenceIndex).setOrder(serviceIndex);
                break;
            }
        }
    }
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory)

Example 37 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.

the class ToggleScreenMagnificationPreferenceFragment method initShortcutPreference.

@Override
protected void initShortcutPreference() {
    mShortcutPreference = new ShortcutPreference(getPrefContext(), null);
    mShortcutPreference.setPersistent(false);
    mShortcutPreference.setKey(getShortcutPreferenceKey());
    mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
    mShortcutPreference.setOnClickCallback(this);
    final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
    mShortcutPreference.setTitle(title);
    final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
    generalCategory.addPreference(mShortcutPreference);
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory)

Example 38 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.

the class ToggleScreenMagnificationPreferenceFragment method initSettingsPreference.

@Override
protected void initSettingsPreference() {
    // If the device doesn't support magnification area, it should hide the settings preference.
    if (!getContext().getResources().getBoolean(com.android.internal.R.bool.config_magnification_area)) {
        return;
    }
    mSettingsPreference = new Preference(getPrefContext());
    mSettingsPreference.setTitle(R.string.accessibility_magnification_mode_title);
    mSettingsPreference.setKey(MagnificationModePreferenceController.PREF_KEY);
    mSettingsPreference.setPersistent(false);
    final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
    generalCategory.addPreference(mSettingsPreference);
    mModePreferenceController = new MagnificationModePreferenceController(getContext(), MagnificationModePreferenceController.PREF_KEY);
    mModePreferenceController.setDialogHelper(this);
    getSettingsLifecycle().addObserver(mModePreferenceController);
    mModePreferenceController.displayPreference(getPreferenceScreen());
}
Also used : Preference(androidx.preference.Preference) PreferenceCategory(androidx.preference.PreferenceCategory)

Example 39 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.

the class PhoneNumberPreferenceController method displayPreference.

@Override
public void displayPreference(PreferenceScreen screen) {
    super.displayPreference(screen);
    final Preference preference = screen.findPreference(getPreferenceKey());
    final PreferenceCategory category = screen.findPreference(KEY_PREFERENCE_CATEGORY);
    mPreferenceList.add(preference);
    final int phonePreferenceOrder = preference.getOrder();
    // Add additional preferences for each sim in the device
    for (int simSlotNumber = 1; simSlotNumber < mTelephonyManager.getPhoneCount(); simSlotNumber++) {
        final Preference multiSimPreference = createNewPreference(screen.getContext());
        multiSimPreference.setOrder(phonePreferenceOrder + simSlotNumber);
        multiSimPreference.setKey(KEY_PHONE_NUMBER + simSlotNumber);
        multiSimPreference.setSelectable(false);
        category.addPreference(multiSimPreference);
        mPreferenceList.add(multiSimPreference);
    }
}
Also used : Preference(androidx.preference.Preference) PreferenceCategory(androidx.preference.PreferenceCategory)

Example 40 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.

the class NetworkProviderSettings method updateWifiEntryPreferences.

protected void updateWifiEntryPreferences() {
    // bypass the update if the activity and the view are not ready, or it's restricted UI.
    if (getActivity() == null || getView() == null || mIsRestricted) {
        return;
    }
    // in case state has changed
    if (mWifiPickerTracker.getWifiState() != WifiManager.WIFI_STATE_ENABLED) {
        return;
    }
    boolean hasAvailableWifiEntries = false;
    mWifiEntryPreferenceCategory.setVisible(true);
    final WifiEntry connectedEntry = mWifiPickerTracker.getConnectedWifiEntry();
    PreferenceCategory connectedWifiPreferenceCategory = getConnectedWifiPreferenceCategory();
    connectedWifiPreferenceCategory.setVisible(connectedEntry != null);
    if (connectedEntry != null) {
        final LongPressWifiEntryPreference connectedPref = connectedWifiPreferenceCategory.findPreference(connectedEntry.getKey());
        if (connectedPref == null || connectedPref.getWifiEntry() != connectedEntry) {
            connectedWifiPreferenceCategory.removeAll();
            final ConnectedWifiEntryPreference pref = createConnectedWifiEntryPreference(connectedEntry);
            pref.setKey(connectedEntry.getKey());
            pref.refresh();
            connectedWifiPreferenceCategory.addPreference(pref);
            pref.setOnPreferenceClickListener(preference -> {
                if (connectedEntry.canSignIn()) {
                    connectedEntry.signIn(null);
                } else {
                    launchNetworkDetailsFragment(pref);
                }
                return true;
            });
            pref.setOnGearClickListener(preference -> {
                launchNetworkDetailsFragment(pref);
            });
            if (mClickedConnect) {
                mClickedConnect = false;
                scrollToPreference(connectedWifiPreferenceCategory);
            }
        }
    } else {
        connectedWifiPreferenceCategory.removeAll();
    }
    int index = 0;
    cacheRemoveAllPrefs(mWifiEntryPreferenceCategory);
    List<WifiEntry> wifiEntries = mWifiPickerTracker.getWifiEntries();
    for (WifiEntry wifiEntry : wifiEntries) {
        hasAvailableWifiEntries = true;
        String key = wifiEntry.getKey();
        LongPressWifiEntryPreference pref = (LongPressWifiEntryPreference) getCachedPreference(key);
        if (pref != null) {
            if (pref.getWifiEntry() == wifiEntry) {
                pref.setOrder(index++);
                continue;
            } else {
                // Create a new preference if the underlying WifiEntry object has changed
                removePreference(key);
            }
        }
        pref = createLongPressWifiEntryPreference(wifiEntry);
        pref.setKey(wifiEntry.getKey());
        pref.setOrder(index++);
        pref.refresh();
        if (wifiEntry.getHelpUriString() != null) {
            pref.setOnButtonClickListener(preference -> {
                openSubscriptionHelpPage(wifiEntry);
            });
        }
        mWifiEntryPreferenceCategory.addPreference(pref);
    }
    removeCachedPrefs(mWifiEntryPreferenceCategory);
    if (!hasAvailableWifiEntries) {
        setProgressBarVisible(true);
        Preference pref = new Preference(getPrefContext());
        pref.setSelectable(false);
        pref.setSummary(R.string.wifi_empty_list_wifi_on);
        pref.setOrder(index++);
        pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
        mWifiEntryPreferenceCategory.addPreference(pref);
    } else {
        // Continuing showing progress bar for an additional delay to overlap with animation
        getView().postDelayed(mHideProgressBarRunnable, 1700);
    }
    mAddWifiNetworkPreference.setOrder(index++);
    mWifiEntryPreferenceCategory.addPreference(mAddWifiNetworkPreference);
    setAdditionalSettingsSummaries();
}
Also used : LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) PreferenceCategory(androidx.preference.PreferenceCategory) FooterPreference(com.android.settingslib.widget.FooterPreference) DataUsagePreference(com.android.settings.datausage.DataUsagePreference) LayoutPreference(com.android.settingslib.widget.LayoutPreference) ConnectedWifiEntryPreference(com.android.settings.wifi.ConnectedWifiEntryPreference) AddWifiNetworkPreference(com.android.settings.wifi.AddWifiNetworkPreference) Preference(androidx.preference.Preference) LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) WifiEntry(com.android.wifitrackerlib.WifiEntry) ConnectedWifiEntryPreference(com.android.settings.wifi.ConnectedWifiEntryPreference)

Aggregations

PreferenceCategory (androidx.preference.PreferenceCategory)111 Preference (androidx.preference.Preference)38 PreferenceManager (androidx.preference.PreferenceManager)24 Before (org.junit.Before)24 PreferenceScreen (androidx.preference.PreferenceScreen)22 Test (org.junit.Test)19 SwitchPreference (androidx.preference.SwitchPreference)13 NotificationChannel (android.app.NotificationChannel)11 ArrayList (java.util.ArrayList)11 NotificationChannelGroup (android.app.NotificationChannelGroup)9 ShortcutInfo (android.content.pm.ShortcutInfo)9 Context (android.content.Context)8 ConversationChannel (android.app.people.ConversationChannel)7 View (android.view.View)7 PreferenceViewHolder (androidx.preference.PreferenceViewHolder)7 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)7 ListPreference (androidx.preference.ListPreference)6 ComponentName (android.content.ComponentName)5 ContentResolver (android.content.ContentResolver)5 Bundle (android.os.Bundle)5