Add a config to force rounded icon for DashboardFragment.

And each page has ability to turn on/off rounded icons. This CL only
adds the flag, it doesn't actually change icon shape yet.

- Boolean config in xml
- New protected method for each DashboardFragment to load config
- Plumb the boolean into DashboardFeatureProvider for future use.
- Remove some unused APIs from DashboardFeatureProvider

Bug: 110405144
Fixes: 79748104
Test: robotests
Change-Id: Id34782e75aa7289967e4dd1f4fe2978688092702
This commit is contained in:
Fan Zhang
2018-08-09 17:32:37 -07:00
parent 2d24e8a839
commit 7d5a9eebb8
14 changed files with 102 additions and 150 deletions

View File

@@ -106,9 +106,6 @@
--> -->
</string-array> </string-array>
<!-- Whether or not we should tint the icon color on setting pages. -->
<bool name="config_tintSettingIcon">true</bool>
<!-- Whether or not App & Notification screen should display recently used apps --> <!-- Whether or not App & Notification screen should display recently used apps -->
<bool name="config_display_recent_apps">true</bool> <bool name="config_display_recent_apps">true</bool>
@@ -133,4 +130,7 @@
devices will be able to vary their amplitude but do not possess enough dynamic range to devices will be able to vary their amplitude but do not possess enough dynamic range to
have distinct intensity levels --> have distinct intensity levels -->
<bool name="config_vibration_supports_multiple_intensities">false</bool> <bool name="config_vibration_supports_multiple_intensities">false</bool>
<!-- Whether or not TopLevelSettings should force rounded icon for injected tiles -->
<bool name="config_force_rounded_icon_TopLevelSettings">true</bool>
</resources> </resources>

View File

@@ -44,6 +44,7 @@ import com.android.settings.dashboard.conditional.Condition;
import com.android.settings.dashboard.conditional.ConditionAdapter; import com.android.settings.dashboard.conditional.ConditionAdapter;
import com.android.settings.dashboard.suggestions.SuggestionAdapter; import com.android.settings.dashboard.suggestions.SuggestionAdapter;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.RoundedHomepageIcon;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.LifecycleObserver;

View File

