Search in sources :

Example 11 with PreferenceScreen

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

the class PaymentSettingsTest method isShowEmptyImage_hasNoVisiblePreference_returnTrue.

@Test
public void isShowEmptyImage_hasNoVisiblePreference_returnTrue() {
    final PaymentSettings paymentSettings = new PaymentSettings();
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
    final Preference preference1 = new Preference(mContext);
    preference1.setVisible(false);
    screen.addPreference(preference1);
    final Preference preference2 = new Preference(mContext);
    screen.addPreference(preference2);
    preference2.setVisible(false);
    assertThat(paymentSettings.isShowEmptyImage(screen)).isTrue();
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 12 with PreferenceScreen

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

the class StorageSelectionPreferenceControllerTest method setUp.

@Before
public void setUp() throws Exception {
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    mContext = ApplicationProvider.getApplicationContext();
    mStorageManager = mContext.getSystemService(StorageManager.class);
    mController = new StorageSelectionPreferenceController(mContext, PREFERENCE_KEY);
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    final PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext);
    final SettingsSpinnerPreference spinnerPreference = new SettingsSpinnerPreference(mContext);
    spinnerPreference.setKey(PREFERENCE_KEY);
    preferenceScreen.addPreference(spinnerPreference);
    mController.displayPreference(preferenceScreen);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) StorageManager(android.os.storage.StorageManager) SettingsSpinnerPreference(com.android.settingslib.widget.SettingsSpinnerPreference) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 13 with PreferenceScreen

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

the class InteractAcrossProfilesSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    final ArrayList<Pair<ApplicationInfo, UserHandle>> crossProfileApps = collectConfigurableApps(mPackageManager, mUserManager, mCrossProfileApps);
    final Context prefContext = getPrefContext();
    for (final Pair<ApplicationInfo, UserHandle> appData : crossProfileApps) {
        final ApplicationInfo appInfo = appData.first;
        final UserHandle user = appData.second;
        final String packageName = appInfo.packageName;
        final CharSequence label = appInfo.loadLabel(mPackageManager);
        final Preference pref = new AppPreference(prefContext);
        pref.setIcon(mIconDrawableFactory.getBadgedIcon(appInfo, user.getIdentifier()));
        pref.setTitle(mPackageManager.getUserBadgedLabel(label, user));
        pref.setSummary(InteractAcrossProfilesDetails.getPreferenceSummary(prefContext, packageName));
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                AppInfoBase.startAppInfoFragment(InteractAcrossProfilesDetails.class, R.string.interact_across_profiles_title, packageName, appInfo.uid, InteractAcrossProfilesSettings.this, /* source */
                -1, /* request */
                getMetricsCategory());
                return true;
            }
        });
        screen.addPreference(pref);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.AppPreference) ApplicationInfo(android.content.pm.ApplicationInfo) OnPreferenceClickListener(androidx.preference.Preference.OnPreferenceClickListener) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) Pair(android.util.Pair)

Example 14 with PreferenceScreen

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

the class ToggleBackupSettingFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE));
    PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(getActivity());
    setPreferenceScreen(preferenceScreen);
    mSummaryPreference = new Preference(getPrefContext()) {

        @Override
        public void onBindViewHolder(PreferenceViewHolder view) {
            super.onBindViewHolder(view);
            final TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
            summaryView.setText(getSummary());
        }
    };
    mSummaryPreference.setPersistent(false);
    mSummaryPreference.setLayoutResource(R.layout.text_description_preference);
    preferenceScreen.addPreference(mSummaryPreference);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) TextView(android.widget.TextView) PreferenceViewHolder(androidx.preference.PreferenceViewHolder)

Example 15 with PreferenceScreen

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

the class PictureInPictureSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    // Clear the prefs
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    // Fetch the set of applications for each profile which have at least one activity that
    // declare that they support picture-in-picture
    final ArrayList<Pair<ApplicationInfo, Integer>> pipApps = collectPipApps(UserHandle.myUserId());
    Collections.sort(pipApps, new AppComparator(mPackageManager));
    // Rebuild the list of prefs
    final Context prefContext = getPrefContext();
    for (final Pair<ApplicationInfo, Integer> appData : pipApps) {
        final ApplicationInfo appInfo = appData.first;
        final int userId = appData.second;
        final UserHandle user = UserHandle.of(userId);
        final String packageName = appInfo.packageName;
        final CharSequence label = appInfo.loadLabel(mPackageManager);
        final Preference pref = new AppPreference(prefContext);
        pref.setIcon(mIconDrawableFactory.getBadgedIcon(appInfo, userId));
        pref.setTitle(mPackageManager.getUserBadgedLabel(label, user));
        pref.setSummary(PictureInPictureDetails.getPreferenceSummary(prefContext, appInfo.uid, packageName));
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                AppInfoBase.startAppInfoFragment(PictureInPictureDetails.class, R.string.picture_in_picture_app_detail_title, packageName, appInfo.uid, PictureInPictureSettings.this, -1, getMetricsCategory());
                return true;
            }
        });
        screen.addPreference(pref);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.AppPreference) ApplicationInfo(android.content.pm.ApplicationInfo) OnPreferenceClickListener(androidx.preference.Preference.OnPreferenceClickListener) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) Pair(android.util.Pair)

Aggregations

PreferenceScreen (androidx.preference.PreferenceScreen)244 Preference (androidx.preference.Preference)81 Test (org.junit.Test)60 Context (android.content.Context)36 PreferenceManager (androidx.preference.PreferenceManager)36 ContentResolver (android.content.ContentResolver)25 PreferenceCategory (androidx.preference.PreferenceCategory)24 Bundle (android.os.Bundle)20 ArrayList (java.util.ArrayList)20 SwitchPreference (androidx.preference.SwitchPreference)19 Resources (android.content.res.Resources)18 Before (org.junit.Before)17 ListPreference (androidx.preference.ListPreference)14 PackageManager (android.content.pm.PackageManager)13 PreferenceGroup (androidx.preference.PreferenceGroup)13 ApplicationInfo (android.content.pm.ApplicationInfo)9 VisibleForTesting (androidx.annotation.VisibleForTesting)9 List (java.util.List)9 UserManager (android.os.UserManager)8 StorageItemPreference (com.android.settings.deviceinfo.StorageItemPreference)8