<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/dashboard_tile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.Icon;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
+import android.util.ArrayMap;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
private final List<Object> mItems = new ArrayList<>();
private final List<Integer> mTypes = new ArrayList<>();
private final List<Integer> mIds = new ArrayList<>();
+ private final IconCache mCache;
private final Context mContext;
- private final SuggestionsChecks mSuggestionsChecks;
private List<DashboardCategory> mCategories;
private List<Condition> mConditions;
public DashboardAdapter(Context context) {
mContext = context;
- mSuggestionsChecks = new SuggestionsChecks(mContext);
+ mCache = new IconCache(context);
setHasStableIds(true);
setShowingAll(true);
return mSuggestions;
}
- public void setSuggestions(SuggestionParser suggestionParser) {
- mSuggestionParser = suggestionParser;
- mSuggestions = suggestionParser.getSuggestions();
- for (int i = 0; i < mSuggestions.size(); i++) {
- if (mSuggestionsChecks.isSuggestionComplete(mSuggestions.get(i))) {
- disableSuggestion(mSuggestions.get(i));
- mSuggestions.remove(i--);
- }
- }
+ public void setSuggestions(List<Tile> suggestions, SuggestionParser parser) {
+ mSuggestions = suggestions;
+ mSuggestionParser = parser;
recountItems();
}
case R.layout.dashboard_tile:
final Tile tile = (Tile) mItems.get(position);
onBindTile(holder, tile);
- holder.itemView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ((SettingsActivity) mContext).openTile(tile);
- }
- });
+ holder.itemView.setTag(tile);
+ holder.itemView.setOnClickListener(this);
break;
case R.layout.suggestion_header:
onBindSuggestionHeader(holder);
popup.show();
}
- private void disableSuggestion(Tile suggestion) {
+ public void disableSuggestion(Tile suggestion) {
if (mSuggestionParser.dismissSuggestion(suggestion)) {
mContext.getPackageManager().setComponentEnabledSetting(
suggestion.intent.getComponent(),
}
private void onBindTile(DashboardItemHolder holder, Tile tile) {
- holder.icon.setImageIcon(tile.icon);
+ holder.icon.setImageDrawable(mCache.getIcon(tile.icon));
holder.title.setText(tile.title);
if (!TextUtils.isEmpty(tile.summary)) {
holder.summary.setText(tile.summary);
@Override
public void onClick(View v) {
+ if (v.getId() == R.id.dashboard_tile) {
+ ((SettingsActivity) mContext).openTile((Tile) v.getTag());
+ return;
+ }
if (v.getTag() == mExpandedCondition) {
MetricsLogger.action(mContext, MetricsEvent.ACTION_SETTINGS_CONDITION_CLICK,
mExpandedCondition.getMetricsConstant());
return packageName;
}
+ private static class IconCache {
+
+ private final Context mContext;
+ private final ArrayMap<Icon, Drawable> mMap = new ArrayMap<>();
+
+ public IconCache(Context context) {
+ mContext = context;
+ }
+
+ public Drawable getIcon(Icon icon) {
+ Drawable drawable = mMap.get(icon);
+ if (drawable == null) {
+ drawable = icon.loadDrawable(mContext);
+ mMap.put(icon, drawable);
+ }
+ return drawable;
+ }
+ }
+
public static class DashboardItemHolder extends RecyclerView.ViewHolder {
public final ImageView icon;
public final TextView title;
package com.android.settings.dashboard;
import android.content.Context;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.ViewGroup;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
-import com.android.settingslib.HelpUtils;
import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
import com.android.settings.Settings;
import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
import com.android.settings.dashboard.conditional.ConditionManager;
import com.android.settings.dashboard.conditional.FocusRecyclerView;
+import com.android.settingslib.HelpUtils;
import com.android.settingslib.SuggestionParser;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.SettingsDrawerActivity;
private ConditionManager mConditionManager;
private SuggestionParser mSuggestionParser;
private LinearLayoutManager mLayoutManager;
+ private SuggestionsChecks mSuggestionsChecks;
@Override
protected int getMetricsCategory() {
mConditionManager = ConditionManager.get(context);
mSuggestionParser = new SuggestionParser(context,
context.getSharedPreferences(SUGGESTIONS, 0), R.xml.suggestion_ordering);
+ mSuggestionsChecks = new SuggestionsChecks(getContext());
if (DEBUG_TIMING) Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
+ " ms");
}
MetricsLogger.visible(getContext(), c.getMetricsConstant());
}
}
- for (Tile suggestion : mAdapter.getSuggestions()) {
- MetricsLogger.action(getContext(), MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
- DashboardAdapter.getSuggestionIdentifier(getContext(), suggestion));
+ if (mAdapter.getSuggestions() != null) {
+ for (Tile suggestion : mAdapter.getSuggestions()) {
+ MetricsLogger.action(getContext(), MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
+ DashboardAdapter.getSuggestionIdentifier(getContext(), suggestion));
+ }
}
if (DEBUG_TIMING) Log.d(TAG, "onResume took " + (System.currentTimeMillis() - startTime)
+ " ms");
return;
}
- long start = System.currentTimeMillis();
- // TODO: Cache summaries from old categories somehow.
List<DashboardCategory> categories =
((SettingsActivity) getActivity()).getDashboardCategories();
mAdapter.setCategories(categories);
// recheck to see if any suggestions have been changed.
- mAdapter.setSuggestions(mSuggestionParser);
-
- long delta = System.currentTimeMillis() - start;
- Log.d(TAG, "rebuildUI took: " + delta + " ms");
+ new SuggestionLoader().execute();
}
@Override
Log.d(TAG, "onConditionsChanged");
mAdapter.setConditions(mConditionManager.getConditions());
}
+
+ private class SuggestionLoader extends AsyncTask<Void, Void, List<Tile>> {
+
+ @Override
+ protected List<Tile> doInBackground(Void... params) {
+ List<Tile> suggestions = mSuggestionParser.getSuggestions();
+ for (int i = 0; i < suggestions.size(); i++) {
+ if (mSuggestionsChecks.isSuggestionComplete(suggestions.get(i))) {
+ mAdapter.disableSuggestion(suggestions.get(i));
+ suggestions.remove(i--);
+ }
+ }
+ return suggestions;
+ }
+
+ @Override
+ protected void onPostExecute(List<Tile> tiles) {
+ mAdapter.setSuggestions(tiles, mSuggestionParser);
+ }
+ }
}
package com.android.settings.dashboard.conditional;
import android.content.Context;
+import android.os.AsyncTask;
import android.os.PersistableBundle;
import android.util.Log;
import android.util.Xml;
private final Context mContext;
private final ArrayList<Condition> mConditions;
- private final File mXmlFile;
+ private File mXmlFile;
private final ArrayList<ConditionListener> mListeners = new ArrayList<>();
private ConditionManager(Context context) {
mContext = context;
mConditions = new ArrayList<Condition>();
- mXmlFile = new File(context.getFilesDir(), FILE_NAME);
- if (mXmlFile.exists()) {
- readFromXml();
- }
- addMissingConditions();
+ new ConditionLoader().execute();
}
public void refreshAll() {
public void addListener(ConditionListener listener) {
mListeners.add(listener);
+ listener.onConditionsChanged();
}
public void remListener(ConditionListener listener) {
mListeners.remove(listener);
}
+ private class ConditionLoader extends AsyncTask<Void, Void, Void> {
+ @Override
+ protected Void doInBackground(Void... params) {
+ mXmlFile = new File(mContext.getFilesDir(), FILE_NAME);
+ if (mXmlFile.exists()) {
+ readFromXml();
+ }
+ addMissingConditions();
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ final int N = mListeners.size();
+ for (int i = 0; i < N; i++) {
+ mListeners.get(i).onConditionsChanged();
+ }
+ }
+ }
+
public static ConditionManager get(Context context) {
if (sInstance == null) {
sInstance = new ConditionManager(context.getApplicationContext());