summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRaj Yengisetty <raj@cyngn.com>2016-01-28 15:28:59 -0800
committerRichard MacGregor <rmacgregor@cyngn.com>2016-04-08 10:42:50 -0700
commit969c8f4ef904a235e0760ed6c9628910a731ca77 (patch)
tree957278a99ec15f681d7b760743d6f2fea9e08d4f /src
parent22fef9c20c52c127c95a50e357324ed921332647 (diff)
downloadandroid_packages_apps_PhoneCommon-969c8f4ef904a235e0760ed6c9628910a731ca77.tar.gz
android_packages_apps_PhoneCommon-969c8f4ef904a235e0760ed6c9628910a731ca77.tar.bz2
android_packages_apps_PhoneCommon-969c8f4ef904a235e0760ed6c9628910a731ca77.zip
InCall: clean up logs and add ImageUtils
Change-Id: I235715af94f96f9ce8bde01643d1c1ed140a8ef3
Diffstat (limited to 'src')
-rw-r--r--src/com/android/phone/common/util/ImageUtils.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/com/android/phone/common/util/ImageUtils.java b/src/com/android/phone/common/util/ImageUtils.java
new file mode 100644
index 0000000..533e080
--- /dev/null
+++ b/src/com/android/phone/common/util/ImageUtils.java
@@ -0,0 +1,36 @@
+package com.android.phone.common.util;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+
+/**
+ * Utility class around Image loading and Bitmap effects
+ */
+public class ImageUtils {
+
+ /**
+ * Used to convert a drawable into a bitmap.
+ *
+ * Drawables that don't have intrinsic dimensions are excluded from this conversion. This
+ * includes drawables such as ColorDrawables
+ */
+ public static Bitmap drawableToBitmap (Drawable drawable) {
+ if (drawable instanceof BitmapDrawable) {
+ return ((BitmapDrawable)drawable).getBitmap();
+ }
+
+ if (drawable.getIntrinsicHeight() <= 0 || drawable.getIntrinsicWidth() <= 0) {
+ return null;
+ }
+
+ Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
+ drawable.getMinimumHeight(), Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bitmap);
+ drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
+ drawable.draw(canvas);
+
+ return bitmap;
+ }
+}