Search in sources :

Example 26 with PreferenceCategory

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

the class PhoneNumberPreferenceControllerTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    mClipboardManager = (ClipboardManager) spy(mContext.getSystemService(CLIPBOARD_SERVICE));
    doReturn(mClipboardManager).when(mContext).getSystemService(CLIPBOARD_SERVICE);
    when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
    when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
    mController = spy(new PhoneNumberPreferenceController(mContext, "phone_number"));
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    mScreen = preferenceManager.createPreferenceScreen(mContext);
    mPreference = spy(new Preference(mContext));
    mPreference.setKey(mController.getPreferenceKey());
    mPreference.setVisible(true);
    mScreen.addPreference(mPreference);
    final String categoryKey = "basic_info_category";
    mCategory = new PreferenceCategory(mContext);
    mCategory.setKey(categoryKey);
    mScreen.addPreference(mCategory);
    doReturn(mSubscriptionInfo).when(mController).getSubscriptionInfo(anyInt());
    doReturn(mSecondPreference).when(mController).createNewPreference(mContext);
}
Also used : Preference(androidx.preference.Preference) PreferenceCategory(androidx.preference.PreferenceCategory) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 27 with PreferenceCategory

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

the class PlatformCompatDashboard method createChangeCategoryPreference.

PreferenceCategory createChangeCategoryPreference(List<CompatibilityChangeInfo> changes, CompatibilityChangeConfig configMappings, String title) {
    final PreferenceCategory category = new PreferenceCategory(getPreferenceScreen().getContext());
    category.setTitle(title);
    getPreferenceScreen().addPreference(category);
    addChangePreferencesToCategory(changes, category, configMappings);
    return category;
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory)

Example 28 with PreferenceCategory

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

the class PriorityConversationsPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    PreferenceCategory pref = (PreferenceCategory) preference;
    // Load conversations
    mConversations = mBackend.getConversations(true).getList();
    Collections.sort(mConversations, mConversationComparator);
    populateList(mConversations, pref);
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory)

Example 29 with PreferenceCategory

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

the class RecentConversationsPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    PreferenceCategory pref = (PreferenceCategory) preference;
    // Load conversations
    try {
        mConversations = mPs.getRecentConversations().getList();
    } catch (RemoteException e) {
        Slog.w(TAG, "Could get recents", e);
    }
    Collections.sort(mConversations, mConversationComparator);
    populateList(mConversations, pref);
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) RemoteException(android.os.RemoteException)

Example 30 with PreferenceCategory

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

the class ZenModeAddBypassingAppsPreferenceController method updateAppList.

@VisibleForTesting
void updateAppList(List<ApplicationsState.AppEntry> apps) {
    if (apps == null) {
        return;
    }
    if (mPreferenceCategory == null) {
        mPreferenceCategory = new PreferenceCategory(mPrefContext);
        mPreferenceCategory.setTitle(R.string.zen_mode_bypassing_apps_add_header);
        mPreferenceScreen.addPreference(mPreferenceCategory);
    }
    List<Preference> appsWithNoBypassingDndNotificationChannels = new ArrayList<>();
    for (ApplicationsState.AppEntry entry : apps) {
        String pkg = entry.info.packageName;
        mApplicationsState.ensureIcon(entry);
        final int appChannels = mNotificationBackend.getChannelCount(pkg, entry.info.uid);
        final int appChannelsBypassingDnd = mNotificationBackend.getNotificationChannelsBypassingDnd(pkg, entry.info.uid).getList().size();
        if (appChannelsBypassingDnd == 0 && appChannels > 0) {
            final String key = ZenModeAllBypassingAppsPreferenceController.getKey(pkg);
            Preference pref = mPreferenceCategory.findPreference("");
            if (pref == null) {
                pref = new AppPreference(mPrefContext);
                pref.setKey(key);
                pref.setOnPreferenceClickListener(preference -> {
                    Bundle args = new Bundle();
                    args.putString(AppInfoBase.ARG_PACKAGE_NAME, entry.info.packageName);
                    args.putInt(AppInfoBase.ARG_PACKAGE_UID, entry.info.uid);
                    new SubSettingLauncher(mContext).setDestination(AppChannelsBypassingDndSettings.class.getName()).setArguments(args).setResultListener(mHostFragment, 0).setUserHandle(new UserHandle(UserHandle.getUserId(entry.info.uid))).setSourceMetricsCategory(SettingsEnums.NOTIFICATION_ZEN_MODE_OVERRIDING_APP).launch();
                    return true;
                });
            }
            pref.setTitle(BidiFormatter.getInstance().unicodeWrap(entry.label));
            pref.setIcon(entry.icon);
            appsWithNoBypassingDndNotificationChannels.add(pref);
        }
    }
    if (appsWithNoBypassingDndNotificationChannels.size() == 0) {
        Preference pref = mPreferenceCategory.findPreference(ZenModeAllBypassingAppsPreferenceController.KEY_NO_APPS);
        if (pref == null) {
            pref = new Preference(mPrefContext);
            pref.setKey(ZenModeAllBypassingAppsPreferenceController.KEY_NO_APPS);
            pref.setTitle(R.string.zen_mode_bypassing_apps_subtext_none);
        }
        mPreferenceCategory.addPreference(pref);
    }
    if (ZenModeAllBypassingAppsPreferenceController.hasAppListChanged(appsWithNoBypassingDndNotificationChannels, mPreferenceCategory)) {
        mPreferenceCategory.removeAll();
        for (Preference prefToAdd : appsWithNoBypassingDndNotificationChannels) {
            mPreferenceCategory.addPreference(prefToAdd);
        }
    }
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) AppPreference(com.android.settingslib.widget.AppPreference) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) ApplicationsState(com.android.settingslib.applications.ApplicationsState) Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) VisibleForTesting(androidx.annotation.VisibleForTesting)

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