Merge "Initial search bar implementation." into oc-dev
am: 91fe76263f
Change-Id: I7e6921134a239e136aaf6380ab4d7993e943435a
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.search2.SearchActivity;
|
||||
import com.android.settings.search2.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,
|
||||
@@ -939,4 +949,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;
|
||||
@@ -55,6 +57,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;
|
||||
@@ -222,6 +225,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));
|
||||
@@ -352,6 +358,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;
|
||||
|
||||
@@ -228,6 +229,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();
|
||||
|
@@ -54,13 +54,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