Use bitmap instead of drawable

This commit is contained in:
Alexander Sytnyk 2017-12-04 14:39:46 +02:00
parent 40b743aeb0
commit 803d009a54
2 changed files with 15 additions and 4 deletions

View file

@ -341,7 +341,8 @@ public class MainActivity extends AppCompatActivity implements SampleLocationLis
public void initMapMarkers() {
// Create my location marker
Drawable myLocationDrawable = OsmandResources.getDrawable("map_pedestrian_location");
String locIconId = "map_pedestrian_location";
Drawable myLocationDrawable = OsmandResources.getDrawable(locIconId);
myMarkersCollection = new MapMarkersCollection();
myLocationMarker = new MapMarkerBuilder()
.setMarkerId(MARKER_ID_MY_LOCATION)
@ -354,13 +355,14 @@ public class MainActivity extends AppCompatActivity implements SampleLocationLis
// SampleUtils.getDrawableAsByteArray(myLocationDrawable)))
.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
myLocationDrawable.getIntrinsicWidth(), myLocationDrawable.getIntrinsicHeight(),
SampleUtils.getDrawableAsByteArray(myLocationDrawable)))
SampleUtils.getBitmapAsByteArray(OsmandResources.getBitmap(locIconId))))
.buildAndAddToCollection(myMarkersCollection);
mapView.addSymbolsProvider(myMarkersCollection);
// Create context pin marker
Drawable pinDrawable = OsmandResources.getDrawable("map_pin_context_menu");
String pinIconId = "map_pin_context_menu";
Drawable pinDrawable = OsmandResources.getDrawable(pinIconId);
contextPinMarkersCollection = new MapMarkersCollection();
contextPinMarker = new MapMarkerBuilder()
.setMarkerId(MARKER_ID_CONTEXT_PIN)
@ -369,7 +371,7 @@ public class MainActivity extends AppCompatActivity implements SampleLocationLis
.setIsHidden(true)
.setPinIcon(SwigUtilities.createSkBitmapARGB888With(
pinDrawable.getIntrinsicWidth(), pinDrawable.getIntrinsicHeight(),
SampleUtils.getDrawableAsByteArray(pinDrawable)))
SampleUtils.getBitmapAsByteArray(OsmandResources.getBitmap(pinIconId))))
.setPinIconVerticalAlignment(MapMarker.PinIconVerticalAlignment.Top)
.setPinIconHorisontalAlignment(MapMarker.PinIconHorisontalAlignment.CenterHorizontal)
.buildAndAddToCollection(contextPinMarkersCollection);

View file

@ -3,6 +3,8 @@ package net.osmand.core.samples.android.sample1;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.drawable.DrawableCompat;
@ -78,6 +80,13 @@ public class OsmandResources {
return getDrawableInternal(id);
}
public static Bitmap getBitmap(String id) {
if (osmandResources != null) {
return BitmapFactory.decodeResource(osmandResources, resolveDrawableId(id));
}
return null;
}
public static Drawable getDrawableNonCached(int id) {
if (osmandResources != null && id != 0) {
Drawable d = osmandResources.getDrawable(id);