use of com.android.settingslib.drawer.DashboardCategory in project android_packages_apps_Settings by omnirom.
the class SiteMapManager method init.
/**
* Initialize a list of {@link SiteMapPair}s. Each pair knows about a single parent-child
* page relationship.
*
* We get the knowledge of such mPairs from 2 sources:
* 1. Static indexing time: we know which page(s) a parent can open by parsing its pref xml.
* 2. IA: We know from {@link DashboardFeatureProvider} which page can be dynamically
* injected to where.
*/
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
@WorkerThread
synchronized void init(Context context) {
if (mInitialized) {
// Make sure only init once.
return;
}
final long startTime = System.currentTimeMillis();
// First load site map from static index table.
final Context appContext = context.getApplicationContext();
final SQLiteDatabase db = IndexDatabaseHelper.getInstance(appContext).getReadableDatabase();
Cursor sitemap = db.query(IndexDatabaseHelper.Tables.TABLE_SITE_MAP, SITE_MAP_COLUMNS, null, null, null, null, null);
while (sitemap.moveToNext()) {
final SiteMapPair pair = new SiteMapPair(sitemap.getString(sitemap.getColumnIndex(SiteMapColumns.PARENT_CLASS)), sitemap.getString(sitemap.getColumnIndex(SiteMapColumns.PARENT_TITLE)), sitemap.getString(sitemap.getColumnIndex(SiteMapColumns.CHILD_CLASS)), sitemap.getString(sitemap.getColumnIndex(SiteMapColumns.CHILD_TITLE)));
mPairs.add(pair);
}
sitemap.close();
// Then prepare a local map that contains class name -> screen title mapping. This is needed
// to figure out the display name for any fragment if it's injected dynamically through IA.
final Map<String, String> classToTitleMap = new HashMap<>();
final Cursor titleQuery = db.query(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, CLASS_TO_SCREEN_TITLE_COLUMNS, null, null, null, null, null);
while (titleQuery.moveToNext()) {
classToTitleMap.put(titleQuery.getString(titleQuery.getColumnIndex(IndexColumns.CLASS_NAME)), titleQuery.getString(titleQuery.getColumnIndex(IndexColumns.SCREEN_TITLE)));
}
titleQuery.close();
// Loop through all IA categories and pages and build additional SiteMapPairs
List<DashboardCategory> categories = FeatureFactory.getFactory(context).getDashboardFeatureProvider(context).getAllCategories();
for (DashboardCategory category : categories) {
// Find the category key first.
final String parentClass = CATEGORY_KEY_TO_PARENT_MAP.get(category.key);
if (parentClass == null) {
continue;
}
// Use the key to look up parent (which page hosts this key)
final String parentName = classToTitleMap.get(parentClass);
if (parentName == null) {
continue;
}
// Build parent-child mPairs for all children listed under this key.
for (Tile tile : category.tiles) {
final String childTitle = tile.title.toString();
String childClass = null;
if (tile.metaData != null) {
childClass = tile.metaData.getString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS);
}
if (childClass == null) {
continue;
}
mPairs.add(new SiteMapPair(parentClass, parentName, childClass, childTitle));
}
}
// Done.
mInitialized = true;
if (DEBUG_TIMING) {
Log.d(TAG, "Init timing: " + (System.currentTimeMillis() - startTime));
}
}
use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class CategoryManagerTest method sortCategories_internalPackageTiles_shouldSkipTileForInternalPackage.
@Test
public void sortCategories_internalPackageTiles_shouldSkipTileForInternalPackage() {
// Create some fake tiles that are not sorted.
final String testPackage = mContext.getPackageName();
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
final ActivityInfo activityInfo1 = new ActivityInfo();
activityInfo1.packageName = testPackage;
activityInfo1.name = "class1";
activityInfo1.metaData = new Bundle();
activityInfo1.metaData.putInt(META_DATA_KEY_ORDER, 100);
final ActivityInfo activityInfo2 = new ActivityInfo();
activityInfo2.packageName = testPackage;
activityInfo2.name = "class2";
activityInfo2.metaData = new Bundle();
activityInfo2.metaData.putInt(META_DATA_KEY_ORDER, 100);
final ActivityInfo activityInfo3 = new ActivityInfo();
activityInfo3.packageName = testPackage;
activityInfo3.name = "class3";
activityInfo3.metaData = new Bundle();
activityInfo3.metaData.putInt(META_DATA_KEY_ORDER, 50);
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(mContext, mCategoryByKeyMap);
// Verify the sorting order is not changed
assertThat(category.getTile(0)).isSameAs(tile1);
assertThat(category.getTile(1)).isSameAs(tile2);
assertThat(category.getTile(2)).isSameAs(tile3);
}
use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class CategoryManagerTest method sortCategories_samePriority_internalPackageTileShouldTakePrecedence.
@Test
public void sortCategories_samePriority_internalPackageTileShouldTakePrecedence() {
// Inject one external tile among internal tiles with same priority.
final String testPackage = mContext.getPackageName();
final String testPackage2 = "com.google.test2";
final String testPackage3 = "com.abcde.test3";
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
final ActivityInfo activityInfo1 = new ActivityInfo();
activityInfo1.packageName = testPackage2;
activityInfo1.name = "class1";
activityInfo1.metaData = new Bundle();
activityInfo1.metaData.putInt(META_DATA_KEY_ORDER, 1);
final ActivityInfo activityInfo2 = new ActivityInfo();
activityInfo2.packageName = testPackage;
activityInfo2.name = "class2";
activityInfo2.metaData = new Bundle();
activityInfo2.metaData.putInt(META_DATA_KEY_ORDER, 1);
final ActivityInfo activityInfo3 = new ActivityInfo();
activityInfo3.packageName = testPackage3;
activityInfo3.name = "class3";
activityInfo3.metaData = new Bundle();
activityInfo3.metaData.putInt(META_DATA_KEY_ORDER, 1);
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(mContext, mCategoryByKeyMap);
// Verify the sorting order is internal first, follow by package name ordering
assertThat(category.getTile(0)).isSameAs(tile2);
assertThat(category.getTile(1)).isSameAs(tile3);
assertThat(category.getTile(2)).isSameAs(tile1);
}
use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class CategoryManagerTest method filterTiles_noDuplicate_noChange.
@Test
public void filterTiles_noDuplicate_noChange() {
// Create some unique tiles
final String testPackage = mContext.getPackageName();
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
final ActivityInfo activityInfo1 = new ActivityInfo();
activityInfo1.packageName = testPackage;
activityInfo1.name = "class1";
activityInfo1.metaData = new Bundle();
activityInfo1.metaData.putInt(META_DATA_KEY_ORDER, 100);
final ActivityInfo activityInfo2 = new ActivityInfo();
activityInfo2.packageName = testPackage;
activityInfo2.name = "class2";
activityInfo2.metaData = new Bundle();
activityInfo2.metaData.putInt(META_DATA_KEY_ORDER, 100);
final ActivityInfo activityInfo3 = new ActivityInfo();
activityInfo3.packageName = testPackage;
activityInfo3.name = "class3";
activityInfo3.metaData = new Bundle();
activityInfo3.metaData.putInt(META_DATA_KEY_ORDER, 50);
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);
mCategoryManager.filterDuplicateTiles(mCategoryByKeyMap);
assertThat(category.getTilesCount()).isEqualTo(3);
}
use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class CategoryManagerTest method sortCategories_internalAndExternalPackageTiles_shouldRetainPriorityOrdering.
@Test
public void sortCategories_internalAndExternalPackageTiles_shouldRetainPriorityOrdering() {
// Inject one external tile among internal tiles.
final String testPackage = mContext.getPackageName();
final String testPackage2 = "com.google.test2";
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
final ActivityInfo activityInfo1 = new ActivityInfo();
activityInfo1.packageName = testPackage;
activityInfo1.name = "class1";
activityInfo1.metaData = new Bundle();
activityInfo1.metaData.putInt(META_DATA_KEY_ORDER, 2);
final ActivityInfo activityInfo2 = new ActivityInfo();
activityInfo2.packageName = testPackage;
activityInfo2.name = "class2";
activityInfo2.metaData = new Bundle();
activityInfo2.metaData.putInt(META_DATA_KEY_ORDER, 1);
final ActivityInfo activityInfo3 = new ActivityInfo();
activityInfo3.packageName = testPackage2;
activityInfo3.name = "class0";
activityInfo3.metaData = new Bundle();
activityInfo3.metaData.putInt(META_DATA_KEY_ORDER, 0);
final ActivityInfo activityInfo4 = new ActivityInfo();
activityInfo4.packageName = testPackage;
activityInfo4.name = "class3";
activityInfo4.metaData = new Bundle();
activityInfo4.metaData.putInt(META_DATA_KEY_ORDER, -1);
final Tile tile1 = new Tile(activityInfo1, category.key);
final Tile tile2 = new Tile(activityInfo2, category.key);
final Tile tile4 = new Tile(activityInfo4, category.key);
final Tile tile3 = new Tile(activityInfo3, category.key);
category.addTile(tile1);
category.addTile(tile2);
category.addTile(tile3);
category.addTile(tile4);
mCategoryByKeyMap.put(CATEGORY_HOMEPAGE, category);
// Sort their priorities
mCategoryManager.sortCategories(mContext, mCategoryByKeyMap);
// Verify the sorting order is not changed
assertThat(category.getTile(0)).isSameAs(tile1);
assertThat(category.getTile(1)).isSameAs(tile2);
assertThat(category.getTile(2)).isSameAs(tile3);
assertThat(category.getTile(3)).isSameAs(tile4);
}
Aggregations