Use vector icons for nearby-map markers (#786)

This commit is contained in:
Mikel 2017-07-22 02:01:08 +01:00 committed by Yusuke Matsubara
parent e022e3d089
commit e9d77a0716
5 changed files with 56 additions and 6 deletions

View file

@ -2,9 +2,10 @@ package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.preference.PreferenceManager;
import android.support.graphics.drawable.VectorDrawableCompat;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import java.util.ArrayList;
@ -18,6 +19,7 @@ import java.util.Map;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.utils.UiUtils;
import timber.log.Timber;
import static fr.free.nrw.commons.utils.LengthUtils.computeDistanceBetween;
@ -98,13 +100,15 @@ public class NearbyController {
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
Bitmap icon = UiUtils.getBitmap(
VectorDrawableCompat.create(
context.getResources(), R.drawable.ic_custom_map_marker, context.getTheme()
));
for (Place place: placeList) {
String distance = formatDistanceBetween(curLatLng, place.location);
place.setDistance(distance);
Icon icon = IconFactory.getInstance(context)
.fromResource(R.drawable.custom_map_marker);
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
nearbyBaseMarker.title(place.name);
nearbyBaseMarker.position(
@ -112,7 +116,8 @@ public class NearbyController {
place.location.getLatitude(),
place.location.getLongitude()));
nearbyBaseMarker.place(place);
nearbyBaseMarker.icon(icon);
nearbyBaseMarker.icon(IconFactory.getInstance(context)
.fromBitmap(icon));
baseMarkerOptions.add(nearbyBaseMarker);
}

View file

@ -0,0 +1,22 @@
package fr.free.nrw.commons.utils;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.support.graphics.drawable.VectorDrawableCompat;
public class UiUtils {
/**
* Draws a vectorial image onto a bitmap.
* @param vectorDrawable vectorial image
* @return bitmap representation of the vectorial image
*/
public static Bitmap getBitmap(VectorDrawableCompat vectorDrawable) {
Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
vectorDrawable.draw(canvas);
return bitmap;
}
}