Search in sources :

Example 71 with PreferenceCategory

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

the class GameDriverAppPreferenceControllerTest method loadConfig.

private void loadConfig(String optIn, String prereleaseOptIn, String optOut) {
    Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS, optIn);
    Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_PRERELEASE_OPT_IN_APPS, prereleaseOptIn);
    Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, optOut);
    mController = new GameDriverAppPreferenceController(mContext, "testKey");
    mGroup = spy(new PreferenceCategory(mContext));
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    when(mGroup.getContext()).thenReturn(mContext);
    when(mGroup.getPreferenceManager()).thenReturn(preferenceManager);
    when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mGroup);
    mController.displayPreference(mScreen);
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) PreferenceManager(androidx.preference.PreferenceManager)

Example 72 with PreferenceCategory

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

the class UserSettingsTest method updateUserList_cannotSwitchUser_shouldNotBeSelectableForGuest.

@Test
public void updateUserList_cannotSwitchUser_shouldNotBeSelectableForGuest() {
    final RestrictedPreference addUser = spy(new RestrictedPreference(mContext));
    final PreferenceGroup userListCategory = spy(new PreferenceCategory(mContext));
    mUserCapabilities.mIsGuest = false;
    mUserCapabilities.mCanAddGuest = true;
    mUserCapabilities.mDisallowAddUser = false;
    mUserCapabilities.mDisallowSwitchUser = false;
    mUserCapabilities.mUserSwitcherEnabled = true;
    mFragment.mUserListCategory = userListCategory;
    mFragment.mAddUser = addUser;
    when(mUserManager.canSwitchUsers()).thenReturn(false);
    doReturn(mMockPreferenceManager).when(mFragment).getPreferenceManager();
    doReturn(mock(PreferenceScreen.class)).when(mFragment).getPreferenceScreen();
    doReturn(mMockPreferenceManager).when(userListCategory).getPreferenceManager();
    mFragment.updateUserList();
    final Preference guest = userListCategory.findPreference(KEY_USER_GUEST);
    assertThat(guest.isSelectable()).isFalse();
}
Also used : RestrictedPreference(com.android.settingslib.RestrictedPreference) PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(androidx.preference.Preference) PreferenceGroup(androidx.preference.PreferenceGroup) Test(org.junit.Test)

Example 73 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project fdroidclient by f-droid.

