diff --git a/res/layout/suggestion_container.xml b/res/layout/suggestion_container.xml
index 95a00cca1c9..ee7631dc24f 100644
--- a/res/layout/suggestion_container.xml
+++ b/res/layout/suggestion_container.xml
@@ -23,40 +23,11 @@
android:paddingTop="2dp"
android:orientation="vertical">
-
-
-
-
-
-
-
-
diff --git a/res/layout/suggestion_tile.xml b/res/layout/suggestion_tile.xml
index 850e55ae025..9493e2d5f80 100644
--- a/res/layout/suggestion_tile.xml
+++ b/res/layout/suggestion_tile.xml
@@ -18,8 +18,10 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/suggestion_card"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_marginEnd="16dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:cardElevation="2dp"
@@ -27,8 +29,8 @@
+ android:layout_marginBottom="6dp" />
diff --git a/res/layout/suggestion_tile_two_cards.xml b/res/layout/suggestion_tile_two_cards.xml
new file mode 100644
index 00000000000..c06fb7aabf3
--- /dev/null
+++ b/res/layout/suggestion_tile_two_cards.xml
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/suggestion_tile_with_button.xml b/res/layout/suggestion_tile_with_button.xml
index 8fb8e84022e..7b9ddf92989 100644
--- a/res/layout/suggestion_tile_with_button.xml
+++ b/res/layout/suggestion_tile_with_button.xml
@@ -18,8 +18,10 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/suggestion_card"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_marginEnd="16dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:cardElevation="2dp"
@@ -27,8 +29,7 @@
+ android:layout_marginBottom="6dp" />
diff --git a/res/values-sw400dp/dimens.xml b/res/values-sw400dp/dimens.xml
index 6a0242246e6..23a11761ebb 100755
--- a/res/values-sw400dp/dimens.xml
+++ b/res/values-sw400dp/dimens.xml
@@ -23,7 +23,6 @@
56dp
- 180dp
22dp
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 6ede7c644af..893773b7974 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -304,13 +304,10 @@
24dp
- 156dp
14dp
12dp
16dp
2dp
- 6dp
- 8dp
8dp
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index f04c3c9da6e..99de73eb075 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -304,14 +304,7 @@ public class DashboardAdapter extends RecyclerView.Adapter suggestions =
(List) mDashboardData.getItemEntityByPosition(position);
- final int suggestionCount = suggestions.size();
- final Typeface fontMedium = Typeface.create(
- mContext.getString(com.android.internal.R.string.config_headlineFontFamilyMedium),
- Typeface.NORMAL);
- holder.title.setTypeface(fontMedium);
- if (suggestions != null && suggestionCount > 0) {
- holder.summary.setText("" + suggestionCount);
- holder.summary.setTypeface(fontMedium);
+ if (suggestions != null && suggestions.size() > 0) {
mSuggestionAdapter.setSuggestions(suggestions);
holder.data.setAdapter(mSuggestionAdapter);
}
diff --git a/src/com/android/settings/dashboard/DashboardData.java b/src/com/android/settings/dashboard/DashboardData.java
index 49de94d606b..45aab9a4f73 100644
--- a/src/com/android/settings/dashboard/DashboardData.java
+++ b/src/com/android/settings/dashboard/DashboardData.java
@@ -41,7 +41,7 @@ import java.util.Objects;
*/
public class DashboardData {
public static final int POSITION_NOT_FOUND = -1;
- public static final int MAX_SUGGESTION_COUNT = 4;
+ public static final int MAX_SUGGESTION_COUNT = 2;
// stable id for different type of items.
@VisibleForTesting
@@ -443,4 +443,4 @@ public class DashboardData {
}
}
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java b/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
index 87b3f4bb502..4c1e93962e1 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
@@ -117,15 +117,13 @@ public class SuggestionAdapter extends RecyclerView.Adapter
mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, id);
mSuggestionsShownLogged.add(id);
}
- mConfig.setCardLayout(holder, suggestionCount, position);
final Icon icon = suggestion.getIcon();
final Drawable drawable = mCache.getIcon(icon);
- if (drawable != null && (suggestion.getFlags() & Suggestion.FLAG_ICON_TINTABLE) != 0) {
+ if (drawable != null) {
drawable.setTint(Utils.getColorAccent(mContext));
}
holder.icon.setImageDrawable(drawable);
holder.title.setText(suggestion.getTitle());
- holder.title.setSingleLine(suggestionCount == 1);
holder.title.setTypeface(Typeface.create(
mContext.getString(com.android.internal.R.string.config_headlineFontFamily),
Typeface.NORMAL));
@@ -139,9 +137,7 @@ public class SuggestionAdapter extends RecyclerView.Adapter
holder.summary.setVisibility(View.GONE);
}
} else {
- // Do not show summary if there are more than 1 suggestions
- holder.summary.setVisibility(View.GONE);
- holder.title.setMaxLines(3);
+ mConfig.setCardLayout(holder, position);
}
final ImageView closeButton = holder.itemView.findViewById(R.id.close_button);
@@ -183,9 +179,11 @@ public class SuggestionAdapter extends RecyclerView.Adapter
final Suggestion suggestion = getSuggestion(position);
if ((suggestion.getFlags() & Suggestion.FLAG_HAS_BUTTON) != 0) {
return R.layout.suggestion_tile_with_button;
- } else {
+ }
+ if (getItemCount() == 1) {
return R.layout.suggestion_tile;
}
+ return R.layout.suggestion_tile_two_cards;
}
@Override
@@ -234,11 +232,6 @@ public class SuggestionAdapter extends RecyclerView.Adapter
// Card start/end margin
private final int mMarginInner;
private final int mMarginOuter;
- // Card width if there are more than 2 cards
- private final int mWidthMultipleCards;
- // padding between icon and title
- private final int mPaddingTitleTopSingleCard;
- private final int mPaddingTitleTopMultipleCards;
private final WindowManager mWindowManager;
private static CardConfig sConfig;
@@ -250,12 +243,6 @@ public class SuggestionAdapter extends RecyclerView.Adapter
res.getDimensionPixelOffset(R.dimen.suggestion_card_inner_margin);
mMarginOuter =
res.getDimensionPixelOffset(R.dimen.suggestion_card_outer_margin);
- mWidthMultipleCards =
- res.getDimensionPixelOffset(R.dimen.suggestion_card_width_multiple_cards);
- mPaddingTitleTopSingleCard =
- res.getDimensionPixelOffset(R.dimen.suggestion_card_title_padding_bottom_one_card);
- mPaddingTitleTopMultipleCards = res.getDimensionPixelOffset(
- R.dimen.suggestion_card_title_padding_bottom_multiple_cards);
}
public static CardConfig get(Context context) {
@@ -266,20 +253,11 @@ public class SuggestionAdapter extends RecyclerView.Adapter
}
@VisibleForTesting
- void setCardLayout(DashboardItemHolder holder, int suggestionCount, int position) {
+ void setCardLayout(DashboardItemHolder holder, int position) {
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
- suggestionCount == 1
- ? LinearLayout.LayoutParams.MATCH_PARENT : suggestionCount == 2
- ? getWidthForTwoCrads() : mWidthMultipleCards,
- LinearLayout.LayoutParams.WRAP_CONTENT);
- if (suggestionCount == 1) {
- params.setMarginStart(mMarginOuter);
- params.setMarginEnd(mMarginOuter);
- } else {
- params.setMarginStart(
- position == 0 ? mMarginOuter : mMarginInner);
- params.setMarginEnd(position == suggestionCount - 1 ? mMarginOuter : 0);
- }
+ getWidthForTwoCrads(), LinearLayout.LayoutParams.WRAP_CONTENT);
+ params.setMarginStart(position == 0 ? mMarginOuter : mMarginInner);
+ params.setMarginEnd(position != 0 ? mMarginOuter : 0);
holder.itemView.setLayoutParams(params);
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
index b85afaa81ce..427f1d0c5ec 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
@@ -138,31 +138,6 @@ public class DashboardAdapterTest {
verify(adapter, never()).notifyDashboardDataChanged(any());
}
- @Test
- public void testSuggestionDismissed_moreThanTwoSuggestions_shouldNotCrash() {
- final RecyclerView data = new RecyclerView(RuntimeEnvironment.application);
- final View itemView = mock(View.class);
- when(itemView.findViewById(R.id.suggestion_list)).thenReturn(data);
- when(itemView.findViewById(android.R.id.summary)).thenReturn(mock(TextView.class));
- when(itemView.findViewById(android.R.id.title)).thenReturn(mock(TextView.class));
- final DashboardAdapter.SuggestionContainerHolder holder =
- new DashboardAdapter.SuggestionContainerHolder(itemView);
- final List suggestions = makeSuggestionsV2("pkg1", "pkg2", "pkg3", "pkg4");
- final DashboardAdapter adapter = spy(new DashboardAdapter(mContext,
- null /*savedInstance */, null /* conditions */,
- null /* suggestionControllerMixin */,
- null /* lifecycle */));
- adapter.setSuggestions(suggestions);
- adapter.onBindSuggestion(holder, 0);
-
- adapter.onSuggestionClosed(suggestions.get(1));
-
- // verify operations that access the lists will not cause ConcurrentModificationException
- assertThat(holder.data.getAdapter().getItemCount()).isEqualTo(3);
- adapter.setSuggestions(suggestions);
- // should not crash
- }
-
@Test
public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
DashboardAdapter adapter =
@@ -205,38 +180,6 @@ public class DashboardAdapterTest {
// should not crash
}
- @Test
- public void testBindSuggestion_shouldSetSummary() {
- mDashboardAdapter = new DashboardAdapter(mContext, null /* savedInstanceState */,
- null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
- final List suggestions = makeSuggestionsV2("pkg1");
-
- mDashboardAdapter.setSuggestions(suggestions);
-
- final RecyclerView data = mock(RecyclerView.class);
- when(data.getResources()).thenReturn(mResources);
- when(data.getContext()).thenReturn(mContext);
- when(mResources.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
- final View itemView = mock(View.class);
- when(itemView.findViewById(R.id.suggestion_list)).thenReturn(data);
- final TextView summary = mock(TextView.class);
- when(itemView.findViewById(android.R.id.summary)).thenReturn(summary);
- when(itemView.findViewById(android.R.id.title)).thenReturn(mock(TextView.class));
- final DashboardAdapter.SuggestionContainerHolder holder =
- new DashboardAdapter.SuggestionContainerHolder(itemView);
-
- mDashboardAdapter.onBindSuggestion(holder, 0);
-
- verify(summary).setText("1");
-
- suggestions.addAll(makeSuggestionsV2("pkg2", "pkg3", "pkg4"));
- mDashboardAdapter.setSuggestions(suggestions);
-
- mDashboardAdapter.onBindSuggestion(holder, 0);
-
- verify(summary).setText("4");
- }
-
@Test
public void onBindTile_internalTile_shouldNotUseGenericBackgroundIcon() {
final Context context = RuntimeEnvironment.application;
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java
index 512ac647404..d96e6608dfe 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java
@@ -94,8 +94,6 @@ public class SuggestionAdapterTest {
.thenReturn(10);
when(mResources.getDimensionPixelOffset(R.dimen.suggestion_card_outer_margin))
.thenReturn(20);
- when(mResources.getDimensionPixelOffset(R.dimen.suggestion_card_width_multiple_cards))
- .thenReturn(120);
mConfig = spy(SuggestionAdapter.CardConfig.get(mActivity));
mFeatureFactory = FakeFeatureFactory.setupForTest();
@@ -238,40 +236,12 @@ public class SuggestionAdapterTest {
}
@Test
- public void onBindViewHolder_iconNotTintable_shouldNotTintIcon()
- throws PendingIntent.CanceledException {
- final Icon icon = mock(Icon.class);
- final Suggestion suggestion = new Suggestion.Builder("pkg1")
- .setPendingIntent(mock(PendingIntent.class))
- .setIcon(icon)
- .build();
- final List suggestions = new ArrayList<>();
- suggestions.add(suggestion);
- mSuggestionAdapter = new SuggestionAdapter(mActivity, mSuggestionControllerMixin,
- null /* savedInstanceState */, null /* callback */, null /* lifecycle */);
- mSuggestionAdapter.setSuggestions(suggestions);
- mSuggestionHolder = mSuggestionAdapter.onCreateViewHolder(
- new FrameLayout(RuntimeEnvironment.application),
- mSuggestionAdapter.getItemViewType(0));
- IconCache cache = mock(IconCache.class);
- final Drawable drawable = mock(Drawable.class);
- when(cache.getIcon(icon)).thenReturn(drawable);
- ReflectionHelpers.setField(mSuggestionAdapter, "mCache", cache);
-
- mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
-
- verify(drawable, never()).setTint(anyInt());
- }
-
- @Test
- public void onBindViewHolder_iconTintable_shouldTintIcon()
- throws PendingIntent.CanceledException {
+ public void onBindViewHolder_shouldTintIcon() throws PendingIntent.CanceledException {
final Icon icon = mock(Icon.class);
final int FLAG_ICON_TINTABLE = 1 << 1;
final Suggestion suggestion = new Suggestion.Builder("pkg1")
.setPendingIntent(mock(PendingIntent.class))
.setIcon(icon)
- .setFlags(FLAG_ICON_TINTABLE)
.build();
final List suggestions = new ArrayList<>();
suggestions.add(suggestion);
@@ -308,24 +278,13 @@ public class SuggestionAdapterTest {
.isNotNull();
}
- @Test
- public void setCardLayout_oneCard_shouldSetCardWidthToMatchParent() {
- final List suggestions = makeSuggestions("pkg1");
- setupSuggestions(mContext, suggestions);
-
- mConfig.setCardLayout(mSuggestionHolder, 1, 0);
-
- assertThat(mSuggestionHolder.itemView.getLayoutParams().width)
- .isEqualTo(LinearLayout.LayoutParams.MATCH_PARENT);
- }
-
@Test
public void setCardLayout_twoCards_shouldSetCardWidthToHalfScreenMinusPadding() {
final List suggestions = makeSuggestions("pkg1");
setupSuggestions(mContext, suggestions);
doReturn(200).when(mConfig).getScreenWidth();
- mConfig.setCardLayout(mSuggestionHolder, 2, 0);
+ mConfig.setCardLayout(mSuggestionHolder, 0);
/*
* card width = (screen width - left margin - inner margin - right margin) / 2
@@ -335,17 +294,6 @@ public class SuggestionAdapterTest {
assertThat(mSuggestionHolder.itemView.getLayoutParams().width).isEqualTo(75);
}
-
- @Test
- public void setCardLayout_multipleCards_shouldSetCardWidthFromResource() {
- final List suggestions = makeSuggestions("pkg1");
- setupSuggestions(mContext, suggestions);
-
- mConfig.setCardLayout(mSuggestionHolder, 3, 0);
-
- assertThat(mSuggestionHolder.itemView.getLayoutParams().width).isEqualTo(120);
- }
-
private void setupSuggestions(Context context, List suggestions) {
mSuggestionAdapter = new SuggestionAdapter(context, mSuggestionControllerMixin,
null /* savedInstanceState */, null /* callback */, null /* lifecycle */);