Add old address plugin to source code
|
@ -13,6 +13,10 @@ public class TurnType {
|
||||||
public static final String TU = "TU"; // U-turn //$NON-NLS-1$
|
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 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 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) {
|
public static TurnType valueOf(String s, boolean leftSide) {
|
||||||
for (String v : predefinedTypes) {
|
for (String v : predefinedTypes) {
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
<category android:name="android.intent.category.BROWSABLE"/>
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
|
<category android:name="android.intent.category.APP_MAPS" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<receiver android:name="net.osmand.plus.audionotes.MediaRemoteControlReceiver">
|
<receiver android:name="net.osmand.plus.audionotes.MediaRemoteControlReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|
|
@ -283,27 +283,29 @@ public class GeoIntentActivity extends OsmandListActivity {
|
||||||
for (RegionAddressRepository rar : countriesToSearch) {
|
for (RegionAddressRepository rar : countriesToSearch) {
|
||||||
final TLongObjectHashMap<City> cityIds = new TLongObjectHashMap<City>();
|
final TLongObjectHashMap<City> cityIds = new TLongObjectHashMap<City>();
|
||||||
for (String element : elements) {
|
for (String element : elements) {
|
||||||
rar.searchMapObjectsByName(element, new ResultMatcher<MapObject>() {
|
if (element != null && element.length() > 0) {
|
||||||
@Override
|
rar.searchMapObjectsByName(element, new ResultMatcher<MapObject>() {
|
||||||
public boolean publish(MapObject object) {
|
@Override
|
||||||
if (object instanceof City && object.getId() != null) {
|
public boolean publish(MapObject object) {
|
||||||
cityIds.put(object.getId(), (City) object);
|
if (object instanceof City && object.getId() != null) {
|
||||||
} else if(object instanceof Street) {
|
cityIds.put(object.getId(), (City) object);
|
||||||
City c = ((Street)object).getCity();
|
} else if (object instanceof Street) {
|
||||||
if(c != null && c.getId() != null && cityIds.containsKey(c.getId().longValue())) {
|
City c = ((Street) object).getCity();
|
||||||
connectedStreets.add((Street) object);
|
if (c != null && c.getId() != null && cityIds.containsKey(c.getId().longValue())) {
|
||||||
return false;
|
connectedStreets.add((Street) object);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
results.add(object);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
results.add(object);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,8 +122,7 @@ public class RouteCalculationResult {
|
||||||
if (locationIndex > interLocations[currentIntermediate]
|
if (locationIndex > interLocations[currentIntermediate]
|
||||||
&& getDistanceToLocation(intermediates.get(currentIntermediate), locationIndex) > 50) {
|
&& getDistanceToLocation(intermediates.get(currentIntermediate), locationIndex) > 50) {
|
||||||
RouteDirectionInfo toSplit = localDirections.get(currentDirection);
|
RouteDirectionInfo toSplit = localDirections.get(currentDirection);
|
||||||
RouteDirectionInfo info = new RouteDirectionInfo(localDirections.get(currentDirection).getAverageSpeed(), TurnType.valueOf(TurnType.C,
|
RouteDirectionInfo info = new RouteDirectionInfo(localDirections.get(currentDirection).getAverageSpeed(), TurnType.sraight());
|
||||||
false));
|
|
||||||
info.setRef(toSplit.getRef());
|
info.setRef(toSplit.getRef());
|
||||||
info.setStreetName(toSplit.getStreetName());
|
info.setStreetName(toSplit.getStreetName());
|
||||||
info.setDestinationName(toSplit.getDestinationName());
|
info.setDestinationName(toSplit.getDestinationName());
|
||||||
|
@ -268,7 +267,7 @@ public class RouteCalculationResult {
|
||||||
|
|
||||||
int previousLocation = 0;
|
int previousLocation = 0;
|
||||||
int prevBearingLocation = 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.routePointOffset = 0;
|
||||||
previousInfo.setDescriptionRoute(ctx.getString( R.string.route_head));
|
previousInfo.setDescriptionRoute(ctx.getString( R.string.route_head));
|
||||||
computeDirections.add(previousInfo);
|
computeDirections.add(previousInfo);
|
||||||
|
@ -512,7 +511,7 @@ public class RouteCalculationResult {
|
||||||
i.routePointOffset++;
|
i.routePointOffset++;
|
||||||
}
|
}
|
||||||
RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(),
|
RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(),
|
||||||
TurnType.valueOf(TurnType.C, false));
|
TurnType.sraight());
|
||||||
info.routePointOffset = 0;
|
info.routePointOffset = 0;
|
||||||
// info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$
|
// info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$
|
||||||
directions.add(0, info);
|
directions.add(0, info);
|
||||||
|
|
|
@ -530,7 +530,7 @@ public class RouteProvider {
|
||||||
if (stype != null) {
|
if (stype != null) {
|
||||||
turnType = TurnType.valueOf(stype.toUpperCase(), leftSide);
|
turnType = TurnType.valueOf(stype.toUpperCase(), leftSide);
|
||||||
} else {
|
} else {
|
||||||
turnType = TurnType.valueOf(TurnType.C, leftSide);
|
turnType = TurnType.sraight();
|
||||||
}
|
}
|
||||||
String sturn = item.getExtensionsToRead().get("turn-angle"); //$NON-NLS-1$
|
String sturn = item.getExtensionsToRead().get("turn-angle"); //$NON-NLS-1$
|
||||||
if (sturn != null) {
|
if (sturn != null) {
|
||||||
|
|
|
@ -240,7 +240,7 @@ public class TurnPathHelper {
|
||||||
paintRouteDirection.setStyle(Style.FILL_AND_STROKE);
|
paintRouteDirection.setStyle(Style.FILL_AND_STROKE);
|
||||||
paintRouteDirection.setColor(resources.getColor(R.color.nav_arrow_distant));
|
paintRouteDirection.setColor(resources.getColor(R.color.nav_arrow_distant));
|
||||||
paintRouteDirection.setAntiAlias(true);
|
paintRouteDirection.setAntiAlias(true);
|
||||||
TurnPathHelper.calcTurnPath(dp, TurnType.valueOf(TurnType.KL, false), null);
|
TurnPathHelper.calcTurnPath(dp, TurnType.sraight(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class RouteInfoWidgetsFactory {
|
||||||
final OsmandSettings settings, Paint textPaint, Paint subtextPaint, boolean horisontalMini) {
|
final OsmandSettings settings, Paint textPaint, Paint subtextPaint, boolean horisontalMini) {
|
||||||
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(ctx, textPaint, subtextPaint, horisontalMini) {
|
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(ctx, textPaint, subtextPaint, horisontalMini) {
|
||||||
NextDirectionInfo calc1 = new NextDirectionInfo();
|
NextDirectionInfo calc1 = new NextDirectionInfo();
|
||||||
TurnType straight = TurnType.valueOf(TurnType.C, true);
|
TurnType straight = TurnType.sraight();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateInfo(DrawSettings drawSettings) {
|
public boolean updateInfo(DrawSettings drawSettings) {
|
||||||
|
@ -502,7 +502,7 @@ public class RouteInfoWidgetsFactory {
|
||||||
final Path laneStraight = new Path();
|
final Path laneStraight = new Path();
|
||||||
Matrix pathTransform = new Matrix();
|
Matrix pathTransform = new Matrix();
|
||||||
pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff);
|
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();
|
final Paint paintBlack = new Paint();
|
||||||
paintBlack.setStyle(Style.STROKE);
|
paintBlack.setStyle(Style.STROKE);
|
||||||
paintBlack.setColor(Color.BLACK);
|
paintBlack.setColor(Color.BLACK);
|
||||||
|
|
8
plugins/OsmAnd-AddressPlugin/.classpath
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="gen"/>
|
||||||
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||||
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||||
|
<classpathentry kind="output" path="bin/classes"/>
|
||||||
|
</classpath>
|
4
plugins/OsmAnd-AddressPlugin/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
bin
|
||||||
|
gen
|
||||||
|
raw
|
||||||
|
obj
|
33
plugins/OsmAnd-AddressPlugin/.project
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>OsmAnd-AddressPlugin</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
43
plugins/OsmAnd-AddressPlugin/AndroidManifest.xml
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="net.osmand.addressPlugin"
|
||||||
|
android:versionCode="5"
|
||||||
|
android:versionName="1.0" >
|
||||||
|
|
||||||
|
<uses-sdk android:minSdkVersion="10" />
|
||||||
|
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
|
||||||
|
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
|
||||||
|
<supports-screens android:resizeable="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true"
|
||||||
|
android:xlargeScreens="true" android:anyDensity="true" />
|
||||||
|
<application
|
||||||
|
android:icon="@drawable/icon"
|
||||||
|
android:label="OsmAnd Contact Plugin" >
|
||||||
|
<activity
|
||||||
|
android:name=".AddressBookPluginActivity"
|
||||||
|
android:label="@string/app_name" >
|
||||||
|
<!--
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
-->
|
||||||
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".ContactAddressPluginActivity"
|
||||||
|
android:label="@string/app_name" >
|
||||||
|
<!-- <intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
<category android:name="android.intent.category.APP_MAPS" />
|
||||||
|
<data android:scheme="geo"></data>
|
||||||
|
</intent-filter>
|
||||||
|
-->
|
||||||
|
<intent-filter android:label="OsmAnd">
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="vnd.android.cursor.item/postal-address_v2" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
20
plugins/OsmAnd-AddressPlugin/proguard-project.txt
Normal file
|
@ -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 *;
|
||||||
|
#}
|
14
plugins/OsmAnd-AddressPlugin/project.properties
Normal file
|
@ -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
|
BIN
plugins/OsmAnd-AddressPlugin/res/drawable-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
plugins/OsmAnd-AddressPlugin/res/drawable-hdpi/icon.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
plugins/OsmAnd-AddressPlugin/res/drawable-ldpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
plugins/OsmAnd-AddressPlugin/res/drawable-ldpi/icon.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
plugins/OsmAnd-AddressPlugin/res/drawable-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
plugins/OsmAnd-AddressPlugin/res/drawable-mdpi/icon.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
plugins/OsmAnd-AddressPlugin/res/drawable-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
plugins/OsmAnd-AddressPlugin/res/drawable-xhdpi/icon.png
Normal file
After Width: | Height: | Size: 9.6 KiB |
13
plugins/OsmAnd-AddressPlugin/res/layout/main.xml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:gravity="center_vertical|center_horizontal"
|
||||||
|
android:text="@string/parking_plugin_installed"
|
||||||
|
android:textSize="22sp"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
8
plugins/OsmAnd-AddressPlugin/res/values/strings.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="default_buttons_no">No</string>
|
||||||
|
<string name="default_buttons_yes">Yes</string>
|
||||||
|
<string name="osmand_app_not_found">OsmAnd is not installed</string>
|
||||||
|
<string name="app_name">OsmAnd Adress Book Plugin</string>
|
||||||
|
<string name="parking_plugin_installed">OsmAnd Adress Book Plugin is installed.</string>
|
||||||
|
</resources>
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|