Reduce max suggestion to show to 2.
- since we now either have 1 or 2 suggestions, putting most layout configuration in the xml instead of dynamically setting it in code. - remove the suggestion header - vertical center align the suggestion title text for 2 cards to make the card with single line looks better. - tint all suggestions icons. Change-Id: I0130f15d530264e164e5afd7c091f165a4a6adc2 Fixes: 70573674 Fixes: 73293989 Fixes: 64986736 Test: visual and make RunSettingsRoboTests
This commit is contained in:
@@ -23,40 +23,11 @@
|
|||||||
android:paddingTop="2dp"
|
android:paddingTop="2dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@android:id/title"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:gravity="start"
|
|
||||||
android:text="@string/suggestions_title_v2"
|
|
||||||
android:textAppearance="@style/TextAppearance.SuggestionHeader" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@android:id/summary"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:gravity="end"
|
|
||||||
android:textAppearance="@style/TextAppearance.SuggestionHeader" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/suggestion_list"
|
android:id="@+id/suggestion_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="12dp"
|
android:paddingBottom="16dp"
|
||||||
android:paddingBottom="13dp"
|
|
||||||
android:scrollbars="none"/>
|
android:scrollbars="none"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@@ -18,8 +18,10 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/suggestion_card"
|
android:id="@+id/suggestion_card"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
app:cardPreventCornerOverlap="false"
|
app:cardPreventCornerOverlap="false"
|
||||||
app:cardUseCompatPadding="true"
|
app:cardUseCompatPadding="true"
|
||||||
app:cardElevation="2dp"
|
app:cardElevation="2dp"
|
||||||
@@ -27,8 +29,8 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="112dp"
|
||||||
android:minHeight="112dp"
|
android:paddingBottom="8dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
@@ -42,7 +44,7 @@
|
|||||||
android:layout_height="@dimen/suggestion_card_icon_size"
|
android:layout_height="@dimen/suggestion_card_icon_size"
|
||||||
style="@style/SuggestionCardIcon"
|
style="@style/SuggestionCardIcon"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginBottom="8dp" />
|
android:layout_marginBottom="6dp" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/close_button"
|
android:id="@+id/close_button"
|
||||||
@@ -66,7 +68,6 @@
|
|||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textAppearance="@style/TextAppearance.SuggestionTitle"
|
android:textAppearance="@style/TextAppearance.SuggestionTitle"
|
||||||
android:ellipsize="end"
|
|
||||||
android:fadingEdge="horizontal" />
|
android:fadingEdge="horizontal" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -76,6 +77,7 @@
|
|||||||
style="@style/SuggestionCardText"
|
style="@style/SuggestionCardText"
|
||||||
android:layout_marginStart="12dp"
|
android:layout_marginStart="12dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
|
android:singleLine="true"
|
||||||
android:textAppearance="@style/TextAppearance.SuggestionSummary" />
|
android:textAppearance="@style/TextAppearance.SuggestionSummary" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
77
res/layout/suggestion_tile_two_cards.xml
Normal file
77
res/layout/suggestion_tile_two_cards.xml
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2017 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<android.support.v7.widget.CardView
|
||||||
|
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_height="wrap_content"
|
||||||
|
app:cardPreventCornerOverlap="false"
|
||||||
|
app:cardUseCompatPadding="true"
|
||||||
|
app:cardElevation="2dp"
|
||||||
|
app:cardCornerRadius="@dimen/suggestion_card_corner_radius">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="112dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@android:id/icon"
|
||||||
|
android:layout_width="@dimen/suggestion_card_icon_size"
|
||||||
|
android:layout_height="@dimen/suggestion_card_icon_size"
|
||||||
|
style="@style/SuggestionCardIcon"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginBottom="8dp" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/close_button"
|
||||||
|
android:layout_width="18dp"
|
||||||
|
android:layout_height="18dp"
|
||||||
|
android:alpha="0.54"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:contentDescription="@string/dlg_close"
|
||||||
|
android:src="@drawable/ic_suggestion_close_button"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
style="@style/SuggestionCardText"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:layout_marginEnd="12dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:textAppearance="@style/TextAppearance.SuggestionTitle"
|
||||||
|
android:maxLines="3"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:fadingEdge="horizontal" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</android.support.v7.widget.CardView>
|
@@ -18,8 +18,10 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/suggestion_card"
|
android:id="@+id/suggestion_card"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
app:cardPreventCornerOverlap="false"
|
app:cardPreventCornerOverlap="false"
|
||||||
app:cardUseCompatPadding="true"
|
app:cardUseCompatPadding="true"
|
||||||
app:cardElevation="2dp"
|
app:cardElevation="2dp"
|
||||||
@@ -27,8 +29,7 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="160dp"
|
||||||
android:minHeight="112dp"
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
android:layout_height="@dimen/suggestion_card_icon_size"
|
android:layout_height="@dimen/suggestion_card_icon_size"
|
||||||
style="@style/SuggestionCardIcon"
|
style="@style/SuggestionCardIcon"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginBottom="8dp" />
|
android:layout_marginBottom="6dp" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/close_button"
|
android:id="@+id/close_button"
|
||||||
@@ -66,7 +67,6 @@
|
|||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textAppearance="@style/TextAppearance.SuggestionTitle"
|
android:textAppearance="@style/TextAppearance.SuggestionTitle"
|
||||||
android:ellipsize="end"
|
|
||||||
android:fadingEdge="horizontal" />
|
android:fadingEdge="horizontal" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -76,6 +76,7 @@
|
|||||||
style="@style/SuggestionCardText"
|
style="@style/SuggestionCardText"
|
||||||
android:layout_marginStart="12dp"
|
android:layout_marginStart="12dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
|
android:singleLine="true"
|
||||||
android:textAppearance="@style/TextAppearance.SuggestionSummary" />
|
android:textAppearance="@style/TextAppearance.SuggestionSummary" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -84,7 +85,7 @@
|
|||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginBottom="18dp"
|
android:layout_marginBottom="18dp"
|
||||||
android:text="@string/suggestion_button_text" />
|
android:text="@string/suggestion_button_text" />
|
||||||
|
|
||||||
|
@@ -23,7 +23,6 @@
|
|||||||
<dimen name="support_escalation_card_padding_end">56dp</dimen>
|
<dimen name="support_escalation_card_padding_end">56dp</dimen>
|
||||||
|
|
||||||
<!-- Suggestion cards-->
|
<!-- Suggestion cards-->
|
||||||
<dimen name="suggestion_card_width_multiple_cards">180dp</dimen>
|
|
||||||
<dimen name="suggestion_card_padding_bottom_one_card">22dp</dimen>
|
<dimen name="suggestion_card_padding_bottom_one_card">22dp</dimen>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -304,13 +304,10 @@
|
|||||||
|
|
||||||
<!-- Suggestion cards size and padding -->
|
<!-- Suggestion cards size and padding -->
|
||||||
<dimen name="suggestion_card_icon_size">24dp</dimen>
|
<dimen name="suggestion_card_icon_size">24dp</dimen>
|
||||||
<dimen name="suggestion_card_width_multiple_cards">156dp</dimen>
|
|
||||||
<dimen name="suggestion_card_outer_margin">14dp</dimen>
|
<dimen name="suggestion_card_outer_margin">14dp</dimen>
|
||||||
<dimen name="suggestion_card_inner_margin">12dp</dimen>
|
<dimen name="suggestion_card_inner_margin">12dp</dimen>
|
||||||
<dimen name="suggestion_card_padding_bottom_one_card">16dp</dimen>
|
<dimen name="suggestion_card_padding_bottom_one_card">16dp</dimen>
|
||||||
<dimen name="suggestion_card_corner_radius">2dp</dimen>
|
<dimen name="suggestion_card_corner_radius">2dp</dimen>
|
||||||
<dimen name="suggestion_card_title_padding_bottom_one_card">6dp</dimen>
|
|
||||||
<dimen name="suggestion_card_title_padding_bottom_multiple_cards">8dp</dimen>
|
|
||||||
|
|
||||||
<!-- Padding for the reset screens -->
|
<!-- Padding for the reset screens -->
|
||||||
<dimen name="reset_checkbox_padding_end">8dp</dimen>
|
<dimen name="reset_checkbox_padding_end">8dp</dimen>
|
||||||
|
@@ -304,14 +304,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
// header anymore.
|
// header anymore.
|
||||||
final List<Suggestion> suggestions =
|
final List<Suggestion> suggestions =
|
||||||
(List<Suggestion>) mDashboardData.getItemEntityByPosition(position);
|
(List<Suggestion>) mDashboardData.getItemEntityByPosition(position);
|
||||||
final int suggestionCount = suggestions.size();
|
if (suggestions != null && suggestions.size() > 0) {
|
||||||
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);
|
|
||||||
mSuggestionAdapter.setSuggestions(suggestions);
|
mSuggestionAdapter.setSuggestions(suggestions);
|
||||||
holder.data.setAdapter(mSuggestionAdapter);
|
holder.data.setAdapter(mSuggestionAdapter);
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,7 @@ import java.util.Objects;
|
|||||||
*/
|
*/
|
||||||
public class DashboardData {
|
public class DashboardData {
|
||||||
public static final int POSITION_NOT_FOUND = -1;
|
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.
|
// stable id for different type of items.
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@@ -117,15 +117,13 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, id);
|
mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, id);
|
||||||
mSuggestionsShownLogged.add(id);
|
mSuggestionsShownLogged.add(id);
|
||||||
}
|
}
|
||||||
mConfig.setCardLayout(holder, suggestionCount, position);
|
|
||||||
final Icon icon = suggestion.getIcon();
|
final Icon icon = suggestion.getIcon();
|
||||||
final Drawable drawable = mCache.getIcon(icon);
|
final Drawable drawable = mCache.getIcon(icon);
|
||||||
if (drawable != null && (suggestion.getFlags() & Suggestion.FLAG_ICON_TINTABLE) != 0) {
|
if (drawable != null) {
|
||||||
drawable.setTint(Utils.getColorAccent(mContext));
|
drawable.setTint(Utils.getColorAccent(mContext));
|
||||||
}
|
}
|
||||||
holder.icon.setImageDrawable(drawable);
|
holder.icon.setImageDrawable(drawable);
|
||||||
holder.title.setText(suggestion.getTitle());
|
holder.title.setText(suggestion.getTitle());
|
||||||
holder.title.setSingleLine(suggestionCount == 1);
|
|
||||||
holder.title.setTypeface(Typeface.create(
|
holder.title.setTypeface(Typeface.create(
|
||||||
mContext.getString(com.android.internal.R.string.config_headlineFontFamily),
|
mContext.getString(com.android.internal.R.string.config_headlineFontFamily),
|
||||||
Typeface.NORMAL));
|
Typeface.NORMAL));
|
||||||
@@ -139,9 +137,7 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
holder.summary.setVisibility(View.GONE);
|
holder.summary.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Do not show summary if there are more than 1 suggestions
|
mConfig.setCardLayout(holder, position);
|
||||||
holder.summary.setVisibility(View.GONE);
|
|
||||||
holder.title.setMaxLines(3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final ImageView closeButton = holder.itemView.findViewById(R.id.close_button);
|
final ImageView closeButton = holder.itemView.findViewById(R.id.close_button);
|
||||||
@@ -183,9 +179,11 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
final Suggestion suggestion = getSuggestion(position);
|
final Suggestion suggestion = getSuggestion(position);
|
||||||
if ((suggestion.getFlags() & Suggestion.FLAG_HAS_BUTTON) != 0) {
|
if ((suggestion.getFlags() & Suggestion.FLAG_HAS_BUTTON) != 0) {
|
||||||
return R.layout.suggestion_tile_with_button;
|
return R.layout.suggestion_tile_with_button;
|
||||||
} else {
|
}
|
||||||
|
if (getItemCount() == 1) {
|
||||||
return R.layout.suggestion_tile;
|
return R.layout.suggestion_tile;
|
||||||
}
|
}
|
||||||
|
return R.layout.suggestion_tile_two_cards;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -234,11 +232,6 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
// Card start/end margin
|
// Card start/end margin
|
||||||
private final int mMarginInner;
|
private final int mMarginInner;
|
||||||
private final int mMarginOuter;
|
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 final WindowManager mWindowManager;
|
||||||
|
|
||||||
private static CardConfig sConfig;
|
private static CardConfig sConfig;
|
||||||
@@ -250,12 +243,6 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
res.getDimensionPixelOffset(R.dimen.suggestion_card_inner_margin);
|
res.getDimensionPixelOffset(R.dimen.suggestion_card_inner_margin);
|
||||||
mMarginOuter =
|
mMarginOuter =
|
||||||
res.getDimensionPixelOffset(R.dimen.suggestion_card_outer_margin);
|
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) {
|
public static CardConfig get(Context context) {
|
||||||
@@ -266,20 +253,11 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setCardLayout(DashboardItemHolder holder, int suggestionCount, int position) {
|
void setCardLayout(DashboardItemHolder holder, int position) {
|
||||||
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||||
suggestionCount == 1
|
getWidthForTwoCrads(), LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
? LinearLayout.LayoutParams.MATCH_PARENT : suggestionCount == 2
|
params.setMarginStart(position == 0 ? mMarginOuter : mMarginInner);
|
||||||
? getWidthForTwoCrads() : mWidthMultipleCards,
|
params.setMarginEnd(position != 0 ? mMarginOuter : 0);
|
||||||
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);
|
|
||||||
}
|
|
||||||
holder.itemView.setLayoutParams(params);
|
holder.itemView.setLayoutParams(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -138,31 +138,6 @@ public class DashboardAdapterTest {
|
|||||||
verify(adapter, never()).notifyDashboardDataChanged(any());
|
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<Suggestion> 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
|
@Test
|
||||||
public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
|
public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
|
||||||
DashboardAdapter adapter =
|
DashboardAdapter adapter =
|
||||||
@@ -205,38 +180,6 @@ public class DashboardAdapterTest {
|
|||||||
// should not crash
|
// should not crash
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBindSuggestion_shouldSetSummary() {
|
|
||||||
mDashboardAdapter = new DashboardAdapter(mContext, null /* savedInstanceState */,
|
|
||||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
|
||||||
final List<Suggestion> 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
|
@Test
|
||||||
public void onBindTile_internalTile_shouldNotUseGenericBackgroundIcon() {
|
public void onBindTile_internalTile_shouldNotUseGenericBackgroundIcon() {
|
||||||
final Context context = RuntimeEnvironment.application;
|
final Context context = RuntimeEnvironment.application;
|
||||||
|
@@ -94,8 +94,6 @@ public class SuggestionAdapterTest {
|
|||||||
.thenReturn(10);
|
.thenReturn(10);
|
||||||
when(mResources.getDimensionPixelOffset(R.dimen.suggestion_card_outer_margin))
|
when(mResources.getDimensionPixelOffset(R.dimen.suggestion_card_outer_margin))
|
||||||
.thenReturn(20);
|
.thenReturn(20);
|
||||||
when(mResources.getDimensionPixelOffset(R.dimen.suggestion_card_width_multiple_cards))
|
|
||||||
.thenReturn(120);
|
|
||||||
mConfig = spy(SuggestionAdapter.CardConfig.get(mActivity));
|
mConfig = spy(SuggestionAdapter.CardConfig.get(mActivity));
|
||||||
|
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
@@ -238,40 +236,12 @@ public class SuggestionAdapterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onBindViewHolder_iconNotTintable_shouldNotTintIcon()
|
public void onBindViewHolder_shouldTintIcon() throws PendingIntent.CanceledException {
|
||||||
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<Suggestion> 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 {
|
|
||||||
final Icon icon = mock(Icon.class);
|
final Icon icon = mock(Icon.class);
|
||||||
final int FLAG_ICON_TINTABLE = 1 << 1;
|
final int FLAG_ICON_TINTABLE = 1 << 1;
|
||||||
final Suggestion suggestion = new Suggestion.Builder("pkg1")
|
final Suggestion suggestion = new Suggestion.Builder("pkg1")
|
||||||
.setPendingIntent(mock(PendingIntent.class))
|
.setPendingIntent(mock(PendingIntent.class))
|
||||||
.setIcon(icon)
|
.setIcon(icon)
|
||||||
.setFlags(FLAG_ICON_TINTABLE)
|
|
||||||
.build();
|
.build();
|
||||||
final List<Suggestion> suggestions = new ArrayList<>();
|
final List<Suggestion> suggestions = new ArrayList<>();
|
||||||
suggestions.add(suggestion);
|
suggestions.add(suggestion);
|
||||||
@@ -308,24 +278,13 @@ public class SuggestionAdapterTest {
|
|||||||
.isNotNull();
|
.isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@Test
|
||||||
public void setCardLayout_twoCards_shouldSetCardWidthToHalfScreenMinusPadding() {
|
public void setCardLayout_twoCards_shouldSetCardWidthToHalfScreenMinusPadding() {
|
||||||
final List<Suggestion> suggestions = makeSuggestions("pkg1");
|
final List<Suggestion> suggestions = makeSuggestions("pkg1");
|
||||||
setupSuggestions(mContext, suggestions);
|
setupSuggestions(mContext, suggestions);
|
||||||
doReturn(200).when(mConfig).getScreenWidth();
|
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
|
* 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);
|
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) {
|
private void setupSuggestions(Context context, List<Suggestion> suggestions) {
|
||||||
mSuggestionAdapter = new SuggestionAdapter(context, mSuggestionControllerMixin,
|
mSuggestionAdapter = new SuggestionAdapter(context, mSuggestionControllerMixin,
|
||||||
null /* savedInstanceState */, null /* callback */, null /* lifecycle */);
|
null /* savedInstanceState */, null /* callback */, null /* lifecycle */);
|
||||||
|
Reference in New Issue
Block a user