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);
}
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);
}
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));
}
}
}
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));
}
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();
}
Aggregations