Initial search bar implementation.

Replaces the default Toolbar in SettingsActivity with one that looks
like a search bar. It uses a Toolbar inside a CardView with some custom
styling.

Since the search bar is a floating element, the new toolbar lives in the
content frame of the dashboard. A FrameLayout is used to provide the
layering that is desired.

Since the search bar is on top, an additional spacer view is added to
the list of items in the dashboard. Its color changes based on what
the first view is so that it always matches.

Adds android-support-v7-cardview as a dependency (and reorders the
other deps to be in alphabetical order).

Remaining work (in future CLs):
- remove search menu option?
- clean up initial window
- remove the line between the header and the first condition
       when there's a condition

Bug: 37477506
Test: make RunSettingsRoboTests
Change-Id: Id7477b90fbaf30eb5cac1ee244c847bddb95b3fd
This commit is contained in:
Andrew Sapperstein
2017-05-28 12:20:10 -07:00
parent 82b92cadd5
commit 048f6fb8b3
11 changed files with 249 additions and 51 deletions

View File

@@ -15,6 +15,8 @@
*/
package com.android.settings.dashboard;
import android.annotation.AttrRes;
import android.annotation.ColorInt;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
@@ -54,6 +56,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
private static final String STATE_CATEGORY_LIST = "category_list";
private static final String STATE_SUGGESTION_MODE = "suggestion_mode";
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
private static final int DONT_SET_BACKGROUND_ATTR = -1;
private final IconCache mCache;
private final Context mContext;
@@ -223,6 +226,9 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
public void onBindViewHolder(DashboardItemHolder holder, int position) {
final int type = mDashboardData.getItemTypeByPosition(position);
switch (type) {
case R.layout.dashboard_header_spacer:
onBindHeaderSpacer(holder, position);
break;
case R.layout.dashboard_category:
onBindCategory(holder,
(DashboardCategory) mDashboardData.getItemEntityByPosition(position));
@@ -343,6 +349,33 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
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
void onBindSuggestionHeader(final DashboardItemHolder holder, DashboardData
.SuggestionHeaderData data) {