the class PreferencesFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String s) {
    Preferences preferences = Preferences.get();
    preferences.migrateOldPreferences();
    addPreferencesFromResource(R.xml.preferences);
    otherPrefGroup = (PreferenceGroup) findPreference("pref_category_other");
    Preference aboutPreference = findPreference("pref_about");
    if (aboutPreference != null) {
        aboutPreference.setOnPreferenceClickListener(aboutPrefClickedListener);
    }
    keepInstallHistoryPref = (CheckBoxPreference) findPreference(Preferences.PREF_KEEP_INSTALL_HISTORY);
    sendToFDroidMetricsPref = findPreference(Preferences.PREF_SEND_TO_FDROID_METRICS);
    sendToFDroidMetricsPref.setEnabled(keepInstallHistoryPref.isChecked());
    installHistoryPref = findPreference("installHistory");
    installHistoryPref.setVisible(keepInstallHistoryPref.isChecked());
    if (preferences.isSendingToFDroidMetrics()) {
        installHistoryPref.setTitle(R.string.install_history_and_metrics);
    } else {
        installHistoryPref.setTitle(R.string.install_history);
    }
    useTorCheckPref = (SwitchPreferenceCompat) findPreference(Preferences.PREF_USE_TOR);
    useTorCheckPref.setOnPreferenceChangeListener(useTorChangedListener);
    enableProxyCheckPref = (SwitchPreferenceCompat) findPreference(Preferences.PREF_ENABLE_PROXY);
    enableProxyCheckPref.setOnPreferenceChangeListener(proxyEnabledChangedListener);
    updateAutoDownloadPref = findPreference(Preferences.PREF_AUTO_DOWNLOAD_INSTALL_UPDATES);
    overWifiSeekBar = (LiveSeekBarPreference) findPreference(Preferences.PREF_OVER_WIFI);
    overWifiPrevious = overWifiSeekBar.getValue();
    overWifiSeekBar.setSeekBarLiveUpdater(new LiveSeekBarPreference.SeekBarLiveUpdater() {

        @Override
        public String seekBarUpdated(int position) {
            return getNetworkSeekBarSummary(position);
        }
    });
    overDataSeekBar = (LiveSeekBarPreference) findPreference(Preferences.PREF_OVER_DATA);
    overDataPrevious = overDataSeekBar.getValue();
    overDataSeekBar.setSeekBarLiveUpdater(new LiveSeekBarPreference.SeekBarLiveUpdater() {

        @Override
        public String seekBarUpdated(int position) {
            return getNetworkSeekBarSummary(position);
        }
    });
    updateIntervalSeekBar = (LiveSeekBarPreference) findPreference(Preferences.PREF_UPDATE_INTERVAL);
    updateIntervalPrevious = updateIntervalSeekBar.getValue();
    updateIntervalSeekBar.setSeekBarLiveUpdater(new LiveSeekBarPreference.SeekBarLiveUpdater() {

        @Override
        public String seekBarUpdated(int position) {
            return getString(UPDATE_INTERVAL_NAMES[position]);
        }
    });
    ListPreference languagePref = (ListPreference) findPreference(Preferences.PREF_LANGUAGE);
    if (Build.VERSION.SDK_INT >= 24) {
        PreferenceCategory category = (PreferenceCategory) findPreference("pref_category_display");
        category.removePreference(languagePref);
    } else {
        Languages languages = Languages.get((AppCompatActivity) getActivity());
        languagePref.setDefaultValue(Languages.USE_SYSTEM_DEFAULT);
        languagePref.setEntries(languages.getAllNames());
        languagePref.setEntryValues(languages.getSupportedLocales());
    }
    if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
        PreferenceCategory category = (PreferenceCategory) findPreference("pref_category_appcompatibility");
        category.removePreference(findPreference(Preferences.PREF_FORCE_TOUCH_APPS));
    }
    topScroller = new LinearSmoothScroller(getActivity()) {

        @Override
        protected int getVerticalSnapPreference() {
            return SNAP_TO_START;
        }
    };
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) SeekBarPreference(androidx.preference.SeekBarPreference) EditTextPreference(androidx.preference.EditTextPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) PreferenceCategory(androidx.preference.PreferenceCategory) LinearSmoothScroller(androidx.recyclerview.widget.LinearSmoothScroller) Languages(org.fdroid.fdroid.Languages) ListPreference(androidx.preference.ListPreference) Preferences(org.fdroid.fdroid.Preferences) SharedPreferences(android.content.SharedPreferences)

Example 74 with PreferenceCategory

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

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 75 with PreferenceCategory

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

the class RestrictedAppDetailsTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    mRestrictedAppDetails = spy(new RestrictedAppDetails());
    mAppInfo = new AppInfo.Builder().setPackageName(PACKAGE_NAME).setUid(UID).build();
    mPreferenceManager = new PreferenceManager(mContext);
    doReturn(mPreferenceManager).when(mRestrictedAppDetails).getPreferenceManager();
    doReturn(mContext).when(mFragment).getContext();
    doReturn(mContext).when(mRestrictedAppDetails).getContext();
    mRestrictedAppDetails.mPackageManager = mPackageManager;
    mRestrictedAppDetails.mIconDrawableFactory = mIconDrawableFactory;
    mRestrictedAppDetails.mAppInfos = new ArrayList<>();
    mRestrictedAppDetails.mAppInfos.add(mAppInfo);
    mRestrictedAppDetails.mRestrictedAppListGroup = spy(new PreferenceCategory(mContext));
    mRestrictedAppDetails.mBatteryUtils = spy(new BatteryUtils(mContext));
    mRestrictedAppDetails.mBatteryDatabaseManager = mBatteryDatabaseManager;
    doReturn(mPreferenceManager).when(mRestrictedAppDetails.mRestrictedAppListGroup).getPreferenceManager();
    mCheckBoxPreference = new CheckBoxPreference(mContext);
    mCheckBoxPreference.setKey(mRestrictedAppDetails.getKeyFromAppInfo(mAppInfo));
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) CheckBoxPreference(androidx.preference.CheckBoxPreference) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

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