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:
@@ -106,9 +106,6 @@
|
||||
-->
|
||||
</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 -->
|
||||
<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
|
||||
have distinct intensity levels -->
|
||||
<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>
|
||||
|
@@ -44,6 +44,7 @@ import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.dashboard.conditional.ConditionAdapter;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionAdapter;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.RoundedHomepageIcon;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
|
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@@ -35,34 +33,11 @@ public interface DashboardFeatureProvider {
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@@ -72,6 +47,7 @@ public interface DashboardFeatureProvider {
|
||||
* Binds preference to data provided by tile.
|
||||
*
|
||||
* @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 pref The preference to bind 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
|
||||
* both this value and tile's own priority.
|
||||
*/
|
||||
void bindPreferenceToTile(FragmentActivity activity, int sourceMetricsCategory, Preference pref,
|
||||
Tile tile, String key, int baseOrder);
|
||||
void bindPreferenceToTile(FragmentActivity activity, boolean forceRoundedIcon,
|
||||
int sourceMetricsCategory, Preference pref, Tile tile, String key, int baseOrder);
|
||||
|
||||
/**
|
||||
* Returns additional intent filter action for dashboard tiles
|
||||
|
@@ -80,39 +80,11 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
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
|
||||
public List<DashboardCategory> getAllCategories() {
|
||||
return mCategoryManager.getCategories(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldTintIcon() {
|
||||
return mContext.getResources().getBoolean(R.bool.config_tintSettingIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDashboardKeyForTile(Tile tile) {
|
||||
if (tile == null) {
|
||||
@@ -128,8 +100,8 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindPreferenceToTile(FragmentActivity activity, int sourceMetricsCategory,
|
||||
Preference pref, Tile tile, String key, int baseOrder) {
|
||||
public void bindPreferenceToTile(FragmentActivity activity, boolean forceRoundedIcon,
|
||||
int sourceMetricsCategory, Preference pref, Tile tile, String key, int baseOrder) {
|
||||
if (pref == null) {
|
||||
return;
|
||||
}
|
||||
|
@@ -207,6 +207,10 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
@Override
|
||||
protected abstract int getPreferenceScreenResId();
|
||||
|
||||
protected boolean shouldForceRoundedIcon() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected <T extends AbstractPreferenceController> T use(Class<T> clazz) {
|
||||
List<AbstractPreferenceController> controllerList = mPreferenceControllers.get(clazz);
|
||||
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));
|
||||
a.recycle();
|
||||
// Install dashboard tiles.
|
||||
final boolean forceRoundedIcons = shouldForceRoundedIcon();
|
||||
for (Tile tile : tiles) {
|
||||
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
@@ -361,13 +366,15 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
if (mDashboardTilePrefKeys.contains(key)) {
|
||||
// Have the key already, will rebind.
|
||||
final Preference preference = screen.findPreference(key);
|
||||
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(),
|
||||
preference, tile, key, mPlaceholderPreferenceController.getOrder());
|
||||
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), forceRoundedIcons,
|
||||
getMetricsCategory(), preference, tile, key,
|
||||
mPlaceholderPreferenceController.getOrder());
|
||||
} else {
|
||||
// Don't have this key, add it.
|
||||
final Preference pref = new Preference(getPrefContext());
|
||||
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(),
|
||||
pref, tile, key, mPlaceholderPreferenceController.getOrder());
|
||||
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), forceRoundedIcons,
|
||||
getMetricsCategory(), pref, tile, key,
|
||||
mPlaceholderPreferenceController.getOrder());
|
||||
screen.addPreference(pref);
|
||||
mDashboardTilePrefKeys.add(key);
|
||||
}
|
||||
|
@@ -42,12 +42,6 @@ import com.android.settingslib.utils.ThreadUtils;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TODO(b/110405144): Remove this when all top level settings are converted to PreferenceControllers
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public class SummaryLoader {
|
||||
private static final boolean DEBUG = DashboardSummary.DEBUG;
|
||||
private static final String TAG = "SummaryLoader";
|
||||
|
@@ -91,6 +91,12 @@ public class TopLevelSettings extends DashboardFragment implements
|
||||
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 =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard;
|
||||
package com.android.settings.widget;
|
||||
|
||||
import static androidx.annotation.VisibleForTesting.NONE;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class RoundedHomepageIcon extends LayerDrawable {
|
||||
private static final String TAG = "RoundedHomepageIcon";
|
||||
|
||||
@VisibleForTesting(otherwise = NONE)
|
||||
int mBackgroundColor = -1;
|
||||
public int mBackgroundColor = -1;
|
||||
|
||||
public RoundedHomepageIcon(Context context, Drawable foreground) {
|
||||
super(new Drawable[] {
|
@@ -15,7 +15,6 @@
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<bool name="config_tintSettingIcon">false</bool>
|
||||
<bool name="config_enableColorTemperature">false</bool>
|
||||
<bool name="config_show_camera_laser_sensor">false</bool>
|
||||
<bool name="config_show_connectivity_monitor">false</bool>
|
||||
|
@@ -130,7 +130,7 @@ public class AccountDetailDashboardFragmentTest {
|
||||
|
||||
final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
|
||||
final Preference preference = new Preference(mContext);
|
||||
dashboardFeatureProvider.bindPreferenceToTile(activity,
|
||||
dashboardFeatureProvider.bindPreferenceToTile(activity, false /* forceRoundedIcon */,
|
||||
MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, preference, tile, null /* key */,
|
||||
Preference.DEFAULT_ORDER);
|
||||
|
||||
|
@@ -50,6 +50,7 @@ import com.android.settings.dashboard.suggestions.SuggestionAdapter;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.widget.RoundedHomepageIcon;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.drawer.TileUtils;
|
||||
@@ -95,7 +96,6 @@ public class DashboardAdapterTest {
|
||||
mActivityInfo.packageName = "pkg";
|
||||
mActivityInfo.name = "class";
|
||||
mActivityInfo.metaData = new Bundle();
|
||||
when(mFactory.dashboardFeatureProvider.shouldTintIcon()).thenReturn(true);
|
||||
|
||||
when(mContext.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mWindowManager);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
@@ -49,7 +49,7 @@ import android.os.UserManager;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
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.SettingsActivity;
|
||||
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.settingslib.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.drawer.TileUtils;
|
||||
|
||||
@@ -88,19 +87,19 @@ public class DashboardFeatureProviderImplTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private CategoryManager mCategoryManager;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private Context mContext;
|
||||
private ActivityInfo mActivityInfo;
|
||||
private DashboardFeatureProviderImpl mImpl;
|
||||
private boolean mForceRoundedIcon;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mForceRoundedIcon = false;
|
||||
mActivityInfo = new ActivityInfo();
|
||||
mActivityInfo.packageName = "pkg";
|
||||
mActivityInfo.name = "class";
|
||||
@@ -127,7 +126,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
doReturn(Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565)))
|
||||
.when(tile).getIcon(any(Context.class));
|
||||
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);
|
||||
|
||||
assertThat(preference.getTitle()).isEqualTo(tile.title);
|
||||
@@ -144,7 +143,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
|
||||
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);
|
||||
|
||||
assertThat(preference.getFragment()).isNull();
|
||||
@@ -163,7 +162,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE))
|
||||
.thenReturn(mUserManager);
|
||||
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.getOnPreferenceClickListener().onPreferenceClick(null);
|
||||
|
||||
@@ -180,14 +179,14 @@ public class DashboardFeatureProviderImplTest {
|
||||
when(mActivity.getSystemService(Context.USER_SERVICE))
|
||||
.thenReturn(mUserManager);
|
||||
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.getOnPreferenceClickListener().onPreferenceClick(null);
|
||||
|
||||
verify(mFeatureFactory.metricsFeatureProvider).logDashboardStartIntent(
|
||||
any(Context.class),
|
||||
any(Intent.class),
|
||||
eq(MetricsProto.MetricsEvent.SETTINGS_GESTURES));
|
||||
eq(MetricsEvent.SETTINGS_GESTURES));
|
||||
verify(mActivity)
|
||||
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
|
||||
}
|
||||
@@ -205,7 +204,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
when(mActivity.getApplicationContext().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.getOnPreferenceClickListener().onPreferenceClick(null);
|
||||
verify(mFeatureFactory.metricsFeatureProvider).logDashboardStartIntent(
|
||||
@@ -219,7 +218,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@Test
|
||||
public void bindPreference_nullPreference_shouldIgnore() {
|
||||
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);
|
||||
|
||||
verifyZeroInteractions(tile);
|
||||
@@ -229,7 +228,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
|
||||
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||
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);
|
||||
|
||||
assertThat(preference.getKey()).isNotNull();
|
||||
@@ -240,7 +239,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
public void bindPreference_noSummary_shouldSetSummaryToPlaceholder() {
|
||||
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||
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);
|
||||
|
||||
assertThat(preference.getSummary())
|
||||
@@ -252,7 +251,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
tile.summary = "test";
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
|
||||
mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN,
|
||||
preference, tile, null /*key */, Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getSummary()).isEqualTo(tile.summary);
|
||||
@@ -266,7 +265,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI,
|
||||
"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);
|
||||
|
||||
assertThat(preference.getSummary()).isEqualTo(ShadowTileUtils.MOCK_SUMMARY);
|
||||
@@ -277,7 +276,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
|
||||
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);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(tile.getKey(mContext));
|
||||
@@ -304,7 +303,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
|
||||
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);
|
||||
|
||||
assertThat(preference.getOrder()).isEqualTo(tile.getOrder() + baseOrder);
|
||||
@@ -317,7 +316,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
|
||||
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
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);
|
||||
|
||||
assertThat(preference.getOrder()).isEqualTo(testOrder);
|
||||
@@ -329,7 +328,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
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);
|
||||
|
||||
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("com.android.settings.intent.action", "TestAction");
|
||||
tile.userHandle = null;
|
||||
mImpl.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
mImpl.bindPreferenceToTile(activity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.performClick();
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||
@@ -352,7 +351,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
assertThat(launchIntent.getAction())
|
||||
.isEqualTo("TestAction");
|
||||
assertThat(launchIntent.getIntExtra(VisibilityLoggerMixin.EXTRA_SOURCE_METRICS_CATEGORY, 0))
|
||||
.isEqualTo(MetricsProto.MetricsEvent.SETTINGS_GESTURES);
|
||||
.isEqualTo(MetricsEvent.SETTINGS_GESTURES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -367,7 +366,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
|
||||
tile.userHandle = null;
|
||||
|
||||
mImpl.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
mImpl.bindPreferenceToTile(activity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.performClick();
|
||||
|
||||
@@ -377,63 +376,11 @@ public class DashboardFeatureProviderImplTest {
|
||||
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
|
||||
public void testGetExtraIntentAction_shouldReturnNull() {
|
||||
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
|
||||
public void openTileIntent_profileSelectionDialog_shouldShow() {
|
||||
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -14,9 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard;
|
||||
package com.android.settings.widget;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
Reference in New Issue
Block a user