Show divider between suggestion and search edit text

This commit is contained in:
seven332 committed 2016-01-28 15:34:23 +08:00
1 parent 97f3d0ae30
commit 7dcdf783ea
4 files changed
+55 -3

No files matched your search

@@ -78,6 +78,8 @@ public class SearchBar extends CardView implements View.OnClickListener,
private SimpleImageView mActionButton;
private SearchEditText mEditText;
private ListView mList;
private View mListHeader;
private boolean mHeaderAttached = false;
private ViewTransition mViewTransition;
@@ -108,12 +110,14 @@ public class SearchBar extends CardView implements View.OnClickListener,
private void init(Context context) {
mSearchDatabase = SearchDatabase.getInstance(getContext());
LayoutInflater.from(context).inflate(R.layout.widget_search_bar, this);
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(R.layout.widget_search_bar, this);
mMenuButton = (SimpleImageView) findViewById(R.id.search_menu);
mTitleTextView = (TextView) findViewById(R.id.search_title);
mActionButton = (SimpleImageView) findViewById(R.id.search_action);
mEditText = (SearchEditText) findViewById(R.id.search_edit_text);
mList = (ListView) findViewById(R.id.search_bar_list);
mListHeader = inflater.inflate(R.layout.header_suggestion_list, mList, false);
mViewTransition = new ViewTransition(mTitleTextView, mEditText);
@@ -136,18 +140,38 @@ public class SearchBar extends CardView implements View.OnClickListener,
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String suggestion = mSuggestionList.get(position);
String suggestion = mSuggestionList.get(MathUtils.clamp(
position - mList.getHeaderViewsCount(), 0, mSuggestionList.size() - 1));
mEditText.setText(suggestion);
mEditText.setSelection(suggestion.length());
}
});
}
private void addListHeader() {
if (!mHeaderAttached) {
mHeaderAttached = true;
mList.addHeaderView(mListHeader, null, false);
}
}
private void removeListHeader() {
if (mHeaderAttached) {
mHeaderAttached = false;
mList.removeHeaderView(mListHeader);
}
}
private void updateSuggestions() {
String prefix = mEditText.getText().toString();
String[] suggestions = mSearchDatabase.getSuggestions(prefix);
mSuggestionList.clear();
Collections.addAll(mSuggestionList, suggestions);
if (mSuggestionList.size() == 0) {
removeListHeader();
} else {
addListHeader();
}
mSuggestionAdapter.notifyDataSetChanged();
}
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2016 Hippo Seven
~
~ 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.
-->
<View
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider"/>
@@ -72,7 +72,10 @@
android:id="@+id/search_bar_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
android:visibility="gone"
android:divider="@color/divider"
android:dividerHeight="1dp"
android:headerDividersEnabled="false"/>
</LinearLayout>
+3
View File
@@ -85,4 +85,7 @@
<color name="misc">#fff06292</color>
<color name="unknown_bg">@android:color/black</color>
<!-- divider -->
<color name="divider">#20000000</color>
</resources>