requests = addressLookupRequestsMap.get(latLon);
- return requests != null && requests.size() > 0;
- }
- }
-
- @SuppressWarnings("unchecked")
- private void execute(AsyncTask
task, P... requests) {
- task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests);
- }
-
- private boolean geocode(final LatLon latLon) {
- Location loc = new Location("");
- loc.setLatitude(latLon.getLatitude());
- loc.setLongitude(latLon.getLongitude());
- return app.getLocationProvider()
- .getGeocodingResult(loc, new ResultMatcher() {
-
- @Override
- public boolean publish(GeocodingResult object) {
- String result = null;
- if (object != null) {
- String lang = SampleApplication.LANGUAGE;
- boolean transliterate = SampleApplication.TRANSLITERATE;
-
- String geocodingResult = "";
- double relevantDistance = -1;
-
- if (object.building != null) {
- String bldName = object.building.getName(lang, transliterate);
- if (!Algorithms.isEmpty(object.buildingInterpolation)) {
- bldName = object.buildingInterpolation;
- }
- geocodingResult = object.street.getName(lang, transliterate) + " " + bldName + ", "
- + object.city.getName(lang, transliterate);
- } else if (object.street != null) {
- geocodingResult = object.street.getName(lang, transliterate) + ", " + object.city.getName(lang, transliterate);
- relevantDistance = object.getDistanceP();
- } else if (object.city != null) {
- geocodingResult = object.city.getName(lang, transliterate);
- } else if (object.point != null) {
- RouteDataObject rd = object.point.getRoad();
- String sname = rd.getName(lang, transliterate);
- if (Algorithms.isEmpty(sname)) {
- sname = "";
- }
- String ref = rd.getRef(lang, transliterate, true);
- if (!Algorithms.isEmpty(ref)) {
- if (!Algorithms.isEmpty(sname)) {
- sname += ", ";
- }
- sname += ref;
- }
- geocodingResult = sname;
- relevantDistance = object.getDistanceP();
- }
-
- result = geocodingResult;
- if (relevantDistance == -1) {
- relevantDistance = object.getDistance();
- }
-
- if (!Algorithms.isEmpty(result) && relevantDistance > 100) {
- result = app.getString("shared_string_near") + " " + result;
- }
- }
-
- lastFoundAddress = result;
- searchDone = true;
-
- return true;
- }
-
- @Override
- public boolean isCancelled() {
- return !hasAnyRequest(latLon);
- }
-
- });
- }
-
- private class AddressLookupRequestsAsyncTask extends AsyncTask {
-
- private SampleApplication app;
-
- public AddressLookupRequestsAsyncTask(SampleApplication app) {
- super();
- this.app = app;
- }
-
- @Override
- protected Void doInBackground(AddressLookupRequest... addressLookupRequests) {
- for (;;) {
- try {
- while (!lookupLocations.isEmpty()) {
- final LatLon latLon;
- synchronized (GeocodingLookupService.this) {
- latLon = lookupLocations.poll();
- currentRequestedLocation = latLon;
- List requests = addressLookupRequestsMap.get(latLon);
- if (requests == null || requests.size() == 0) {
- addressLookupRequestsMap.remove(latLon);
- continue;
- }
- }
-
- // geocode
- searchDone = false;
- while (!geocode(latLon)) {
- try {
- Thread.sleep(50);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- long counter = 0;
- while (!searchDone) {
- try {
- Thread.sleep(50);
- counter++;
- // call progress every 500 ms
- if (counter == 10) {
- counter = 0;
- synchronized (GeocodingLookupService.this) {
- List requests = addressLookupRequestsMap.get(latLon);
- for (final AddressLookupRequest request : requests) {
- if (request.uiProgressCallback != null) {
- app.runInUIThread(new Runnable() {
- @Override
- public void run() {
- request.uiProgressCallback.geocodingInProgress();
- }
- });
- }
- }
- }
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- synchronized (GeocodingLookupService.this) {
- List requests = addressLookupRequestsMap.get(latLon);
- for (final AddressLookupRequest request : requests) {
- if (request.uiResultCallback != null) {
- app.runInUIThread(new Runnable() {
- @Override
- public void run() {
- request.uiResultCallback.geocodingDone(lastFoundAddress);
- }
- });
- }
- }
- addressLookupRequestsMap.remove(latLon);
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- synchronized (GeocodingLookupService.this) {
- currentRequestedLocation = null;
- if (lookupLocations.isEmpty()) {
- break;
- }
- }
- }
-
- return null;
- }
- }
-}
diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/IconsCache.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/IconsCache.java
deleted file mode 100644
index ac51a63303..0000000000
--- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/IconsCache.java
+++ /dev/null
@@ -1,194 +0,0 @@
-package net.osmand.core.samples.android.sample1;
-
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.LayerDrawable;
-
-import androidx.annotation.ColorInt;
-import androidx.annotation.ColorRes;
-import androidx.annotation.DrawableRes;
-import androidx.core.content.ContextCompat;
-import androidx.core.graphics.drawable.DrawableCompat;
-
-import net.osmand.core.android.CoreResourcesFromAndroidAssets;
-
-import gnu.trove.map.hash.TLongObjectHashMap;
-
-public class IconsCache {
-
- private TLongObjectHashMap drawable = new TLongObjectHashMap<>();
- private TLongObjectHashMap osmandDrawable = new TLongObjectHashMap<>();
- private SampleApplication app;
- private CoreResourcesFromAndroidAssets assets;
- private float displayDensityFactor;
-
- public IconsCache(CoreResourcesFromAndroidAssets assets, SampleApplication app) {
- this.assets = assets;
- this.app = app;
- }
-
- public float getDisplayDensityFactor() {
- return displayDensityFactor;
- }
-
- public void setDisplayDensityFactor(float displayDensityFactor) {
- this.displayDensityFactor = displayDensityFactor;
- }
-
- public Drawable getMapIcon(String name) {
- return assets.getIcon("map/icons/" + name + ".png", displayDensityFactor);
- }
-
- private Drawable getDrawable(@DrawableRes int resId, @ColorRes int clrId) {
- long hash = ((long)resId << 31L) + clrId;
- Drawable d = drawable.get(hash);
- if (d == null) {
- d = ContextCompat.getDrawable(app, resId);
- d = DrawableCompat.wrap(d);
- d.mutate();
- if (clrId != 0) {
- DrawableCompat.setTint(d, ContextCompat.getColor(app, clrId));
- }
- drawable.put(hash, d);
- }
- return d;
- }
-
- private Drawable getPaintedDrawable(@DrawableRes int resId, @ColorInt int color){
- long hash = ((long)resId << 31L) + color;
- Drawable d = drawable.get(hash);
- if(d == null) {
- d = ContextCompat.getDrawable(app, resId);
- d = DrawableCompat.wrap(d);
- d.mutate();
- DrawableCompat.setTint(d, color);
-
- drawable.put(hash, d);
- }
- return d;
- }
-
- public Drawable getPaintedIcon(@DrawableRes int id, @ColorInt int color){
- return getPaintedDrawable(id, color);
- }
-
- public Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) {
- return getDrawable(id, colorId);
- }
-
- public Drawable getIcon(@DrawableRes int backgroundId, @DrawableRes int id, @ColorRes int colorId) {
- Drawable b = getDrawable(backgroundId, 0);
- Drawable f = getDrawable(id, colorId);
- Drawable[] layers = new Drawable[2];
- layers[0] = b;
- layers[1] = f;
- return new LayerDrawable(layers);
- }
-
- public Drawable getThemedIcon(@DrawableRes int id) {
- return getDrawable(id, R.color.icon_color);
- }
-
- public Drawable getIcon(@DrawableRes int id) {
- return getDrawable(id, 0);
- }
-
- public Drawable getIcon(@DrawableRes int id, boolean light) {
- return getDrawable(id, light ? R.color.icon_color : 0);
- }
-
-
- // Osmand resources
- private Drawable getOsmandDrawable(int resId, @ColorRes int clrId) {
- long hash = ((long)resId << 31L) + clrId;
- Drawable d = osmandDrawable.get(hash);
- if (d == null) {
- d = OsmandResources.getDrawableNonCached(resId);
- if (d != null) {
- d = DrawableCompat.wrap(d);
- d.mutate();
- if (clrId != 0) {
- DrawableCompat.setTint(d, ContextCompat.getColor(app, clrId));
- }
- osmandDrawable.put(hash, d);
- }
- }
- return d;
- }
-
- private Drawable getPaintedOsmandDrawable(int resId, @ColorInt int color){
- long hash = ((long)resId << 31L) + color;
- Drawable d = osmandDrawable.get(hash);
- if(d == null) {
- d = OsmandResources.getDrawableNonCached(resId);
- if (d != null) {
- d = DrawableCompat.wrap(d);
- d.mutate();
- DrawableCompat.setTint(d, color);
- osmandDrawable.put(hash, d);
- }
- }
- return d;
- }
-
- public Drawable getPaintedOsmandIcon(int resId, @ColorInt int color){
- return getPaintedOsmandDrawable(resId, color);
- }
-
- public Drawable getPaintedIcon(String osmandId, @ColorInt int color){
- int id = OsmandResources.getDrawableId(osmandId);
- if (id != 0) {
- return getPaintedOsmandDrawable(id, color);
- }
- return null;
- }
-
- public Drawable getOsmandIcon(@DrawableRes int id, @ColorRes int colorId) {
- return getOsmandDrawable(id, colorId);
- }
-
- public Drawable getIcon(String osmandId, @ColorRes int colorId) {
- int id = OsmandResources.getDrawableId(osmandId);
- if (id != 0) {
- return getOsmandDrawable(id, colorId);
- }
- return null;
- }
-
- public Drawable getIcon(String osmandBackgroundId, String osmandId, @ColorRes int colorId) {
- int backgroundId = OsmandResources.getDrawableId(osmandBackgroundId);
- int id = OsmandResources.getDrawableId(osmandId);
- if (backgroundId != 0 && id != 0) {
- Drawable b = getOsmandDrawable(backgroundId, 0);
- Drawable f = getOsmandDrawable(id, colorId);
- Drawable[] layers = new Drawable[2];
- layers[0] = b;
- layers[1] = f;
- return new LayerDrawable(layers);
- }
- return null;
- }
-
- public Drawable getThemedIcon(String osmandId) {
- int id = OsmandResources.getDrawableId(osmandId);
- if (id != 0) {
- return getOsmandDrawable(id, R.color.icon_color);
- }
- return null;
- }
-
- public Drawable getIcon(String osmandId) {
- int id = OsmandResources.getDrawableId(osmandId);
- if (id != 0) {
- return getOsmandDrawable(id, 0);
- }
- return null;
- }
-
- public Drawable getIcon(String osmandId, boolean light) {
- int id = OsmandResources.getDrawableId(osmandId);
- if (id != 0) {
- return getOsmandDrawable(id, light ? R.color.icon_color : 0);
- }
- return null;
- }
-}
diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/InstallOsmandAppDialog.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/InstallOsmandAppDialog.java
deleted file mode 100644
index c7d5b9d1d8..0000000000
--- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/InstallOsmandAppDialog.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package net.osmand.core.samples.android.sample1;
-
-import android.app.Dialog;
-import android.content.ActivityNotFoundException;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.view.View;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.app.AppCompatDialogFragment;
-import androidx.fragment.app.FragmentManager;
-
-public class InstallOsmandAppDialog extends AppCompatDialogFragment {
- private static final String TAG = "InstallOsmandAppDialog";
- private static final String OSMAND_PLUS_PACKAGE_NAME = "net.osmand.plus";
- private static final String OSMAND_PACKAGE_NAME = "net.osmand";
- private static boolean processed = false;
- private static boolean shown = false;
-
- @NonNull
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder.setTitle(R.string.install_osmand_title);
- builder.setNegativeButton(R.string.shared_string_cancel, null);
- builder.setPositiveButton(getString(R.string.restart_app), new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- SampleUtils.doRestart(getActivity());
- }
- });
-
- View view = getActivity().getLayoutInflater().inflate(R.layout.install_osmand_dialog, null);
- view.findViewById(R.id.install_osmand_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- boolean success = execOsmAndInstall("market://details?id=");
- if (!success) {
- success = execOsmAndInstall("https://play.google.com/store/apps/details?id=");
- }
- if (!success) {
- execOsmAndInstall("http://osmand.net/apps?id=");
- }
- }
- });
- builder.setView(view);
- return builder.create();
- }
-
- private boolean execOsmAndInstall(String prefix) {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(prefix + OSMAND_PACKAGE_NAME));
- try {
- getActivity().startActivity(intent);
- return true;
- } catch (ActivityNotFoundException e) {
- e.printStackTrace();
- }
- return false;
- }
-
- public static boolean wasShown() {
- return shown;
- }
-
- public static boolean show(FragmentManager manager, Context ctx) {
- if (processed) {
- return false;
- }
- processed = true;
- if (!SampleUtils.isPackageInstalled(OSMAND_PACKAGE_NAME, ctx)
- && !SampleUtils.isPackageInstalled(OSMAND_PLUS_PACKAGE_NAME, ctx)) {
- new InstallOsmandAppDialog().show(manager, TAG);
- shown = true;
- }
- return shown;
- }
-}
diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java
deleted file mode 100644
index bd6fc03b2a..0000000000
--- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java
+++ /dev/null
@@ -1,1063 +0,0 @@
-package net.osmand.core.samples.android.sample1;
-
-import android.Manifest;
-import android.annotation.SuppressLint;
-import android.content.DialogInterface;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
-import android.content.pm.PackageManager;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.ColorFilter;
-import android.graphics.PointF;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.util.DisplayMetrics;
-import android.util.Log;
-import android.view.GestureDetector;
-import android.view.GestureDetector.SimpleOnGestureListener;
-import android.view.MotionEvent;
-import android.view.View;
-import android.widget.ImageButton;
-import android.widget.TextView;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.core.app.ActivityCompat;
-import androidx.core.content.ContextCompat;
-import androidx.fragment.app.Fragment;
-
-import net.osmand.Location;
-import net.osmand.binary.BinaryMapIndexReader;
-import net.osmand.core.android.AtlasMapRendererView;
-import net.osmand.core.jni.AmenitySymbolsProvider.AmenitySymbolsGroup;
-import net.osmand.core.jni.AreaI;
-import net.osmand.core.jni.FColorRGB;
-import net.osmand.core.jni.IBillboardMapSymbol;
-import net.osmand.core.jni.IMapLayerProvider;
-import net.osmand.core.jni.IMapRenderer.MapSymbolInformation;
-import net.osmand.core.jni.IMapStylesCollection;
-import net.osmand.core.jni.Logger;
-import net.osmand.core.jni.MapMarker;
-import net.osmand.core.jni.MapMarker.SymbolsGroup;
-import net.osmand.core.jni.MapMarkerBuilder;
-import net.osmand.core.jni.MapMarkersCollection;
-import net.osmand.core.jni.MapObject;
-import net.osmand.core.jni.MapObjectsSymbolsProvider;
-import net.osmand.core.jni.MapObjectsSymbolsProvider.MapObjectSymbolsGroup;
-import net.osmand.core.jni.MapPresentationEnvironment;
-import net.osmand.core.jni.MapPrimitivesProvider;
-import net.osmand.core.jni.MapPrimitiviser;
-import net.osmand.core.jni.MapRasterLayerProvider_Software;
-import net.osmand.core.jni.MapStylesCollection;
-import net.osmand.core.jni.MapSymbolInformationList;
-import net.osmand.core.jni.MapSymbolsGroup.AdditionalBillboardSymbolInstanceParameters;
-import net.osmand.core.jni.ObfMapObject;
-import net.osmand.core.jni.ObfMapObjectsProvider;
-import net.osmand.core.jni.ObfsCollection;
-import net.osmand.core.jni.PointI;
-import net.osmand.core.jni.QIODeviceLogSink;
-import net.osmand.core.jni.ResolvedMapStyle;
-import net.osmand.core.jni.SwigUtilities;
-import net.osmand.core.jni.Utilities;
-import net.osmand.core.samples.android.sample1.MultiTouchSupport.MultiTouchZoomListener;
-import net.osmand.core.samples.android.sample1.SampleLocationProvider.SampleCompassListener;
-import net.osmand.core.samples.android.sample1.SampleLocationProvider.SampleLocationListener;
-import net.osmand.core.samples.android.sample1.data.PointDescription;
-import net.osmand.core.samples.android.sample1.mapcontextmenu.MapContextMenu;
-import net.osmand.core.samples.android.sample1.mapcontextmenu.MenuController;
-import net.osmand.core.samples.android.sample1.search.QuickSearchDialogFragment;
-import net.osmand.data.Amenity;
-import net.osmand.data.LatLon;
-import net.osmand.data.QuadRect;
-import net.osmand.data.RotatedTileBox;
-import net.osmand.osm.PoiCategory;
-import net.osmand.util.MapUtils;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.util.ArrayList;
-import java.util.List;
-
-import static net.osmand.core.samples.android.sample1.SampleApplication.PERMISSION_REQUEST_LOCATION_ON_BUTTON;
-import static net.osmand.core.samples.android.sample1.SampleApplication.PERMISSION_REQUEST_LOCATION_ON_RESUME;
-import static net.osmand.core.samples.android.sample1.SampleApplication.PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE;
-
-public class MainActivity extends AppCompatActivity implements SampleLocationListener, SampleCompassListener {
- private static final String TAG = "OsmAndCoreSample";
-
- private float displayDensityFactor;
- private int referenceTileSize;
- private int rasterTileSize;
- private IMapStylesCollection mapStylesCollection;
- private ResolvedMapStyle mapStyle;
- private ObfsCollection obfsCollection;
- private MapPresentationEnvironment mapPresentationEnvironment;
- private MapPrimitiviser mapPrimitiviser;
- private ObfMapObjectsProvider obfMapObjectsProvider;
- private MapPrimitivesProvider mapPrimitivesProvider;
- private MapObjectsSymbolsProvider mapObjectsSymbolsProvider;
- private IMapLayerProvider mapLayerProvider0;
- private QIODeviceLogSink fileLogSink;
-
- private AtlasMapRendererView mapView;
- private TextView textZoom;
- private ImageButton searchButton;
- private ImageButton compassButton;
- private CompassDrawable compassDrawable;
-
- private GestureDetector gestureDetector;
- private PointI target31;
- private float zoom;
- private float azimuth = 0;
- private float elevationAngle;
- private MultiTouchSupport multiTouchSupport;
-
- private MapContextMenu menu;
-
- // Context pin marker
- private MapMarkersCollection contextPinMarkersCollection;
- private MapMarker contextPinMarker;
- private static final int MARKER_ID_CONTEXT_PIN = 1;
-
- // "My location" marker, "My course" marker and collection
- private MapMarkersCollection myMarkersCollection;
- private MapMarker myLocationMarker;
- private static final int MARKER_ID_MY_LOCATION = 2;
-
- // Germany
- private final static float INIT_LAT = 49.353953f;
- private final static float INIT_LON = 11.214384f;
- // Kyiv
- //private final static float INIT_LAT = 50.450117f;
- //private final static float INIT_LON = 30.524142f;
- private final static float INIT_ZOOM = 6.0f;
- private final static float INIT_AZIMUTH = 0.0f;
- private final static float INIT_ELEVATION_ANGLE = 90.0f;
- private final static int MIN_ZOOM_LEVEL = 2;
- private final static int MAX_ZOOM_LEVEL = 22;
-
- private static final String PREF_MAP_CENTER_LAT = "MAP_CENTER_LAT";
- private static final String PREF_MAP_CENTER_LON = "MAP_CENTER_LON";
- private static final String PREF_MAP_AZIMUTH = "MAP_AZIMUTH";
- private static final String PREF_MAP_ZOOM = "MAP_ZOOM";
- private static final String PREF_MAP_ELEVATION_ANGLE = "MAP_ELEVATION_ANGLE";
-
- public SampleApplication getMyApplication() {
- return (SampleApplication) getApplication();
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- switch (requestCode) {
- case PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE:
- if (!InstallOsmandAppDialog.wasShown()) {
- checkMapsInstalled();
- }
- getMyApplication().initPoiTypes();
- break;
- case PERMISSION_REQUEST_LOCATION_ON_BUTTON:
- goToLocation();
- case PERMISSION_REQUEST_LOCATION_ON_RESUME:
- getMyApplication().getLocationProvider().resumeAllUpdates();
- break;
- }
- }
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- SampleApplication app = getMyApplication();
-
- gestureDetector = new GestureDetector(this, new MapViewOnGestureListener());
- multiTouchSupport = new MultiTouchSupport(this, new MapViewMultiTouchZoomListener());
-
- // Inflate views
- setContentView(R.layout.activity_main);
-
- boolean externalStoragePermissionGranted = ContextCompat.checkSelfPermission(this,
- Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
- if (!externalStoragePermissionGranted) {
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
- PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
- }
-
- // Get map view
- mapView = (AtlasMapRendererView) findViewById(R.id.mapRendererView);
-
- textZoom = (TextView) findViewById(R.id.text_zoom);
-
- searchButton = (ImageButton) findViewById(R.id.search_button);
- searchButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showQuickSearch(ShowQuickSearchMode.NEW_IF_EXPIRED, false);
- }
- });
-
- compassButton = (ImageButton) findViewById(R.id.map_compass_button);
- compassButton.setContentDescription(app.getString("rotate_map_compass_opt"));
- compassDrawable = new CompassDrawable(app.getIconsCache().getIcon(R.drawable.map_compass));
- compassButton.setImageDrawable(compassDrawable);
- compassButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- setAzimuth(0f);
- }
- });
-
- ImageButton myLocationButton = (ImageButton) findViewById(R.id.map_my_location_button);
- myLocationButton.setImageDrawable(app.getIconsCache().getIcon("map_my_location", R.color.color_myloc_distance));
- myLocationButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (SampleLocationProvider.isLocationPermissionAvailable(MainActivity.this)) {
- goToLocation();
- } else {
- ActivityCompat.requestPermissions(MainActivity.this,
- new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
- PERMISSION_REQUEST_LOCATION_ON_BUTTON);
- }
- }
- });
-
- findViewById(R.id.map_zoom_in_button).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- setZoom(zoom + 1f);
- }
- });
-
- findViewById(R.id.map_zoom_out_button).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- setZoom(zoom - 1f);
- }
- });
-
- // Additional log sink
- fileLogSink = QIODeviceLogSink.createFileLogSink(app.getAbsoluteAppPath() + "/osmandcore.log");
- Logger.get().addLogSink(fileLogSink);
-
- // Get device display density factor
- DisplayMetrics displayMetrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
- displayDensityFactor = displayMetrics.densityDpi / 160.0f;
- referenceTileSize = (int) (256 * displayDensityFactor);
- rasterTileSize = Integer.highestOneBit(referenceTileSize - 1) * 2;
- Log.i(TAG, "displayDensityFactor = " + displayDensityFactor);
- Log.i(TAG, "referenceTileSize = " + referenceTileSize);
- Log.i(TAG, "rasterTileSize = " + rasterTileSize);
-
- Log.i(TAG, "Going to resolve default embedded style...");
- mapStylesCollection = new MapStylesCollection();
- mapStyle = mapStylesCollection.getResolvedStyleByName("default");
- if (mapStyle == null) {
- Log.e(TAG, "Failed to resolve style 'default'");
- System.exit(0);
- }
-
- Log.i(TAG, "Going to prepare OBFs collection");
- obfsCollection = new ObfsCollection();
- Log.i(TAG, "Will load OBFs from " + app.getAbsoluteAppPath());
- obfsCollection.addDirectory(app.getAbsoluteAppPath(), false);
-
- Log.i(TAG, "Going to prepare all resources for renderer");
- mapPresentationEnvironment = new MapPresentationEnvironment(
- mapStyle,
- displayDensityFactor,
- 1.0f,
- 1.0f,
- SampleApplication.LANGUAGE);
- //mapPresentationEnvironment->setSettings(configuration.styleSettings);
- mapPrimitiviser = new MapPrimitiviser(
- mapPresentationEnvironment);
- obfMapObjectsProvider = new ObfMapObjectsProvider(
- obfsCollection);
- mapPrimitivesProvider = new MapPrimitivesProvider(
- obfMapObjectsProvider,
- mapPrimitiviser,
- rasterTileSize);
- mapObjectsSymbolsProvider = new MapObjectsSymbolsProvider(
- mapPrimitivesProvider,
- rasterTileSize);
-
- mapView.setReferenceTileSizeOnScreenInPixels(referenceTileSize);
- mapView.addSymbolsProvider(mapObjectsSymbolsProvider);
-
- restoreMapState();
-
- mapLayerProvider0 = new MapRasterLayerProvider_Software(mapPrimitivesProvider);
- mapView.setMapLayerProvider(0, mapLayerProvider0);
-
- app.getIconsCache().setDisplayDensityFactor(displayDensityFactor);
-
- initMapMarkers();
-
- menu = new MapContextMenu();
- menu.setMainActivity(this);
-
- if (!InstallOsmandAppDialog.show(getSupportFragmentManager(), this)
- && externalStoragePermissionGranted) {
- checkMapsInstalled();
- }
- }
-
- private void checkMapsInstalled() {
- File mapsDir = new File(getMyApplication().getAbsoluteAppPath());
- boolean noMapsFound;
- if (mapsDir.exists()) {
- File[] maps = mapsDir.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String filename) {
- return filename.toLowerCase().endsWith(".obf");
- }
- });
- noMapsFound = maps == null || maps.length == 0;
- } else {
- noMapsFound = true;
- }
-
- if (noMapsFound) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.install_maps_title);
- builder.setMessage(R.string.install_maps_desc);
- builder.setNegativeButton(R.string.shared_string_cancel, null);
- builder.setPositiveButton(R.string.restart_app, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- SampleUtils.doRestart(MainActivity.this);
- }
- });
- builder.create().show();
- }
- }
-
- public void initMapMarkers() {
-
- // Create my location marker
- myMarkersCollection = new MapMarkersCollection();
- MapMarkerBuilder myLocMarkerBuilder = new MapMarkerBuilder();
- myLocMarkerBuilder.setMarkerId(MARKER_ID_MY_LOCATION);
- myLocMarkerBuilder.setIsAccuracyCircleSupported(true);
- myLocMarkerBuilder.setAccuracyCircleBaseColor(new FColorRGB(32/255f, 173/255f, 229/255f));
- myLocMarkerBuilder.setBaseOrder(-206000);
- myLocMarkerBuilder.setIsHidden(true);
- Bitmap myLocationBitmap = OsmandResources.getBitmap("map_pedestrian_location");
- if (myLocationBitmap != null) {
- myLocMarkerBuilder.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
- myLocationBitmap.getWidth(), myLocationBitmap.getHeight(),
- SampleUtils.getBitmapAsByteArray(myLocationBitmap)));
- }
- myLocationMarker = myLocMarkerBuilder.buildAndAddToCollection(myMarkersCollection);
-
- mapView.addSymbolsProvider(myMarkersCollection);
-
- // Create context pin marker
- contextPinMarkersCollection = new MapMarkersCollection();
- MapMarkerBuilder contextMarkerBuilder = new MapMarkerBuilder();
- contextMarkerBuilder.setMarkerId(MARKER_ID_CONTEXT_PIN);
- contextMarkerBuilder.setIsAccuracyCircleSupported(false);
- contextMarkerBuilder.setBaseOrder(-210000);
- contextMarkerBuilder.setIsHidden(true);
- Bitmap pinBitmap = OsmandResources.getBitmap("map_pin_context_menu");
- if (pinBitmap != null) {
- contextMarkerBuilder.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
- pinBitmap.getWidth(), pinBitmap.getHeight(),
- SampleUtils.getBitmapAsByteArray(pinBitmap)));
- contextMarkerBuilder.setPinIconVerticalAlignment(MapMarker.PinIconVerticalAlignment.Top);
- contextMarkerBuilder.setPinIconHorisontalAlignment(MapMarker.PinIconHorisontalAlignment.CenterHorizontal);
- }
- contextPinMarker = contextMarkerBuilder.buildAndAddToCollection(contextPinMarkersCollection);
-
- mapView.addSymbolsProvider(contextPinMarkersCollection);
- }
-
- public void showContextMarker(@NonNull LatLon location) {
- mapView.suspendSymbolsUpdate();
- PointI locationI = Utilities.convertLatLonTo31(new net.osmand.core.jni.LatLon(location.getLatitude(), location.getLongitude()));
- contextPinMarker.setPosition(locationI);
- contextPinMarker.setIsHidden(false);
- mapView.resumeSymbolsUpdate();
- }
-
- public void hideContextMarker() {
- mapView.suspendSymbolsUpdate();
- contextPinMarker.setIsHidden(true);
- mapView.resumeSymbolsUpdate();
- }
-
- public void goToLocation() {
- if (mapView != null) {
- SampleLocationProvider locationProvider = getMyApplication().getLocationProvider();
- if (locationProvider.getLastKnownLocation() != null) {
- net.osmand.Location lastKnownLocation = locationProvider.getLastKnownLocation();
- int fZoom = zoom < 15 ? 15 : (int)zoom;
- showOnMap(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), fZoom);
- //todo animation
- //AnimateDraggingMapThread thread = mapView.getAnimatedDraggingThread();
- //thread.startMoving(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), fZoom, false);
- }
- if (locationProvider.getLastKnownLocation() == null) {
- getMyApplication().showToastMessage(getMyApplication().getString("unknown_location"));
- }
- }
- }
-
- @Override
- public void updateLocation(Location location) {
- final SampleApplication app = getMyApplication();
- final Location lastKnownLocation = app.getLocationProvider().getLastKnownLocation();
- if (lastKnownLocation == null || mapView == null){
- app.runInUIThread(new Runnable() {
- @Override
- public void run() {
- if (!myLocationMarker.isHidden()) {
- mapView.suspendSymbolsUpdate();
- myLocationMarker.setIsHidden(true);
- mapView.resumeSymbolsUpdate();
- }
- }
- });
- return;
- }
-
- final PointI target31 = Utilities.convertLatLonTo31(
- new net.osmand.core.jni.LatLon(location.getLatitude(), location.getLongitude()));
-
- app.runInUIThread(new Runnable() {
- @Override
- public void run() {
- mapView.suspendSymbolsUpdate();
- myLocationMarker.setIsHidden(false);
- myLocationMarker.setPosition(target31);
- myLocationMarker.setIsAccuracyCircleVisible(true);
- myLocationMarker.setAccuracyCircleRadius(lastKnownLocation.getAccuracy());
- mapView.resumeSymbolsUpdate();
- }
- });
-
- if (menu != null) {
- menu.updateMyLocation(location);
- }
- }
-
- @Override
- public void updateCompassValue(float value) {
- if (menu != null) {
- menu.updateCompassValue(value);
- }
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- SampleApplication app = getMyApplication();
- app.getLocationProvider().checkIfLastKnownLocationIsValid();
- app.getLocationProvider().addLocationListener(this);
- if (SampleLocationProvider.isLocationPermissionAvailable(this)) {
- app.getLocationProvider().resumeAllUpdates();
- } else {
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
- PERMISSION_REQUEST_LOCATION_ON_RESUME);
- }
- mapView.handleOnResume();
- }
-
- @Override
- protected void onPause() {
- SampleApplication app = getMyApplication();
- app.getLocationProvider().pauseAllUpdates();
- app.getLocationProvider().removeLocationListener(this);
- saveMapState();
- mapView.handleOnPause();
- super.onPause();
- }
-
- @Override
- protected void onDestroy() {
- mapView.handleOnDestroy();
- super.onDestroy();
- }
-
- public AtlasMapRendererView getMapView() {
- return mapView;
- }
-
- public void showOnMap(LatLon latLon, int zoom) {
- if (latLon != null) {
- showOnMap(latLon.getLatitude(), latLon.getLongitude(), zoom);
- }
- }
-
- public void showOnMap(double latitude, double longitude, int zoom) {
- PointI target = Utilities.convertLatLonTo31(
- new net.osmand.core.jni.LatLon(latitude, longitude));
- setTarget(target);
- setZoom(zoom);
- }
-
- public void refreshMap() {
- }
-
- public MapContextMenu getContextMenu() {
- return menu;
- }
-
- public boolean showContextMenu(@NonNull LatLon latLon,
- @Nullable PointDescription pointDescription,
- @Nullable Object object) {
- if (menu.getMultiSelectionMenu().isVisible()) {
- menu.getMultiSelectionMenu().hide();
- }
- if (!getBox().containsLatLon(latLon)) {
- menu.setMapCenter(latLon);
- menu.setCenterMarker(true);
- }
- menu.show(latLon, pointDescription, object);
- return true;
- }
-
- private void showContextMenuForSelectedObjects(final LatLon latLon, final List