|
@@ -1,11 +1,13 @@
|
1
|
1
|
package com.reactnativenavigation.utils;
|
2
|
2
|
|
3
|
3
|
import android.content.Context;
|
|
4
|
+import android.content.res.Resources;
|
4
|
5
|
import android.graphics.Bitmap;
|
5
|
6
|
import android.graphics.BitmapFactory;
|
6
|
7
|
import android.graphics.drawable.BitmapDrawable;
|
7
|
8
|
import android.graphics.drawable.Drawable;
|
8
|
9
|
import android.net.Uri;
|
|
10
|
+import android.util.DisplayMetrics;
|
9
|
11
|
|
10
|
12
|
import com.reactnativenavigation.BuildConfig;
|
11
|
13
|
|
|
@@ -19,6 +21,15 @@ public class IconUtils {
|
19
|
21
|
private static ResourceDrawableIdHelper sResDrawableIdHelper = new ResourceDrawableIdHelper();
|
20
|
22
|
|
21
|
23
|
public static Drawable getIcon(Context ctx, String iconSource) {
|
|
24
|
+ return getIcon(ctx, iconSource, -1);
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ /**
|
|
28
|
+ * @param iconSource Icon source. In release builds this would be a path in assets, In debug it's
|
|
29
|
+ * a url and the image needs to be decoded from input stream.
|
|
30
|
+ * @param dimensions The requested icon dimensions
|
|
31
|
+ */
|
|
32
|
+ public static Drawable getIcon(Context ctx, String iconSource, int dimensions) {
|
22
|
33
|
if (iconSource == null) {
|
23
|
34
|
return null;
|
24
|
35
|
}
|
|
@@ -32,7 +43,9 @@ public class IconUtils {
|
32
|
43
|
} else {
|
33
|
44
|
URL url = new URL(iconUri.toString());
|
34
|
45
|
Bitmap bitmap = BitmapFactory.decodeStream(url.openStream());
|
35
|
|
- icon = new BitmapDrawable(bitmap);
|
|
46
|
+ bitmap = dimensions > 0 ?
|
|
47
|
+ Bitmap.createScaledBitmap(bitmap, dimensions, dimensions, false) : bitmap;
|
|
48
|
+ icon = new BitmapDrawable(ctx.getResources(), bitmap);
|
36
|
49
|
}
|
37
|
50
|
return icon;
|
38
|
51
|
} catch (Exception e) {
|