diff --git a/OsmAnd-java/src/net/osmand/router/TurnType.java b/OsmAnd-java/src/net/osmand/router/TurnType.java index 42b8b05674..a58f1cb82f 100644 --- a/OsmAnd-java/src/net/osmand/router/TurnType.java +++ b/OsmAnd-java/src/net/osmand/router/TurnType.java @@ -13,6 +13,10 @@ public class TurnType { public static final String TU = "TU"; // U-turn //$NON-NLS-1$ public static final String TRU = "TRU"; // Right U-turn //$NON-NLS-1$ public static String[] predefinedTypes = new String[] { C, KL, KR, TL, TSLL, TSHL, TR, TSLR, TSHR, TU, TRU }; + + public static TurnType sraight() { + return valueOf(C, false); + } public static TurnType valueOf(String s, boolean leftSide) { for (String v : predefinedTypes) { diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 62689561e5..a2cd46b5c1 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -62,6 +62,7 @@ + diff --git a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java index 78db195651..fe7211e84e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java @@ -283,27 +283,29 @@ public class GeoIntentActivity extends OsmandListActivity { for (RegionAddressRepository rar : countriesToSearch) { final TLongObjectHashMap cityIds = new TLongObjectHashMap(); for (String element : elements) { - rar.searchMapObjectsByName(element, new ResultMatcher() { - @Override - public boolean publish(MapObject object) { - if (object instanceof City && object.getId() != null) { - cityIds.put(object.getId(), (City) object); - } else if(object instanceof Street) { - City c = ((Street)object).getCity(); - if(c != null && c.getId() != null && cityIds.containsKey(c.getId().longValue())) { - connectedStreets.add((Street) object); - return false; + if (element != null && element.length() > 0) { + rar.searchMapObjectsByName(element, new ResultMatcher() { + @Override + public boolean publish(MapObject object) { + if (object instanceof City && object.getId() != null) { + cityIds.put(object.getId(), (City) object); + } else if (object instanceof Street) { + City c = ((Street) object).getCity(); + if (c != null && c.getId() != null && cityIds.containsKey(c.getId().longValue())) { + connectedStreets.add((Street) object); + return false; + } } + results.add(object); + return false; } - results.add(object); - return false; - } - @Override - public boolean isCancelled() { - return false; - } - }); + @Override + public boolean isCancelled() { + return false; + } + }); + } } } diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 290e241dfa..2da7f9274a 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -122,8 +122,7 @@ public class RouteCalculationResult { if (locationIndex > interLocations[currentIntermediate] && getDistanceToLocation(intermediates.get(currentIntermediate), locationIndex) > 50) { RouteDirectionInfo toSplit = localDirections.get(currentDirection); - RouteDirectionInfo info = new RouteDirectionInfo(localDirections.get(currentDirection).getAverageSpeed(), TurnType.valueOf(TurnType.C, - false)); + RouteDirectionInfo info = new RouteDirectionInfo(localDirections.get(currentDirection).getAverageSpeed(), TurnType.sraight()); info.setRef(toSplit.getRef()); info.setStreetName(toSplit.getStreetName()); info.setDestinationName(toSplit.getDestinationName()); @@ -268,7 +267,7 @@ public class RouteCalculationResult { int previousLocation = 0; int prevBearingLocation = 0; - RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.valueOf(TurnType.C, leftSide)); + RouteDirectionInfo previousInfo = new RouteDirectionInfo(speed, TurnType.sraight()); previousInfo.routePointOffset = 0; previousInfo.setDescriptionRoute(ctx.getString( R.string.route_head)); computeDirections.add(previousInfo); @@ -512,7 +511,7 @@ public class RouteCalculationResult { i.routePointOffset++; } RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(), - TurnType.valueOf(TurnType.C, false)); + TurnType.sraight()); info.routePointOffset = 0; // info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$ directions.add(0, info); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 2d77b587a3..f42be507de 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -530,7 +530,7 @@ public class RouteProvider { if (stype != null) { turnType = TurnType.valueOf(stype.toUpperCase(), leftSide); } else { - turnType = TurnType.valueOf(TurnType.C, leftSide); + turnType = TurnType.sraight(); } String sturn = item.getExtensionsToRead().get("turn-angle"); //$NON-NLS-1$ if (sturn != null) { diff --git a/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java b/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java index 90c9fda9c3..c12441d470 100644 --- a/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/TurnPathHelper.java @@ -240,7 +240,7 @@ public class TurnPathHelper { paintRouteDirection.setStyle(Style.FILL_AND_STROKE); paintRouteDirection.setColor(resources.getColor(R.color.nav_arrow_distant)); paintRouteDirection.setAntiAlias(true); - TurnPathHelper.calcTurnPath(dp, TurnType.valueOf(TurnType.KL, false), null); + TurnPathHelper.calcTurnPath(dp, TurnType.sraight(), null); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 15d68f1672..74dc0ab57e 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -52,7 +52,7 @@ public class RouteInfoWidgetsFactory { final OsmandSettings settings, Paint textPaint, Paint subtextPaint, boolean horisontalMini) { final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(ctx, textPaint, subtextPaint, horisontalMini) { NextDirectionInfo calc1 = new NextDirectionInfo(); - TurnType straight = TurnType.valueOf(TurnType.C, true); + TurnType straight = TurnType.sraight(); @Override public boolean updateInfo(DrawSettings drawSettings) { @@ -502,7 +502,7 @@ public class RouteInfoWidgetsFactory { final Path laneStraight = new Path(); Matrix pathTransform = new Matrix(); pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff); - TurnPathHelper.calcTurnPath(laneStraight, TurnType.valueOf(TurnType.C, false), pathTransform); + TurnPathHelper.calcTurnPath(laneStraight, TurnType.sraight(), pathTransform); final Paint paintBlack = new Paint(); paintBlack.setStyle(Style.STROKE); paintBlack.setColor(Color.BLACK); diff --git a/plugins/OsmAnd-AddressPlugin/.classpath b/plugins/OsmAnd-AddressPlugin/.classpath new file mode 100644 index 0000000000..a4763d1eec --- /dev/null +++ b/plugins/OsmAnd-AddressPlugin/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/plugins/OsmAnd-AddressPlugin/.gitignore b/plugins/OsmAnd-AddressPlugin/.gitignore new file mode 100644 index 0000000000..36986d81cf --- /dev/null +++ b/plugins/OsmAnd-AddressPlugin/.gitignore @@ -0,0 +1,4 @@ +bin +gen +raw +obj diff --git a/plugins/OsmAnd-AddressPlugin/.project b/plugins/OsmAnd-AddressPlugin/.project new file mode 100644 index 0000000000..e8967665b4 --- /dev/null +++ b/plugins/OsmAnd-AddressPlugin/.project @@ -0,0 +1,33 @@ + + + OsmAnd-AddressPlugin + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/plugins/OsmAnd-AddressPlugin/AndroidManifest.xml b/plugins/OsmAnd-AddressPlugin/AndroidManifest.xml new file mode 100644 index 0000000000..4fc7ea3f17 --- /dev/null +++ b/plugins/OsmAnd-AddressPlugin/AndroidManifest.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/OsmAnd-AddressPlugin/proguard-project.txt b/plugins/OsmAnd-AddressPlugin/proguard-project.txt new file mode 100644 index 0000000000..f2fe1559a2 --- /dev/null +++ b/plugins/OsmAnd-AddressPlugin/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/plugins/OsmAnd-AddressPlugin/project.properties b/plugins/OsmAnd-AddressPlugin/project.properties new file mode 100644 index 0000000000..9b84a6b4bf --- /dev/null +++ b/plugins/OsmAnd-AddressPlugin/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-16 diff --git a/plugins/OsmAnd-AddressPlugin/res/drawable-hdpi/ic_launcher.png b/plugins/OsmAnd-AddressPlugin/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000000..96a442e5b8 Binary files /dev/null and b/plugins/OsmAnd-AddressPlugin/res/drawable-hdpi/ic_launcher.png differ diff --git a/plugins/OsmAnd-AddressPlugin/res/drawable-hdpi/icon.png b/plugins/OsmAnd-AddressPlugin/res/drawable-hdpi/icon.png new file mode 100644 index 0000000000..23bcb31f3a Binary files /dev/null and b/plugins/OsmAnd-AddressPlugin/res/drawable-hdpi/icon.png differ diff --git a/plugins/OsmAnd-AddressPlugin/res/drawable-ldpi/ic_launcher.png b/plugins/OsmAnd-AddressPlugin/res/drawable-ldpi/ic_launcher.png new file mode 100644 index 0000000000..99238729d8 Binary files /dev/null and b/plugins/OsmAnd-AddressPlugin/res/drawable-ldpi/ic_launcher.png differ diff --git a/plugins/OsmAnd-AddressPlugin/res/drawable-ldpi/icon.png b/plugins/OsmAnd-AddressPlugin/res/drawable-ldpi/icon.png new file mode 100644 index 0000000000..4d16e761bf Binary files /dev/null and b/plugins/OsmAnd-AddressPlugin/res/drawable-ldpi/icon.png differ diff --git a/plugins/OsmAnd-AddressPlugin/res/drawable-mdpi/ic_launcher.png b/plugins/OsmAnd-AddressPlugin/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000000..359047dfa4 Binary files /dev/null and b/plugins/OsmAnd-AddressPlugin/res/drawable-mdpi/ic_launcher.png differ diff --git a/plugins/OsmAnd-AddressPlugin/res/drawable-mdpi/icon.png b/plugins/OsmAnd-AddressPlugin/res/drawable-mdpi/icon.png new file mode 100644 index 0000000000..60455f8c8f Binary files /dev/null and b/plugins/OsmAnd-AddressPlugin/res/drawable-mdpi/icon.png differ diff --git a/plugins/OsmAnd-AddressPlugin/res/drawable-xhdpi/ic_launcher.png b/plugins/OsmAnd-AddressPlugin/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000000..71c6d760f0 Binary files /dev/null and b/plugins/OsmAnd-AddressPlugin/res/drawable-xhdpi/ic_launcher.png differ diff --git a/plugins/OsmAnd-AddressPlugin/res/drawable-xhdpi/icon.png b/plugins/OsmAnd-AddressPlugin/res/drawable-xhdpi/icon.png new file mode 100644 index 0000000000..9f0621e681 Binary files /dev/null and b/plugins/OsmAnd-AddressPlugin/res/drawable-xhdpi/icon.png differ diff --git a/plugins/OsmAnd-AddressPlugin/res/layout/main.xml b/plugins/OsmAnd-AddressPlugin/res/layout/main.xml new file mode 100644 index 0000000000..35e8b132cc --- /dev/null +++ b/plugins/OsmAnd-AddressPlugin/res/layout/main.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/plugins/OsmAnd-AddressPlugin/res/values/strings.xml b/plugins/OsmAnd-AddressPlugin/res/values/strings.xml new file mode 100644 index 0000000000..7f24413cd7 --- /dev/null +++ b/plugins/OsmAnd-AddressPlugin/res/values/strings.xml @@ -0,0 +1,8 @@ + + + No + Yes + OsmAnd is not installed + OsmAnd Adress Book Plugin + OsmAnd Adress Book Plugin is installed. + \ No newline at end of file diff --git a/plugins/OsmAnd-AddressPlugin/src/net/osmand/addressPlugin/AddressBookPluginActivity.java b/plugins/OsmAnd-AddressPlugin/src/net/osmand/addressPlugin/AddressBookPluginActivity.java new file mode 100644 index 0000000000..01b79ccf16 --- /dev/null +++ b/plugins/OsmAnd-AddressPlugin/src/net/osmand/addressPlugin/AddressBookPluginActivity.java @@ -0,0 +1,60 @@ +package net.osmand.addressPlugin; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.ActivityNotFoundException; +import android.content.ComponentName; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.net.Uri; +import android.os.Bundle; + +public class AddressBookPluginActivity extends Activity { + private static final String OSMAND_COMPONENT = "net.osmand"; //$NON-NLS-1$ + private static final String OSMAND_COMPONENT_PLUS = "net.osmand.plus"; //$NON-NLS-1$ + private static final String OSMAND_ACTIVITY = "net.osmand.plus.activities.MainMenuActivity"; //$NON-NLS-1$ + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + Intent intentPlus = new Intent(); + intentPlus.setComponent(new ComponentName(OSMAND_COMPONENT_PLUS, OSMAND_ACTIVITY)); + intentPlus.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + ResolveInfo resolved = getPackageManager().resolveActivity(intentPlus, PackageManager.MATCH_DEFAULT_ONLY); + if(resolved != null) { + stopService(intentPlus); + startActivity(intentPlus); + } else { + Intent intentNormal = new Intent(); + intentNormal.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + intentNormal.setComponent(new ComponentName(OSMAND_COMPONENT, OSMAND_ACTIVITY)); + resolved = getPackageManager().resolveActivity(intentNormal, PackageManager.MATCH_DEFAULT_ONLY); + if (resolved != null) { + stopService(intentNormal); + startActivity(intentNormal); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(getString(R.string.osmand_app_not_found)); + builder.setPositiveButton(getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + OSMAND_COMPONENT_PLUS)); + try { + stopService(intent); + startActivity(intent); + } catch (ActivityNotFoundException e) { + } + } + }); + builder.setNegativeButton(getString(R.string.default_buttons_no), null); + builder.show(); + } + } + } + +} \ No newline at end of file diff --git a/plugins/OsmAnd-AddressPlugin/src/net/osmand/addressPlugin/ContactAddressPluginActivity.java b/plugins/OsmAnd-AddressPlugin/src/net/osmand/addressPlugin/ContactAddressPluginActivity.java new file mode 100644 index 0000000000..e020f5b25b --- /dev/null +++ b/plugins/OsmAnd-AddressPlugin/src/net/osmand/addressPlugin/ContactAddressPluginActivity.java @@ -0,0 +1,120 @@ +package net.osmand.addressPlugin; + +import java.util.StringTokenizer; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.ActivityNotFoundException; +import android.content.ComponentName; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; +import android.provider.ContactsContract; + +public class ContactAddressPluginActivity extends Activity { + private static final String OSMAND_COMPONENT = "net.osmand"; //$NON-NLS-1$ + private static final String OSMAND_COMPONENT_PLUS = "net.osmand.plus"; //$NON-NLS-1$ + private static final String OSMAND_ACTIVITY = "net.osmand.plus.activities.search.GeoIntentActivity"; //$NON-NLS-1$ + private static final int CONTACT_PICKER_RESULT = 1001; + //content://com.android.contacts/data/5 + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + final Intent intent = getIntent(); + if (intent != null) { + + Cursor cur=getContentResolver().query(intent.getData(),null,null,null,null); + if (cur.moveToFirst() == false) + { + //no rows empty cursor + return; + } + + final String street = cur.getString(cur.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS)); + StringTokenizer token=new StringTokenizer(street, ","); + boolean latlong=false; + String latitude=null; + String longitude=null; + if(token.countTokens()==2){ + String temp=token.nextToken(); + if(temp.startsWith("loc:")){ + temp=temp.substring(4); + } + if (temp.trim().matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+")) { + latitude=temp.trim(); + } + temp=token.nextToken(); + if(temp.trim().matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+")){ + longitude= temp.trim(); + } + if(latitude!=null && longitude!=null){ + latlong=true; + } + } + String data="geo:"; + if(latlong){ + data=data+latitude+","+longitude; + }else{ + data=data+"0,0?q="+street; + } + + //The cursor is already positioned at the begining of the cursor + //let's access a few columns + + //let's now see how we can loop through a cursor + startOSMAND(intent, data); + /*while(cur.moveToNext()) + { + //cursor moved successfully + //access fields + }*/ + + } + finish(); + } + + + public void startOSMAND(Intent original,String data){ + Intent intentPlus = new Intent(); + intentPlus.setComponent(new ComponentName(OSMAND_COMPONENT_PLUS, OSMAND_ACTIVITY)); + intentPlus.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + intentPlus.setData(Uri.parse(data)); + intentPlus.setAction(original.getAction()); + ResolveInfo resolved = getPackageManager().resolveActivity(intentPlus, PackageManager.MATCH_DEFAULT_ONLY); + if(resolved != null) { + stopService(intentPlus); + startActivity(intentPlus); + } else { + Intent intentNormal = new Intent(); + intentNormal.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + intentNormal.setData(original.getData()); + intentNormal.setComponent(new ComponentName(OSMAND_COMPONENT, OSMAND_ACTIVITY)); + resolved = getPackageManager().resolveActivity(intentNormal, PackageManager.MATCH_DEFAULT_ONLY); + if (resolved != null) { + stopService(intentNormal); + startActivity(intentNormal); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(getString(R.string.osmand_app_not_found)); + builder.setPositiveButton(getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + OSMAND_COMPONENT_PLUS)); + try { + stopService(intent); + startActivity(intent); + } catch (ActivityNotFoundException e) { + } + } + }); + builder.setNegativeButton(getString(R.string.default_buttons_no), null); + builder.show(); + } + } + + } +} \ No newline at end of file