Update poi search ui

This commit is contained in:
Victor Shcherb 2015-04-07 23:05:52 +02:00
parent 019634049e
commit ca31455f0e
10 changed files with 170 additions and 97 deletions

View file

@ -205,7 +205,7 @@ public class BinaryMapPoiReaderAdapter {
case OsmandOdb.OsmAndCategoryTable.CATEGORY_FIELD_NUMBER : case OsmandOdb.OsmAndCategoryTable.CATEGORY_FIELD_NUMBER :
String cat = codedIS.readString().intern(); String cat = codedIS.readString().intern();
region.categories.add(cat); region.categories.add(cat);
region.categoriesType.add(poiTypes.getPoiCategoryByName(cat)); region.categoriesType.add(poiTypes.getPoiCategoryByName(cat.toLowerCase()));
region.subcategories.add(new ArrayList<String>()); region.subcategories.add(new ArrayList<String>());
break; break;
case OsmandOdb.OsmAndCategoryTable.SUBCATEGORIES_FIELD_NUMBER : case OsmandOdb.OsmAndCategoryTable.SUBCATEGORIES_FIELD_NUMBER :

View file

@ -97,11 +97,6 @@ public class MapPoiTypes {
return otherCategory; return otherCategory;
} }
public PoiCategory getPoiCategoryByName(String name) {
name = name.toLowerCase();
return getPoiCategoryByName(name, false);
}
public PoiType getPoiTypeByKey(String name) { public PoiType getPoiTypeByKey(String name) {
for(PoiCategory pc : categories) { for(PoiCategory pc : categories) {
PoiType pt = pc.getPoiTypeByKeyName(name); PoiType pt = pc.getPoiTypeByKeyName(name);
@ -137,9 +132,16 @@ public class MapPoiTypes {
return translation; return translation;
} }
public PoiCategory getPoiCategoryByName(String name) {
return getPoiCategoryByName(name, false);
}
public PoiCategory getPoiCategoryByName(String name, boolean create) { public PoiCategory getPoiCategoryByName(String name, boolean create) {
if(name.equals("entertainment") && !create) { if(name.equals("leisure") && !create) {
name = "leisure"; name = "entertainment";
}
if(name.equals("historic") && !create) {
name = "tourism";
} }
for(PoiCategory p : categories ) { for(PoiCategory p : categories ) {
if(p.getName().equals(name) || p.getKey().equalsIgnoreCase(name)) { if(p.getName().equals(name) || p.getKey().equalsIgnoreCase(name)) {

View file

@ -3,44 +3,66 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical"> android:orientation="vertical" >
<LinearLayout <LinearLayout
android:id="@+id/SearchFilterLayout" android:id="@+id/SearchFilterLayout"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:orientation="horizontal" android:orientation="horizontal" >
android:visibility="gone">
<TextView <ImageView
android:id="@+id/TextView" android:id="@+id/search_icon"
android:layout_width="wrap_content" android:layout_width="@dimen/standard_icon_size"
android:layout_height="wrap_content" android:layout_height="@dimen/standard_icon_size"
android:textColor="?android:textColorPrimary" android:layout_gravity="center_vertical"
tools:text="@string/lorem_ipsum" android:layout_marginRight="8dp"
android:text="@string/search_poi_filter" /> android:src="@android:drawable/ic_search_category_default" />
<!-- to not gain focus everytime -->
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
<EditText <EditText
android:id="@+id/SearchFilter" android:id="@+id/edit"
android:layout_width="fill_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_gravity="bottom"
android:layout_marginRight="5dp" android:layout_marginRight="@dimen/list_content_padding"
android:text="" /> android:layout_weight="1"
android:hint="@string/shared_string_search"
android:maxLines="1"
android:nextFocusLeft="@id/edit"
android:nextFocusUp="@id/edit"
android:textColor="?android:textColorPrimary"
tools:text="@string/lorem_ipsum" >
</EditText>
<ImageView
android:id="@+id/options"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="center_vertical"
android:background="?attr/dashboard_button"
android:scaleType="center"
android:src="?attr/ic_action_overflow" />
</LinearLayout> </LinearLayout>
<ListView <ListView
android:id="@android:id/list" android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1"/> android:layout_weight="1" />
<net.osmand.plus.activities.search.toolbar.SplitToolbar <net.osmand.plus.activities.search.toolbar.SplitToolbar
android:orientation="horizontal"
android:background="?attr/bottomToolBarColor"
android:id="@+id/bottomControls" android:id="@+id/bottomControls"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"
android:background="?attr/bottomToolBarColor"
android:orientation="horizontal" />
</LinearLayout> </LinearLayout>

View file

@ -7,7 +7,9 @@
android:minHeight="@dimen/list_item_height" android:minHeight="@dimen/list_item_height"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingLeft="@dimen/list_content_padding" android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding" > android:paddingRight="@dimen/list_content_padding"
android:descendantFocusability="blocksDescendants"
>
<ImageView <ImageView
android:id="@+id/poi_icon" android:id="@+id/poi_icon"

View file

@ -6,15 +6,13 @@
android:minHeight="@dimen/list_item_height" android:minHeight="@dimen/list_item_height"
android:orientation="horizontal" android:orientation="horizontal"
android:background="?attr/expandable_list_item_background" android:background="?attr/expandable_list_item_background"
android:paddingLeft="@dimen/list_content_padding" android:paddingLeft="@dimen/list_content_padding">
android:paddingRight="@dimen/list_content_padding">
<ImageView <ImageView
android:id="@+id/folder_icon" android:id="@+id/folder_icon"
android:layout_width="@dimen/standard_icon_size" android:layout_width="@dimen/standard_icon_size"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_height="@dimen/standard_icon_size" android:layout_height="@dimen/standard_icon_size"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"/> android:layout_marginRight="8dp"/>
<TextView <TextView
@ -26,14 +24,16 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:maxLines="1" android:maxLines="1"
tools:text="@string/lorem_ipsum"/> tools:text="@string/lorem_ipsum"
android:layout_marginRight="@dimen/list_content_padding"/>
<ImageView <ImageView
android:id="@+id/folder_edit_icon" android:id="@+id/options"
android:layout_width="@dimen/list_item_height" android:layout_width="@dimen/list_item_height"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_height="@dimen/list_item_height" android:layout_height="@dimen/list_item_height"
android:scaleType="center" android:scaleType="center"
android:visibility="gone"
android:background="?attr/dashboard_button" android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_filter_dark" /> android:src="?attr/ic_action_overflow" />
</LinearLayout> </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 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="agps_info">A-GPS info</string> <string name="agps_info">A-GPS info</string>
<string name="shared_string_search">Search</string>
<string name="shared_string_show_description">Show description</string> <string name="shared_string_show_description">Show description</string>
<string name="shared_string_message">Message</string> <string name="shared_string_message">Message</string>
<string name="agps_data_last_downloaded">A-GPS data last downloaded: %1$s</string> <string name="agps_data_last_downloaded">A-GPS data last downloaded: %1$s</string>

View file

@ -183,18 +183,13 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
updateSelectionMode(actionMode); updateSelectionMode(actionMode);
} else { } else {
final FavouritePoint point = (FavouritePoint) favouritesAdapter.getChild(groupPosition, childPosition); final FavouritePoint point = (FavouritePoint) favouritesAdapter.getChild(groupPosition, childPosition);
ContextMenuAdapter qa = new ContextMenuAdapter(v.getContext());
qa.setAnchor(v);
final OsmandSettings settings = getMyApplication().getSettings(); final OsmandSettings settings = getMyApplication().getSettings();
LatLon location = new LatLon(point.getLatitude(), point.getLongitude()); LatLon location = new LatLon(point.getLatitude(), point.getLongitude());
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v); final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
DirectionsDialogs.createDirectionActionsPopUpMenu(optionsMenu, location, point, DirectionsDialogs.createDirectionActionsPopUpMenu(optionsMenu, location, point,
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), settings.getLastKnownMapZoom(),
getActivity(), true, false); getActivity(), true, false);
boolean light = getMyApplication().getSettings().isLightContent();
MenuItem item = optionsMenu.getMenu().add(R.string.favourites_context_menu_edit) MenuItem item = optionsMenu.getMenu().add(R.string.favourites_context_menu_edit)
.setIcon(iconsCache.getContentIcon(R.drawable.ic_action_edit_dark)); .setIcon(iconsCache.getContentIcon(R.drawable.ic_action_edit_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

View file

@ -25,10 +25,10 @@ import net.osmand.osm.PoiType;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.R.color;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.R.color;
import net.osmand.plus.activities.EditPOIFilterActivity; import net.osmand.plus.activities.EditPOIFilterActivity;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandListActivity; import net.osmand.plus.activities.OsmandListActivity;
@ -121,7 +121,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
menu = getClearToolbar(true).getMenu(); menu = getClearToolbar(true).getMenu();
boolean light = getMyApplication().getSettings().isLightActionBar();
searchPOILevel = menu.add(0, SEARCH_MORE, 0, R.string.search_POI_level_btn); searchPOILevel = menu.add(0, SEARCH_MORE, 0, R.string.search_POI_level_btn);
MenuItemCompat.setShowAsAction(searchPOILevel, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); MenuItemCompat.setShowAsAction(searchPOILevel, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
searchPOILevel.setOnMenuItemClickListener(new OnMenuItemClickListener() { searchPOILevel.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@ -231,7 +230,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
app = (OsmandApplication) getApplication(); app = (OsmandApplication) getApplication();
uiHandler = new Handler(); uiHandler = new Handler();
searchFilter = (EditText) findViewById(R.id.SearchFilter); searchFilter = (EditText) findViewById(R.id.edit);
searchFilterLayout = findViewById(R.id.SearchFilterLayout); searchFilterLayout = findViewById(R.id.SearchFilterLayout);
settings = ((OsmandApplication) getApplication()).getSettings(); settings = ((OsmandApplication) getApplication()).getSettings();
@ -352,8 +351,10 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
app.getLocationProvider().addCompassListener(this); app.getLocationProvider().addCompassListener(this);
app.getLocationProvider().registerOrUnregisterCompassListener(true); app.getLocationProvider().registerOrUnregisterCompassListener(true);
} }
if(searchFilterLayout.getVisibility() == View.VISIBLE) {
searchFilter.requestFocus(); searchFilter.requestFocus();
} }
}
private void updateShowFilterItem() { private void updateShowFilterItem() {
if (showFilterItem != null) { if (showFilterItem != null) {

View file

@ -3,21 +3,8 @@
*/ */
package net.osmand.plus.activities.search; package net.osmand.plus.activities.search;
import android.content.Intent; import java.util.ArrayList;
import android.os.Bundle; import java.util.List;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -32,9 +19,26 @@ import net.osmand.plus.poi.PoiLegacyFilter;
import net.osmand.plus.poi.SearchByNameFilter; import net.osmand.plus.poi.SearchByNameFilter;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
import android.content.Intent;
import java.util.ArrayList; import android.os.AsyncTask;
import java.util.List; import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.ListFragment;
import android.support.v7.widget.PopupMenu;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@ -44,26 +48,47 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
public static final String SEARCH_LON = SearchActivity.SEARCH_LON; public static final String SEARCH_LON = SearchActivity.SEARCH_LON;
public static final int REQUEST_POI_EDIT = 55; public static final int REQUEST_POI_EDIT = 55;
private EditText searchEditText;
private SearchPoiByNameTask currentTask = null;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.searchpoi, container, false);
setupSearchEditText((EditText) v.findViewById(R.id.edit));
setupOptions(v.findViewById(R.id.options));
v.findViewById(R.id.bottomControls).setVisibility(View.GONE);
return v;
}
private void setupOptions(View options) {
options.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showOptionsMenu(v);
}
});
}
private void setupSearchEditText(EditText e) {
searchEditText = e;
searchEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
// ListActivity has a ListView, which you can get with:
ListView lv = getListView();
// Then you can create a listener like so:
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
PoiLegacyFilter poi = ((AmenityAdapter) getListAdapter()).getItem(pos);
if(!poi.isStandardFilter() || poi.getFilterId().equals(PoiLegacyFilter.CUSTOM_FILTER_ID)) {
showEditActivity(poi);
return true;
}
return false;
}
});
setHasOptionsMenu(true); setHasOptionsMenu(true);
refreshPoiListAdapter(); refreshPoiListAdapter();
} }
@ -113,7 +138,7 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
} }
@Override @Override
public void onListItemClick(ListView parent, View v, int position, long id) { public void onListItemClick(ListView listView, View v, int position, long id) {
final PoiLegacyFilter filter = ((AmenityAdapter) getListAdapter()).getItem(position); final PoiLegacyFilter filter = ((AmenityAdapter) getListAdapter()).getItem(position);
if (filter.getFilterId().equals(PoiLegacyFilter.CUSTOM_FILTER_ID)) { if (filter.getFilterId().equals(PoiLegacyFilter.CUSTOM_FILTER_ID)) {
filter.clearFilter(); filter.clearFilter();
@ -127,15 +152,34 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
return; return;
} }
} }
showFilterActivity(filter);
}
private void showFilterActivity(final PoiLegacyFilter filter) {
final Intent newIntent = new Intent(getActivity(), SearchPOIActivity.class); final Intent newIntent = new Intent(getActivity(), SearchPOIActivity.class);
newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId()); newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
updateIntentToLaunch(newIntent); updateIntentToLaunch(newIntent);
startActivityForResult(newIntent, 0); startActivityForResult(newIntent, 0);
} }
class SearchPoiByNameTask extends AsyncTask<Void, PoiLegacyFilter, List<PoiLegacyFilter>> {
@Override
protected List<PoiLegacyFilter> doInBackground(Void... params) {
return null;
}
@Override
protected void onPostExecute(List<PoiLegacyFilter> result) {
super.onPostExecute(result);
}
}
class AmenityAdapter extends ArrayAdapter<PoiLegacyFilter> { class AmenityAdapter extends ArrayAdapter<PoiLegacyFilter> {
AmenityAdapter(List<PoiLegacyFilter> list) { AmenityAdapter(List<PoiLegacyFilter> list) {
super(getActivity(), R.layout.searchpoifolder_list, list); super(getActivity(), R.layout.searchpoifolder_list, list);
} }
@ -164,23 +208,29 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
icon.setImageResource(R.drawable.mx_user_defined); icon.setImageResource(R.drawable.mx_user_defined);
} }
} }
ImageView editIcon = (ImageView) row.findViewById(R.id.folder_edit_icon);
editIcon.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_edit_dark));
if (model.isStandardFilter()) {
editIcon.setVisibility(View.GONE);
} else {
editIcon.setVisibility(View.VISIBLE);
}
editIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showEditActivity(model);
}
});
return (row); return (row);
} }
}
private void showOptionsMenu(View v) {
// Show menu with search all, name finder, name finder poi
IconsCache iconsCache = getMyApplication().getIconsCache();
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
MenuItem item = optionsMenu.getMenu().add(R.string.poi_filter_custom_filter)
.setIcon(iconsCache.getContentIcon(R.drawable.ic_action_filter_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
PoiLegacyFilter filter = getApp().getPoiFilters().getFilterById(PoiLegacyFilter.CUSTOM_FILTER_ID);
if(filter != null) {
filter.clearFilter();
showEditActivity(filter);
}
return true;
}
});
optionsMenu.show();
} }

View file

@ -318,7 +318,7 @@ public class PoiFiltersHelper {
map.put(filterId, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>()); map.put(filterId, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>());
} }
Map<PoiCategory, LinkedHashSet<String>> m = map.get(filterId); Map<PoiCategory, LinkedHashSet<String>> m = map.get(filterId);
PoiCategory a = mapPoiTypes.getPoiCategoryByName(query.getString(1)); PoiCategory a = mapPoiTypes.getPoiCategoryByName(query.getString(1).toLowerCase(), false);
String subCategory = query.getString(2); String subCategory = query.getString(2);
if(subCategory == null){ if(subCategory == null){
m.put(a, null); m.put(a, null);