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
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 7034dc3..fd22c63 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2275,6 +2275,8 @@
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.device" />
+ <meta-data android:name="com.android.settings.iacategory"
+ android:value="com.android.settings.category.homepage" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.fuelgauge.PowerUsageSummary" />
</activity>
@@ -3030,6 +3032,22 @@
android:value="com.android.settings.deletionhelper.AutomaticStorageManagerSettings" />
</activity>
+ <!-- Information architecture host activities -->
+ <activity
+ android:name=".Settings$SupportActivity"
+ android:label="@string/page_tab_title_support"
+ android:icon="@drawable/ic_help_24dp">
+ <intent-filter android:priority="-1">
+ <action android:name="com.android.settings.action.SETTINGS" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.iacategory"
+ android:value="com.android.settings.category.homepage" />
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.dashboard.SupportFragment"/>
+ <meta-data android:name="com.android.settings.summary"
+ android:resource="@string/help_label" />
+ </activity>
+
<service
android:name=".SettingsDumpService"
android:exported="true"
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 559b9ce..cf08f4a 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -159,4 +159,8 @@
public static class DeviceSettings extends SettingsActivity { /* empty */ }
public static class PersonalSettings extends SettingsActivity { /* empty */ }
public static class SystemSettings extends SettingsActivity { /* empty */ }
+
+ // Top level categories for new IA
+ public static class SupportActivity extends SettingsActivity {}
+
}
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 69b86fe..ecfc373 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -55,6 +55,7 @@
import com.android.settings.accessibility.AccessibilitySettings;
import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
import com.android.settings.accessibility.CaptionPropertiesFragment;
+import com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment;
import com.android.settings.accounts.AccountSettings;
import com.android.settings.accounts.AccountSyncSettings;
import com.android.settings.accounts.ChooseAccountActivity;
@@ -74,7 +75,10 @@
import com.android.settings.bluetooth.BluetoothSettings;
import com.android.settings.core.instrumentation.SharedPreferencesLogger;
import com.android.settings.dashboard.DashboardContainerFragment;
+import com.android.settings.dashboard.DashboardFeatureProvider;
+import com.android.settings.dashboard.DashboardSummary;
import com.android.settings.dashboard.SearchResultsSummary;
+import com.android.settings.dashboard.SupportFragment;
import com.android.settings.datausage.DataUsageSummary;
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
import com.android.settings.deviceinfo.ImeiInformation;
@@ -113,6 +117,7 @@
import com.android.settings.notification.ZenModeScheduleRuleSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.notification.ZenModeVisualInterruptionSettings;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.print.PrintJobSettingsFragment;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.qstile.DevelopmentTiles;
@@ -294,7 +299,7 @@
AccessibilitySettings.class.getName(),
AccessibilitySettingsForSetupWizard.class.getName(),
CaptionPropertiesFragment.class.getName(),
- com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
+ ToggleDaltonizerPreferenceFragment.class.getName(),
TextToSpeechSettings.class.getName(),
StorageSettings.class.getName(),
PrivateVolumeForget.class.getName(),
@@ -357,7 +362,8 @@
MasterClear.class.getName(),
NightDisplaySettings.class.getName(),
ManageDomainUrls.class.getName(),
- AutomaticStorageManagerSettings.class.getName()
+ AutomaticStorageManagerSettings.class.getName(),
+ SupportFragment.class.getName()
};
@@ -424,6 +430,7 @@
private boolean mNeedToRevertToInitialFragment = false;
+ private DashboardFeatureProvider mDashboardFeatureProvider;
private Intent mResultIntentData;
private ComponentName mCurrentSuggestion;
@@ -533,7 +540,8 @@
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
long startTime = System.currentTimeMillis();
-
+ mDashboardFeatureProvider =
+ FeatureFactory.getFactory(this).getDashboardFeatureProvider(this);
// Should happen before any call to getIntent()
getMetaData();
@@ -643,9 +651,13 @@
final Bundle args = new Bundle();
final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
args.putString(extraName, intent.getStringExtra(extraName));
-
- switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
- mInitialTitleResId, mInitialTitle, false);
+ if (isDashboardFeatureEnabled()) {
+ switchToFragment(DashboardSummary.class.getName(), args, false, false,
+ mInitialTitleResId, mInitialTitle, false);
+ } else {
+ switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
+ mInitialTitleResId, mInitialTitle, false);
+ }
}
}
@@ -1114,7 +1126,13 @@
if (UserHandle.MU_ENABLED && !isAdmin) {
// When on restricted users, disable all extra categories (but only the settings ones).
- List<DashboardCategory> categories = getDashboardCategories();
+ List<DashboardCategory> categories;
+ if (isDashboardFeatureEnabled()) {
+ categories = mDashboardFeatureProvider.getAllCategories();
+ } else {
+ categories = getDashboardCategories();
+ }
+
for (DashboardCategory category : categories) {
for (Tile tile : category.tiles) {
ComponentName component = tile.intent.getComponent();
@@ -1165,6 +1183,15 @@
}
}
+ @Override
+ protected boolean isDashboardFeatureEnabled() {
+ if (mDashboardFeatureProvider == null) {
+ mDashboardFeatureProvider =
+ FeatureFactory.getFactory(this).getDashboardFeatureProvider(this);
+ }
+ return mDashboardFeatureProvider.isEnabled();
+ }
+
// give subclasses access to the Next button
public boolean hasNextButton() {
return mNextButton != null;
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProvider.java b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
index e4976f5..c093748 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProvider.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
@@ -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();
}
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index d07729a..1f0b7f2 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -18,14 +18,38 @@
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);
+ }
}
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index fb8c959..d63eb0f 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -35,6 +35,7 @@
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 @@
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 @@
private SuggestionsChecks mSuggestionsChecks;
private ArrayList<String> mSuggestionsShownLogged;
private ArrayList<String> mSuggestionsHiddenLogged;
+ private DashboardFeatureProvider mDashboardFeatureProvider;
@Override
public int getMetricsCategory() {
@@ -84,10 +86,18 @@
public void onCreate(Bundle savedInstanceState) {
long startTime = System.currentTimeMillis();
super.onCreate(savedInstanceState);
+ final Activity activity = getActivity();
+ mDashboardFeatureProvider = FeatureFactory.getFactory(activity)
+ .getDashboardFeatureProvider(activity);
- List<DashboardCategory> categories =
- ((SettingsActivity) getActivity()).getDashboardCategories();
- mSummaryLoader = new SummaryLoader(getActivity(), categories);
+ if (mDashboardFeatureProvider.isEnabled()) {
+ mSummaryLoader = new SummaryLoader(activity,
+ mDashboardFeatureProvider.getTilesForHomepage());
+ } else {
+ mSummaryLoader = new SummaryLoader(activity,
+ ((SettingsActivity) getActivity()).getDashboardCategories());
+ }
+
Context context = getContext();
mConditionManager = ConditionManager.get(context, false);
mSuggestionParser = new SuggestionParser(context,
@@ -102,8 +112,10 @@
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 @@
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 @@
} 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 @@
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 @@
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);
+ }
+
}
}
}
diff --git a/src/com/android/settings/dashboard/SummaryLoader.java b/src/com/android/settings/dashboard/SummaryLoader.java
index 4232852..d55ec06 100644
--- a/src/com/android/settings/dashboard/SummaryLoader.java
+++ b/src/com/android/settings/dashboard/SummaryLoader.java
@@ -30,6 +30,7 @@
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 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 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 @@
}
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 @@
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;
diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java
index 7099b3f..dd3e9c8 100644
--- a/src/com/android/settings/overlay/FeatureFactory.java
+++ b/src/com/android/settings/overlay/FeatureFactory.java
@@ -68,7 +68,7 @@
public abstract PowerUsageFeatureProvider getPowerUsageFeatureProvider();
- public abstract DashboardFeatureProvider getDashboardFeatureProvider();
+ public abstract DashboardFeatureProvider getDashboardFeatureProvider(Context context);
public static final class FactoryNotFoundException extends RuntimeException {
public FactoryNotFoundException(Throwable throwable) {
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index 8f71363..65015c3 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -53,9 +53,9 @@
}
@Override
- public DashboardFeatureProvider getDashboardFeatureProvider() {
+ public DashboardFeatureProvider getDashboardFeatureProvider(Context context) {
if (mDashboardFeatureProvider == null) {
- mDashboardFeatureProvider = new DashboardFeatureProviderImpl();
+ mDashboardFeatureProvider = new DashboardFeatureProviderImpl(context);
}
return mDashboardFeatureProvider;
}