Add basic API methods showPoint(s)OnMap

This commit is contained in:
moving-bits 2023-07-27 10:07:38 +02:00 committed by Alexander Borsuk
parent 363d7f07d9
commit f3a87782f0

View file

@ -0,0 +1,51 @@
package app.organicmaps.api;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import java.util.ArrayList;
public class OrganicMapsApi {
static final String PACKAGE_NAME = "app.organicmaps";
private OrganicMapsApi() {
// utility class
}
public static void showPointOnMap(final Activity activity, final double lat, final double lon, final String name) {
final ArrayList<Point> points = new ArrayList<>(1);
points.add(new Point(lat, lon, name));
showPointsOnMap(activity, name, points);
}
public static void showPointsOnMap(final Activity activity, final String name, final ArrayList<Point> points) {
final Intent intent = new MapRequest()
.setPoints(points)
.setAppName(name)
.toIntent();
sendRequest(activity, intent);
};
public static void sendRequest(final Activity caller, final Intent intent) {
if (isOrganicMapsInstalled(caller)) {
// Match activity for intent
final ActivityInfo aInfo = caller.getPackageManager().resolveActivity(intent, 0).activityInfo;
intent.setClassName(aInfo.packageName, aInfo.name);
caller.startActivity(intent);
} else {
new DownloadDialog(caller).show();
}
}
/**
* Detects if any version of OrganicMaps is installed on the device
*/
public static boolean isOrganicMapsInstalled(final Context context) {
final Intent i = context.getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);
return i != null;
}
}