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:
@@ -50,6 +50,7 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.Settings.WifiSettingsActivity;
|
||||
@@ -62,6 +63,7 @@ import com.android.settings.dashboard.DashboardSummary;
|
||||
import com.android.settings.development.DevelopmentSettings;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.DynamicIndexableContentMonitor;
|
||||
import com.android.settings.search.SearchActivity;
|
||||
import com.android.settings.search.SearchFeatureProvider;
|
||||
import com.android.settings.wfd.WifiDisplaySettings;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
@@ -75,7 +77,7 @@ import java.util.Set;
|
||||
public class SettingsActivity extends SettingsDrawerActivity
|
||||
implements PreferenceManager.OnPreferenceTreeClickListener,
|
||||
PreferenceFragment.OnPreferenceStartFragmentCallback,
|
||||
ButtonBarHandler, FragmentManager.OnBackStackChangedListener {
|
||||
ButtonBarHandler, FragmentManager.OnBackStackChangedListener, OnClickListener {
|
||||
|
||||
private static final String LOG_TAG = "Settings";
|
||||
|
||||
@@ -345,6 +347,14 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
launchSettingFragment(initialFragmentName, isSubSettings, intent);
|
||||
}
|
||||
|
||||
if (mIsShowingDashboard) {
|
||||
findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.action_bar).setVisibility(View.GONE);
|
||||
Toolbar toolbar = findViewById(R.id.search_action_bar);
|
||||
toolbar.setOnClickListener(this);
|
||||
setActionBar(toolbar);
|
||||
}
|
||||
|
||||
mActionBar = getActionBar();
|
||||
if (mActionBar != null) {
|
||||
mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
|
||||
@@ -432,10 +442,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
switchToFragment(initialFragmentName, initialArguments, true, false,
|
||||
mInitialTitleResId, mInitialTitle, false);
|
||||
} else {
|
||||
// No UP affordance if we are displaying the main Dashboard
|
||||
mDisplayHomeAsUpEnabled = false;
|
||||
// Show Search affordance
|
||||
mDisplaySearch = true;
|
||||
// Show search icon as up affordance if we are displaying the main Dashboard
|
||||
mDisplayHomeAsUpEnabled = true;
|
||||
// toolbar is search affordance so don't show search
|
||||
mDisplaySearch = false;
|
||||
mInitialTitleResId = R.string.dashboard_title;
|
||||
|
||||
switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
|
||||
@@ -940,4 +950,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -45,7 +45,8 @@ public class DashboardData {
|
||||
public static final int DEFAULT_SUGGESTION_COUNT = 2;
|
||||
|
||||
// id namespace for different type of items.
|
||||
private static final int NS_SPACER = 0;
|
||||
private static final int NS_HEADER_SPACER = 0;
|
||||
private static final int NS_SPACER = 1000;
|
||||
private static final int NS_ITEMS = 2000;
|
||||
private static final int NS_CONDITION = 3000;
|
||||
|
||||
@@ -234,6 +235,9 @@ public class DashboardData {
|
||||
* and mIsShowingAll, mSuggestionMode flag.
|
||||
*/
|
||||
private void buildItemsData() {
|
||||
// add the view that goes under the search bar
|
||||
countItem(null, R.layout.dashboard_header_spacer, true, NS_HEADER_SPACER);
|
||||
resetCount();
|
||||
boolean hasConditions = false;
|
||||
for (int i = 0; mConditions != null && i < mConditions.size(); i++) {
|
||||
boolean shouldShow = mConditions.get(i).shouldShow();
|
||||
|
@@ -51,13 +51,10 @@ public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
||||
String menuTitle = activity.getString(R.string.search_menu);
|
||||
MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, menuTitle)
|
||||
.setIcon(R.drawable.ic_search_24dp)
|
||||
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
Intent intent = new Intent(activity, SearchActivity.class);
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
.setOnMenuItemClickListener(item -> {
|
||||
Intent intent = new Intent(activity, SearchActivity.class);
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
|
||||
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
Reference in New Issue
Block a user