Search in sources :

Example 11 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CreateShortcutPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    if (!(preference instanceof PreferenceGroup)) {
        return;
    }
    final PreferenceGroup group = (PreferenceGroup) preference;
    group.removeAll();
    final List<ResolveInfo> shortcuts = queryShortcuts();
    final Context uiContext = preference.getContext();
    if (shortcuts.isEmpty()) {
        return;
    }
    PreferenceCategory category = new PreferenceCategory(uiContext);
    group.addPreference(category);
    int bucket = 0;
    for (ResolveInfo info : shortcuts) {
        // Priority is not consecutive (aka, jumped), add a divider between prefs.
        final int currentBucket = info.priority / 10;
        boolean needDivider = currentBucket != bucket;
        bucket = currentBucket;
        if (needDivider) {
            // add a new Category
            category = new PreferenceCategory(uiContext);
            group.addPreference(category);
        }
        final Preference pref = new Preference(uiContext);
        pref.setTitle(info.loadLabel(mPackageManager));
        pref.setKey(info.activityInfo.getComponentName().flattenToString());
        pref.setOnPreferenceClickListener(clickTarget -> {
            if (mHost == null) {
                return false;
            }
            final Intent shortcutIntent = createResultIntent(buildShortcutIntent(info), info, clickTarget.getTitle());
            mHost.setResult(Activity.RESULT_OK, shortcutIntent);
            logCreateShortcut(info);
            mHost.finish();
            return true;
        });
        category.addPreference(pref);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Context(android.content.Context) PreferenceCategory(androidx.preference.PreferenceCategory) Preference(androidx.preference.Preference) PreferenceGroup(androidx.preference.PreferenceGroup) Intent(android.content.Intent)

Example 12 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PrivateVolumeSettings method addCategory.

private PreferenceCategory addCategory(PreferenceGroup group, CharSequence title) {
    PreferenceCategory category;
    if (mHeaderPoolIndex < mHeaderPreferencePool.size()) {
        category = mHeaderPreferencePool.get(mHeaderPoolIndex);
    } else {
        category = new PreferenceCategory(getPrefContext());
        mHeaderPreferencePool.add(category);
    }
    category.setTitle(title);
    category.removeAll();
    addPreference(group, category);
    ++mHeaderPoolIndex;
    return category;
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory)

Example 13 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConfigureNotificationSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final PreferenceScreen screen = getPreferenceScreen();
    final Bundle arguments = getArguments();
    if (screen == null) {
        return;
    }
    if (arguments != null) {
        final String highlightKey = arguments.getString(EXTRA_FRAGMENT_ARG_KEY);
        if (!TextUtils.isEmpty(highlightKey)) {
            final PreferenceCategory advancedCategory = screen.findPreference(KEY_ADVANCED_CATEGORY);
            // Has highlight row - expand everything
            advancedCategory.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
            scrollToPreference(advancedCategory);
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) Bundle(android.os.Bundle)

Example 14 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project Signal-Android by signalapp.

the class CorrectedPreferenceFragment method onCreateAdapter.

@Override
@SuppressLint("RestrictedApi")
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
    return new PreferenceGroupAdapter(preferenceScreen) {

        @Override
        public void onBindViewHolder(PreferenceViewHolder holder, int position) {
            super.onBindViewHolder(holder, position);
            Preference preference = getItem(position);
            if (preference instanceof PreferenceCategory) {
                setZeroPaddingToLayoutChildren(holder.itemView);
            } else {
                View iconFrame = holder.itemView.findViewById(R.id.icon_frame);
                if (iconFrame != null) {
                    iconFrame.setVisibility(preference.getIcon() == null ? View.GONE : View.VISIBLE);
                }
            }
        }
    };
}
Also used : ColorPickerPreference(org.thoughtcrime.securesms.preferences.widgets.ColorPickerPreference) Preference(androidx.preference.Preference) CustomDefaultPreference(org.thoughtcrime.securesms.components.CustomDefaultPreference) PreferenceCategory(androidx.preference.PreferenceCategory) PreferenceGroupAdapter(androidx.preference.PreferenceGroupAdapter) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SuppressLint(android.annotation.SuppressLint)

Example 15 with PreferenceCategory

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

the class PhysicalKeyboardFragment method updateHardKeyboards.

private void updateHardKeyboards(@NonNull List<HardKeyboardDeviceInfo> newHardKeyboards) {
    if (Objects.equals(mLastHardKeyboards, newHardKeyboards)) {
        // Nothing has changed.  Ignore.
        return;
    }
    // TODO(yukawa): Maybe we should follow the style used in ConnectedDeviceDashboardFragment.
    mLastHardKeyboards.clear();
    mLastHardKeyboards.addAll(newHardKeyboards);
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    preferenceScreen.removeAll();
    final PreferenceCategory category = new PreferenceCategory(getPrefContext());
    category.setTitle(R.string.builtin_keyboard_settings_title);
    category.setOrder(0);
    preferenceScreen.addPreference(category);
    for (HardKeyboardDeviceInfo hardKeyboardDeviceInfo : newHardKeyboards) {
        // TODO(yukawa): Consider using com.android.settings.widget.GearPreference
        final Preference pref = new Preference(getPrefContext());
        pref.setTitle(hardKeyboardDeviceInfo.mDeviceName);
        pref.setSummary(hardKeyboardDeviceInfo.mLayoutLabel);
        pref.setOnPreferenceClickListener(preference -> {
            showKeyboardLayoutDialog(hardKeyboardDeviceInfo.mDeviceIdentifier);
            return true;
        });
        category.addPreference(pref);
    }
    mKeyboardAssistanceCategory.setOrder(1);
    preferenceScreen.addPreference(mKeyboardAssistanceCategory);
    updateShowVirtualKeyboardSwitch();
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference)

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