Fix #4815
This commit is contained in:
parent
803d009a54
commit
62517c4c81
3 changed files with 58 additions and 41 deletions
|
@ -6,6 +6,7 @@ import android.content.DialogInterface;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
|
@ -341,40 +342,39 @@ public class MainActivity extends AppCompatActivity implements SampleLocationLis
|
||||||
public void initMapMarkers() {
|
public void initMapMarkers() {
|
||||||
|
|
||||||
// Create my location marker
|
// Create my location marker
|
||||||
String locIconId = "map_pedestrian_location";
|
|
||||||
Drawable myLocationDrawable = OsmandResources.getDrawable(locIconId);
|
|
||||||
myMarkersCollection = new MapMarkersCollection();
|
myMarkersCollection = new MapMarkersCollection();
|
||||||
myLocationMarker = new MapMarkerBuilder()
|
MapMarkerBuilder myLocMarkerBuilder = new MapMarkerBuilder();
|
||||||
.setMarkerId(MARKER_ID_MY_LOCATION)
|
myLocMarkerBuilder.setMarkerId(MARKER_ID_MY_LOCATION);
|
||||||
.setIsAccuracyCircleSupported(true)
|
myLocMarkerBuilder.setIsAccuracyCircleSupported(true);
|
||||||
.setAccuracyCircleBaseColor(new FColorRGB(32/255f, 173/255f, 229/255f))
|
myLocMarkerBuilder.setAccuracyCircleBaseColor(new FColorRGB(32/255f, 173/255f, 229/255f));
|
||||||
.setBaseOrder(-206000)
|
myLocMarkerBuilder.setBaseOrder(-206000);
|
||||||
.setIsHidden(true)
|
myLocMarkerBuilder.setIsHidden(true);
|
||||||
//.addOnMapSurfaceIcon(SwigUtilities.getOnSurfaceIconKey(0), SwigUtilities.createSkBitmapARGB888With(
|
Bitmap myLocationBitmap = OsmandResources.getBitmap("map_pedestrian_location");
|
||||||
// myLocationDrawable.getIntrinsicWidth(), myLocationDrawable.getIntrinsicHeight(),
|
if (myLocationBitmap != null) {
|
||||||
// SampleUtils.getDrawableAsByteArray(myLocationDrawable)))
|
myLocMarkerBuilder.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
|
||||||
.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
|
myLocationBitmap.getWidth(), myLocationBitmap.getHeight(),
|
||||||
myLocationDrawable.getIntrinsicWidth(), myLocationDrawable.getIntrinsicHeight(),
|
SampleUtils.getBitmapAsByteArray(myLocationBitmap)));
|
||||||
SampleUtils.getBitmapAsByteArray(OsmandResources.getBitmap(locIconId))))
|
}
|
||||||
.buildAndAddToCollection(myMarkersCollection);
|
myLocationMarker = myLocMarkerBuilder.buildAndAddToCollection(myMarkersCollection);
|
||||||
|
|
||||||
mapView.addSymbolsProvider(myMarkersCollection);
|
mapView.addSymbolsProvider(myMarkersCollection);
|
||||||
|
|
||||||
// Create context pin marker
|
// Create context pin marker
|
||||||
String pinIconId = "map_pin_context_menu";
|
|
||||||
Drawable pinDrawable = OsmandResources.getDrawable(pinIconId);
|
|
||||||
contextPinMarkersCollection = new MapMarkersCollection();
|
contextPinMarkersCollection = new MapMarkersCollection();
|
||||||
contextPinMarker = new MapMarkerBuilder()
|
MapMarkerBuilder contextMarkerBuilder = new MapMarkerBuilder();
|
||||||
.setMarkerId(MARKER_ID_CONTEXT_PIN)
|
contextMarkerBuilder.setMarkerId(MARKER_ID_CONTEXT_PIN);
|
||||||
.setIsAccuracyCircleSupported(false)
|
contextMarkerBuilder.setIsAccuracyCircleSupported(false);
|
||||||
.setBaseOrder(-210000)
|
contextMarkerBuilder.setBaseOrder(-210000);
|
||||||
.setIsHidden(true)
|
contextMarkerBuilder.setIsHidden(true);
|
||||||
.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
|
Bitmap pinBitmap = OsmandResources.getBitmap("map_pin_context_menu");
|
||||||
pinDrawable.getIntrinsicWidth(), pinDrawable.getIntrinsicHeight(),
|
if (pinBitmap != null) {
|
||||||
SampleUtils.getBitmapAsByteArray(OsmandResources.getBitmap(pinIconId))))
|
contextMarkerBuilder.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
|
||||||
.setPinIconVerticalAlignment(MapMarker.PinIconVerticalAlignment.Top)
|
pinBitmap.getWidth(), pinBitmap.getHeight(),
|
||||||
.setPinIconHorisontalAlignment(MapMarker.PinIconHorisontalAlignment.CenterHorizontal)
|
SampleUtils.getBitmapAsByteArray(pinBitmap)));
|
||||||
.buildAndAddToCollection(contextPinMarkersCollection);
|
contextMarkerBuilder.setPinIconVerticalAlignment(MapMarker.PinIconVerticalAlignment.Top);
|
||||||
|
contextMarkerBuilder.setPinIconHorisontalAlignment(MapMarker.PinIconHorisontalAlignment.CenterHorizontal);
|
||||||
|
}
|
||||||
|
contextPinMarker = contextMarkerBuilder.buildAndAddToCollection(contextPinMarkersCollection);
|
||||||
|
|
||||||
mapView.addSymbolsProvider(contextPinMarkersCollection);
|
mapView.addSymbolsProvider(contextPinMarkersCollection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -52,15 +54,18 @@ public class OsmandResources {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Resources getOsmandResources() {
|
public static Resources getOsmandResources() {
|
||||||
return osmandResources;
|
return osmandResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getString(String id) {
|
@Nullable
|
||||||
|
public static String getString(@NonNull String id) {
|
||||||
return getStringInternal(resolveStringId(id));
|
return getStringInternal(resolveStringId(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getString(String id, Object... formatArgs) {
|
@Nullable
|
||||||
|
public static String getString(@NonNull String id, @NonNull Object... formatArgs) {
|
||||||
int resolvedId = resolveStringId(id);
|
int resolvedId = resolveStringId(id);
|
||||||
if (resolvedId != 0) {
|
if (resolvedId != 0) {
|
||||||
return osmandResources.getString(resolvedId, formatArgs);
|
return osmandResources.getString(resolvedId, formatArgs);
|
||||||
|
@ -68,25 +73,31 @@ public class OsmandResources {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Drawable getDrawable(String id) {
|
@Nullable
|
||||||
|
public static Drawable getDrawable(@NonNull String id) {
|
||||||
return getDrawableInternal(resolveDrawableId(id));
|
return getDrawableInternal(resolveDrawableId(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Drawable getBigDrawable(String id) {
|
@Nullable
|
||||||
|
public static Drawable getBigDrawable(@NonNull String id) {
|
||||||
return getDrawableInternal(resolveDrawableId(BIG_ICON_PREFIX + id));
|
return getDrawableInternal(resolveDrawableId(BIG_ICON_PREFIX + id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Drawable getDrawable(int id) {
|
public static Drawable getDrawable(int id) {
|
||||||
return getDrawableInternal(id);
|
return getDrawableInternal(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getBitmap(String id) {
|
@Nullable
|
||||||
if (osmandResources != null) {
|
public static Bitmap getBitmap(@NonNull String id) {
|
||||||
return BitmapFactory.decodeResource(osmandResources, resolveDrawableId(id));
|
int resId = resolveDrawableId(id);
|
||||||
|
if (osmandResources != null && resId != 0) {
|
||||||
|
return BitmapFactory.decodeResource(osmandResources, resId);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Drawable getDrawableNonCached(int id) {
|
public static Drawable getDrawableNonCached(int id) {
|
||||||
if (osmandResources != null && id != 0) {
|
if (osmandResources != null && id != 0) {
|
||||||
Drawable d = osmandResources.getDrawable(id);
|
Drawable d = osmandResources.getDrawable(id);
|
||||||
|
@ -99,14 +110,15 @@ public class OsmandResources {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDrawableId(String id) {
|
public static int getDrawableId(@NonNull String id) {
|
||||||
return resolveDrawableId(id);
|
return resolveDrawableId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getBigDrawableId(String id) {
|
public static int getBigDrawableId(@NonNull String id) {
|
||||||
return resolveDrawableId(BIG_ICON_PREFIX + id);
|
return resolveDrawableId(BIG_ICON_PREFIX + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private static Drawable getDrawableInternal(int resId) {
|
private static Drawable getDrawableInternal(int resId) {
|
||||||
if (osmandResources != null && resId != 0) {
|
if (osmandResources != null && resId != 0) {
|
||||||
long hash = getResIdHash(resId);
|
long hash = getResIdHash(resId);
|
||||||
|
@ -124,6 +136,7 @@ public class OsmandResources {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private static String getStringInternal(int resId) {
|
private static String getStringInternal(int resId) {
|
||||||
if (osmandResources != null && resId != 0) {
|
if (osmandResources != null && resId != 0) {
|
||||||
long hash = getResIdHash(resId);
|
long hash = getResIdHash(resId);
|
||||||
|
@ -137,7 +150,7 @@ public class OsmandResources {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int resolveStringId(String id) {
|
private static int resolveStringId(@NonNull String id) {
|
||||||
if (osmandResources != null) {
|
if (osmandResources != null) {
|
||||||
Integer resolvedId = stringIds.get(id);
|
Integer resolvedId = stringIds.get(id);
|
||||||
if (resolvedId == null) {
|
if (resolvedId == null) {
|
||||||
|
@ -149,7 +162,7 @@ public class OsmandResources {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int resolveDrawableId(String id) {
|
private static int resolveDrawableId(@NonNull String id) {
|
||||||
if (osmandResources != null) {
|
if (osmandResources != null) {
|
||||||
Integer resolvedId = drawableIds.get(id);
|
Integer resolvedId = drawableIds.get(id);
|
||||||
if (resolvedId == null) {
|
if (resolvedId == null) {
|
||||||
|
|
|
@ -10,6 +10,8 @@ import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
@ -189,7 +191,8 @@ public class SampleUtils {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getDrawableAsByteArray(Drawable drawable) {
|
@Nullable
|
||||||
|
public static byte[] getDrawableAsByteArray(@NonNull Drawable drawable) {
|
||||||
if (drawable instanceof BitmapDrawable) {
|
if (drawable instanceof BitmapDrawable) {
|
||||||
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
|
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
|
||||||
return getBitmapAsByteArray(bitmap);
|
return getBitmapAsByteArray(bitmap);
|
||||||
|
@ -197,7 +200,8 @@ public class SampleUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getBitmapAsByteArray(Bitmap bitmap) {
|
@NonNull
|
||||||
|
public static byte[] getBitmapAsByteArray(@NonNull Bitmap bitmap) {
|
||||||
int size = bitmap.getRowBytes() * bitmap.getHeight();
|
int size = bitmap.getRowBytes() * bitmap.getHeight();
|
||||||
ByteBuffer byteBuffer = ByteBuffer.allocate(size);
|
ByteBuffer byteBuffer = ByteBuffer.allocate(size);
|
||||||
bitmap.copyPixelsToBuffer(byteBuffer);
|
bitmap.copyPixelsToBuffer(byteBuffer);
|
||||||
|
|
Loading…
Reference in a new issue