diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2017-11-10 06:16:35 +0100 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2017-11-10 06:16:35 +0100 |
commit | 225fba8a0aad5ea52ff878443f58d65bb2221d74 (patch) | |
tree | 8fef9e5353ec33f2fc0cec378a77d7146f9c67d0 /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java | |
parent | 6b5afaab7611cc59c86f749fd9130edb512b4945 (diff) | |
parent | 91dabd01dfcd52dc40aa1c1d1db9d3f48f7abc97 (diff) | |
download | qtlocation-mapboxgl-225fba8a0aad5ea52ff878443f58d65bb2221d74.tar.gz |
Merge branch 'release-agua' into tvn-merge-release
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java index 14b18b00dc..1c0e439afc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java @@ -5,6 +5,7 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.Drawable; +import android.os.Build; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.v4.graphics.drawable.DrawableCompat; @@ -30,10 +31,15 @@ public class ColorUtils { */ @ColorInt public static int getPrimaryColor(@NonNull Context context) { - TypedValue typedValue = new TypedValue(); - Resources.Theme theme = context.getTheme(); - theme.resolveAttribute(R.attr.colorPrimary, typedValue, true); - return typedValue.data; + try { + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = context.getTheme(); + int id = context.getResources().getIdentifier("colorPrimary", "attrs", context.getPackageName()); + theme.resolveAttribute(id, typedValue, true); + return typedValue.data; + } catch (Exception exception) { + return getColorCompat(context, R.color.mapbox_blue); + } } /** @@ -44,10 +50,15 @@ public class ColorUtils { */ @ColorInt public static int getPrimaryDarkColor(@NonNull Context context) { - TypedValue typedValue = new TypedValue(); - Resources.Theme theme = context.getTheme(); - theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); - return typedValue.data; + try { + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = context.getTheme(); + int id = context.getResources().getIdentifier("colorPrimaryDark", "attrs", context.getPackageName()); + theme.resolveAttribute(id, typedValue, true); + return typedValue.data; + } catch (Exception exception) { + return getColorCompat(context, R.color.mapbox_blue); + } } /** @@ -58,10 +69,15 @@ public class ColorUtils { */ @ColorInt public static int getAccentColor(@NonNull Context context) { - TypedValue typedValue = new TypedValue(); - Resources.Theme theme = context.getTheme(); - theme.resolveAttribute(R.attr.colorAccent, typedValue, true); - return typedValue.data; + try { + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = context.getTheme(); + int id = context.getResources().getIdentifier("colorAccent", "attrs", context.getPackageName()); + theme.resolveAttribute(id, typedValue, true); + return typedValue.data; + } catch (Exception exception) { + return getColorCompat(context, R.color.mapbox_gray); + } } /** @@ -122,4 +138,12 @@ public class ColorUtils { throw new ConversionException("Not a valid rgb/rgba value"); } } + + private static int getColorCompat(Context context, int id) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + return context.getResources().getColor(id, context.getTheme()); + } else { + return context.getResources().getColor(id); + } + } } |