@@ -15,8 +15,6 @@
*/ */
package com.android.settings.dashboard; package com.android.settings.dashboard;
import android.content.Context;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference; import androidx.preference.Preference;
@@ -35,34 +33,11 @@ public interface DashboardFeatureProvider {
*/ */
DashboardCategory getTilesForCategory(String key); DashboardCategory getTilesForCategory(String key);
/**
* Get tiles (wrapped as a list of Preference) for key defined in CategoryKey.
*
* @param activity Activity hosting the preference
* @param context UI context to inflate preference
* @param sourceMetricsCategory The context (source) from which an action is performed
* @param key Value from CategoryKey
* @deprecated Pages implementing {@code DashboardFragment} should use
* {@link #getTilesForCategory(String)} instead. Using this method will not get the benefit
* of auto-ordering, progressive disclosure, auto-refreshing summary text etc.
*/
@Deprecated
List<Preference> getPreferencesForCategory(FragmentActivity activity, Context context,
int sourceMetricsCategory, String key);
/** /**
* Get all tiles, grouped by category. * Get all tiles, grouped by category.
*/ */
List<DashboardCategory> getAllCategories(); List<DashboardCategory> getAllCategories();
/**
* Whether or not we should tint icons in setting pages.
*
* @deprecated in favor of color icons in homepage
*/
@Deprecated
boolean shouldTintIcon();
/** /**
* Returns an unique string key for the tile. * Returns an unique string key for the tile.
*/ */
@@ -72,6 +47,7 @@ public interface DashboardFeatureProvider {
* Binds preference to data provided by tile. * Binds preference to data provided by tile.
* *
* @param activity If tile contains intent to launch, it will be launched from this activity * @param activity If tile contains intent to launch, it will be launched from this activity
* @param forceRoundedIcon Whether or not injected tiles from other packages should be forced to rounded icon.
* @param sourceMetricsCategory The context (source) from which an action is performed * @param sourceMetricsCategory The context (source) from which an action is performed
* @param pref The preference to bind data * @param pref The preference to bind data
* @param tile The binding data * @param tile The binding data
@@ -79,8 +55,8 @@ public interface DashboardFeatureProvider {
* @param baseOrder The order offset value. When binding, pref's order is determined by * @param baseOrder The order offset value. When binding, pref's order is determined by
* both this value and tile's own priority. * both this value and tile's own priority.
*/ */
void bindPreferenceToTile(FragmentActivity activity, int sourceMetricsCategory, Preference pref, void bindPreferenceToTile(FragmentActivity activity, boolean forceRoundedIcon,
Tile tile, String key, int baseOrder); int sourceMetricsCategory, Preference pref, Tile tile, String key, int baseOrder);
/** /**
* Returns additional intent filter action for dashboard tiles * Returns additional intent filter action for dashboard tiles

View File

@@ -80,39 +80,11 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
return mCategoryManager.getTilesByCategory(mContext, key); return mCategoryManager.getTilesByCategory(mContext, key);
} }
@Override
public List<Preference> getPreferencesForCategory(FragmentActivity activity, Context context,
int sourceMetricsCategory, String key) {
final DashboardCategory category = getTilesForCategory(key);
if (category == null) {
Log.d(TAG, "NO dashboard tiles for " + TAG);
return null;
}
final List<Tile> tiles = category.getTiles();
if (tiles == null || tiles.isEmpty()) {
Log.d(TAG, "tile list is empty, skipping category " + category.key);
return null;
}
final List<Preference> preferences = new ArrayList<>();
for (Tile tile : tiles) {
final Preference pref = new Preference(context);
bindPreferenceToTile(activity, sourceMetricsCategory, pref, tile, null /* key */,
Preference.DEFAULT_ORDER /* baseOrder */);
preferences.add(pref);
}
return preferences;
}
@Override @Override
public List<DashboardCategory> getAllCategories() { public List<DashboardCategory> getAllCategories() {
return mCategoryManager.getCategories(mContext); return mCategoryManager.getCategories(mContext);
} }
@Override
public boolean shouldTintIcon() {
return mContext.getResources().getBoolean(R.bool.config_tintSettingIcon);
}
@Override @Override
public String getDashboardKeyForTile(Tile tile) { public String getDashboardKeyForTile(Tile tile) {
if (tile == null) { if (tile == null) {
@@ -128,8 +100,8 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
} }
@Override @Override
public void bindPreferenceToTile(FragmentActivity activity, int sourceMetricsCategory, public void bindPreferenceToTile(FragmentActivity activity, boolean forceRoundedIcon,
Preference pref, Tile tile, String key, int baseOrder) { int sourceMetricsCategory, Preference pref, Tile tile, String key, int baseOrder) {
if (pref == null) { if (pref == null) {
return; return;
} }

View File

@@ -207,6 +207,10 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
@Override @Override
protected abstract int getPreferenceScreenResId(); protected abstract int getPreferenceScreenResId();
protected boolean shouldForceRoundedIcon() {
return false;
}
protected <T extends AbstractPreferenceController> T use(Class<T> clazz) { protected <T extends AbstractPreferenceController> T use(Class<T> clazz) {
List<AbstractPreferenceController> controllerList = mPreferenceControllers.get(clazz); List<AbstractPreferenceController> controllerList = mPreferenceControllers.get(clazz);
if (controllerList != null) { if (controllerList != null) {
@@ -343,6 +347,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
final int tintColor = a.getColor(0, context.getColor(android.R.color.white)); final int tintColor = a.getColor(0, context.getColor(android.R.color.white));
a.recycle(); a.recycle();
// Install dashboard tiles. // Install dashboard tiles.
final boolean forceRoundedIcons = shouldForceRoundedIcon();
for (Tile tile : tiles) { for (Tile tile : tiles) {
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile); final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
if (TextUtils.isEmpty(key)) { if (TextUtils.isEmpty(key)) {
@@ -361,13 +366,15 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
if (mDashboardTilePrefKeys.contains(key)) { if (mDashboardTilePrefKeys.contains(key)) {
// Have the key already, will rebind. // Have the key already, will rebind.
final Preference preference = screen.findPreference(key); final Preference preference = screen.findPreference(key);
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(), mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), forceRoundedIcons,
preference, tile, key, mPlaceholderPreferenceController.getOrder()); getMetricsCategory(), preference, tile, key,
mPlaceholderPreferenceController.getOrder());
} else { } else {
// Don't have this key, add it. // Don't have this key, add it.
final Preference pref = new Preference(getPrefContext()); final Preference pref = new Preference(getPrefContext());
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(), mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), forceRoundedIcons,
pref, tile, key, mPlaceholderPreferenceController.getOrder()); getMetricsCategory(), pref, tile, key,
mPlaceholderPreferenceController.getOrder());
screen.addPreference(pref); screen.addPreference(pref);
mDashboardTilePrefKeys.add(key); mDashboardTilePrefKeys.add(key);
} }

View File

@@ -42,12 +42,6 @@ import com.android.settingslib.utils.ThreadUtils;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.List; import java.util.List;
/**
* TODO(b/110405144): Remove this when all top level settings are converted to PreferenceControllers
*
* @deprecated
*/
@Deprecated
public class SummaryLoader { public class SummaryLoader {
private static final boolean DEBUG = DashboardSummary.DEBUG; private static final boolean DEBUG = DashboardSummary.DEBUG;
private static final String TAG = "SummaryLoader"; private static final String TAG = "SummaryLoader";

View File

@@ -91,6 +91,12 @@ public class TopLevelSettings extends DashboardFragment implements
return true; return true;
} }
@Override
protected boolean shouldForceRoundedIcon() {
return getContext().getResources()
.getBoolean(R.bool.config_force_rounded_icon_TopLevelSettings);
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() { new BaseSearchIndexProvider() {
@Override @Override

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.dashboard; package com.android.settings.widget;
import static androidx.annotation.VisibleForTesting.NONE; import static androidx.annotation.VisibleForTesting.NONE;
@@ -33,7 +33,7 @@ public class RoundedHomepageIcon extends LayerDrawable {
private static final String TAG = "RoundedHomepageIcon"; private static final String TAG = "RoundedHomepageIcon";
@VisibleForTesting(otherwise = NONE) @VisibleForTesting(otherwise = NONE)
int mBackgroundColor = -1; public int mBackgroundColor = -1;
public RoundedHomepageIcon(Context context, Drawable foreground) { public RoundedHomepageIcon(Context context, Drawable foreground) {
super(new Drawable[] { super(new Drawable[] {

View File

@@ -15,7 +15,6 @@
--> -->
<resources> <resources>
<bool name="config_tintSettingIcon">false</bool>
<bool name="config_enableColorTemperature">false</bool> <bool name="config_enableColorTemperature">false</bool>
<bool name="config_show_camera_laser_sensor">false</bool> <bool name="config_show_camera_laser_sensor">false</bool>
<bool name="config_show_connectivity_monitor">false</bool> <bool name="config_show_connectivity_monitor">false</bool>

View File

@@ -130,7 +130,7 @@ public class AccountDetailDashboardFragmentTest {
final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class); final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
final Preference preference = new Preference(mContext); final Preference preference = new Preference(mContext);
dashboardFeatureProvider.bindPreferenceToTile(activity, dashboardFeatureProvider.bindPreferenceToTile(activity, false /* forceRoundedIcon */,
MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, preference, tile, null /* key */, MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, preference, tile, null /* key */,
Preference.DEFAULT_ORDER); Preference.DEFAULT_ORDER);

View File

@@ -50,6 +50,7 @@ import com.android.settings.dashboard.suggestions.SuggestionAdapter;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources; import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.widget.RoundedHomepageIcon;
import com.android.settingslib.drawer.CategoryKey; import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.Tile; import com.android.settingslib.drawer.Tile;
import com.android.settingslib.drawer.TileUtils; import com.android.settingslib.drawer.TileUtils;
@@ -95,7 +96,6 @@ public class DashboardAdapterTest {
mActivityInfo.packageName = "pkg"; mActivityInfo.packageName = "pkg";
mActivityInfo.name = "class"; mActivityInfo.name = "class";
mActivityInfo.metaData = new Bundle(); mActivityInfo.metaData = new Bundle();
when(mFactory.dashboardFeatureProvider.shouldTintIcon()).thenReturn(true);
when(mContext.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mWindowManager); when(mContext.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mWindowManager);
when(mContext.getResources()).thenReturn(mResources); when(mContext.getResources()).thenReturn(mResources);

View File

@@ -49,7 +49,7 @@ import android.os.UserManager;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
@@ -59,7 +59,6 @@ import com.android.settings.testutils.shadow.ShadowTileUtils;
import com.android.settings.testutils.shadow.ShadowUserManager; import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin; import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
import com.android.settingslib.drawer.CategoryKey; import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.Tile; import com.android.settingslib.drawer.Tile;
import com.android.settingslib.drawer.TileUtils; import com.android.settingslib.drawer.TileUtils;
@@ -88,19 +87,19 @@ public class DashboardFeatureProviderImplTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS) @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private UserManager mUserManager; private UserManager mUserManager;
@Mock @Mock
private CategoryManager mCategoryManager;
@Mock
private PackageManager mPackageManager; private PackageManager mPackageManager;
private FakeFeatureFactory mFeatureFactory; private FakeFeatureFactory mFeatureFactory;
private Context mContext; private Context mContext;
private ActivityInfo mActivityInfo; private ActivityInfo mActivityInfo;
private DashboardFeatureProviderImpl mImpl; private DashboardFeatureProviderImpl mImpl;
private boolean mForceRoundedIcon;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
mForceRoundedIcon = false;
mActivityInfo = new ActivityInfo(); mActivityInfo = new ActivityInfo();
mActivityInfo.packageName = "pkg"; mActivityInfo.packageName = "pkg";
mActivityInfo.name = "class"; mActivityInfo.name = "class";
@@ -127,7 +126,7 @@ public class DashboardFeatureProviderImplTest {
doReturn(Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565))) doReturn(Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565)))
.when(tile).getIcon(any(Context.class)); .when(tile).getIcon(any(Context.class));
mActivityInfo.metaData.putString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS, "HI"); mActivityInfo.metaData.putString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS, "HI");
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
preference, tile, "123", Preference.DEFAULT_ORDER); preference, tile, "123", Preference.DEFAULT_ORDER);
assertThat(preference.getTitle()).isEqualTo(tile.title); assertThat(preference.getTitle()).isEqualTo(tile.title);
@@ -144,7 +143,7 @@ public class DashboardFeatureProviderImplTest {
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10); mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
preference, tile, "123", Preference.DEFAULT_ORDER); preference, tile, "123", Preference.DEFAULT_ORDER);
assertThat(preference.getFragment()).isNull(); assertThat(preference.getFragment()).isNull();
@@ -163,7 +162,7 @@ public class DashboardFeatureProviderImplTest {
when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE)) when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE))
.thenReturn(mUserManager); .thenReturn(mUserManager);
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
preference, tile, "123", Preference.DEFAULT_ORDER); preference, tile, "123", Preference.DEFAULT_ORDER);
preference.getOnPreferenceClickListener().onPreferenceClick(null); preference.getOnPreferenceClickListener().onPreferenceClick(null);
@@ -180,14 +179,14 @@ public class DashboardFeatureProviderImplTest {
when(mActivity.getSystemService(Context.USER_SERVICE)) when(mActivity.getSystemService(Context.USER_SERVICE))
.thenReturn(mUserManager); .thenReturn(mUserManager);
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
preference, tile, "123", Preference.DEFAULT_ORDER); preference, tile, "123", Preference.DEFAULT_ORDER);
preference.getOnPreferenceClickListener().onPreferenceClick(null); preference.getOnPreferenceClickListener().onPreferenceClick(null);
verify(mFeatureFactory.metricsFeatureProvider).logDashboardStartIntent( verify(mFeatureFactory.metricsFeatureProvider).logDashboardStartIntent(
any(Context.class), any(Context.class),
any(Intent.class), any(Intent.class),
eq(MetricsProto.MetricsEvent.SETTINGS_GESTURES)); eq(MetricsEvent.SETTINGS_GESTURES));
verify(mActivity) verify(mActivity)
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class)); .startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
} }
@@ -205,7 +204,7 @@ public class DashboardFeatureProviderImplTest {
when(mActivity.getApplicationContext().getPackageName()) when(mActivity.getApplicationContext().getPackageName())
.thenReturn(RuntimeEnvironment.application.getPackageName()); .thenReturn(RuntimeEnvironment.application.getPackageName());
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
preference, tile, "123", Preference.DEFAULT_ORDER); preference, tile, "123", Preference.DEFAULT_ORDER);
preference.getOnPreferenceClickListener().onPreferenceClick(null); preference.getOnPreferenceClickListener().onPreferenceClick(null);
verify(mFeatureFactory.metricsFeatureProvider).logDashboardStartIntent( verify(mFeatureFactory.metricsFeatureProvider).logDashboardStartIntent(
@@ -219,7 +218,7 @@ public class DashboardFeatureProviderImplTest {
@Test @Test
public void bindPreference_nullPreference_shouldIgnore() { public void bindPreference_nullPreference_shouldIgnore() {
final Tile tile = mock(Tile.class); final Tile tile = mock(Tile.class);
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN,
null, tile, "123", Preference.DEFAULT_ORDER); null, tile, "123", Preference.DEFAULT_ORDER);
verifyZeroInteractions(tile); verifyZeroInteractions(tile);
@@ -229,7 +228,7 @@ public class DashboardFeatureProviderImplTest {
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() { public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
final Preference preference = new Preference(RuntimeEnvironment.application); final Preference preference = new Preference(RuntimeEnvironment.application);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN,
preference, tile, null /*key */, Preference.DEFAULT_ORDER); preference, tile, null /*key */, Preference.DEFAULT_ORDER);
assertThat(preference.getKey()).isNotNull(); assertThat(preference.getKey()).isNotNull();
@@ -240,7 +239,7 @@ public class DashboardFeatureProviderImplTest {
public void bindPreference_noSummary_shouldSetSummaryToPlaceholder() { public void bindPreference_noSummary_shouldSetSummaryToPlaceholder() {
final Preference preference = new Preference(RuntimeEnvironment.application); final Preference preference = new Preference(RuntimeEnvironment.application);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN,
preference, tile, null /*key */, Preference.DEFAULT_ORDER); preference, tile, null /*key */, Preference.DEFAULT_ORDER);
assertThat(preference.getSummary()) assertThat(preference.getSummary())
@@ -252,7 +251,7 @@ public class DashboardFeatureProviderImplTest {
final Preference preference = new Preference(RuntimeEnvironment.application); final Preference preference = new Preference(RuntimeEnvironment.application);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.summary = "test"; tile.summary = "test";
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN,
preference, tile, null /*key */, Preference.DEFAULT_ORDER); preference, tile, null /*key */, Preference.DEFAULT_ORDER);
assertThat(preference.getSummary()).isEqualTo(tile.summary); assertThat(preference.getSummary()).isEqualTo(tile.summary);
@@ -266,7 +265,7 @@ public class DashboardFeatureProviderImplTest {
mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI,
"content://com.android.settings/tile_summary"); "content://com.android.settings/tile_summary");
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN,
preference, tile, null /*key */, Preference.DEFAULT_ORDER); preference, tile, null /*key */, Preference.DEFAULT_ORDER);
assertThat(preference.getSummary()).isEqualTo(ShadowTileUtils.MOCK_SUMMARY); assertThat(preference.getSummary()).isEqualTo(ShadowTileUtils.MOCK_SUMMARY);
@@ -277,7 +276,7 @@ public class DashboardFeatureProviderImplTest {
final Preference preference = new Preference(RuntimeEnvironment.application); final Preference preference = new Preference(RuntimeEnvironment.application);
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key"); mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN,
preference, tile, null /* key */, Preference.DEFAULT_ORDER); preference, tile, null /* key */, Preference.DEFAULT_ORDER);
assertThat(preference.getKey()).isEqualTo(tile.getKey(mContext)); assertThat(preference.getKey()).isEqualTo(tile.getKey(mContext));
@@ -304,7 +303,7 @@ public class DashboardFeatureProviderImplTest {
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10); mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN,
preference, tile, "123", baseOrder); preference, tile, "123", baseOrder);
assertThat(preference.getOrder()).isEqualTo(tile.getOrder() + baseOrder); assertThat(preference.getOrder()).isEqualTo(tile.getOrder() + baseOrder);
@@ -317,7 +316,7 @@ public class DashboardFeatureProviderImplTest {
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10); mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, testOrder); mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, testOrder);
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN,
preference, tile, "123", Preference.DEFAULT_ORDER); preference, tile, "123", Preference.DEFAULT_ORDER);
assertThat(preference.getOrder()).isEqualTo(testOrder); assertThat(preference.getOrder()).isEqualTo(testOrder);
@@ -329,7 +328,7 @@ public class DashboardFeatureProviderImplTest {
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
mActivityInfo.metaData.putString(META_DATA_KEY_ORDER, "hello"); mActivityInfo.metaData.putString(META_DATA_KEY_ORDER, "hello");
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN, mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN,
preference, tile, "123", Preference.DEFAULT_ORDER); preference, tile, "123", Preference.DEFAULT_ORDER);
assertThat(preference.getOrder()).isEqualTo(Preference.DEFAULT_ORDER); assertThat(preference.getOrder()).isEqualTo(Preference.DEFAULT_ORDER);
@@ -343,7 +342,7 @@ public class DashboardFeatureProviderImplTest {
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key"); mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction"); mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
tile.userHandle = null; tile.userHandle = null;
mImpl.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, mImpl.bindPreferenceToTile(activity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
preference, tile, "123", Preference.DEFAULT_ORDER); preference, tile, "123", Preference.DEFAULT_ORDER);
preference.performClick(); preference.performClick();
ShadowActivity shadowActivity = Shadows.shadowOf(activity); ShadowActivity shadowActivity = Shadows.shadowOf(activity);
@@ -352,7 +351,7 @@ public class DashboardFeatureProviderImplTest {
assertThat(launchIntent.getAction()) assertThat(launchIntent.getAction())
.isEqualTo("TestAction"); .isEqualTo("TestAction");
assertThat(launchIntent.getIntExtra(VisibilityLoggerMixin.EXTRA_SOURCE_METRICS_CATEGORY, 0)) assertThat(launchIntent.getIntExtra(VisibilityLoggerMixin.EXTRA_SOURCE_METRICS_CATEGORY, 0))
.isEqualTo(MetricsProto.MetricsEvent.SETTINGS_GESTURES); .isEqualTo(MetricsEvent.SETTINGS_GESTURES);
} }
@Test @Test
@@ -367,7 +366,7 @@ public class DashboardFeatureProviderImplTest {
mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction"); mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
tile.userHandle = null; tile.userHandle = null;
mImpl.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, mImpl.bindPreferenceToTile(activity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
preference, tile, "123", Preference.DEFAULT_ORDER); preference, tile, "123", Preference.DEFAULT_ORDER);
preference.performClick(); preference.performClick();
@@ -377,63 +376,11 @@ public class DashboardFeatureProviderImplTest {
assertThat(launchIntent).isNull(); assertThat(launchIntent).isNull();
} }
@Test
public void getPreferences_noCategory_shouldReturnNull() {
mImpl = new DashboardFeatureProviderImpl(mActivity);
ReflectionHelpers.setField(mImpl, "mCategoryManager", mCategoryManager);
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
.thenReturn(null);
assertThat(mImpl.getPreferencesForCategory(null, null,
MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
.isNull();
}
@Test
public void getPreferences_noTileForCategory_shouldReturnNull() {
mImpl = new DashboardFeatureProviderImpl(mActivity);
ReflectionHelpers.setField(mImpl, "mCategoryManager", mCategoryManager);
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
.thenReturn(new DashboardCategory(CategoryKey.CATEGORY_HOMEPAGE));
assertThat(mImpl.getPreferencesForCategory(null, null,
MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
.isNull();
}
@Test
public void getPreferences_hasTileForCategory_shouldReturnPrefList() {
mImpl = new DashboardFeatureProviderImpl(mActivity);
ReflectionHelpers.setField(mImpl, "mCategoryManager", mCategoryManager);
final DashboardCategory category = new DashboardCategory(CategoryKey.CATEGORY_HOMEPAGE);
category.addTile(new Tile(mActivityInfo, category.key));
when(mCategoryManager
.getTilesByCategory(any(Context.class), eq(CategoryKey.CATEGORY_HOMEPAGE)))
.thenReturn(category);
assertThat(mImpl.getPreferencesForCategory(mActivity,
ShadowApplication.getInstance().getApplicationContext(),
MetricsProto.MetricsEvent.SETTINGS_GESTURES,
CategoryKey.CATEGORY_HOMEPAGE).isEmpty())
.isFalse();
}
@Test @Test
public void testGetExtraIntentAction_shouldReturnNull() { public void testGetExtraIntentAction_shouldReturnNull() {
assertThat(mImpl.getExtraIntentAction()).isNull(); assertThat(mImpl.getExtraIntentAction()).isNull();
} }
@Test
public void testShouldTintIcon_enabledInResources_shouldBeTrue() {
assertThat(mImpl.shouldTintIcon()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testShouldTintIcon_disabledInResources_shouldBeFalse() {
assertThat(mImpl.shouldTintIcon()).isFalse();
}
@Test @Test
public void openTileIntent_profileSelectionDialog_shouldShow() { public void openTileIntent_profileSelectionDialog_shouldShow() {
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE); final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);

View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.homepage;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class TopLevelSettingsTest {
private Context mContext;
private TopLevelSettings mSettings;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mSettings = spy(new TopLevelSettings());
when(mSettings.getContext()).thenReturn(mContext);
}
@Test
public void shouldForceRoundedIcon_true() {
assertThat(mSettings.shouldForceRoundedIcon()).isTrue();
}
}

View File

@@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.dashboard; package com.android.settings.widget;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;