From bee67b7054a31cdca8360a454286339a0ecd5425 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Wed, 19 Oct 2016 22:13:24 +0300 Subject: [PATCH] Added search for categories. Fixed search duplicates --- .../src/net/osmand/search/SearchUICore.java | 2 - .../osmand/search/core/SearchCoreFactory.java | 7 +++ OsmAnd/res/layout/xmas_dialog.xml | 30 ++++++++++++ OsmAnd/res/layout/xmas_dialog_title.xml | 20 ++++++++ OsmAnd/res/values/colors.xml | 2 + OsmAnd/res/values/strings.xml | 7 ++- OsmAnd/res/values/styles.xml | 4 ++ .../osmand/plus/activities/MapActivity.java | 46 +++++++++++++++++++ 8 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 OsmAnd/res/layout/xmas_dialog.xml create mode 100644 OsmAnd/res/layout/xmas_dialog_title.xml diff --git a/OsmAnd-java/src/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/net/osmand/search/SearchUICore.java index 74f1918ffd..0047517a6a 100644 --- a/OsmAnd-java/src/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/net/osmand/search/SearchUICore.java @@ -108,7 +108,6 @@ public class SearchUICore { searchResults.add(addedResult); } j++; - i = searchResults.size(); continue; } SearchResult existingResult = searchResults.get(i); @@ -119,7 +118,6 @@ public class SearchUICore { int compare = cmp.compare(existingResult, addedResult); if(compare == 0) { // existingResult == addedResult - this.searchResults.add(addedResults.get(j)); j++; } else if(compare > 0) { // existingResult > addedResult diff --git a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java index fe82c4a22d..bb4112aadf 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java @@ -488,6 +488,7 @@ public class SearchCoreFactory { private Map translatedNames = new LinkedHashMap<>(); private List topVisibleFilters; + private List categories; private List customPoiFilters = new ArrayList<>(); private TIntArrayList customPoiFiltersPriorites = new TIntArrayList(); private MapPoiTypes types; @@ -511,6 +512,7 @@ public class SearchCoreFactory { if(translatedNames.isEmpty()) { translatedNames = types.getAllTranslatedNames(false); topVisibleFilters = types.getTopVisibleFilters(); + categories = types.getCategories(false); } // results.clear(); TreeMap results = new TreeMap() ; @@ -521,6 +523,11 @@ public class SearchCoreFactory { } } if (phrase.isUnknownSearchWordPresent()) { + for (PoiCategory c : categories) { + if (!phrase.isUnknownSearchWordPresent() || nm.matches(c.getTranslation())) { + results.put(c.getTranslation(), c); + } + } Iterator> it = translatedNames.entrySet().iterator(); while (it.hasNext()) { Entry e = it.next(); diff --git a/OsmAnd/res/layout/xmas_dialog.xml b/OsmAnd/res/layout/xmas_dialog.xml new file mode 100644 index 0000000000..4e8d4b0859 --- /dev/null +++ b/OsmAnd/res/layout/xmas_dialog.xml @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/xmas_dialog_title.xml b/OsmAnd/res/layout/xmas_dialog_title.xml new file mode 100644 index 0000000000..065872d7b6 --- /dev/null +++ b/OsmAnd/res/layout/xmas_dialog_title.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index 092c5a1135..975b617fdd 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -1,6 +1,8 @@ + #3f51b5 + #a0a0a0 #357ef2 diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 4fbb9c1193..2a490816a2 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,4 +1,4 @@ - + + Christmas POI + Anticipating Christmas and New Year holidays, you can choose to display the POI associated with Christmas: the Christmas tree, markets. + Show Christmas POI? Light brown Dark brown Color scheme of contours @@ -19,7 +22,7 @@ Edit filter Subcategories Selected categories - Create custom POI + Create custom filter Custom search Filters Apply filters diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index d3c386737a..ff9ab7b647 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -411,4 +411,8 @@ @dimen/default_desc_text_size + + diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 385469c5f2..7d37a843fa 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -12,6 +12,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.content.res.ColorStateList; import android.media.AudioManager; import android.net.Uri; import android.os.AsyncTask; @@ -25,19 +26,24 @@ import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; +import android.support.v4.view.ViewCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.SwitchCompat; import android.util.DisplayMetrics; import android.view.Gravity; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewStub; import android.view.Window; import android.view.WindowManager; +import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; + import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.StateChangedListener; @@ -635,6 +641,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven getSupportFragmentManager().beginTransaction() .add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(), FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss(); + } else { + //showXMasDialog(); } FirstUsageWelcomeFragment.SHOW = false; } @@ -1501,6 +1509,44 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven mapInfoLayer.removeTopToolbarController(controller); } + private void showXMasDialog() { + final AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.XmasDialogTheme); + View titleView = getLayoutInflater().inflate(R.layout.xmas_dialog_title, null); + builder.setCustomTitle(titleView); + builder.setCancelable(true); + builder.setNegativeButton(getString(R.string.shared_string_cancel), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + builder.setPositiveButton(getString(R.string.shared_string_show), new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + //showQuickSearch(); + } + }); + + builder.setView(getLayoutInflater().inflate(R.layout.xmas_dialog, null)); + + AlertDialog dialog = builder.create(); + dialog.setOnShowListener(new DialogInterface.OnShowListener() { + @Override + public void onShow(DialogInterface dialog) { + // Customize POSITIVE, NEGATIVE and NEUTRAL buttons. + Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE); + positiveButton.setTextColor(getResources().getColor(R.color.color_white)); + positiveButton.invalidate(); + + Button negativeButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE); + negativeButton.setTextColor(getResources().getColor(R.color.color_white)); + negativeButton.invalidate(); + } + }); + dialog.show(); + } + public enum ShowQuickSearchMode { NEW, NEW_IF_EXPIRED,