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));
}
}
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);
}
}
}
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);
}
}
}
}
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;
}
}
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);
});
}
Aggregations