Search in sources :

Example 36 with PreferenceScreen

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

the class ModuleLicensesPreferenceControllerTest method displayPreference_includeOnlyModulesWithLicenseFile.

@Test
public void displayPreference_includeOnlyModulesWithLicenseFile() throws PackageManager.NameNotFoundException, IOException {
    Context context = mock(Context.class);
    ModuleLicensesPreferenceController controller = new ModuleLicensesPreferenceController(context, PREFERENCE_KEY);
    PackageManager packageManager = mock(PackageManager.class);
    when(context.getPackageManager()).thenReturn(packageManager);
    PreferenceScreen screen = mock(PreferenceScreen.class);
    PreferenceGroup group = spy(new MockPreferenceGroup(RuntimeEnvironment.application, null));
    when(screen.findPreference(PREFERENCE_KEY)).thenReturn(group);
    when(group.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    when(packageManager.getInstalledModules(0)).thenReturn(Arrays.asList(mModuleTwo, mModuleOne));
    PackageInfo packageInfo = new PackageInfo();
    ApplicationInfo applicationInfo = new ApplicationInfo();
    packageInfo.applicationInfo = applicationInfo;
    when(packageManager.getPackageInfo(MODULE_1_PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(packageInfo);
    Resources resources = mock(Resources.class);
    when(packageManager.getResourcesForApplication(applicationInfo)).thenReturn(resources);
    AssetManager manager = mock(AssetManager.class);
    when(resources.getAssets()).thenReturn(manager);
    when(manager.list("")).thenReturn(new String[] { GZIPPED_LICENSE_FILE_NAME });
    PackageInfo packageInfo2 = new PackageInfo();
    ApplicationInfo applicationInfo2 = new ApplicationInfo();
    packageInfo2.applicationInfo = applicationInfo2;
    when(packageManager.getPackageInfo(MODULE_2_PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(packageInfo2);
    Resources resources2 = mock(Resources.class);
    when(packageManager.getResourcesForApplication(applicationInfo2)).thenReturn(resources2);
    AssetManager manager2 = mock(AssetManager.class);
    when(resources2.getAssets()).thenReturn(manager2);
    when(manager2.list("")).thenReturn(new String[] {});
    controller.displayPreference(screen);
    assertThat(group.getPreferenceCount()).isEqualTo(1);
    assertThat(group.getPreference(0).getTitle()).isEqualTo(MODULE_1_NAME);
}
Also used : Context(android.content.Context) AssetManager(android.content.res.AssetManager) PackageManager(android.content.pm.PackageManager) PreferenceScreen(androidx.preference.PreferenceScreen) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) PreferenceGroup(androidx.preference.PreferenceGroup) Resources(android.content.res.Resources) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 37 with PreferenceScreen

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

the class ModuleLicensesPreferenceControllerTest method displayPreference_alphabeticalOrder.

@Test
public void displayPreference_alphabeticalOrder() throws PackageManager.NameNotFoundException, IOException {
    Context context = mock(Context.class);
    ModuleLicensesPreferenceController controller = new ModuleLicensesPreferenceController(context, PREFERENCE_KEY);
    PackageManager packageManager = mock(PackageManager.class);
    when(context.getPackageManager()).thenReturn(packageManager);
    PreferenceScreen screen = mock(PreferenceScreen.class);
    PreferenceGroup group = spy(new MockPreferenceGroup(RuntimeEnvironment.application, null));
    when(screen.findPreference(PREFERENCE_KEY)).thenReturn(group);
    when(group.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    when(packageManager.getInstalledModules(0)).thenReturn(Arrays.asList(mModuleTwo, mModuleOne));
    PackageInfo packageInfo = new PackageInfo();
    ApplicationInfo applicationInfo = new ApplicationInfo();
    packageInfo.applicationInfo = applicationInfo;
    when(packageManager.getPackageInfo(MODULE_1_PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(packageInfo);
    when(packageManager.getPackageInfo(MODULE_2_PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(packageInfo);
    Resources resources = mock(Resources.class);
    when(packageManager.getResourcesForApplication(applicationInfo)).thenReturn(resources);
    AssetManager manager = mock(AssetManager.class);
    when(resources.getAssets()).thenReturn(manager);
    when(manager.list("")).thenReturn(new String[] { GZIPPED_LICENSE_FILE_NAME });
    controller.displayPreference(screen);
    assertThat(group.getPreferenceCount()).isEqualTo(2);
    assertThat(group.getPreference(0).getTitle()).isEqualTo(MODULE_1_NAME);
    assertThat(group.getPreference(1).getTitle()).isEqualTo(MODULE_2_NAME);
}
Also used : Context(android.content.Context) AssetManager(android.content.res.AssetManager) PackageManager(android.content.pm.PackageManager) PreferenceScreen(androidx.preference.PreferenceScreen) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) PreferenceGroup(androidx.preference.PreferenceGroup) Resources(android.content.res.Resources) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 38 with PreferenceScreen

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

the class EnterpriseSetDefaultAppsListPreferenceController method updateUi.

private void updateUi() {
    final Context prefContext = mParent.getPreferenceManager().getContext();
    final PreferenceScreen screen = mParent.getPreferenceScreen();
    if (screen == null) {
        return;
    }
    if (!mEnterprisePrivacyFeatureProvider.isInCompMode() && mUsers.size() == 1) {
        createPreferences(prefContext, screen, mApps.get(0));
    } else {
        for (int i = 0; i < mUsers.size(); i++) {
            final UserInfo userInfo = mUsers.get(i);
            final PreferenceCategory category = new PreferenceCategory(prefContext);
            screen.addPreference(category);
            if (userInfo.isManagedProfile()) {
                category.setTitle(R.string.category_work);
            } else {
                category.setTitle(R.string.category_personal);
            }
            category.setOrder(i);
            createPreferences(prefContext, category, mApps.get(i));
        }
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) UserInfo(android.content.pm.UserInfo)

Example 39 with PreferenceScreen

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

the class AbstractMobileNetworkSettings method updatePreferenceStates.

/*
     * Replace design within {@link DashboardFragment#updatePreferenceStates()}
     */
@Override
protected void updatePreferenceStates() {
    mHiddenControllerList.clear();
    if (mIsRedrawRequired) {
        redrawPreferenceControllers();
        return;
    }
    final PreferenceScreen screen = getPreferenceScreen();
    getPreferenceControllersAsList().forEach(controller -> updateVisiblePreferenceControllers(screen, controller));
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen)

Example 40 with PreferenceScreen

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

the class AbstractMobileNetworkSettings method redrawPreferenceControllers.

void redrawPreferenceControllers() {
    mHiddenControllerList.clear();
    if (!isResumed()) {
        mIsRedrawRequired = true;
        return;
    }
    mIsRedrawRequired = false;
    final long startTime = SystemClock.elapsedRealtime();
    final List<AbstractPreferenceController> controllers = getPreferenceControllersAsList();
    final TelephonyStatusControlSession session = setTelephonyAvailabilityStatus(controllers);
    final PreferenceScreen screen = getPreferenceScreen();
    controllers.forEach(controller -> {
        controller.displayPreference(screen);
        updateVisiblePreferenceControllers(screen, controller);
    });
    final long endTime = SystemClock.elapsedRealtime();
    Log.d(LOG_TAG, "redraw fragment: +" + (endTime - startTime) + "ms");
    session.close();
}
Also used : AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) PreferenceScreen(androidx.preference.PreferenceScreen)

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