Search in sources :

Example 51 with Tile

use of com.android.settingslib.drawer.Tile 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 52 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.

the class DashboardAdapter method setCategoriesAndSuggestions.

public void setCategoriesAndSuggestions(DashboardCategory category, List<Tile> suggestions) {
    tintIcons(category, suggestions);
    final DashboardData prevData = mDashboardData;
    mDashboardData = new DashboardData.Builder(prevData).setSuggestions(suggestions.subList(0, Math.min(suggestions.size(), MAX_SUGGESTION_TO_SHOW))).setCategory(category).build();
    notifyDashboardDataChanged(prevData);
    List<Tile> shownSuggestions = null;
    final int mode = mDashboardData.getSuggestionConditionMode();
    if (mode == DashboardData.HEADER_MODE_DEFAULT) {
        shownSuggestions = suggestions.subList(0, Math.min(suggestions.size(), DashboardData.DEFAULT_SUGGESTION_COUNT));
    } else if (mode != DashboardData.HEADER_MODE_COLLAPSED) {
        shownSuggestions = suggestions;
    }
    if (shownSuggestions != null) {
        for (Tile suggestion : shownSuggestions) {
            final String identifier = mSuggestionFeatureProvider.getSuggestionIdentifier(mContext, suggestion);
            mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, identifier, getSuggestionTaggedData());
            mSuggestionsShownLogged.add(identifier);
        }
    }
}
Also used : Tile(com.android.settingslib.drawer.Tile)

Example 53 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.

the class DashboardAdapter method tintIcons.

private void tintIcons(DashboardCategory category, List<Tile> suggestions) {
    if (!mDashboardFeatureProvider.shouldTintIcon()) {
        return;
    }
    // TODO: Better place for tinting?
    final TypedArray a = mContext.obtainStyledAttributes(new int[] { android.R.attr.colorControlNormal });
    final int tintColor = a.getColor(0, mContext.getColor(R.color.fallback_tintColor));
    a.recycle();
    if (category != null) {
        for (Tile tile : category.tiles) {
            if (tile.isIconTintable) {
                // If this drawable is tintable, tint it to match the color.
                tile.icon.setTint(tintColor);
            }
        }
    }
    if (suggestions != null) {
        for (Tile suggestion : suggestions) {
            if (suggestion.isIconTintable) {
                suggestion.icon.setTint(tintColor);
            }
        }
    }
}
Also used : TypedArray(android.content.res.TypedArray) Tile(com.android.settingslib.drawer.Tile)

Example 54 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.

the class DashboardAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(DashboardItemHolder holder, int position) {
    final int type = mDashboardData.getItemTypeByPosition(position);
    switch(type) {
        case R.layout.dashboard_tile:
            final Tile tile = (Tile) mDashboardData.getItemEntityByPosition(position);
            onBindTile(holder, tile);
            holder.itemView.setTag(tile);
            holder.itemView.setOnClickListener(mTileClickListener);
            break;
        case R.layout.suggestion_condition_container:
            onBindConditionAndSuggestion((SuggestionAndConditionContainerHolder) holder, position);
            break;
        case R.layout.suggestion_condition_header:
            onBindSuggestionConditionHeader((SuggestionAndConditionHeaderHolder) holder, (SuggestionConditionHeaderData) mDashboardData.getItemEntityByPosition(position));
            break;
        case R.layout.suggestion_condition_footer:
            holder.itemView.setOnClickListener(v -> {
                mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND, false);
                DashboardData prevData = mDashboardData;
                mDashboardData = new DashboardData.Builder(prevData).setSuggestionConditionMode(DashboardData.HEADER_MODE_COLLAPSED).build();
                notifyDashboardDataChanged(prevData);
                mRecyclerView.scrollToPosition(SUGGESTION_CONDITION_HEADER_POSITION);
            });
            break;
    }
}
Also used : Tile(com.android.settingslib.drawer.Tile)

Example 55 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.

the class SuggestionAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(DashboardItemHolder holder, int position) {
    final Tile suggestion = (Tile) mSuggestions.get(position);
    final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(mContext, suggestion);
    // This is for cases when a suggestion is dismissed and the next one comes to view
    if (!mSuggestionsShownLogged.contains(suggestionId)) {
        mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, suggestionId, getSuggestionTaggedData());
        mSuggestionsShownLogged.add(suggestionId);
    }
    if (suggestion.remoteViews != null) {
        final ViewGroup itemView = (ViewGroup) holder.itemView;
        itemView.removeAllViews();
        itemView.addView(suggestion.remoteViews.apply(itemView.getContext(), itemView));
    } else {
        holder.icon.setImageDrawable(mCache.getIcon(suggestion.icon));
        holder.title.setText(suggestion.title);
        if (!TextUtils.isEmpty(suggestion.summary)) {
            holder.summary.setText(suggestion.summary);
            holder.summary.setVisibility(View.VISIBLE);
        } else {
            holder.summary.setVisibility(View.GONE);
        }
    }
    final View divider = holder.itemView.findViewById(R.id.divider);
    if (divider != null) {
        divider.setVisibility(position < mSuggestions.size() - 1 ? View.VISIBLE : View.GONE);
    }
    View clickHandler = holder.itemView;
    // If a view with @android:id/primary is defined, use that as the click handler
    // instead.
    final View primaryAction = holder.itemView.findViewById(android.R.id.primary);
    if (primaryAction != null) {
        clickHandler = primaryAction;
    }
    clickHandler.setOnClickListener(v -> {
        mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_SUGGESTION, suggestionId, getSuggestionTaggedData());
        ((SettingsActivity) mContext).startSuggestion(suggestion.intent);
    });
}
Also used : ViewGroup(android.view.ViewGroup) Tile(com.android.settingslib.drawer.Tile) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SettingsActivity(com.android.settings.SettingsActivity)

Aggregations

Tile (com.android.settingslib.drawer.Tile)506 Test (org.junit.Test)345 Intent (android.content.Intent)160 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)117 Bundle (android.os.Bundle)108 Preference (android.support.v7.preference.Preference)98 ComponentName (android.content.ComponentName)93 ArrayList (java.util.ArrayList)87 Context (android.content.Context)70 ActivityTile (com.android.settingslib.drawer.ActivityTile)50 ProviderTile (com.android.settingslib.drawer.ProviderTile)45 UserHandle (android.os.UserHandle)39 Preference (androidx.preference.Preference)39 RecyclerView (android.support.v7.widget.RecyclerView)31 View (android.view.View)31 Icon (android.graphics.drawable.Icon)30 Activity (android.app.Activity)29 VisibleForTesting (android.support.annotation.VisibleForTesting)29 PackageManager (android.content.pm.PackageManager)25 ViewGroup (android.view.ViewGroup)24