From 0380aafccd754b028bc3698bdc0cddb581504a5b Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 8 Oct 2014 17:37:17 +0300 Subject: [PATCH 1/2] Fixed issue with emoticons names in favorites names --- OsmAnd/res/values/strings.xml | 1 + .../net/osmand/plus/FavouritesDbHelper.java | 51 +++++++++++++++++-- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 1 + 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 2e9887054b..f1ac4b49c9 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + We changed your favorite point name to %1$s because it is not possible to save string with emoticons to file. Print route Test native render Starts activity with native render diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 3a07436805..84bc074d91 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -1,6 +1,8 @@ package net.osmand.plus; import java.io.File; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Array; import java.text.Collator; import java.util.ArrayList; import java.util.Collections; @@ -9,6 +11,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import android.app.AlertDialog; import android.content.ActivityNotFoundException; @@ -165,9 +169,13 @@ public class FavouritesDbHelper { private void checkDublicates(FavouritePoint p){ boolean fl = true; + boolean emoticons = false; String index = ""; int number = 0; - String name = p.getName(); + String name = checkEmoticons(p.getName()); + if (name.length() != p.getName().length()){ + emoticons = true; + } while (fl){ fl = false; for (FavouritePoint fp : cachedFavoritePoints){ @@ -180,16 +188,51 @@ public class FavouritesDbHelper { } } } - if (index.length() > 0){ - p.setName(name); + if (index.length() > 0 || emoticons){ AlertDialog.Builder builder = new AlertDialog.Builder(context.getMapActivity()); builder.setTitle(R.string.fav_point_dublicate); - builder.setMessage(context.getString(R.string.fav_point_dublicate_message, name)); + if (emoticons){ + builder.setMessage(context.getString(R.string.fav_point_emoticons_message, name)); + } else { + builder.setMessage(context.getString(R.string.fav_point_dublicate_message, name)); + } builder.setPositiveButton(R.string.default_buttons_ok, null); + p.setName(name); builder.show(); } } + private String checkEmoticons(String name){ + char[] chars = name.toCharArray(); + int index; + char ch1; + char ch2; + + index = 0; + StringBuilder builder = new StringBuilder(); + while (index < chars.length) { + ch1 = chars[index]; + if ((int)ch1 == 0xD83C) { + ch2 = chars[index+1]; + if ((int)ch2 >= 0xDF00 && (int)ch2 <= 0xDFFF) { + index += 2; + continue; + } + } + else if ((int)ch1 == 0xD83D) { + ch2 = chars[index+1]; + if ((int)ch2 >= 0xDC00 && (int)ch2 <= 0xDDFF) { + index += 2; + continue; + } + } + builder.append(ch1); + ++index; + } + + return builder.toString(); + } + public boolean editFavouriteName(FavouritePoint p, String newName, String category) { String oldCategory = p.getCategory(); p.setName(newName); diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index 70eb6d8f5e..565a763192 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -12,6 +12,7 @@ import java.io.OutputStreamWriter; import java.io.Reader; import java.io.StringWriter; import java.io.Writer; +import java.net.URLEncoder; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; From fa0a23450bca295d6961abf51dd5168c2f2a8853 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 8 Oct 2014 17:56:53 +0300 Subject: [PATCH 2/2] Added checking for emoticons in favorites category --- OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 84bc074d91..d59e6d4ac0 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -173,6 +173,8 @@ public class FavouritesDbHelper { String index = ""; int number = 0; String name = checkEmoticons(p.getName()); + String category = checkEmoticons(p.getCategory()); + p.setCategory(category); if (name.length() != p.getName().length()){ emoticons = true; } @@ -202,7 +204,7 @@ public class FavouritesDbHelper { } } - private String checkEmoticons(String name){ + public String checkEmoticons(String name){ char[] chars = name.toCharArray(); int index; char ch1;