Search in sources :

Example 81 with PreferenceCategory

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

the class ChannelListPreferenceController method findOrCreateGroupCategoryForKey.

/**
 * Looks for the category for the given group's key at the expected index, if that doesn't
 * match, it checks all groups, and if it can't find that group anywhere, it creates it.
 */
@NonNull
private PreferenceCategory findOrCreateGroupCategoryForKey(@NonNull PreferenceCategory groupPrefsList, @Nullable String key, int expectedIndex) {
    if (key == null) {
        key = KEY_GENERAL_CATEGORY;
    }
    int preferenceCount = groupPrefsList.getPreferenceCount();
    if (expectedIndex < preferenceCount) {
        Preference preference = groupPrefsList.getPreference(expectedIndex);
        if (key.equals(preference.getKey())) {
            return (PreferenceCategory) preference;
        }
    }
    for (int i = 0; i < preferenceCount; i++) {
        Preference preference = groupPrefsList.getPreference(i);
        if (key.equals(preference.getKey())) {
            preference.setOrder(expectedIndex);
            return (PreferenceCategory) preference;
        }
    }
    PreferenceCategory groupCategory = new PreferenceCategory(mContext);
    groupCategory.setOrder(expectedIndex);
    groupCategory.setKey(key);
    groupPrefsList.addPreference(groupCategory);
    return groupCategory;
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(androidx.preference.Preference) PrimarySwitchPreference(com.android.settings.widget.PrimarySwitchPreference) PreferenceCategory(androidx.preference.PreferenceCategory) NonNull(androidx.annotation.NonNull)

Example 82 with PreferenceCategory

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

the class NotificationAccessSettings method updateList.

private void updateList(List<ServiceInfo> services) {
    final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    final int managedProfileId = Utils.getManagedProfileId(um, UserHandle.myUserId());
    final PreferenceScreen screen = getPreferenceScreen();
    final PreferenceCategory allowedCategory = screen.findPreference(ALLOWED_KEY);
    allowedCategory.removeAll();
    final PreferenceCategory notAllowedCategory = screen.findPreference(NOT_ALLOWED_KEY);
    notAllowedCategory.removeAll();
    services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
    for (ServiceInfo service : services) {
        final ComponentName cn = new ComponentName(service.packageName, service.name);
        CharSequence title = null;
        try {
            title = mPm.getApplicationInfoAsUser(service.packageName, 0, UserHandle.myUserId()).loadLabel(mPm);
        } catch (PackageManager.NameNotFoundException e) {
            // unlikely, as we are iterating over live services.
            Log.e(TAG, "can't find package name", e);
        }
        final AppPreference pref = new AppPreference(getPrefContext());
        pref.setTitle(title);
        pref.setIcon(mIconDrawableFactory.getBadgedIcon(service, service.applicationInfo, UserHandle.getUserId(service.applicationInfo.uid)));
        pref.setKey(cn.flattenToString());
        pref.setSummary(mBackend.getDeviceList(ICompanionDeviceManager.Stub.asInterface(ServiceManager.getService(Context.COMPANION_DEVICE_SERVICE)), com.android.settings.bluetooth.Utils.getLocalBtManager(mContext), service.packageName, UserHandle.myUserId()));
        if (managedProfileId != UserHandle.USER_NULL && !mDpm.isNotificationListenerServicePermitted(service.packageName, managedProfileId)) {
            pref.setSummary(R.string.work_profile_notification_access_blocked_summary);
        }
        pref.setOnPreferenceClickListener(preference -> {
            final Bundle args = new Bundle();
            args.putString(AppInfoBase.ARG_PACKAGE_NAME, cn.getPackageName());
            args.putInt(AppInfoBase.ARG_PACKAGE_UID, service.applicationInfo.uid);
            Bundle extras = new Bundle();
            extras.putString(Settings.EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME, cn.flattenToString());
            new SubSettingLauncher(getContext()).setDestination(NotificationAccessDetails.class.getName()).setSourceMetricsCategory(getMetricsCategory()).setTitleRes(R.string.manage_notification_access_title).setArguments(args).setExtras(extras).setUserHandle(UserHandle.getUserHandleForUid(service.applicationInfo.uid)).launch();
            return true;
        });
        pref.setKey(cn.flattenToString());
        if (mNm.isNotificationListenerAccessGranted(cn)) {
            allowedCategory.addPreference(pref);
        } else {
            notAllowedCategory.addPreference(pref);
        }
    }
    highlightPreferenceIfNeeded();
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.AppPreference) Bundle(android.os.Bundle) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) PreferenceCategory(androidx.preference.PreferenceCategory) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) UserManager(android.os.UserManager) PackageItemInfo(android.content.pm.PackageItemInfo) ComponentName(android.content.ComponentName) NotificationAccessDetails(com.android.settings.applications.specialaccess.notificationaccess.NotificationAccessDetails)

