Search in sources :

Example 21 with DashboardCategory

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));
    }
}
Also used : Context(android.content.Context) DashboardCategory(com.android.settingslib.drawer.DashboardCategory) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) HashMap(java.util.HashMap) Tile(com.android.settingslib.drawer.Tile) Cursor(android.database.Cursor) VisibleForTesting(android.support.annotation.VisibleForTesting) WorkerThread(android.support.annotation.WorkerThread)

Example 22 with DashboardCategory

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);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ActivityInfo(android.content.pm.ActivityInfo) Bundle(android.os.Bundle) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Example 23 with DashboardCategory

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);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ActivityInfo(android.content.pm.ActivityInfo) Bundle(android.os.Bundle) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Example 24 with DashboardCategory

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);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ActivityInfo(android.content.pm.ActivityInfo) Bundle(android.os.Bundle) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Example 25 with DashboardCategory

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);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ActivityInfo(android.content.pm.ActivityInfo) Bundle(android.os.Bundle) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Aggregations

DashboardCategory (com.android.settingslib.drawer.DashboardCategory)449 Tile (com.android.settingslib.drawer.Tile)302 Test (org.junit.Test)225 ProviderTile (com.android.settingslib.drawer.ProviderTile)184 ActivityTile (com.android.settingslib.drawer.ActivityTile)179 Bundle (android.os.Bundle)77 ArrayList (java.util.ArrayList)71 VisibleForTesting (androidx.annotation.VisibleForTesting)52 ActivityInfo (android.content.pm.ActivityInfo)41 Intent (android.content.Intent)32 ComponentName (android.content.ComponentName)31 Context (android.content.Context)31 Before (org.junit.Before)30 Activity (android.app.Activity)27 View (android.view.View)27 PreferenceScreen (android.support.v7.preference.PreferenceScreen)26 List (java.util.List)26 ProviderInfo (android.content.pm.ProviderInfo)23 HashMap (java.util.HashMap)20 TestConfig (com.android.settings.TestConfig)18