This commit is contained in:
Alexander Sytnyk 2017-12-04 17:09:10 +02:00
parent 803d009a54
commit 62517c4c81
3 changed files with 58 additions and 41 deletions

View file

@ -6,6 +6,7 @@ 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;
@ -341,40 +342,39 @@ public class MainActivity extends AppCompatActivity implements SampleLocationLis
public void initMapMarkers() {
// Create my location marker
String locIconId = "map_pedestrian_location";
Drawable myLocationDrawable = OsmandResources.getDrawable(locIconId);
myMarkersCollection = new MapMarkersCollection();
myLocationMarker = new MapMarkerBuilder()
.setMarkerId(MARKER_ID_MY_LOCATION)
.setIsAccuracyCircleSupported(true)
.setAccuracyCircleBaseColor(new FColorRGB(32/255f, 173/255f, 229/255f))
.setBaseOrder(-206000)
.setIsHidden(true)
//.addOnMapSurfaceIcon(SwigUtilities.getOnSurfaceIconKey(0), SwigUtilities.createSkBitmapARGB888With(
// myLocationDrawable.getIntrinsicWidth(), myLocationDrawable.getIntrinsicHeight(),
// SampleUtils.getDrawableAsByteArray(myLocationDrawable)))
.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
myLocationDrawable.getIntrinsicWidth(), myLocationDrawable.getIntrinsicHeight(),
SampleUtils.getBitmapAsByteArray(OsmandResources.getBitmap(locIconId))))
.buildAndAddToCollection(myMarkersCollection);
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
String pinIconId = "map_pin_context_menu";
Drawable pinDrawable = OsmandResources.getDrawable(pinIconId);
contextPinMarkersCollection = new MapMarkersCollection();
contextPinMarker = new MapMarkerBuilder()
.setMarkerId(MARKER_ID_CONTEXT_PIN)
.setIsAccuracyCircleSupported(false)
.setBaseOrder(-210000)
.setIsHidden(true)
.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
pinDrawable.getIntrinsicWidth(), pinDrawable.getIntrinsicHeight(),
SampleUtils.getBitmapAsByteArray(OsmandResources.getBitmap(pinIconId))))
.setPinIconVerticalAlignment(MapMarker.PinIconVerticalAlignment.Top)
.setPinIconHorisontalAlignment(MapMarker.PinIconHorisontalAlignment.CenterHorizontal)
.buildAndAddToCollection(contextPinMarkersCollection);
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);
}

View file

@ -6,6 +6,8 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.DrawableCompat;
import java.util.HashMap;
@ -52,15 +54,18 @@ public class OsmandResources {
}
}
@Nullable
public static Resources getOsmandResources() {
return osmandResources;
}
public static String getString(String id) {
@Nullable
public static String getString(@NonNull String 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);
if (resolvedId != 0) {
return osmandResources.getString(resolvedId, formatArgs);
@ -68,25 +73,31 @@ public class OsmandResources {
return null;
}
public static Drawable getDrawable(String id) {
@Nullable
public static Drawable getDrawable(@NonNull String 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));
}
@Nullable
public static Drawable getDrawable(int id) {
return getDrawableInternal(id);
}
public static Bitmap getBitmap(String id) {
if (osmandResources != null) {
return BitmapFactory.decodeResource(osmandResources, resolveDrawableId(id));
@Nullable
public static Bitmap getBitmap(@NonNull String id) {
int resId = resolveDrawableId(id);
if (osmandResources != null && resId != 0) {
return BitmapFactory.decodeResource(osmandResources, resId);
}
return null;
}
@Nullable
public static Drawable getDrawableNonCached(int id) {
if (osmandResources != null && id != 0) {
Drawable d = osmandResources.getDrawable(id);
@ -99,14 +110,15 @@ public class OsmandResources {
return null;
}
public static int getDrawableId(String id) {
public static int getDrawableId(@NonNull String id) {
return resolveDrawableId(id);
}
public static int getBigDrawableId(String id) {
public static int getBigDrawableId(@NonNull String id) {
return resolveDrawableId(BIG_ICON_PREFIX + id);
}
@Nullable
private static Drawable getDrawableInternal(int resId) {
if (osmandResources != null && resId != 0) {
long hash = getResIdHash(resId);
@ -124,6 +136,7 @@ public class OsmandResources {
return null;
}
@Nullable
private static String getStringInternal(int resId) {
if (osmandResources != null && resId != 0) {
long hash = getResIdHash(resId);
@ -137,7 +150,7 @@ public class OsmandResources {
return null;
}
private static int resolveStringId(String id) {
private static int resolveStringId(@NonNull String id) {
if (osmandResources != null) {
Integer resolvedId = stringIds.get(id);
if (resolvedId == null) {
@ -149,7 +162,7 @@ public class OsmandResources {
return 0;
}
private static int resolveDrawableId(String id) {
private static int resolveDrawableId(@NonNull String id) {
if (osmandResources != null) {
Integer resolvedId = drawableIds.get(id);
if (resolvedId == null) {

View file

@ -10,6 +10,8 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Surface;
@ -189,7 +191,8 @@ public class SampleUtils {
return files;
}
public static byte[] getDrawableAsByteArray(Drawable drawable) {
@Nullable
public static byte[] getDrawableAsByteArray(@NonNull Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
return getBitmapAsByteArray(bitmap);
@ -197,7 +200,8 @@ public class SampleUtils {
return null;
}
public static byte[] getBitmapAsByteArray(Bitmap bitmap) {
@NonNull
public static byte[] getBitmapAsByteArray(@NonNull Bitmap bitmap) {
int size = bitmap.getRowBytes() * bitmap.getHeight();
ByteBuffer byteBuffer = ByteBuffer.allocate(size);
bitmap.copyPixelsToBuffer(byteBuffer);