Example 83 with PreferenceCategory

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

the class WifiDisplaySettings method buildCertificationMenu.

private void buildCertificationMenu(final PreferenceScreen preferenceScreen) {
    if (mCertCategory == null) {
        mCertCategory = new PreferenceCategory(getPrefContext());
        mCertCategory.setTitle(R.string.wifi_display_certification_heading);
        mCertCategory.setOrder(ORDER_CERTIFICATION);
    } else {
        mCertCategory.removeAll();
    }
    preferenceScreen.addPreference(mCertCategory);
    // display session info if there is an active p2p session
    if (!mWifiDisplayStatus.getSessionInfo().getGroupId().isEmpty()) {
        Preference p = new Preference(getPrefContext());
        p.setTitle(R.string.wifi_display_session_info);
        p.setSummary(mWifiDisplayStatus.getSessionInfo().toString());
        mCertCategory.addPreference(p);
        // show buttons for Pause/Resume when a WFD session is established
        if (mWifiDisplayStatus.getSessionInfo().getSessionId() != 0) {
            mCertCategory.addPreference(new Preference(getPrefContext()) {

                @Override
                public void onBindViewHolder(PreferenceViewHolder view) {
                    super.onBindViewHolder(view);
                    Button b = (Button) view.findViewById(R.id.left_button);
                    b.setText(R.string.wifi_display_pause);
                    b.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            mDisplayManager.pauseWifiDisplay();
                        }
                    });
                    b = (Button) view.findViewById(R.id.right_button);
                    b.setText(R.string.wifi_display_resume);
                    b.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            mDisplayManager.resumeWifiDisplay();
                        }
                    });
                }
            });
            mCertCategory.setLayoutResource(R.layout.two_buttons_panel);
        }
    }
    // switch for Listen Mode
    SwitchPreference pref = new SwitchPreference(getPrefContext()) {

        @Override
        protected void onClick() {
            mListen = !mListen;
            setListenMode(mListen);
            setChecked(mListen);
        }
    };
    pref.setTitle(R.string.wifi_display_listen_mode);
    pref.setChecked(mListen);
    mCertCategory.addPreference(pref);
    // switch for Autonomous GO
    pref = new SwitchPreference(getPrefContext()) {

        @Override
        protected void onClick() {
            mAutoGO = !mAutoGO;
            if (mAutoGO) {
                startAutoGO();
            } else {
                stopAutoGO();
            }
            setChecked(mAutoGO);
        }
    };
    pref.setTitle(R.string.wifi_display_autonomous_go);
    pref.setChecked(mAutoGO);
    mCertCategory.addPreference(pref);
    // Drop down list for choosing WPS method (PBC/KEYPAD/DISPLAY)
    ListPreference lp = new ListPreference(getPrefContext());
    lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            int wpsConfig = Integer.parseInt((String) value);
            if (wpsConfig != mWpsConfig) {
                mWpsConfig = wpsConfig;
                getActivity().invalidateOptionsMenu();
                Settings.Global.putInt(getActivity().getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, mWpsConfig);
            }
            return true;
        }
    });
    mWpsConfig = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, WpsInfo.INVALID);
    String[] wpsEntries = { "Default", "PBC", "KEYPAD", "DISPLAY" };
    String[] wpsValues = { "" + WpsInfo.INVALID, "" + WpsInfo.PBC, "" + WpsInfo.KEYPAD, "" + WpsInfo.DISPLAY };
    lp.setKey("wps");
    lp.setTitle(R.string.wifi_display_wps_config);
    lp.setEntries(wpsEntries);
    lp.setEntryValues(wpsValues);
    lp.setValue("" + mWpsConfig);
    lp.setSummary("%1$s");
    mCertCategory.addPreference(lp);
    // Drop down list for choosing listen channel
    lp = new ListPreference(getPrefContext());
    lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            int channel = Integer.parseInt((String) value);
            if (channel != mListenChannel) {
                mListenChannel = channel;
                getActivity().invalidateOptionsMenu();
                setWifiP2pChannels(mListenChannel, mOperatingChannel);
            }
            return true;
        }
    });
    String[] lcEntries = { "Auto", "1", "6", "11" };
    String[] lcValues = { "0", "1", "6", "11" };
    lp.setKey("listening_channel");
    lp.setTitle(R.string.wifi_display_listen_channel);
    lp.setEntries(lcEntries);
    lp.setEntryValues(lcValues);
    lp.setValue("" + mListenChannel);
    lp.setSummary("%1$s");
    mCertCategory.addPreference(lp);
    // Drop down list for choosing operating channel
    lp = new ListPreference(getPrefContext());
    lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            int channel = Integer.parseInt((String) value);
            if (channel != mOperatingChannel) {
                mOperatingChannel = channel;
                getActivity().invalidateOptionsMenu();
                setWifiP2pChannels(mListenChannel, mOperatingChannel);
            }
            return true;
        }
    });
    String[] ocEntries = { "Auto", "1", "6", "11", "36" };
    String[] ocValues = { "0", "1", "6", "11", "36" };
    lp.setKey("operating_channel");
    lp.setTitle(R.string.wifi_display_operating_channel);
    lp.setEntries(ocEntries);
    lp.setEntryValues(ocValues);
    lp.setValue("" + mOperatingChannel);
    lp.setSummary("%1$s");
    mCertCategory.addPreference(lp);
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) ListPreference(androidx.preference.ListPreference) OnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) PreferenceCategory(androidx.preference.PreferenceCategory) TwoTargetPreference(com.android.settingslib.widget.TwoTargetPreference) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) PreferenceViewHolder(androidx.preference.PreferenceViewHolder)

