diff options
author | Chulwoo Lee <chulwoo@google.com> | 2014-06-23 19:09:49 +0900 |
---|---|---|
committer | Chulwoo Lee <chulwoo@google.com> | 2014-06-23 20:39:18 +0900 |
commit | 321dc68fb0a8a0621d0f8751b66fb1cf0e86b7db (patch) | |
tree | 4fd47a1d059c404d82c023de0c49122d8f9d3829 | |
parent | c3ceb144c65e81f5a18005dc816004fe63a8d60c (diff) | |
download | TV-321dc68fb0a8a0621d0f8751b66fb1cf0e86b7db.tar.gz |
Decode sample bitmap
When the original size of poster art is too large, we don't need to
load the full image. Now, for external TV input 3, the dimension ofr
the poster art bitmap is 1920 x 1080 = 7.9M. But the card size in TV
is 320 x 180 = 220K.
BUG: 15737903
Change-Id: Ib509445d11e081f7762a1f3617935e0c48f0b4c3
-rw-r--r-- | res/values/dimens.xml | 9 | ||||
-rw-r--r-- | src/com/android/tv/notification/NotificationService.java | 9 | ||||
-rw-r--r-- | src/com/android/tv/ui/ChannelTileView.java | 3 | ||||
-rw-r--r-- | src/com/android/tv/util/BitmapUtils.java | 40 |
4 files changed, 55 insertions, 6 deletions
diff --git a/res/values/dimens.xml b/res/values/dimens.xml index ab8784c4..c878f427 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -89,10 +89,13 @@ <dimen name="channel_banner_small_text_size">14sp</dimen> <dimen name="channel_banner_track_meta_text_size">8sp</dimen> - <!-- Recommendation cards in LeanbackLauncher dimensions --> + <!-- Recommendation cards in LeanbackLauncher dimensions + These values should be synchnorized with + //vendor/unbundled_google/packages/LeanbackLauncher/res/values/dimens.xml --> <dimen name="notif_card_img_height">176dp</dimen> - <dimen name="notif_card_img_min_width">120dp</dimen> - <dimen name="notif_card_img_max_width">250dp</dimen> + <dimen name="notif_card_img_min_width">117dp</dimen> + <dimen name="notif_card_img_max_width">235dp</dimen> + <dimen name="notif_ch_logo_max_width">64dp</dimen> <dimen name="notif_ch_logo_max_height">44dp</dimen> <dimen name="notif_ch_logo_padding_left">12dp</dimen> diff --git a/src/com/android/tv/notification/NotificationService.java b/src/com/android/tv/notification/NotificationService.java index 84fe0a41..967bd4d8 100644 --- a/src/com/android/tv/notification/NotificationService.java +++ b/src/com/android/tv/notification/NotificationService.java @@ -87,6 +87,9 @@ public class NotificationService extends Service { private final HandlerThread mHandlerThread; private final Handler mHandler; + private final float mNotificationCardWidth; + private final float mNotificationCardHeight; + public NotificationService() { mHandlerThread = new HandlerThread("tv notification"); mHandlerThread.start(); @@ -119,6 +122,8 @@ public class NotificationService extends Service { } } }; + mNotificationCardWidth = getResources().getDimension(R.dimen.notif_card_img_max_width); + mNotificationCardHeight = getResources().getDimension(R.dimen.notif_card_img_height); } @Override @@ -225,7 +230,9 @@ public class NotificationService extends Service { if (is == null) { return false; } - Bitmap posterArtBitmap = BitmapFactory.decodeStream(is); + // We doesn't trust TIS to provide us with proper sized image + Bitmap posterArtBitmap = BitmapUtils.decodeSampledBitmapFromStream(is, + (int) mNotificationCardWidth, (int) mNotificationCardHeight); try { is.close(); } catch (IOException e) { diff --git a/src/com/android/tv/ui/ChannelTileView.java b/src/com/android/tv/ui/ChannelTileView.java index 4d8ef997..95773cae 100644 --- a/src/com/android/tv/ui/ChannelTileView.java +++ b/src/com/android/tv/ui/ChannelTileView.java @@ -167,7 +167,8 @@ public class ChannelTileView extends ShadowContainer InputStream is = null; try { is = getContext().getContentResolver().openInputStream(Uri.parse(posterArtUri)); - bm = BitmapFactory.decodeStream(is); + bm = BitmapUtils.decodeSampledBitmapFromStream(is, (int) mPosterArtWidth, + (int) mPosterArtHeight); } catch (IOException ie) { // Ignore exception } finally { diff --git a/src/com/android/tv/util/BitmapUtils.java b/src/com/android/tv/util/BitmapUtils.java index e866d850..528fc02f 100644 --- a/src/com/android/tv/util/BitmapUtils.java +++ b/src/com/android/tv/util/BitmapUtils.java @@ -17,15 +17,17 @@ package com.android.tv.util; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; +import java.io.InputStream; + public class BitmapUtils { private BitmapUtils() { /* cannot be instantiated */ } @@ -67,4 +69,40 @@ public class BitmapUtils { canvas.drawBitmap(bm, null, rect, null); return result; } + + /* + * Decode large sized bitmap into required size. + */ + public static Bitmap decodeSampledBitmapFromStream(InputStream is, int reqWidth, + int reqHeight) { + // First decode with inJustDecodeBounds=true to check dimensions + final BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeStream(is, null, options); + + // Calculate inSampleSize + options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); + + // Decode bitmap with inSampleSize set + options.inJustDecodeBounds = false; + return BitmapFactory.decodeStream(is, null, options); + } + + private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, + int reqHeight) { + // Raw height and width of image + int width = options.outWidth; + int height = options.outHeight; + int inSampleSize = 1; + + // Calculate the largest inSampleSize value that is a power of 2 and keeps either + // height and width larger than the requested height and width. + while (width > reqWidth || height > reqHeight) { + width >>= 1; + height >>= 1; + inSampleSize <<= 1; + } + + return inSampleSize; + } }
\ No newline at end of file |