Merge branch 'r1.9' of ssh://github.com/osmandapp/Osmand into r1.9

This commit is contained in:
Victor Shcherb 2015-01-15 02:46:11 +01:00
commit 741099b6ed
14 changed files with 165 additions and 98 deletions

View file

@ -247,4 +247,8 @@ public class TurnType {
public static boolean isRightTurn(int type) {
return type == TR || type == TSHR || type == TSLR || type == TU;
}
public static boolean isSlightTurn(int type) {
return type == TSLR || type == TSLL || type == KL || type == KR || type == C;
}
}

View file

@ -1,6 +1,8 @@
package net.osmand.util;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -82,15 +84,15 @@ public class GeoPointParserUtil {
// google calendar
// geo:0,0?q=760 West Genesee Street Syracuse NY 13204
String qstr = "q=760 West Genesee Street Syracuse NY 13204";
url = "geo:0,0?" + qstr;
String qstr = "760 West Genesee Street Syracuse NY 13204";
url = "geo:0,0?q=" + qstr;
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse("geo", url);
assertGeoPoint(actual, new GeoParsedPoint(qstr.replaceAll("\\s+", "+")));
assertGeoPoint(actual, new GeoParsedPoint(qstr));
// geo:0,0?z=11&q=1600+Amphitheatre+Parkway,+CA
qstr = "q=1600+Amphitheatre+Parkway,+CA";
url = "geo:0,0?z=11&" + qstr;
qstr = "1600 Amphitheatre Parkway, CA";
url = "geo:0,0?z=11&q=" + URLEncoder.encode(qstr);
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse("geo", url);
assertGeoPoint(actual, new GeoParsedPoint(qstr));
@ -450,48 +452,79 @@ public class GeoPointParserUtil {
return null;
}
if ("geo".equals(scheme) || "osmand.geo".equals(scheme)) {
final String schemeSpecific = data.getSchemeSpecificPart();
String schemeSpecific = data.getSchemeSpecificPart();
if (schemeSpecific == null) {
return null;
}
if (schemeSpecific.startsWith("0,0?")) {
// geo:0,0?q=34.99,-106.61(Treasure Island)
// geo:0,0?z=11&q=34.99,-106.61(Treasure Island)
String query = schemeSpecific.substring("0,0?".length());
final String pattern = "(?:z=(\\d{1,2}))?&?q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?)[\\+]?(?:\\((.+?)\\))?";
final Matcher matcher = Pattern.compile(pattern).matcher(query);
if (matcher.matches()) {
final String z = matcher.group(1);
final String name = matcher.group(4);
final int zoom = z != null ? Integer.parseInt(z) : GeoParsedPoint.NO_ZOOM;
final double lat = Double.parseDouble(matcher.group(2));
final double lon = Double.parseDouble(matcher.group(3));
return new GeoParsedPoint(lat, lon, zoom, name);
} else {
// geo:0,0?q=1600+Amphitheatre+Parkway%2C+CA
if (query.contains("z="))
query = query.substring(query.indexOf("&") + 1);
return new GeoParsedPoint(query);
}
} else {
// geo:47.6,-122.3
// geo:47.6,-122.3?z=11 (Treasure Island)
final String pattern = "([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?)(?:(?:\\?z=(\\d{1,2}))?|(?:\\?q=.*?)?)[\\+]?(?:\\((.*?)\\))?";
final Matcher matcher = Pattern.compile(pattern).matcher(schemeSpecific);
if (matcher.matches()) {
final double lat = Double.valueOf(matcher.group(1));
final double lon = Double.valueOf(matcher.group(2));
final String name = matcher.group(4);
int zoom = matcher.group(3) != null ? Integer.parseInt(matcher.group(3)) : GeoParsedPoint.NO_ZOOM;
if (zoom != GeoParsedPoint.NO_ZOOM) {
return new GeoParsedPoint(lat, lon, zoom, name);
} else {
return new GeoParsedPoint(lat, lon, name);
}
} else {
return null;
String name = null;
final Pattern namePattern = Pattern.compile("[\\+\\s]*\\((.*)\\)[\\+\\s]*$");
final Matcher nameMatcher = namePattern.matcher(schemeSpecific);
if (nameMatcher.find()) {
name = URLDecoder.decode(nameMatcher.group(1));
if (name != null) {
schemeSpecific = schemeSpecific.substring(0, nameMatcher.start());
}
}
String positionPart;
String queryPart = "";
int queryStartIndex = schemeSpecific.indexOf('?');
if (queryStartIndex == -1) {
positionPart = schemeSpecific;
} else {
positionPart = schemeSpecific.substring(0, queryStartIndex);
if (queryStartIndex < schemeSpecific.length())
queryPart = schemeSpecific.substring(queryStartIndex + 1);
}
final Pattern positionPattern = Pattern.compile(
"([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?)");
final Matcher positionMatcher = positionPattern.matcher(positionPart);
if (!positionMatcher.find()) {
return null;
}
double lat = Double.valueOf(positionMatcher.group(1));
double lon = Double.valueOf(positionMatcher.group(2));
int zoom = GeoParsedPoint.NO_ZOOM;
String searchRequest = null;
for (String param : queryPart.split("&")) {
String paramName;
String paramValue = null;
int nameValueDelimititerIndex = param.indexOf('=');
if (nameValueDelimititerIndex == -1) {
paramName = param;
} else {
paramName = param.substring(0, nameValueDelimititerIndex);
if (nameValueDelimititerIndex < param.length())
paramValue = param.substring(nameValueDelimititerIndex + 1);
}
if ("z".equals(paramName) && paramValue != null) {
zoom = Integer.parseInt(paramValue);
} else if ("q".equals(paramName) && paramValue != null) {
searchRequest = URLDecoder.decode(paramValue);
}
}
if (searchRequest != null) {
final Matcher positionInSearchRequestMatcher =
positionPattern.matcher(searchRequest);
if (lat == 0.0 && lon == 0.0 && positionInSearchRequestMatcher.find()) {
lat = Double.valueOf(positionInSearchRequestMatcher.group(1));
lon = Double.valueOf(positionInSearchRequestMatcher.group(2));
}
}
if (lat == 0.0 && lon == 0.0 && searchRequest != null) {
return new GeoParsedPoint(searchRequest);
}
if (zoom != GeoParsedPoint.NO_ZOOM) {
return new GeoParsedPoint(lat, lon, zoom, name);
}
return new GeoParsedPoint(lat, lon, name);
}
return null;
}

View file

@ -165,11 +165,16 @@
<activity android:name="net.osmand.plus.activities.search.GeoIntentActivity" android:label="@string/app_name">
<intent-filter>
<data android:scheme="geo" />
<data android:scheme="osmand.geo" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<data android:scheme="geo" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
<intent-filter>
<data android:scheme="http" android:host="maps.google.com" />
<data android:scheme="https" android:host="maps.google.com" />

View file

@ -38,14 +38,14 @@
</target>
<target name="fix_apostrophe_issues">
<replace token="version='1.0'" value="version=&quot;1.0&quot;">
<replace token="version='1.0'" value="version=&quot;1.0&quot;" encoding="UTF-8">
<fileset dir="res" includes="**/strings.xml" />
</replace>
<replace token="encoding='utf-8'" value="encoding=&quot;utf-8&quot;">
<replace token="encoding='utf-8'" value="encoding=&quot;utf-8&quot;" encoding="UTF-8">
<fileset dir="res" includes="**/strings.xml" />
</replace>
<replaceregexp match="([^\\])'" replace="\1\\\\'" flags="-g" byline="off">
<replaceregexp match="([^\\])'" replace="\1\\\\'" flags="-g" byline="off" encoding="UTF-8">
<fileset dir="res" includes="**/strings.xml" />
</replaceregexp>
</target>

View file

@ -16,6 +16,7 @@ import java.util.regex.Pattern;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
@ -151,9 +152,6 @@ public class FavouritesDbHelper {
}
FavoriteGroup group = getOrCreateGroup(p, 0);
//making sure that dublicated names will not occur in favorites
checkDublicates(p);
if (!p.getName().equals("")) {
p.setVisible(group.visible);
p.setColor(group.color);
@ -167,45 +165,45 @@ public class FavouritesDbHelper {
return true;
}
private void checkDublicates(FavouritePoint p){
boolean fl = true;
public static AlertDialog.Builder checkDublicates(FavouritePoint p, FavouritesDbHelper fdb, Context uiContext) {
boolean emoticons = false;
String index = "";
int number = 0;
String name = checkEmoticons(p.getName());
String category = checkEmoticons(p.getCategory());
p.setCategory(category);
if (name.length() != p.getName().length()){
if (name.length() != p.getName().length()) {
emoticons = true;
}
while (fl){
boolean fl = true;
while (fl) {
fl = false;
for (FavouritePoint fp : cachedFavoritePoints){
if (fp.getName().equals(name)){
for (FavouritePoint fp : fdb.getFavouritePoints()) {
if (fp.getName().equals(name)) {
number++;
index = " (" + number + ")";
name = p.getName() + index;
fl=true;
fl = true;
break;
}
}
}
if ((index.length() > 0 || emoticons)&&
context.getMapActivity() != null){
AlertDialog.Builder builder = new AlertDialog.Builder(context.getMapActivity());
if ((index.length() > 0 || emoticons) ) {
AlertDialog.Builder builder = new AlertDialog.Builder(uiContext);
builder.setTitle(R.string.fav_point_dublicate);
if (emoticons){
builder.setMessage(context.getString(R.string.fav_point_emoticons_message, name));
if (emoticons) {
builder.setMessage(uiContext.getString(R.string.fav_point_emoticons_message, name));
} else {
builder.setMessage(context.getString(R.string.fav_point_dublicate_message, name));
builder.setMessage(uiContext.getString(R.string.fav_point_dublicate_message, name));
}
builder.setPositiveButton(R.string.default_buttons_ok, null);
p.setName(name);
builder.show();
return builder;
}
return null;
}
public String checkEmoticons(String name){
public static String checkEmoticons(String name){
char[] chars = name.toCharArray();
int index;
char ch1;
@ -317,7 +315,7 @@ public class FavouritesDbHelper {
return false;
}
private File getExternalFile() {
public File getExternalFile() {
return new File(context.getAppPath(null), FILE_TO_SAVE);
}

View file

@ -87,6 +87,7 @@ public class GPXUtilities {
public double lat;
public double lon;
public String name = null;
// previous undocumented feature 'category' ,now 'type'
public String category = null;
public String desc = null;
// by default
@ -754,7 +755,7 @@ public class GPXUtilities {
}
writeNotNullText(serializer, "name", p.name);
writeNotNullText(serializer, "desc", p.desc);
writeNotNullText(serializer, "category", p.category);
writeNotNullText(serializer, "type", p.category);
if (!Double.isNaN(p.hdop)) {
writeNotNullText(serializer, "hdop", p.hdop + "");
}
@ -917,6 +918,10 @@ public class GPXUtilities {
((WptPt) parse).desc = readText(parser, "desc");
} else if (tag.equals("category")) {
((WptPt) parse).category = readText(parser, "category");
} else if (tag.equals("type")) {
if(((WptPt) parse).category == null) {
((WptPt) parse).category = readText(parser, "type");
}
} else if (parser.getName().equals("ele")) {
String text = readText(parser, "ele");
if (text != null) {

View file

@ -152,5 +152,14 @@ public class OsmAndAppCustomization {
public boolean showNavigationControls() { return true;}
public boolean onlyTourDownload() { return false;}
public boolean onlyTourDownload() {
return false;
}
public <T> void resumeActivity(Class<T> class1, T d) {
}
public <T> void pauseActivity(Class<T> class1) {
}
}

View file

@ -118,9 +118,6 @@ public class OsmandApplication extends Application {
SQLiteAPI sqliteAPI;
BRouterServiceConnection bRouterServiceConnection;
MapActivity mapActivity;
DownloadActivity downloadActivity;
@Override
public void onCreate() {
long timeToStart = System.currentTimeMillis();
@ -911,19 +908,5 @@ public class OsmandApplication extends Application {
}
}
public MapActivity getMapActivity() {
return mapActivity;
}
public void setMapActivity(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
public void setDownloadActivity(DownloadActivity downloadActivity) {
this.downloadActivity = downloadActivity;
}
public DownloadActivity getDownloadActivity() {
return downloadActivity;
}
}

View file

@ -38,6 +38,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v4.app.FragmentActivity;
import android.text.Spannable;
@ -524,9 +525,11 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
hideProgressBar();
final Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, GPXUtilities.asString(gpxFile, getMyApplication()));
sendIntent.putExtra(Intent.EXTRA_TEXT, "Favourites.gpx:\n\n\n"+GPXUtilities.asString(gpxFile, getMyApplication()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject));
sendIntent.setType("application/gpx+xml");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(helper.getExternalFile()));
// sendIntent.setType("application/gpx+xml");
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
};

View file

@ -346,7 +346,6 @@ public class MapActivity extends AccessibleActivity implements
}
settings.MAP_ACTIVITY_ENABLED.set(true);
app.setMapActivity(this);
checkExternalStorage();
showAndHideMapPosition();
@ -420,6 +419,7 @@ public class MapActivity extends AccessibleActivity implements
if(glSurfaceView != null) {
glSurfaceView.onResume();
}
getMyApplication().getAppCustomization().resumeActivity(MapActivity.class, this);
}
@ -623,7 +623,7 @@ public class MapActivity extends AccessibleActivity implements
settings.setLastKnownMapZoom(mapView.getZoom());
settings.MAP_ACTIVITY_ENABLED.set(false);
app.setMapActivity(null);
getMyApplication().getAppCustomization().pauseActivity(MapActivity.class);
app.getResourceManager().interruptRendering();
app.getResourceManager().setBusyIndicator(null);
OsmandPlugin.onMapActivityPause(this);

View file

@ -12,17 +12,17 @@ import net.osmand.AndroidUtils;
import net.osmand.access.AccessibleToast;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Build;
@ -202,13 +202,27 @@ public class FavoriteDialogs {
builder.setPositiveButton(R.string.default_buttons_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
final FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
OsmandApplication app = (OsmandApplication) activity.getApplication();
String categoryStr = cat.getText().toString().trim();
final FavouritesDbHelper helper = app.getFavorites();
app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(categoryStr);
point.setName(editText.getText().toString().trim());
point.setCategory(categoryStr);
Builder bld = FavouritesDbHelper.checkDublicates(point, helper, activity);
if(bld != null) {
bld.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
addFavorite(activity, point, helper);
}
});
} else {
addFavorite(activity, point, helper);
}
}
protected void addFavorite(final Activity activity, FavouritePoint point, final FavouritesDbHelper helper) {
boolean added = helper.addFavourite(point);
if (added) {
AccessibleToast.makeText(activity, MessageFormat.format(

View file

@ -217,8 +217,7 @@ public class DownloadActivity extends SherlockFragmentActivity {
@Override
protected void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
getMyApplication().getAppCustomization().resumeActivity(DownloadActivity.class, this);
}
@ -289,7 +288,7 @@ public class DownloadActivity extends SherlockFragmentActivity {
@Override
public void onPause() {
super.onPause();
(getMyApplication()).setDownloadActivity(null);
getMyApplication().getAppCustomization().pauseActivity(DownloadActivity.class);
}
protected void downloadFilesCheckFreeVersion() {

View file

@ -65,7 +65,8 @@ public class GpxImportHelper {
if (fileName != null && fileName.endsWith(KML_SUFFIX)) {
handleKmlImport(intentUri, fileName, saveFile);
} else if (fileName != null && fileName.endsWith("favourites.gpx")) {
} else if (fileName != null && (fileName.contains("favourite")||
fileName.contains("favorite"))) {
handleFavouritesImport(intentUri, fileName, saveFile);
} else {
handleGpxImport(intentUri, fileName, saveFile);

View file

@ -5,6 +5,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -84,6 +85,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
public static final String TOUR_SERVER = "download.osmand.net";
private static final String SAVE_GPX_FOLDER = "save_gpx_folder";
private Object originalGlobal;
private Map<Class<Object>, Object> activities = new HashMap<Class<Object>, Object>();
@Override
public void setup(OsmandApplication app) {
@ -230,7 +232,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
this.tourPresent = tourPresent;
if(!suggestToDownloadMap.isEmpty()) {
final DownloadActivity da = app.getDownloadActivity();
final DownloadActivity da = (DownloadActivity) activities.get(DownloadActivity.class);
if (da != null) {
app.runInUIThread(new Runnable() {
@ -687,7 +689,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
public boolean onDestinationReached() {
final MapActivity map = app.getMapActivity();
final MapActivity map = (MapActivity) activities.get(MapActivity.class);
if(map != null && getSelectedStage() != null) {
app.runInUIThread(new Runnable() {
@ -700,6 +702,17 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
return true;
}
@Override
public <T> void pauseActivity(Class<T> class1) {
super.pauseActivity(class1);
}
@Override
@SuppressWarnings("unchecked")
public <T> void resumeActivity(Class<T> class1, T d) {
activities.put((Class<Object>) class1, d);
}
public void runStage(Activity a, TourInformation tour, StageInformation stage, boolean startOver) {
WptPt point = null;
GPXFile gpx = null;