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:
@@ -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"
|
||||
|
@@ -159,4 +159,8 @@ public class Settings extends SettingsActivity {
|
||||
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 {}
|
||||
|
||||
}
|
||||
|
@@ -55,6 +55,7 @@ import com.android.settings.Settings.WifiSettingsActivity;
|
||||
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.applications.WriteSettingsDetails;
|
||||
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.ZenModePrioritySettings;
|
||||
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 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
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 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
MasterClear.class.getName(),
|
||||
NightDisplaySettings.class.getName(),
|
||||
ManageDomainUrls.class.getName(),
|
||||
AutomaticStorageManagerSettings.class.getName()
|
||||
AutomaticStorageManagerSettings.class.getName(),
|
||||
SupportFragment.class.getName()
|
||||
};
|
||||
|
||||
|
||||
@@ -424,6 +430,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
|
||||
private boolean mNeedToRevertToInitialFragment = false;
|
||||
|
||||
private DashboardFeatureProvider mDashboardFeatureProvider;
|
||||
private Intent mResultIntentData;
|
||||
private ComponentName mCurrentSuggestion;
|
||||
|
||||
@@ -533,7 +540,8 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
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,11 +651,15 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
final Bundle args = new Bundle();
|
||||
final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
|
||||
args.putString(extraName, intent.getStringExtra(extraName));
|
||||
|
||||
if (isDashboardFeatureEnabled()) {
|
||||
switchToFragment(DashboardSummary.class.getName(), args, false, false,
|
||||
mInitialTitleResId, mInitialTitle, false);
|
||||
} else {
|
||||
switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
|
||||
mInitialTitleResId, mInitialTitle, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mActionBar = getActionBar();
|
||||
if (mActionBar != null) {
|
||||
@@ -1114,7 +1126,13 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
|
||||
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 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
|
@@ -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;
|
||||
@@ -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,9 +112,11 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
mSuggestionsHiddenLogged =
|
||||
savedInstanceState.getStringArrayList(EXTRA_SUGGESTION_HIDDEN_LOGGED);
|
||||
}
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
@@ -124,9 +136,11 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
mMetricsFeatureProvider.visible(getContext(), c.getMetricsConstant());
|
||||
}
|
||||
}
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onResume took " + (System.currentTimeMillis() - startTime)
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(TAG, "onResume took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
@@ -163,9 +177,11 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
} else {
|
||||
mConditionManager.remListener(this);
|
||||
}
|
||||
if (DEBUG_TIMING) Log.d(TAG, "onWindowFocusChanged took "
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(TAG, "onWindowFocusChanged took "
|
||||
+ (System.currentTimeMillis() - startTime) + " ms");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
@@ -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 "
|
||||
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();
|
||||
|
||||
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.
|
||||
@@ -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,6 +237,15 @@ public class SummaryLoader {
|
||||
final int categorySize = categories.size();
|
||||
for (int i = 0; i < categorySize; i++) {
|
||||
final DashboardCategory category = categories.get(i);
|
||||
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);
|
||||
@@ -221,7 +253,6 @@ public class SummaryLoader {
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@@ -68,7 +68,7 @@ public abstract class FeatureFactory {
|
||||
|
||||
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) {
|
||||
|
@@ -53,9 +53,9 @@ public final class FeatureFactoryImpl extends FeatureFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardFeatureProvider getDashboardFeatureProvider() {
|
||||
public DashboardFeatureProvider getDashboardFeatureProvider(Context context) {
|
||||
if (mDashboardFeatureProvider == null) {
|
||||
mDashboardFeatureProvider = new DashboardFeatureProviderImpl();
|
||||
mDashboardFeatureProvider = new DashboardFeatureProviderImpl(context);
|
||||
}
|
||||
return mDashboardFeatureProvider;
|
||||
}
|
||||
|
Reference in New Issue
Block a user