Example 84 with PreferenceCategory

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

the class AppsPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final Context context = RuntimeEnvironment.application;
    ReflectionHelpers.setStaticField(ApplicationsState.class, "sInstance", mAppState);
    mRecentAppsCategory = spy(new PreferenceCategory(context));
    mGeneralCategory = new PreferenceCategory(context);
    mSeeAllPref = new Preference(context);
    mAllAppsInfoPref = new Preference(context);
    when(mScreen.findPreference(KEY_RECENT_APPS_CATEGORY)).thenReturn(mRecentAppsCategory);
    when(mScreen.findPreference(KEY_GENERAL_CATEGORY)).thenReturn(mGeneralCategory);
    when(mScreen.findPreference(KEY_SEE_ALL)).thenReturn(mSeeAllPref);
    when(mScreen.findPreference(KEY_ALL_APP_INFO)).thenReturn(mAllAppsInfoPref);
    mController = spy(new AppsPreferenceController(context));
    mController.setFragment(mFragment);
    mController.mRecentAppsCategory = mRecentAppsCategory;
    mController.mGeneralCategory = mGeneralCategory;
    mController.mSeeAllPref = mSeeAllPref;
    mController.mAllAppsInfoPref = mAllAppsInfoPref;
}
Also used : Context(android.content.Context) PreferenceCategory(androidx.preference.PreferenceCategory) Preference(androidx.preference.Preference) Before(org.junit.Before)

Example 85 with PreferenceCategory

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

the class ToggleFeaturePreferenceFragment method initShortcutPreference.

protected void initShortcutPreference() {
    // Initial the shortcut preference.
    mShortcutPreference = new ShortcutPreference(getPrefContext(), /* attrs= */
    null);
    mShortcutPreference.setPersistent(false);
    mShortcutPreference.setKey(getShortcutPreferenceKey());
    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)

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