Merge "Search results page polish" into oc-dr1-dev

This commit is contained in:
TreeHugger Robot
2017-06-27 16:53:52 +00:00
committed by Android (Google) Code Review
7 changed files with 75 additions and 172 deletions

View File

@@ -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.search;
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);
}
}

View File

@@ -36,6 +36,8 @@ import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toolbar;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
@@ -168,14 +170,32 @@ 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);
Toolbar toolbar = view.findViewById(R.id.search_toolbar);
getActivity().setActionBar(toolbar);
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
mSearchView = toolbar.findViewById(R.id.search_view);
mSearchView.setQuery(mQuery, false /* submitQuery */);
mSearchView.setOnQueryTextListener(this);
mSearchView.requestFocus();
// Updating internal views inside SearchView was the easiest way to get this too look right.
// We null-check here so that tests pass since the robotests can't find the internal views.
TextView searchText = mSearchView.findViewById(com.android.internal.R.id.search_src_text);
if (searchText != null) {
searchText.setTextColor(getContext().getColorStateList(
com.android.internal.R.color.text_color_primary));
}
View editFrame = mSearchView.findViewById(com.android.internal.R.id.search_edit_frame);
if (editFrame != null) {
ViewGroup.MarginLayoutParams params =
(ViewGroup.MarginLayoutParams) editFrame.getLayoutParams();
params.setMarginStart(0);
editFrame.setLayoutParams(params);
}
return view;
}