Search in sources :

Example 1 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SummaryLoader method getTileFromCategory.

private Tile getTileFromCategory(List<DashboardCategory> categories, ComponentName component) {
    if (categories == null) {
        if (DEBUG) {
            Log.d(TAG, "Category is null, can't find tile");
        }
        return null;
    }
    final int categorySize = categories.size();
    for (int i = 0; i < categorySize; i++) {
        final DashboardCategory category = categories.get(i);
        final int tileCount = category.tiles.size();
        for (int j = 0; j < tileCount; j++) {
            final Tile tile = category.tiles.get(j);
            if (component.equals(tile.intent.getComponent())) {
                return tile;
            }
        }
    }
    return null;
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Tile(com.android.settingslib.drawer.Tile)

Example 2 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project android_packages_apps_Settings by LineageOS.

the class DashboardAdapter method onSaveInstanceState.

void onSaveInstanceState(Bundle outState) {
    final List<Tile> suggestions = mDashboardData.getSuggestions();
    final DashboardCategory category = mDashboardData.getCategory();
    if (suggestions != null) {
        outState.putParcelableArrayList(STATE_SUGGESTION_LIST, new ArrayList<>(suggestions));
    }
    if (category != null) {
        outState.putParcelable(STATE_CATEGORY_LIST, category);
    }
    outState.putStringArrayList(STATE_SUGGESTIONS_SHOWN_LOGGED, mSuggestionsShownLogged);
    outState.putInt(STATE_SUGGESTION_CONDITION_MODE, mDashboardData.getSuggestionConditionMode());
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Tile(com.android.settingslib.drawer.Tile)

Example 3 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project android_packages_apps_Settings by LineageOS.

the class DashboardFeatureProviderImpl method getPreferencesForCategory.

@Override
public List<Preference> getPreferencesForCategory(Activity activity, Context context, int sourceMetricsCategory, String key) {
    final DashboardCategory category = getTilesForCategory(key);
    if (category == null) {
        Log.d(TAG, "NO dashboard tiles for " + TAG);
        return null;
    }
    final List<Tile> tiles = category.tiles;
    if (tiles == null || tiles.isEmpty()) {
        Log.d(TAG, "tile list is empty, skipping category " + category.title);
        return null;
    }
    final List<Preference> preferences = new ArrayList<>();
    for (Tile tile : tiles) {
        final Preference pref = new Preference(context);
        bindPreferenceToTile(activity, sourceMetricsCategory, pref, tile, null, /* key */
        Preference.DEFAULT_ORDER);
        preferences.add(pref);
    }
    return preferences;
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Preference(android.support.v7.preference.Preference) ArrayList(java.util.ArrayList) Tile(com.android.settingslib.drawer.Tile)

Example 4 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project android_packages_apps_Settings by LineageOS.

the class DashboardFragment method onCategoriesChanged.

@Override
public void onCategoriesChanged() {
    final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
    if (category == null) {
        return;
    }
    refreshDashboardTiles(getLogTag());
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory)

Example 5 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project android_packages_apps_Settings by LineageOS.

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)

Aggregations

DashboardCategory (com.android.settingslib.drawer.DashboardCategory)162 Tile (com.android.settingslib.drawer.Tile)96 Test (org.junit.Test)83 Bundle (android.os.Bundle)45 ArrayList (java.util.ArrayList)38 PreferenceScreen (android.support.v7.preference.PreferenceScreen)30 Intent (android.content.Intent)25 Context (android.content.Context)21 Activity (android.app.Activity)19 View (android.view.View)19 VisibleForTesting (android.support.annotation.VisibleForTesting)18 TestConfig (com.android.settings.TestConfig)18 Config (org.robolectric.annotation.Config)18 ComponentName (android.content.ComponentName)14 TypedArray (android.content.res.TypedArray)12 Preference (android.support.v7.preference.Preference)12 RecyclerView (android.support.v7.widget.RecyclerView)12 DisplayMetrics (android.util.DisplayMetrics)12 SettingsDrawerActivity (com.android.settingslib.drawer.SettingsDrawerActivity)12 ActivityInfo (android.content.pm.ActivityInfo)9