From 97f987ebe7fd920f8e05fe1d97e23489b9993b08 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 8 Apr 2015 18:08:58 +0200 Subject: [PATCH] Update poi ui --- .../activities/EditPOIFilterActivity.java | 110 ++++-------------- .../plus/activities/MapActivityLayers.java | 4 +- .../activities/search/SearchPOIActivity.java | 98 +++++++++++++++- .../search/SearchPoiFilterFragment.java | 19 ++- .../net/osmand/plus/poi/PoiFiltersHelper.java | 6 +- .../net/osmand/plus/poi/PoiLegacyFilter.java | 38 ++++++ 6 files changed, 168 insertions(+), 107 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java b/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java index 77113c6168..e414429d5d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java @@ -4,6 +4,25 @@ package net.osmand.plus.activities; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import net.osmand.data.LatLon; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.activities.search.SearchActivity; +import net.osmand.plus.activities.search.SearchPOIActivity; +import net.osmand.plus.poi.PoiFiltersHelper; +import net.osmand.plus.poi.PoiLegacyFilter; +import net.osmand.util.Algorithms; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; @@ -19,35 +38,9 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.LinearLayout.LayoutParams; import android.widget.ListView; import android.widget.ScrollView; import android.widget.TextView; -import android.widget.Toast; - -import net.osmand.access.AccessibleToast; -import net.osmand.data.LatLon; -import net.osmand.osm.PoiCategory; -import net.osmand.osm.PoiType; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.R; -import net.osmand.plus.activities.search.SearchActivity; -import net.osmand.plus.activities.search.SearchPOIActivity; -import net.osmand.plus.poi.PoiFiltersHelper; -import net.osmand.plus.poi.PoiLegacyFilter; -import net.osmand.util.Algorithms; - -import java.text.Collator; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; /** * @@ -59,8 +52,6 @@ public class EditPOIFilterActivity extends OsmandListActivity { public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; //$NON-NLS-1$ public static final String SEARCH_LON = SearchActivity.SEARCH_LON; //$NON-NLS-1$ private static final int FILTER = 2; - private static final int DELETE_FILTER = 3; - private static final int SAVE_FILTER = 4; @Override @@ -90,33 +81,20 @@ public class EditPOIFilterActivity extends OsmandListActivity { if (item.getItemId() == FILTER) { filterPOI(); return true; - } else if (item.getItemId() == DELETE_FILTER) { - removePoiFilter(); - return true; - } else if (item.getItemId() == SAVE_FILTER) { - savePoiFilter(); - return true; } return super.onOptionsItemSelected(item); } + @Override public boolean onCreateOptionsMenu(Menu menu) { if(filter == null) { return super.onCreateOptionsMenu(menu); } - createMenuItem(menu, SAVE_FILTER, R.string.edit_filter_save_as_menu_item, - R.drawable.ic_action_gsave_dark , - MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); createMenuItem(menu, FILTER, R.string.filter_current_poiButton, - 0, + R.drawable.ic_action_done, //R.drawable.a_1_navigation_accept_light, R.drawable.a_1_navigation_accept_dark, MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT | MenuItemCompat.SHOW_AS_ACTION_ALWAYS); - if(!filter.isStandardFilter()){ - createMenuItem(menu, DELETE_FILTER, R.string.shared_string_delete, - R.drawable.ic_action_delete_dark, - MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); - } return super.onCreateOptionsMenu(menu); } @@ -156,55 +134,9 @@ public class EditPOIFilterActivity extends OsmandListActivity { } } - public void savePoiFilter() { - Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.edit_filter_save_as_menu_item); - final EditText editText = new EditText(this); - LinearLayout ll = new LinearLayout(this); - ll.setPadding(5, 3, 5, 0); - ll.addView(editText, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); - builder.setView(ll); - builder.setNegativeButton(R.string.shared_string_cancel, null); - builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - PoiLegacyFilter nFilter = new PoiLegacyFilter(editText.getText().toString(), - null, - filter.getAcceptedTypes(), (OsmandApplication) getApplication()); - if (helper.createPoiFilter(nFilter)) { - AccessibleToast.makeText( - EditPOIFilterActivity.this, - MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_create_message).toString(), - editText.getText().toString()), Toast.LENGTH_SHORT).show(); - } - EditPOIFilterActivity.this.finish(); - } - }); - builder.create().show(); - - } - private void removePoiFilter() { - Builder builder = new AlertDialog.Builder(this); - builder.setMessage(R.string.edit_filter_delete_dialog_title); - builder.setNegativeButton(R.string.shared_string_no, null); - builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (helper.removePoiFilter(filter)) { - AccessibleToast.makeText( - EditPOIFilterActivity.this, - MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_delete_message).toString(), - filter.getName()), Toast.LENGTH_SHORT).show(); - EditPOIFilterActivity.this.finish(); - } - - } - }); - builder.create().show(); - } private void showDialog(final PoiCategory poiCategory) { ListView lv = EditPOIFilterActivity.this.getListView(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index 542ab531a3..5351bed783 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -281,8 +281,8 @@ public class MapActivityLayers { } else { getApplication().getSettings().setPoiFilterForMap(filterId); pf = poiFilters.getFilterById(filterId); - if (pf != null && pf.isStandardFilter()) { - pf.setFilterByName(null); + if (pf != null) { + pf.setFilterByName(pf.getSavedFilterByName()); } poiMapLayer.setFilter(pf); mapView.refreshMap(); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 31360ce141..9a1bbcda99 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -5,6 +5,7 @@ package net.osmand.plus.activities.search; import gnu.trove.set.hash.TLongHashSet; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -40,6 +41,7 @@ import net.osmand.util.OpeningHoursParser; import net.osmand.util.OpeningHoursParser.OpeningHours; import android.app.AlertDialog; import android.app.AlertDialog.Builder; +import android.content.Context; import android.content.DialogInterface; import android.graphics.drawable.Drawable; import android.os.AsyncTask; @@ -60,11 +62,14 @@ import android.view.MenuItem.OnMenuItemClickListener; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Filter; import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.Toast; @@ -81,6 +86,11 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa private static final int SEARCH_MORE = 0; private static final int SHOW_ON_MAP = 1; private static final int FILTER = 2; + + private static final int EDIT_FILTER = 4; + private static final int DELETE_FILTER = 5; + private static final int SAVE_FILTER = 6; + private PoiLegacyFilter filter; private AmenityAdapter amenityAdapter; @@ -98,8 +108,8 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa private MenuItem searchPOILevel; @Override - public boolean onCreateOptionsMenu(Menu menu) { - menu = getClearToolbar(true).getMenu(); + public boolean onCreateOptionsMenu(Menu omenu) { + Menu menu = getClearToolbar(true).getMenu(); searchPOILevel = menu.add(0, SEARCH_MORE, 0, R.string.search_POI_level_btn); MenuItemCompat.setShowAsAction(searchPOILevel, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); searchPOILevel.setOnMenuItemClickListener(new OnMenuItemClickListener() { @@ -119,6 +129,8 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa if (searchFilterLayout.getVisibility() == View.GONE) { searchFilterLayout.setVisibility(View.VISIBLE); searchFilter.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(searchFilter, InputMethodManager.SHOW_IMPLICIT); } else { if(filter != null) { searchFilter.setText(filter.getSavedFilterByName() == null ? "" : @@ -148,6 +160,14 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa } }); + if (filter != null && !isNameSearch()) { + createMenuItem(omenu, SAVE_FILTER, R.string.edit_filter_save_as_menu_item, R.drawable.ic_action_gsave_dark, + MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); + if (!filter.isStandardFilter()) { + createMenuItem(omenu, DELETE_FILTER, R.string.shared_string_delete, R.drawable.ic_action_delete_dark, + MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); + } + } updateButtonState(); return true; } @@ -272,7 +292,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa private void changeFilter(CharSequence s) { // if (!isNameSearch() ) { amenityAdapter.getFilter().filter(s); - String cfilter = filter.getFilterByName() == null ? "" : + String cfilter = filter == null || filter.getFilterByName() == null ? "" : filter.getFilterByName().toLowerCase(); if(!isNameSearch() && !s.toString().toLowerCase().startsWith(cfilter)) { filter.setFilterByName(s.toString()); @@ -286,13 +306,17 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa showFilterItem.setVisible(filter != null && !isNameSearch()); } if (filter != null) { - String name = filter.getName(); + int maxLength = 30; + String name = filter.getGeneratedName(maxLength); + if(name.length() >= maxLength) { + name = name.substring(0, maxLength) + getString(R.string.shared_string_ellipsis); + } if(filter instanceof NominatimPoiFilter && !((NominatimPoiFilter) filter).isPlacesQuery()) { // nothing to add } else { name += " " + filter.getSearchArea(); } - getSupportActionBar().setSubtitle(name); + getSupportActionBar().setTitle(name); } if (searchPOILevel != null) { int title = location == null ? R.string.search_poi_location : R.string.search_POI_level_btn; @@ -732,5 +756,69 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa }); b.show(); } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == DELETE_FILTER) { + removePoiFilter(); + return true; + } else if (item.getItemId() == SAVE_FILTER) { + savePoiFilter(); + return true; + } + return super.onOptionsItemSelected(item); + } + + private void removePoiFilter() { + Builder builder = new AlertDialog.Builder(this); + builder.setMessage(R.string.edit_filter_delete_dialog_title); + builder.setNegativeButton(R.string.shared_string_no, null); + builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + if (app.getPoiFilters().removePoiFilter(filter)) { + AccessibleToast.makeText( + SearchPOIActivity.this, + MessageFormat.format(SearchPOIActivity.this.getText(R.string.edit_filter_delete_message).toString(), + filter.getName()), Toast.LENGTH_SHORT).show(); + SearchPOIActivity.this.finish(); + } + + } + }); + builder.create().show(); + } + + public void savePoiFilter() { + Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.edit_filter_save_as_menu_item); + final EditText editText = new EditText(this); + LinearLayout ll = new LinearLayout(this); + ll.setPadding(5, 3, 5, 0); + ll.addView(editText, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); + builder.setView(ll); + builder.setNegativeButton(R.string.shared_string_cancel, null); + builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + PoiLegacyFilter nFilter = new PoiLegacyFilter(editText.getText().toString(), + null, + filter.getAcceptedTypes(), (OsmandApplication) getApplication()); + if(searchFilter.getText().toString().length() > 0) { + nFilter.setFilterByName(searchFilter.getText().toString()); + } + if (app.getPoiFilters().createPoiFilter(nFilter)) { + AccessibleToast.makeText( + SearchPOIActivity.this, + MessageFormat.format(SearchPOIActivity.this.getText(R.string.edit_filter_create_message).toString(), + editText.getText().toString()), Toast.LENGTH_SHORT).show(); + } + SearchPOIActivity.this.finish(); + } + }); + builder.create().show(); + + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java index 2cca7a154d..884fea4d40 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java @@ -108,6 +108,12 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv setListAdapter(poiFitlersAdapter); setHasOptionsMenu(true); } + + @Override + public void onResume() { + super.onResume(); + poiFitlersAdapter.setResult(getFilters(searchEditText == null ? "" : searchEditText.getText().toString())); + } public List getFilters(String s) { List filters = new ArrayList() ; @@ -162,16 +168,9 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv // folder selected newIntent.putExtra(EditPOIFilterActivity.AMENITY_FILTER, poi.getFilterId()); updateIntentToLaunch(newIntent); - startActivityForResult(newIntent, REQUEST_POI_EDIT); + startActivity(newIntent); } - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - if(requestCode == REQUEST_POI_EDIT) { - poiFitlersAdapter.setResult(getFilters(searchEditText == null ? "" : searchEditText.getText().toString())); - } - } - @Override public void onListItemClick(ListView listView, View v, int position, long id) { final Object item = ((PoiFiltersAdapter) getListAdapter()).getItem(position); @@ -185,8 +184,8 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv if (PoiLegacyFilter.BY_NAME_FILTER_ID.equals(model.getFilterId()) || model instanceof NominatimPoiFilter) { model.setFilterByName(searchEditText.getText().toString()); - } else if(model.isStandardFilter()) { - model.setFilterByName(null); + } else { + model.setFilterByName(model.getSavedFilterByName()); } showFilterActivity(model.getFilterId()); } else { diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index b0d9c6fd19..8b6d2de56d 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -10,11 +10,13 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import net.osmand.access.AccessibilityPlugin; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; @@ -172,7 +174,9 @@ public class PoiFiltersHelper { sortListOfFilters(cacheTopStandardFilters); } List result = new ArrayList(); - result.add(getShowAllPOIFilter()); + if(OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) != null) { + result.add(getShowAllPOIFilter()); + } result.addAll(cacheTopStandardFilters); return result; } diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java index 9a463e9f6d..0084f1e263 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java @@ -20,6 +20,7 @@ import net.osmand.data.LatLon; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -272,6 +273,43 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { return name; } + public String getGeneratedName(int chars) { + if (areAllTypesAccepted() || acceptedTypes.isEmpty()) { + return getName(); + } + StringBuilder res = new StringBuilder(); + for (PoiCategory p : acceptedTypes.keySet()) { + LinkedHashSet set = acceptedTypes.get(p); + if (set == null) { + if (res.length() > 0) { + res.append(", "); + } + res.append(p.getTranslation()); + } + if (res.length() > chars) { + return res.toString(); + } + } + for (PoiCategory p : acceptedTypes.keySet()) { + LinkedHashSet set = acceptedTypes.get(p); + if (set != null) { + for (String st : set) { + if (res.length() > 0) { + res.append(", "); + } + PoiType pt = poiTypes.getPoiTypeByKey(st); + if (pt != null) { + res.append(pt.getTranslation()); + if (res.length() > chars) { + return res.toString(); + } + } + } + } + } + return res.toString(); + } + /** * @param type * @return null if all subtypes are accepted/ empty list if type is not accepted at all