Use DashboardFeatureProvider to load homepage tiles.
Adding support to homepage category. Test: SettingsRoboTests for regression. Will write tests for new feature soon once we are set on the data structure. Bug: 31781480 Change-Id: I25fa367fecb643f17e23f0182df7585bf1fcdd02
This commit is contained in:
@@ -15,12 +15,27 @@
|
||||
*/
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.content.Context;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FeatureProvider for dashboard (aka settings homepage).
|
||||
*/
|
||||
public interface DashboardFeatureProvider {
|
||||
|
||||
boolean shouldUseNewIALayout(Context context);
|
||||
/**
|
||||
* Whether or not this feature is enabled.
|
||||
*/
|
||||
boolean isEnabled();
|
||||
|
||||
/**
|
||||
* Get tiles (wrapped in {@link DashboardCategory}) for homepage.
|
||||
*/
|
||||
DashboardCategory getTilesForHomepage();
|
||||
|
||||
/**
|
||||
* Get all tiles, grouped by category.
|
||||
*/
|
||||
List<DashboardCategory> getAllCategories();
|
||||
}
|
||||
|
||||
@@ -18,14 +18,38 @@ package com.android.settings.dashboard;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.CategoryManager;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Impl for {@code DashboardFeatureProvider}.
|
||||
*/
|
||||
public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
|
||||
protected final Context mContext;
|
||||
|
||||
private final CategoryManager mCategoryManager;
|
||||
|
||||
public DashboardFeatureProviderImpl(Context context) {
|
||||
mContext = context;
|
||||
mCategoryManager = CategoryManager.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseNewIALayout(Context context) {
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardCategory getTilesForHomepage() {
|
||||
return mCategoryManager.getTilesByCategory(mContext, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardCategory> getAllCategories() {
|
||||
return mCategoryManager.getCategories(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
|
||||
import com.android.settings.dashboard.conditional.ConditionManager;
|
||||
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.SuggestionParser;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||
@@ -50,7 +51,7 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
private static final boolean DEBUG_TIMING = false;
|
||||
private static final String TAG = "DashboardSummary";
|
||||
|
||||
public static final String[] INITIAL_ITEMS = new String[] {
|
||||
public static final String[] INITIAL_ITEMS = new String[]{
|
||||
Settings.WifiSettingsActivity.class.getName(),
|
||||
Settings.BluetoothSettingsActivity.class.getName(),
|
||||
Settings.DataUsageSummaryActivity.class.getName(),
|
||||
@@ -74,6 +75,7 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
private SuggestionsChecks mSuggestionsChecks;
|
||||
private ArrayList<String> mSuggestionsShownLogged;
|
||||
private ArrayList<String> mSuggestionsHiddenLogged;
|
||||
private DashboardFeatureProvider mDashboardFeatureProvider;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
@@ -84,10 +86,18 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
super.onCreate(savedInstanceState);
|
||||
final Activity activity = getActivity();
|
||||
mDashboardFeatureProvider = FeatureFactory.getFactory(activity)
|
||||
.getDashboardFeatureProvider(activity);
|
||||
|
||||
if (mDashboardFeatureProvider.isEnabled()) {
|
||||
mSummaryLoader = new SummaryLoader(activity,
|
||||
mDashboardFeatureProvider.getTilesForHomepage());
|
||||
} else {
|
||||
mSummaryLoader = new SummaryLoader(activity,
|
||||
((SettingsActivity) getActivity()).getDashboardCategories());
|
||||
}
|
||||
|
||||
List<DashboardCategory> categories =
|
||||
((SettingsActivity) getActivity()).getDashboardCategories();
|
||||
mSummaryLoader = new SummaryLoader(getActivity(), categories);
|
||||
Context context = getContext();
|
||||
mConditionManager = ConditionManager.get(context, false);
|
||||
mSuggestionParser = new SuggestionParser(context,
|
||||
@@ -102,8 +112,10 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
mSuggestionsHiddenLogged =
|
||||
savedInstanceState.getStringArrayList(EXTRA_SUGGESTION_HIDDEN_LOGGED);
|
||||
}
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,8 +136,10 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
mMetricsFeatureProvider.visible(getContext(), c.getMetricsConstant());
|
||||
}
|
||||
}
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onResume took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(TAG, "onResume took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,13 +177,15 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
} else {
|
||||
mConditionManager.remListener(this);
|
||||
}
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onWindowFocusChanged took "
|
||||
+ (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(TAG, "onWindowFocusChanged took "
|
||||
+ (System.currentTimeMillis() - startTime) + " ms");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.dashboard, container, false);
|
||||
}
|
||||
|
||||
@@ -204,8 +220,10 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
mDashboard.setAdapter(mAdapter);
|
||||
mSummaryLoader.setAdapter(mAdapter);
|
||||
ConditionAdapterUtils.addDismiss(mDashboard);
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onViewCreated took "
|
||||
+ (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(TAG, "onViewCreated took "
|
||||
+ (System.currentTimeMillis() - startTime) + " ms");
|
||||
}
|
||||
rebuildUI();
|
||||
}
|
||||
|
||||
@@ -259,9 +277,18 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
List<DashboardCategory> categories =
|
||||
((SettingsActivity) activity).getDashboardCategories();
|
||||
mAdapter.setCategoriesAndSuggestions(categories, tiles);
|
||||
|
||||
if (mDashboardFeatureProvider.isEnabled()) {
|
||||
// Temporary hack to wrap homepage category into a list. Soon we will create adapter
|
||||
// API that takes a single category.
|
||||
List<DashboardCategory> categories = new ArrayList<>();
|
||||
categories.add(mDashboardFeatureProvider.getTilesForHomepage());
|
||||
mAdapter.setCategoriesAndSuggestions(categories, tiles);
|
||||
} else {
|
||||
mAdapter.setCategoriesAndSuggestions(
|
||||
((SettingsActivity) activity).getDashboardCategories(), tiles);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
@@ -72,6 +73,19 @@ public class SummaryLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public SummaryLoader(Activity activity, DashboardCategory categories) {
|
||||
mHandler = new Handler();
|
||||
mWorkerThread = new HandlerThread("SummaryLoader", Process.THREAD_PRIORITY_BACKGROUND);
|
||||
mWorkerThread.start();
|
||||
mWorker = new Worker(mWorkerThread.getLooper());
|
||||
mActivity = activity;
|
||||
List<Tile> tiles = categories.tiles;
|
||||
for (int j = 0; j < tiles.size(); j++) {
|
||||
Tile tile = tiles.get(j);
|
||||
mWorker.obtainMessage(Worker.MSG_GET_PROVIDER, tile).sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
mWorkerThread.quitSafely();
|
||||
// Make sure we aren't listening.
|
||||
@@ -83,7 +97,7 @@ public class SummaryLoader {
|
||||
}
|
||||
|
||||
public void setSummary(SummaryProvider provider, final CharSequence summary) {
|
||||
final ComponentName component= mSummaryMap.get(provider);
|
||||
final ComponentName component = mSummaryMap.get(provider);
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -95,9 +109,18 @@ public class SummaryLoader {
|
||||
}
|
||||
return;
|
||||
}
|
||||
final List<DashboardCategory> categories =
|
||||
((SettingsDrawerActivity) mActivity).getDashboardCategories();
|
||||
final Tile tile = getTileFromCategory(categories, component);
|
||||
final Tile tile;
|
||||
final DashboardFeatureProvider dashboardFeatureProvider =
|
||||
FeatureFactory.getFactory(mActivity).getDashboardFeatureProvider(mActivity);
|
||||
if (dashboardFeatureProvider.isEnabled()) {
|
||||
tile = getTileFromCategory(dashboardFeatureProvider.getTilesForHomepage(),
|
||||
component);
|
||||
} else {
|
||||
tile = getTileFromCategory(
|
||||
((SettingsDrawerActivity) mActivity).getDashboardCategories(),
|
||||
component);
|
||||
}
|
||||
|
||||
if (tile == null) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Can't find tile for " + component);
|
||||
@@ -214,12 +237,20 @@ public class SummaryLoader {
|
||||
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;
|
||||
}
|
||||
final Tile tile = getTileFromCategory(category, component);
|
||||
if (tile != null) {
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Tile getTileFromCategory(DashboardCategory category, ComponentName component) {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user