From 7c3c4c13f932281d48b15c70d7c1706cdf7f5378 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Thu, 14 Jul 2016 00:02:56 +0300 Subject: [PATCH] [Quick search] UI fixes --- OsmAnd/res/layout/search_list_item.xml | 3 +- .../search/QuickSearchDialogFragment.java | 26 ++-------- .../osmand/plus/search/SearchListAdapter.java | 12 ++++- .../osmand/plus/search/SearchListItem.java | 49 ++++++++++++++----- 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/OsmAnd/res/layout/search_list_item.xml b/OsmAnd/res/layout/search_list_item.xml index 9ee483bb0c..304bf98861 100644 --- a/OsmAnd/res/layout/search_list_item.xml +++ b/OsmAnd/res/layout/search_list_item.xml @@ -15,7 +15,7 @@ android:layout_width="24dp" android:layout_height="24dp" android:layout_marginRight="8dp" - android:layout_gravity="top" + android:layout_gravity="center_vertical" android:scaleType="centerInside" android:visibility="visible"/> @@ -23,6 +23,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:layout_marginLeft="8dp" android:orientation="vertical"> files = new ArrayList<>(); - File file = new File(Environment.getExternalStorageDirectory() + "/osmand"); - if (file.exists() && file.listFiles() != null) { - for (File obf : file.listFiles()) { - if (!obf.isDirectory() && obf.getName().endsWith(".obf")) { - try { - BinaryMapIndexReader bmir = new BinaryMapIndexReader(new RandomAccessFile(obf, "r"), obf); - files.add(bmir); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - } - } - - searchUICore = new SearchUICore(app.getPoiTypes(), locale, files.toArray(new BinaryMapIndexReader[files.size()])); - */ - Collection regionAddressRepositories = app.getResourceManager().getAddressRepositories(); BinaryMapIndexReader[] binaryMapIndexReaderArray = new BinaryMapIndexReader[regionAddressRepositories.size()]; int i = 0; @@ -381,10 +364,7 @@ public class QuickSearchDialogFragment extends DialogFragment { bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery); QuickSearchDialogFragment fragment = new QuickSearchDialogFragment(); fragment.setArguments(bundle); - mapActivity.getSupportFragmentManager().beginTransaction() - //.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_left) - .add(R.id.fragmentContainer, fragment, TAG) - .addToBackStack(TAG).commitAllowingStateLoss(); + fragment.show(mapActivity.getSupportFragmentManager(), TAG); } private MapActivity getMapActivity() { diff --git a/OsmAnd/src/net/osmand/plus/search/SearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/SearchListAdapter.java index c9fa79e10c..320938d7ac 100644 --- a/OsmAnd/src/net/osmand/plus/search/SearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/SearchListAdapter.java @@ -12,6 +12,7 @@ import android.widget.TextView; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.util.Algorithms; import java.util.List; @@ -81,8 +82,15 @@ public class SearchListAdapter extends ArrayAdapter { TextView distance = (TextView) view.findViewById(R.id.distance); imageView.setImageDrawable(listItem.getIcon()); - title.setText(listItem.getName()); - subtitle.setText(listItem.getTypeName()); + String name = listItem.getName(); + title.setText(name); + String desc = listItem.getTypeName(); + if (!Algorithms.isEmpty(desc) && !desc.equals(name)) { + subtitle.setText(desc); + subtitle.setVisibility(View.VISIBLE); + } else { + subtitle.setVisibility(View.GONE); + } float dist = (float) listItem.getDistance(); if (dist == 0) { distance.setText(""); diff --git a/OsmAnd/src/net/osmand/plus/search/SearchListItem.java b/OsmAnd/src/net/osmand/plus/search/SearchListItem.java index 16d229ec5d..80d336fab8 100644 --- a/OsmAnd/src/net/osmand/plus/search/SearchListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/SearchListItem.java @@ -11,6 +11,8 @@ import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.render.RenderingIcons; import net.osmand.search.core.SearchResult; import net.osmand.util.Algorithms; @@ -59,17 +61,17 @@ public class SearchListItem { return streetCity.getName() + " - " + Algorithms.capitalizeFirstLetterAndLowercase(streetCity.getType().name()); } case HOUSE: - return "House"; + return ""; case STREET_INTERSECTION: - return "Street intersection"; + return ""; case POI_TYPE: AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object; String res; if (abstractPoiType instanceof PoiCategory) { - res = "POI category"; + res = ""; } else if (abstractPoiType instanceof PoiFilter) { PoiFilter poiFilter = (PoiFilter) abstractPoiType; - res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : "POI filter"; + res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : ""; } else if (abstractPoiType instanceof PoiType) { PoiType poiType = (PoiType) abstractPoiType; @@ -78,15 +80,23 @@ public class SearchListItem { res = poiType.getCategory() != null ? poiType.getCategory().getTranslation() : null; } if (res == null) { - res = "POI type"; + res = ""; } } else { - res = "POI type"; + res = ""; } return res; case POI: Amenity amenity = (Amenity) searchResult.object; - return amenity.getType().toString(); + PoiCategory pc = amenity.getType(); + PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); + String typeStr = amenity.getSubType(); + if (pt != null) { + typeStr = pt.getTranslation(); + } else if (typeStr != null) { + typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' ')); + } + return typeStr; case LOCATION: break; case FAVORITE: @@ -118,15 +128,32 @@ public class SearchListItem { case STREET_INTERSECTION: break; case POI_TYPE: - break; + AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object; + if (RenderingIcons.containsBigIcon(abstractPoiType.getIconKeyName())) { + int iconId = RenderingIcons.getBigIconResourceId(abstractPoiType.getIconKeyName()); + return app.getIconsCache().getIcon(iconId, + app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark); + } else { + return null; + } case POI: Amenity amenity = (Amenity) searchResult.object; - Drawable drawable = null; + String id = null; PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType()); if (st != null) { - //drawable = app.getIconsCache().getMapIcon(st.getOsmTag() + "_" + st.getOsmValue()); + if (RenderingIcons.containsBigIcon(st.getIconKeyName())) { + id = st.getIconKeyName(); + } else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) { + id = st.getOsmTag() + "_" + st.getOsmValue(); + } + } + if (id != null) { + int iconId = RenderingIcons.getBigIconResourceId(id); + return app.getIconsCache().getIcon(iconId, + app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark); + } else { + return null; } - return drawable; case LOCATION: break; case FAVORITE: