Skip to content

Commit e9d77a0

Browse files
akaitawhym
authored andcommitted
Use vector icons for nearby-map markers (#786)
1 parent e022e3d commit e9d77a0

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

app/src/androidTest/java/fr/free/nrw/commons/NearbyControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class NearbyControllerTest {
2525

2626
@Before
2727
public void setup() {
28-
instrumentationContext = InstrumentationRegistry.getContext();
28+
instrumentationContext = InstrumentationRegistry.getTargetContext();
2929
}
3030

3131
@Test public void testNullAttractions() {

app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import android.content.Context;
44
import android.content.SharedPreferences;
5+
import android.graphics.Bitmap;
56
import android.preference.PreferenceManager;
7+
import android.support.graphics.drawable.VectorDrawableCompat;
68

7-
import com.mapbox.mapboxsdk.annotations.Icon;
89
import com.mapbox.mapboxsdk.annotations.IconFactory;
910

1011
import java.util.ArrayList;
@@ -18,6 +19,7 @@
1819
import fr.free.nrw.commons.CommonsApplication;
1920
import fr.free.nrw.commons.R;
2021
import fr.free.nrw.commons.location.LatLng;
22+
import fr.free.nrw.commons.utils.UiUtils;
2123
import timber.log.Timber;
2224

2325
import static fr.free.nrw.commons.utils.LengthUtils.computeDistanceBetween;
@@ -98,21 +100,24 @@ public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOpti
98100

99101
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
100102

103+
Bitmap icon = UiUtils.getBitmap(
104+
VectorDrawableCompat.create(
105+
context.getResources(), R.drawable.ic_custom_map_marker, context.getTheme()
106+
));
107+
101108
for (Place place: placeList) {
102109
String distance = formatDistanceBetween(curLatLng, place.location);
103110
place.setDistance(distance);
104111

105-
Icon icon = IconFactory.getInstance(context)
106-
.fromResource(R.drawable.custom_map_marker);
107-
108112
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
109113
nearbyBaseMarker.title(place.name);
110114
nearbyBaseMarker.position(
111115
new com.mapbox.mapboxsdk.geometry.LatLng(
112116
place.location.getLatitude(),
113117
place.location.getLongitude()));
114118
nearbyBaseMarker.place(place);
115-
nearbyBaseMarker.icon(icon);
119+
nearbyBaseMarker.icon(IconFactory.getInstance(context)
120+
.fromBitmap(icon));
116121

117122
baseMarkerOptions.add(nearbyBaseMarker);
118123
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package fr.free.nrw.commons.utils;
2+
3+
import android.graphics.Bitmap;
4+
import android.graphics.Canvas;
5+
import android.support.graphics.drawable.VectorDrawableCompat;
6+
7+
public class UiUtils {
8+
9+
/**
10+
* Draws a vectorial image onto a bitmap.
11+
* @param vectorDrawable vectorial image
12+
* @return bitmap representation of the vectorial image
13+
*/
14+
public static Bitmap getBitmap(VectorDrawableCompat vectorDrawable) {
15+
Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
16+
vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
17+
Canvas canvas = new Canvas(bitmap);
18+
vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
19+
vectorDrawable.draw(canvas);
20+
return bitmap;
21+
}
22+
}
-993 Bytes
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="28dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="28.0">
6+
<path
7+
android:fillAlpha="0.1"
8+
android:fillColor="#000000"
9+
android:pathData="M6.072,22.223a6.031,3.672 0,1 0,12.062 0a6.031,3.672 0,1 0,-12.062 0z"
10+
android:strokeWidth="1" />
11+
<path
12+
android:fillAlpha="1"
13+
android:fillColor="#f84d4d"
14+
android:pathData="M11.575,11.62C10.689,11.462 9.902,10.759 9.625,9.878 9.553,9.65 9.535,9.499 9.538,9.14c0.004,-0.397 0.019,-0.492 0.13,-0.787 0.236,-0.631 0.646,-1.099 1.212,-1.382 0.386,-0.193 0.709,-0.272 1.116,-0.272 0.676,0 1.263,0.247 1.744,0.734 0.355,0.359 0.541,0.682 0.657,1.136 0.327,1.278 -0.442,2.611 -1.723,2.987 -0.282,0.083 -0.817,0.114 -1.099,0.063z"
15+
android:strokeWidth="1" />
16+
<path
17+
android:fillAlpha="1"
18+
android:fillColor="#006699"
19+
android:pathData="M11.617,21.707C10.518,20.424 9.338,18.864 8.395,17.449 6.524,14.641 5.455,12.305 5.102,10.255 5.014,9.744 5.006,8.628 5.088,8.137 5.348,6.561 6.043,5.221 7.158,4.148 9.148,2.231 12.016,1.668 14.593,2.688c2.043,0.809 3.607,2.581 4.162,4.719 0.174,0.67 0.204,0.933 0.203,1.761 -0.001,0.81 -0.035,1.098 -0.22,1.857 -0.614,2.524 -2.571,5.977 -5.383,9.501 -0.645,0.809 -1.321,1.61 -1.358,1.61 -0.008,0 -0.179,-0.193 -0.381,-0.428zM12.617,11.603c0.783,-0.188 1.457,-0.795 1.738,-1.564 0.516,-1.415 -0.317,-2.962 -1.783,-3.312 -0.216,-0.052 -0.317,-0.059 -0.661,-0.047 -0.354,0.012 -0.441,0.025 -0.682,0.104 -0.673,0.221 -1.205,0.695 -1.506,1.344 -0.176,0.38 -0.218,0.584 -0.217,1.054 0.001,0.324 0.014,0.452 0.064,0.635 0.266,0.97 1.077,1.689 2.079,1.844 0.243,0.038 0.68,0.012 0.968,-0.057z"
20+
android:strokeAlpha="1"
21+
android:strokeColor="#003b59"
22+
android:strokeWidth="1" />
23+
</vector>

0 commit comments

Comments
 (0)