Dashboard search bar polish
Various tweaks to match redlines: - background is now grey all the time - the search icon is aligned with the other icons - the title text is primary colored instead of accent colored - the background of search bar doesn't scroll anymore Deletes a bunch of logic to add an initial view that would be colored based on the first view. It never quite worked right. Now it's consistent and never moves. Bug: 37477506 Fixes: 62267378 Fixes: 62379978 Fixes: 62361213 Test: robotests Change-Id: Iddfd45a64a0a8d0365397a207889d7225d1ebb70 Merged-In: I82c584e8f8ecc6fc298c5cdbce08516c6a069a39
This commit is contained in:
@@ -1,25 +0,0 @@
|
|||||||
<?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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:padding="@dimen/search_bar_margin">
|
|
||||||
<View
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?android:attr/actionBarSize"/>
|
|
||||||
</LinearLayout>
|
|
@@ -17,14 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout 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:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_width="match_parent">
|
android:orientation="vertical">
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/main_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent"/>
|
android:background="@color/material_grey_300">
|
||||||
<android.support.v7.widget.CardView
|
<android.support.v7.widget.CardView
|
||||||
android:id="@+id/search_bar"
|
android:id="@+id/search_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -37,12 +38,15 @@
|
|||||||
android:id="@+id/search_action_bar"
|
android:id="@+id/search_action_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/search_bar_negative_margin"
|
|
||||||
android:background="?android:attr/selectableItemBackground"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
android:contentInsetStartWithNavigation="64dp"
|
||||||
android:navigationIcon="@drawable/ic_search_24dp"
|
android:navigationIcon="@drawable/ic_search_24dp"
|
||||||
android:title="@string/search_menu"
|
android:titleTextColor="@*android:color/text_color_primary"
|
||||||
android:titleTextAppearance="?android:attr/subtitleTextAppearance"
|
|
||||||
android:titleTextColor="?android:attr/textColorHint"
|
|
||||||
android:theme="?android:attr/actionBarTheme"/>
|
android:theme="?android:attr/actionBarTheme"/>
|
||||||
</android.support.v7.widget.CardView>
|
</android.support.v7.widget.CardView>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/main_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_width="match_parent"/>
|
||||||
|
</LinearLayout>
|
||||||
|
@@ -337,6 +337,14 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
Toolbar toolbar = findViewById(R.id.search_action_bar);
|
Toolbar toolbar = findViewById(R.id.search_action_bar);
|
||||||
toolbar.setOnClickListener(this);
|
toolbar.setOnClickListener(this);
|
||||||
setActionBar(toolbar);
|
setActionBar(toolbar);
|
||||||
|
|
||||||
|
// Please forgive me for what I am about to do.
|
||||||
|
//
|
||||||
|
// Need to make the navigation icon non-clickable so that the entire card is clickable
|
||||||
|
// and goes to the search UI. Also set the background to null so there's no ripple.
|
||||||
|
View navView = toolbar.getNavigationView();
|
||||||
|
navView.setClickable(false);
|
||||||
|
navView.setBackground(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionBar actionBar = getActionBar();
|
ActionBar actionBar = getActionBar();
|
||||||
|
@@ -65,7 +65,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
private static final String STATE_CATEGORY_LIST = "category_list";
|
private static final String STATE_CATEGORY_LIST = "category_list";
|
||||||
private static final String STATE_SUGGESTION_MODE = "suggestion_mode";
|
private static final String STATE_SUGGESTION_MODE = "suggestion_mode";
|
||||||
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
|
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
|
||||||
private static final int DONT_SET_BACKGROUND_ATTR = -1;
|
|
||||||
private static final String STATE_SUGGESTION_CONDITION_MODE = "suggestion_condition_mode";
|
private static final String STATE_SUGGESTION_CONDITION_MODE = "suggestion_condition_mode";
|
||||||
|
|
||||||
private final IconCache mCache;
|
private final IconCache mCache;
|
||||||
@@ -305,9 +304,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||||
final int type = mDashboardData.getItemTypeByPosition(position);
|
final int type = mDashboardData.getItemTypeByPosition(position);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case R.layout.dashboard_header_spacer:
|
|
||||||
onBindHeaderSpacer(holder, position);
|
|
||||||
break;
|
|
||||||
case R.layout.dashboard_category:
|
case R.layout.dashboard_category:
|
||||||
onBindCategory(holder,
|
onBindCategory(holder,
|
||||||
(DashboardCategory) mDashboardData.getItemEntityByPosition(position));
|
(DashboardCategory) mDashboardData.getItemEntityByPosition(position));
|
||||||
@@ -484,33 +480,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
notifyDashboardDataChanged(prevData);
|
notifyDashboardDataChanged(prevData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onBindHeaderSpacer(DashboardItemHolder holder, int position) {
|
|
||||||
if (mDashboardData.size() > (position + 1)) {
|
|
||||||
// The spacer that goes underneath the search bar needs to match the
|
|
||||||
// background of the first real view. That view is either a condition,
|
|
||||||
// a suggestion, or the dashboard item.
|
|
||||||
//
|
|
||||||
// If it's a dashboard item, set null background so it uses the parent's
|
|
||||||
// background like the other views. Otherwise, match the colors.
|
|
||||||
int nextType = mDashboardData.getItemTypeByPosition(position + 1);
|
|
||||||
int colorAttr = nextType == R.layout.suggestion_header
|
|
||||||
? android.R.attr.colorSecondary
|
|
||||||
: nextType == R.layout.condition_card
|
|
||||||
? android.R.attr.colorAccent
|
|
||||||
: DONT_SET_BACKGROUND_ATTR;
|
|
||||||
|
|
||||||
if (colorAttr != DONT_SET_BACKGROUND_ATTR) {
|
|
||||||
TypedArray array = holder.itemView.getContext()
|
|
||||||
.obtainStyledAttributes(new int[]{colorAttr});
|
|
||||||
@ColorInt int color = array.getColor(0, 0);
|
|
||||||
array.recycle();
|
|
||||||
holder.itemView.setBackgroundColor(color);
|
|
||||||
} else {
|
|
||||||
holder.itemView.setBackground(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void onBindSuggestionHeader(final DashboardItemHolder holder, DashboardData
|
void onBindSuggestionHeader(final DashboardItemHolder holder, DashboardData
|
||||||
.SuggestionHeaderData data) {
|
.SuggestionHeaderData data) {
|
||||||
|
@@ -60,8 +60,7 @@ public class DashboardData {
|
|||||||
public static final int DEFAULT_SUGGESTION_COUNT = 2;
|
public static final int DEFAULT_SUGGESTION_COUNT = 2;
|
||||||
|
|
||||||
// id namespace for different type of items.
|
// id namespace for different type of items.
|
||||||
private static final int NS_HEADER_SPACER = 0;
|
private static final int NS_SPACER = 0;
|
||||||
private static final int NS_SPACER = 1000;
|
|
||||||
private static final int NS_ITEMS = 2000;
|
private static final int NS_ITEMS = 2000;
|
||||||
private static final int NS_CONDITION = 3000;
|
private static final int NS_CONDITION = 3000;
|
||||||
private static final int NS_SUGGESTION_CONDITION = 4000;
|
private static final int NS_SUGGESTION_CONDITION = 4000;
|
||||||
@@ -283,9 +282,6 @@ public class DashboardData {
|
|||||||
* and mIsShowingAll, mSuggestionMode flag.
|
* and mIsShowingAll, mSuggestionMode flag.
|
||||||
*/
|
*/
|
||||||
private void buildItemsData() {
|
private void buildItemsData() {
|
||||||
// add the view that goes under the search bar
|
|
||||||
countItem(null, R.layout.dashboard_header_spacer, true, NS_HEADER_SPACER);
|
|
||||||
resetCount();
|
|
||||||
final boolean hasSuggestions = sizeOf(mSuggestions) > 0;
|
final boolean hasSuggestions = sizeOf(mSuggestions) > 0;
|
||||||
if (!mCombineSuggestionAndCondition) {
|
if (!mCombineSuggestionAndCondition) {
|
||||||
boolean hasConditions = false;
|
boolean hasConditions = false;
|
||||||
|
@@ -123,53 +123,6 @@ public class DashboardAdapterTest {
|
|||||||
when(mView.getTag()).thenReturn(mCondition);
|
when(mView.getTag()).thenReturn(mCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnBindViewHolder_spacer_noSuggestions_noConditions() {
|
|
||||||
makeCategory();
|
|
||||||
DashboardAdapter.DashboardItemHolder holder = setupSpacer();
|
|
||||||
|
|
||||||
mDashboardAdapter.onBindViewHolder(holder, 0);
|
|
||||||
|
|
||||||
assertThat(holder.itemView.getBackground()).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnBindViewHolder_spacer_suggestion_noConditions() {
|
|
||||||
setupSuggestions(makeSuggestions("pkg1"));
|
|
||||||
makeCategory();
|
|
||||||
DashboardAdapter.DashboardItemHolder holder = setupSpacer();
|
|
||||||
|
|
||||||
mDashboardAdapter.onBindViewHolder(holder, 0);
|
|
||||||
|
|
||||||
assertThat(holder.itemView.getBackground()).isNotNull();
|
|
||||||
assertThat(holder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnBindViewHolder_spacer_noSuggestion_condition() {
|
|
||||||
makeCondition();
|
|
||||||
makeCategory();
|
|
||||||
DashboardAdapter.DashboardItemHolder holder = setupSpacer();
|
|
||||||
|
|
||||||
mDashboardAdapter.onBindViewHolder(holder, 0);
|
|
||||||
|
|
||||||
assertThat(holder.itemView.getBackground()).isNotNull();
|
|
||||||
assertThat(holder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnBindViewHolder_spacer_suggestion_condition() {
|
|
||||||
setupSuggestions(makeSuggestions("pkg1"));
|
|
||||||
makeCondition();
|
|
||||||
makeCategory();
|
|
||||||
DashboardAdapter.DashboardItemHolder holder = setupSpacer();
|
|
||||||
|
|
||||||
mDashboardAdapter.onBindViewHolder(holder, 0);
|
|
||||||
|
|
||||||
assertThat(holder.itemView.getBackground()).isNotNull();
|
|
||||||
assertThat(holder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_NotExpanded() {
|
public void testSuggestionsLogs_NotExpanded() {
|
||||||
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
|
||||||
@@ -388,7 +341,7 @@ public class DashboardAdapterTest {
|
|||||||
new FrameLayout(RuntimeEnvironment.application),
|
new FrameLayout(RuntimeEnvironment.application),
|
||||||
R.layout.suggestion_tile_card);
|
R.layout.suggestion_tile_card);
|
||||||
|
|
||||||
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
|
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
|
||||||
assertThat(textView.getParent()).isSameAs(mSuggestionHolder.itemView);
|
assertThat(textView.getParent()).isSameAs(mSuggestionHolder.itemView);
|
||||||
mSuggestionHolder.itemView.performClick();
|
mSuggestionHolder.itemView.performClick();
|
||||||
|
|
||||||
@@ -413,7 +366,7 @@ public class DashboardAdapterTest {
|
|||||||
new FrameLayout(context),
|
new FrameLayout(context),
|
||||||
R.layout.suggestion_tile_card);
|
R.layout.suggestion_tile_card);
|
||||||
|
|
||||||
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
|
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
|
||||||
|
|
||||||
mSuggestionHolder.itemView.performClick();
|
mSuggestionHolder.itemView.performClick();
|
||||||
assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isNull();
|
assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isNull();
|
||||||
@@ -442,8 +395,8 @@ public class DashboardAdapterTest {
|
|||||||
new FrameLayout(context),
|
new FrameLayout(context),
|
||||||
R.layout.suggestion_tile_card);
|
R.layout.suggestion_tile_card);
|
||||||
|
|
||||||
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
|
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
|
||||||
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
|
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
|
||||||
|
|
||||||
ViewGroup itemView = (ViewGroup) mSuggestionHolder.itemView;
|
ViewGroup itemView = (ViewGroup) mSuggestionHolder.itemView;
|
||||||
assertThat(itemView.getChildCount()).isEqualTo(1);
|
assertThat(itemView.getChildCount()).isEqualTo(1);
|
||||||
@@ -509,25 +462,4 @@ public class DashboardAdapterTest {
|
|||||||
new FrameLayout(RuntimeEnvironment.application),
|
new FrameLayout(RuntimeEnvironment.application),
|
||||||
mDashboardAdapter.getItemViewType(1));
|
mDashboardAdapter.getItemViewType(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeCondition() {
|
|
||||||
final List<Condition> conditions = new ArrayList<>();
|
|
||||||
Condition condition = mock(Condition.class);
|
|
||||||
when(condition.shouldShow()).thenReturn(true);
|
|
||||||
conditions.add(condition);
|
|
||||||
mDashboardAdapter.setConditions(conditions);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void makeCategory() {
|
|
||||||
List<DashboardCategory> categories = new ArrayList<>();
|
|
||||||
categories.add(new DashboardCategory());
|
|
||||||
mDashboardAdapter.setCategory(categories);
|
|
||||||
}
|
|
||||||
|
|
||||||
private DashboardAdapter.DashboardItemHolder setupSpacer() {
|
|
||||||
Context context = RuntimeEnvironment.application;
|
|
||||||
final View view = LayoutInflater.from(context)
|
|
||||||
.inflate(R.layout.dashboard_header_spacer, new LinearLayout(context), false);
|
|
||||||
return new DashboardAdapter.DashboardItemHolder(view);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -117,7 +117,7 @@ public class DashboardDataTest {
|
|||||||
final DashboardData.SuggestionConditionHeaderData data =
|
final DashboardData.SuggestionConditionHeaderData data =
|
||||||
new DashboardData.SuggestionConditionHeaderData(
|
new DashboardData.SuggestionConditionHeaderData(
|
||||||
mDashboardDataWithOneConditions.getConditions(), 0);
|
mDashboardDataWithOneConditions.getConditions(), 0);
|
||||||
final Object[] expectedObjects = {null, data,
|
final Object[] expectedObjects = {data,
|
||||||
mDashboardDataWithOneConditions.getSuggestions(),
|
mDashboardDataWithOneConditions.getSuggestions(),
|
||||||
mDashboardDataWithOneConditions.getConditions(),
|
mDashboardDataWithOneConditions.getConditions(),
|
||||||
null, mDashboardCategory, mTestCategoryTile};
|
null, mDashboardCategory, mTestCategoryTile};
|
||||||
@@ -196,11 +196,11 @@ public class DashboardDataTest {
|
|||||||
// Item in position 1 is the header, which contains the number of conditions, changed from
|
// Item in position 1 is the header, which contains the number of conditions, changed from
|
||||||
// 1 to 2
|
// 1 to 2
|
||||||
testResultData.add(new ListUpdateResult.ResultData(
|
testResultData.add(new ListUpdateResult.ResultData(
|
||||||
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 1, 1));
|
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 0, 1));
|
||||||
// Item in position 3 is the condition container containing the list of conditions, which
|
// Item in position 3 is the condition container containing the list of conditions, which
|
||||||
// gets 1 more item
|
// gets 1 more item
|
||||||
testResultData.add(new ListUpdateResult.ResultData(
|
testResultData.add(new ListUpdateResult.ResultData(
|
||||||
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 3, 1));
|
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 2, 1));
|
||||||
|
|
||||||
testDiffUtil(mDashboardDataWithOneConditions,
|
testDiffUtil(mDashboardDataWithOneConditions,
|
||||||
mDashboardDataWithTwoConditions, testResultData);
|
mDashboardDataWithTwoConditions, testResultData);
|
||||||
@@ -211,7 +211,7 @@ public class DashboardDataTest {
|
|||||||
//Build testResultData
|
//Build testResultData
|
||||||
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
||||||
testResultData.add(new ListUpdateResult.ResultData(
|
testResultData.add(new ListUpdateResult.ResultData(
|
||||||
ListUpdateResult.ResultData.TYPE_OPERATION_REMOVE, 1, 6));
|
ListUpdateResult.ResultData.TYPE_OPERATION_REMOVE, 0, 6));
|
||||||
|
|
||||||
testDiffUtil(mDashboardDataWithOneConditions, mDashboardDataWithNoItems, testResultData);
|
testDiffUtil(mDashboardDataWithOneConditions, mDashboardDataWithNoItems, testResultData);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user