Merge "Revert "Add search bar to SearchActivity."" into oc-dev
am: 37f87b6c64
Change-Id: Icbdb586e3e1a35c004298f50a57812e50ee73eea
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Rect;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class HeaderDecorator extends RecyclerView.ItemDecoration {
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
|
||||
RecyclerView.State state) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
if (parent.getChildAdapterPosition(view) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = view.getContext();
|
||||
TypedArray ta = context.obtainStyledAttributes(new int[]{android.R.attr.actionBarSize});
|
||||
outRect.top = ta.getDimensionPixelSize(0, 0);
|
||||
ta.recycle();
|
||||
|
||||
outRect.top += 2 * context.getResources().getDimensionPixelSize(R.dimen.search_bar_margin);
|
||||
}
|
||||
}
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.LoaderManager;
|
||||
import android.content.Context;
|
||||
@@ -31,6 +32,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.SearchView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
@@ -58,6 +60,9 @@ public class SearchFragment extends InstrumentedFragment implements SearchView.O
|
||||
LoaderManager.LoaderCallbacks<List<? extends SearchResult>>, IndexingCallback {
|
||||
private static final String TAG = "SearchFragment";
|
||||
|
||||
@VisibleForTesting
|
||||
static final int SEARCH_TAG = "SearchViewTag".hashCode();
|
||||
|
||||
// State values
|
||||
private static final String STATE_QUERY = "state_query";
|
||||
private static final String STATE_SHOWING_SAVED_QUERY = "state_showing_saved_query";
|
||||
@@ -90,12 +95,12 @@ public class SearchFragment extends InstrumentedFragment implements SearchView.O
|
||||
@VisibleForTesting
|
||||
SavedQueryController mSavedQueryController;
|
||||
|
||||
@VisibleForTesting
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
SearchFeatureProvider mSearchFeatureProvider;
|
||||
|
||||
private SearchResultsAdapter mSearchAdapter;
|
||||
|
||||
@VisibleForTesting
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
RecyclerView mResultsRecyclerView;
|
||||
@VisibleForTesting
|
||||
SearchView mSearchView;
|
||||
@@ -144,6 +149,13 @@ public class SearchFragment extends InstrumentedFragment implements SearchView.O
|
||||
}
|
||||
|
||||
final Activity activity = getActivity();
|
||||
final ActionBar actionBar = activity.getActionBar();
|
||||
mSearchView = makeSearchView(actionBar, mQuery);
|
||||
actionBar.setCustomView(mSearchView);
|
||||
actionBar.setDisplayShowCustomEnabled(true);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
mSearchView.requestFocus();
|
||||
|
||||
// Run the Index update only if we have some space
|
||||
if (!Utils.isLowStorage(activity)) {
|
||||
mSearchFeatureProvider.updateIndex(activity, this /* indexingCallback */);
|
||||
@@ -160,14 +172,8 @@ public class SearchFragment extends InstrumentedFragment implements SearchView.O
|
||||
mResultsRecyclerView.setAdapter(mSearchAdapter);
|
||||
mResultsRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
mResultsRecyclerView.addOnScrollListener(mScrollListener);
|
||||
mResultsRecyclerView.addItemDecoration(new HeaderDecorator());
|
||||
|
||||
mNoResultsView = view.findViewById(R.id.no_results_layout);
|
||||
|
||||
mSearchView = view.findViewById(R.id.search_view);
|
||||
mSearchView.setQuery(mQuery, false /* submitQuery */);
|
||||
mSearchView.setOnQueryTextListener(this);
|
||||
mSearchView.requestFocus();
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -341,6 +347,19 @@ public class SearchFragment extends InstrumentedFragment implements SearchView.O
|
||||
onQueryTextChange(query);
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
SearchView makeSearchView(ActionBar actionBar, String query) {
|
||||
final SearchView searchView = new SearchView(actionBar.getThemedContext());
|
||||
searchView.setIconifiedByDefault(false);
|
||||
searchView.setQuery(query, false /* submitQuery */);
|
||||
searchView.setOnQueryTextListener(this);
|
||||
searchView.setTag(SEARCH_TAG, searchView);
|
||||
final LayoutParams lp =
|
||||
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||
searchView.setLayoutParams(lp);
|
||||
return searchView;
|
||||
}
|
||||
|
||||
private void hideKeyboard() {
|
||||
final Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
|
Reference in New Issue
Block a user