Fix city search UI

This commit is contained in:
Alexey Kulish 2016-11-07 17:23:57 +03:00
parent e35edc2b90
commit 9bbe2ed141
5 changed files with 155 additions and 72 deletions

View file

@ -25,43 +25,7 @@
app:contentInsetLeft="54dp"
app:contentInsetStart="54dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:focusableInTouchMode="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<EditText
android:id="@+id/searchEditText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:gravity="center_vertical"
android:hint="@string/search_poi_category_hint"
android:lines="1"
android:singleLine="true"
android:textColor="?attr/searchbar_text"
android:textColorHint="?attr/searchbar_text_hint"/>
<ProgressBar
android:id="@+id/searchProgressBar"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginRight="8dp"
android:indeterminate="true"
android:visibility="gone"/>
<ImageButton
android:id="@+id/clearButton"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/shared_string_close"
android:src="@drawable/ic_action_remove_dark"/>
</LinearLayout>
<include layout="@layout/search_text_layout"/>
</android.support.v7.widget.Toolbar>

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="56dp"
android:focusableInTouchMode="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<EditText
android:id="@+id/searchEditText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:gravity="center_vertical"
android:hint="@string/search_poi_category_hint"
android:lines="1"
android:singleLine="true"
android:textColor="?attr/searchbar_text"
android:textColorHint="?attr/searchbar_text_hint"/>
<ProgressBar
android:id="@+id/searchProgressBar"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginRight="8dp"
android:indeterminate="true"
android:visibility="gone"/>
<ImageButton
android:id="@+id/clearButton"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/shared_string_close"
android:src="@drawable/ic_action_remove_dark"/>
</LinearLayout>

View file

@ -10,6 +10,7 @@
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="search_map_hint">Search city or region</string>
<string name="route_roundabout_short">Take %1$d exit and go</string>
<string name="upload_poi">Upload POI</string>
<string name="route_calculation">Route calculation</string>

View file

@ -49,6 +49,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
private DownloadResourceGroup group;
private DownloadActivity activity;
private Toolbar toolbar;
private View searchView;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -101,6 +102,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
}
listView = (ExpandableListView) view.findViewById(android.R.id.list);
addSearchRow();
listView.setOnChildClickListener(this);
listAdapter = new DownloadResourceGroupAdapter(activity);
listView.setAdapter(listAdapter);
@ -108,6 +110,37 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
return view;
}
private void addSearchRow() {
if (!openAsDialog() ) {
searchView = activity.getLayoutInflater().inflate(R.layout.simple_list_menu_item, null);
searchView.setBackgroundResource(android.R.drawable.list_selector_background);
TextView title = (TextView) searchView.findViewById(R.id.title);
title.setCompoundDrawablesWithIntrinsicBounds(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_search_dark), null, null, null);
title.setHint(R.string.search_map_hint);
searchView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getDownloadActivity().showDialog(getActivity(), SearchDialogFragment.createInstance(""));
}
});
listView.addHeaderView(searchView);
listView.setHeaderDividersEnabled(false);
IndexItem worldBaseMapItem = activity.getDownloadThread().getIndexes().getWorldBaseMapItem();
if (worldBaseMapItem == null || !worldBaseMapItem.isDownloaded()) {
title.setVisibility(View.GONE);
}
}
}
private void updateSearchView() {
if (searchView != null && searchView.findViewById(R.id.title).getVisibility() == View.GONE) {
IndexItem worldBaseMapItem = activity.getDownloadThread().getIndexes().getWorldBaseMapItem();
if (worldBaseMapItem != null && worldBaseMapItem.isDownloaded()) {
searchView.findViewById(R.id.title).setVisibility(View.VISIBLE);
}
}
}
@Override
public void onResume() {
super.onResume();
@ -133,6 +166,9 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
}
private void reloadData() {
if (!openAsDialog()) {
updateSearchView();
}
DownloadResources indexes = activity.getDownloadThread().getIndexes();
group = indexes.getGroupById(groupId);
if (group != null) {

View file

@ -1,13 +1,14 @@
package net.osmand.plus.download.ui;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
@ -15,13 +16,14 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.ProgressBar;
import net.osmand.Collator;
import net.osmand.CollatorStringMatcher;
@ -67,7 +69,10 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
private SearchListAdapter listAdapter;
private BannerAndDownloadFreeVersion banner;
private String searchText;
private SearchView searchView;
private View searchView;
private EditText searchEditText;
private ProgressBar progressBar;
private ImageButton clearButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -121,42 +126,48 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
TypedValue typedValue = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.toolbar_theme, typedValue, true);
searchView = new SearchView(new ContextThemeWrapper(getActivity(), typedValue.data));
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0);
searchView.setLayoutParams(params);
searchView = inflater.inflate(R.layout.search_text_layout, toolbar, false);
toolbar.addView(searchView);
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
searchEditText = (EditText) view.findViewById(R.id.searchEditText);
searchEditText.setHint(R.string.search_map_hint);
searchEditText.setTextColor(Color.WHITE);
boolean isLight = getMyApplication().getSettings().isLightContent();
searchEditText.setHintTextColor(isLight ?
getMyApplication().getResources().getColor(R.color.inactive_item_orange) : getMyApplication().getResources().getColor(R.color.searchbar_tab_inactive_dark));
progressBar = (ProgressBar) view.findViewById(R.id.searchProgressBar);
clearButton = (ImageButton) view.findViewById(R.id.clearButton);
clearButton.setVisibility(View.GONE);
searchEditText.addTextChangedListener(new TextWatcher() {
@Override
public boolean onClose() {
if (searchView.getQuery().length() == 0) {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
updateSearchText(s.toString());
}
});
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (searchEditText.getText().length() == 0) {
dismiss();
return true;
} else {
searchEditText.setText("");
}
return false;
}
});
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
updateSearchText(newText);
return true;
}
});
searchEditText.requestFocus();
return view;
}
@ -203,9 +214,8 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
@Override
public void onResume() {
super.onResume();
searchView.setIconified(false);
if (!Algorithms.isEmpty(searchText)) {
searchView.setQuery(searchText, true);
searchEditText.setText(searchText);
}
}
@ -248,6 +258,24 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
}
}
private void showProgressBar() {
updateClearButtonVisibility(false);
progressBar.setVisibility(View.VISIBLE);
}
private void hideProgressBar() {
updateClearButtonVisibility(true);
progressBar.setVisibility(View.GONE);
}
private void updateClearButtonVisibility(boolean show) {
if (show) {
clearButton.setVisibility(searchEditText.length() > 0 ? View.VISIBLE : View.GONE);
} else {
clearButton.setVisibility(View.GONE);
}
}
private class SearchListAdapter extends BaseAdapter implements Filterable {
private SearchIndexFilter mFilter;
@ -523,6 +551,14 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
@Override
protected FilterResults performFiltering(CharSequence constraint) {
getMyApplication().runInUIThread(new Runnable() {
@Override
public void run() {
showProgressBar();
}
});
DownloadResources root = ctx.getDownloadThread().getIndexes();
FilterResults results = new FilterResults();
@ -593,6 +629,14 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
results.values = filter;
results.count = filter.size();
}
getMyApplication().runInUIThread(new Runnable() {
@Override
public void run() {
hideProgressBar();
}
});
return results;
}