Update suggestion card width.
- instead of using hard-coded width for 1 or 2 cards, they should take up the whole screen width minus the defined padding, so that when the device is in landscape mode, they look better. Change-Id: Ic6485c858c7742a154a6d9b05fff180f161be323 Fixes: 72850225 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -23,8 +23,6 @@
|
||||
<dimen name="support_escalation_card_padding_end">56dp</dimen>
|
||||
|
||||
<!-- Suggestion cards-->
|
||||
<dimen name="suggestion_card_width_one_card">384dp</dimen>
|
||||
<dimen name="suggestion_card_width_two_cards">188dp</dimen>
|
||||
<dimen name="suggestion_card_width_multiple_cards">180dp</dimen>
|
||||
<dimen name="suggestion_card_padding_bottom_one_card">22dp</dimen>
|
||||
|
||||
|
@@ -304,8 +304,6 @@
|
||||
|
||||
<!-- Suggestion cards size and padding -->
|
||||
<dimen name="suggestion_card_icon_size">24dp</dimen>
|
||||
<dimen name="suggestion_card_width_one_card">332dp</dimen>
|
||||
<dimen name="suggestion_card_width_two_cards">162dp</dimen>
|
||||
<dimen name="suggestion_card_width_multiple_cards">156dp</dimen>
|
||||
<dimen name="suggestion_card_outer_margin">14dp</dimen>
|
||||
<dimen name="suggestion_card_inner_margin">12dp</dimen>
|
||||
|
@@ -23,12 +23,15 @@ import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
@@ -117,7 +120,7 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
mConfig.setCardLayout(holder, suggestionCount, position);
|
||||
final Icon icon = suggestion.getIcon();
|
||||
final Drawable drawable = mCache.getIcon(icon);
|
||||
if ((suggestion.getFlags() & Suggestion.FLAG_ICON_TINTABLE) != 0) {
|
||||
if (drawable != null && (suggestion.getFlags() & Suggestion.FLAG_ICON_TINTABLE) != 0) {
|
||||
drawable.setTint(Utils.getColorAccent(mContext));
|
||||
}
|
||||
holder.icon.setImageDrawable(drawable);
|
||||
@@ -226,28 +229,27 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
return mSuggestions;
|
||||
}
|
||||
|
||||
private static class CardConfig {
|
||||
@VisibleForTesting
|
||||
static class CardConfig {
|
||||
// Card start/end margin
|
||||
private final int mMarginInner;
|
||||
private final int mMarginOuter;
|
||||
// Card width for different numbers of cards
|
||||
private final int mWidthSingleCard;
|
||||
private final int mWidthTwoCards;
|
||||
// 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;
|
||||
|
||||
private CardConfig(Context context) {
|
||||
mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
final Resources res = context.getResources();
|
||||
mMarginInner =
|
||||
res.getDimensionPixelOffset(R.dimen.suggestion_card_inner_margin);
|
||||
mMarginOuter =
|
||||
res.getDimensionPixelOffset(R.dimen.suggestion_card_outer_margin);
|
||||
mWidthSingleCard = res.getDimensionPixelOffset(R.dimen.suggestion_card_width_one_card);
|
||||
mWidthTwoCards = res.getDimensionPixelOffset(R.dimen.suggestion_card_width_two_cards);
|
||||
mWidthMultipleCards =
|
||||
res.getDimensionPixelOffset(R.dimen.suggestion_card_width_multiple_cards);
|
||||
mPaddingTitleTopSingleCard =
|
||||
@@ -263,12 +265,12 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
return sConfig;
|
||||
}
|
||||
|
||||
private void setCardLayout(DashboardItemHolder holder, int suggestionCount,
|
||||
int position) {
|
||||
@VisibleForTesting
|
||||
void setCardLayout(DashboardItemHolder holder, int suggestionCount, int position) {
|
||||
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||
suggestionCount == 1
|
||||
? mWidthSingleCard : suggestionCount == 2
|
||||
? mWidthTwoCards : mWidthMultipleCards,
|
||||
? LinearLayout.LayoutParams.MATCH_PARENT : suggestionCount == 2
|
||||
? getWidthForTwoCrads() : mWidthMultipleCards,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
if (suggestionCount == 1) {
|
||||
params.setMarginStart(mMarginOuter);
|
||||
@@ -281,6 +283,16 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
holder.itemView.setLayoutParams(params);
|
||||
}
|
||||
|
||||
private int getWidthForTwoCrads() {
|
||||
return (getScreenWidth() - mMarginInner - mMarginOuter * 2) / 2;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getScreenWidth() {
|
||||
final DisplayMetrics metrics = new DisplayMetrics();
|
||||
mWindowManager.getDefaultDisplay().getMetrics(metrics);
|
||||
return metrics.widthPixels;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -77,6 +78,8 @@ public class DashboardAdapterTest {
|
||||
private Condition mCondition;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
@Mock
|
||||
private WindowManager mWindowManager;
|
||||
private FakeFeatureFactory mFactory;
|
||||
private DashboardAdapter mDashboardAdapter;
|
||||
private List<Condition> mConditionList;
|
||||
@@ -87,6 +90,7 @@ public class DashboardAdapterTest {
|
||||
mFactory = FakeFeatureFactory.setupForTest();
|
||||
when(mFactory.dashboardFeatureProvider.shouldTintIcon()).thenReturn(true);
|
||||
|
||||
when(mContext.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mWindowManager);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getQuantityString(any(int.class), any(int.class), any()))
|
||||
.thenReturn("");
|
||||
|
@@ -28,12 +28,15 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.view.Display;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
@@ -67,17 +70,33 @@ public class SuggestionAdapterTest {
|
||||
private SettingsActivity mActivity;
|
||||
@Mock
|
||||
private SuggestionControllerMixin mSuggestionControllerMixin;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
@Mock
|
||||
private WindowManager mWindowManager;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private Context mContext;
|
||||
private SuggestionAdapter mSuggestionAdapter;
|
||||
private DashboardAdapter.DashboardItemHolder mSuggestionHolder;
|
||||
private List<Suggestion> mOneSuggestion;
|
||||
private List<Suggestion> mTwoSuggestions;
|
||||
private SuggestionAdapter.CardConfig mConfig;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mActivity.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mWindowManager);
|
||||
when(mActivity.getResources()).thenReturn(mResources);
|
||||
when(mResources.getDimensionPixelOffset(R.dimen.suggestion_card_inner_margin))
|
||||
.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();
|
||||
|
||||
final Suggestion suggestion1 = new Suggestion.Builder("id1")
|
||||
@@ -275,6 +294,44 @@ public class SuggestionAdapterTest {
|
||||
verify(drawable).setTint(colorAccent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCardLayout_oneCard_shouldSetCardWidthToMatchParent() {
|
||||
final List<Suggestion> 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<Suggestion> suggestions = makeSuggestions("pkg1");
|
||||
setupSuggestions(mContext, suggestions);
|
||||
doReturn(200).when(mConfig).getScreenWidth();
|
||||
|
||||
mConfig.setCardLayout(mSuggestionHolder, 2, 0);
|
||||
|
||||
/*
|
||||
* card width = (screen width - left margin - inner margin - right margin) / 2
|
||||
* = (200 - 20 - 10 - 20) / 2
|
||||
* = 75
|
||||
*/
|
||||
assertThat(mSuggestionHolder.itemView.getLayoutParams().width).isEqualTo(75);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setCardLayout_multipleCards_shouldSetCardWidthFromResource() {
|
||||
final List<Suggestion> suggestions = makeSuggestions("pkg1");
|
||||
setupSuggestions(mContext, suggestions);
|
||||
|
||||
mConfig.setCardLayout(mSuggestionHolder, 3, 0);
|
||||
|
||||
assertThat(mSuggestionHolder.itemView.getLayoutParams().width).isEqualTo(120);
|
||||
}
|
||||
|
||||
private void setupSuggestions(Context context, List<Suggestion> suggestions) {
|
||||
mSuggestionAdapter = new SuggestionAdapter(context, mSuggestionControllerMixin,
|
||||
null /* savedInstanceState */, null /* callback */, null /* lifecycle */);
|
||||
|
Reference in New Issue
Block a user