use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class CategoryManagerTest method sortCategories_singlePackage_shouldReorderBasedOnPriority.
@Test
public void sortCategories_singlePackage_shouldReorderBasedOnPriority() {
// Create some fake tiles that are not sorted.
final String testPackage = "com.android.test";
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
final ActivityInfo activityInfo1 = new ActivityInfo();
activityInfo1.metaData = new Bundle();
activityInfo1.metaData.putInt(META_DATA_KEY_ORDER, 100);
activityInfo1.packageName = testPackage;
activityInfo1.name = "class1";
final ActivityInfo activityInfo2 = new ActivityInfo();
activityInfo2.metaData = new Bundle();
activityInfo2.metaData.putInt(META_DATA_KEY_ORDER, 50);
activityInfo2.packageName = testPackage;
activityInfo2.name = "class2";
final ActivityInfo activityInfo3 = new ActivityInfo();
activityInfo3.metaData = new Bundle();
activityInfo3.metaData.putInt(META_DATA_KEY_ORDER, 200);
activityInfo3.packageName = testPackage;
activityInfo3.name = "class3";
final Tile tile1 = new Tile(activityInfo1, category.key);
final Tile tile2 = new Tile(activityInfo2, category.key);
final Tile tile3 = new Tile(activityInfo3, category.key);
category.addTile(tile1);
category.addTile(tile2);
category.addTile(tile3);
mCategoryByKeyMap.put(CATEGORY_HOMEPAGE, category);
// Sort their priorities
mCategoryManager.sortCategories(RuntimeEnvironment.application, mCategoryByKeyMap);
// Verify they are now sorted.
assertThat(category.getTile(0)).isSameAs(tile3);
assertThat(category.getTile(1)).isSameAs(tile1);
assertThat(category.getTile(2)).isSameAs(tile2);
}
use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DashboardFragmentTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mActivityInfo = new ActivityInfo();
mActivityInfo.packageName = "pkg";
mActivityInfo.name = "class";
mActivityInfo.metaData = new Bundle();
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "injected_tile_key");
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mDashboardCategory = new DashboardCategory("key");
mDashboardCategory.addTile(new Tile(mActivityInfo, mDashboardCategory.key));
mTestFragment = new TestFragment(RuntimeEnvironment.application);
when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(nullable(String.class))).thenReturn(mDashboardCategory);
mTestFragment.onAttach(RuntimeEnvironment.application);
when(mContext.getPackageName()).thenReturn("TestPackage");
mControllers = new ArrayList<>();
}
use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class CategoryManagerTest method backwardCompatCleanupForCategory_shouldChangeCategoryForOldKeys.
@Test
public void backwardCompatCleanupForCategory_shouldChangeCategoryForOldKeys() {
final String oldCategory = "com.android.settings.category.wireless";
final Tile tile1 = new Tile(mActivityInfo, oldCategory);
tile1.setCategory(oldCategory);
final DashboardCategory category1 = new DashboardCategory(oldCategory);
category1.addTile(tile1);
mCategoryByKeyMap.put(oldCategory, category1);
mTileByComponentCache.put(new Pair<>("PACKAGE", "CLASS1"), tile1);
mCategoryManager.backwardCompatCleanupForCategory(mTileByComponentCache, mCategoryByKeyMap);
// Added 1 more category to category map.
assertThat(mCategoryByKeyMap.size()).isEqualTo(2);
// The new category map has CATEGORY_NETWORK type now, which contains 1 tile.
assertThat(mCategoryByKeyMap.get(CategoryKey.CATEGORY_NETWORK).getTilesCount()).isEqualTo(1);
// Old category still exists.
assertThat(mCategoryByKeyMap.get(oldCategory).getTilesCount()).isEqualTo(1);
}
use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DashboardFragment method refreshDashboardTiles.
/**
* Refresh preference items backed by DashboardCategory.
*/
@VisibleForTesting
void refreshDashboardTiles(final String TAG) {
final PreferenceScreen screen = getPreferenceScreen();
final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
if (category == null) {
Log.d(TAG, "NO dashboard tiles for " + TAG);
return;
}
final List<Tile> tiles = category.getTiles();
if (tiles == null) {
Log.d(TAG, "tile list is empty, skipping category " + category.key);
return;
}
// Create a list to track which tiles are to be removed.
final List<String> remove = new ArrayList<>(mDashboardTilePrefKeys);
// There are dashboard tiles, so we need to install SummaryLoader.
if (mSummaryLoader != null) {
mSummaryLoader.release();
}
final Context context = getContext();
mSummaryLoader = new SummaryLoader(getActivity(), getCategoryKey());
mSummaryLoader.setSummaryConsumer(this);
// Install dashboard tiles.
final boolean forceRoundedIcons = shouldForceRoundedIcon();
for (Tile tile : tiles) {
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
if (TextUtils.isEmpty(key)) {
Log.d(TAG, "tile does not contain a key, skipping " + tile);
continue;
}
if (!displayTile(tile)) {
continue;
}
if (mDashboardTilePrefKeys.contains(key)) {
// Have the key already, will rebind.
final Preference preference = screen.findPreference(key);
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), forceRoundedIcons, getMetricsCategory(), preference, tile, key, mPlaceholderPreferenceController.getOrder());
} else {
// Don't have this key, add it.
final Preference pref = new Preference(getPrefContext());
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), forceRoundedIcons, getMetricsCategory(), pref, tile, key, mPlaceholderPreferenceController.getOrder());
screen.addPreference(pref);
mDashboardTilePrefKeys.add(key);
}
remove.remove(key);
}
// Finally remove tiles that are gone.
for (String key : remove) {
mDashboardTilePrefKeys.remove(key);
final Preference preference = screen.findPreference(key);
if (preference != null) {
screen.removePreference(preference);
}
}
mSummaryLoader.setListening(true);
}
use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DashboardFragment method onStart.
@Override
public void onStart() {
super.onStart();
final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
if (category == null) {
return;
}
if (mSummaryLoader != null) {
// SummaryLoader can be null when there is no dynamic tiles.
mSummaryLoader.setListening(true);
}
final Activity activity = getActivity();
if (activity instanceof SettingsBaseActivity) {
mListeningToCategoryChange = true;
((SettingsBaseActivity) activity).addCategoryListener(this);
}
}
Aggregations