Merge pull request #910 from Bars107/master

Emoticons fix.
This commit is contained in:
vshcherb 2014-10-08 17:28:10 +02:00
commit 6cdf56dd17
3 changed files with 51 additions and 4 deletions

View file

@ -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
-->
<string name="fav_point_emoticons_message">We changed your favorite point name to %1$s because it is not possible to save string with emoticons to file.</string>
<string name="print_route">Print route</string>
<string name="test_native_render">Test native render</string>
<string name="test_native_render_msg">Starts activity with native render</string>

View file

@ -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,15 @@ 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());
String category = checkEmoticons(p.getCategory());
p.setCategory(category);
if (name.length() != p.getName().length()){
emoticons = true;
}
while (fl){
fl = false;
for (FavouritePoint fp : cachedFavoritePoints){
@ -180,16 +190,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);
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();
}
}
public 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);

View file

@ -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;