Bug 1189585 - Add DrawableUtil class. r=sebastian
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 30 Jul 2015 19:16:41 -0700
changeset 255631 431678640625918feadb3eb599e2973257816260
parent 255630 0f05c264c1dcb33210c449dd86255ba262a9c401
child 255632 61e8be8a63d18490809565d31ab8e6e33c70a309
push id14350
push usermichael.l.comella@gmail.com
push dateFri, 31 Jul 2015 19:00:23 +0000
treeherderfx-team@61e8be8a63d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1189585
milestone42.0a1
Bug 1189585 - Add DrawableUtil class. r=sebastian This includes a method to tint drawables.
mobile/android/base/moz.build
mobile/android/base/util/DrawableUtil.java
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -71,16 +71,17 @@ mgjar.extra_jars += [
 mgjar.javac_flags += ['-Xlint:all']
 
 gujar = add_java_jar('gecko-util')
 gujar.sources += [
     'util/ActivityResultHandler.java',
     'util/ActivityResultHandlerMap.java',
     'util/ActivityUtils.java',
     'util/Clipboard.java',
+    'util/DrawableUtil.java',
     'util/EventCallback.java',
     'util/FileUtils.java',
     'util/FloatUtils.java',
     'util/GamepadUtils.java',
     'util/GeckoBackgroundThread.java',
     'util/GeckoEventListener.java',
     'util/GeckoJarReader.java',
     'util/GeckoRequest.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/util/DrawableUtil.java
@@ -0,0 +1,21 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.util;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.support.v4.content.ContextCompat;
+import android.support.v4.graphics.drawable.DrawableCompat;
+
+public class DrawableUtil {
+
+    public static Drawable tintDrawable(final Context context, final int drawableID, final int colorID) {
+        final Drawable icon = DrawableCompat.wrap(
+                ContextCompat.getDrawable(context, drawableID).mutate());
+        DrawableCompat.setTint(icon, context.getResources().getColor(colorID));
+        return icon;
+    }
+}