diff options
Diffstat (limited to 'src/com/android/tv/util/images/ImageLoader.java')
-rw-r--r-- | src/com/android/tv/util/images/ImageLoader.java | 80 |
1 files changed, 17 insertions, 63 deletions
diff --git a/src/com/android/tv/util/images/ImageLoader.java b/src/com/android/tv/util/images/ImageLoader.java index e026f26a..d2ad0eb1 100644 --- a/src/com/android/tv/util/images/ImageLoader.java +++ b/src/com/android/tv/util/images/ImageLoader.java @@ -29,13 +29,9 @@ import android.support.annotation.UiThread; import android.support.annotation.WorkerThread; import android.util.ArraySet; import android.util.Log; - -import androidx.tvprovider.media.tv.TvContractCompat.PreviewPrograms; - import com.android.tv.R; import com.android.tv.common.concurrent.NamedThreadFactory; import com.android.tv.util.images.BitmapUtils.ScaledBitmapInfo; - import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; @@ -168,8 +164,8 @@ public final class ImageLoader { * @return {@code true} if the load is complete and the callback is executed. */ @UiThread - public static <T> boolean loadBitmap( - Context context, String uriString, ImageLoaderCallback<T> callback) { + public static boolean loadBitmap( + Context context, String uriString, ImageLoaderCallback callback) { return loadBitmap(context, uriString, Integer.MAX_VALUE, Integer.MAX_VALUE, callback); } @@ -182,12 +178,12 @@ public final class ImageLoader { * @return {@code true} if the load is complete and the callback is executed. */ @UiThread - public static <T> boolean loadBitmap( + public static boolean loadBitmap( Context context, String uriString, int maxWidth, int maxHeight, - ImageLoaderCallback<T> callback) { + ImageLoaderCallback callback) { if (DEBUG) { Log.d(TAG, "loadBitmap() " + uriString); } @@ -195,12 +191,12 @@ public final class ImageLoader { context, uriString, maxWidth, maxHeight, callback, IMAGE_THREAD_POOL_EXECUTOR); } - private static <T> boolean doLoadBitmap( + private static boolean doLoadBitmap( Context context, String uriString, int maxWidth, int maxHeight, - ImageLoaderCallback<T> callback, + ImageLoaderCallback callback, Executor executor) { // Check the cache before creating a Task. The cache will be checked again in doLoadBitmap // but checking a cache is much cheaper than creating an new task. @@ -226,8 +222,7 @@ public final class ImageLoader { * @return {@code true} if the load is complete and the callback is executed. */ @UiThread - public static <T> boolean loadBitmap( - ImageLoaderCallback<T> callback, LoadBitmapTask<T> loadBitmapTask) { + public static boolean loadBitmap(ImageLoaderCallback callback, LoadBitmapTask loadBitmapTask) { if (DEBUG) { Log.d(TAG, "loadBitmap() " + loadBitmapTask); } @@ -236,8 +231,8 @@ public final class ImageLoader { /** @return {@code true} if the load is complete and the callback is executed. */ @UiThread - private static <T> boolean doLoadBitmap( - ImageLoaderCallback<T> callback, Executor executor, LoadBitmapTask<T> loadBitmapTask) { + private static boolean doLoadBitmap( + ImageLoaderCallback callback, Executor executor, LoadBitmapTask loadBitmapTask) { ScaledBitmapInfo bitmapInfo = loadBitmapTask.getFromCache(); boolean needToReload = loadBitmapTask.isReloadNeeded(); if (bitmapInfo != null && !needToReload) { @@ -272,11 +267,11 @@ public final class ImageLoader { * * <p>Implement {@link #doGetBitmapInBackground} to do the actual loading. */ - public abstract static class LoadBitmapTask<T> extends AsyncTask<Void, Void, ScaledBitmapInfo> { + public abstract static class LoadBitmapTask extends AsyncTask<Void, Void, ScaledBitmapInfo> { protected final Context mAppContext; protected final int mMaxWidth; protected final int mMaxHeight; - private final Set<ImageLoaderCallback<T>> mCallbacks = new ArraySet<>(); + private final Set<ImageLoaderCallback> mCallbacks = new ArraySet<>(); private final ImageCache mImageCache; private final String mKey; @@ -358,7 +353,7 @@ public final class ImageLoader { public final void onPostExecute(ScaledBitmapInfo scaledBitmapInfo) { if (DEBUG) Log.d(ImageLoader.TAG, "Bitmap is loaded " + mKey); - for (ImageLoader.ImageLoaderCallback<T> callback : mCallbacks) { + for (ImageLoader.ImageLoaderCallback callback : mCallbacks) { callback.onBitmapLoaded(scaledBitmapInfo == null ? null : scaledBitmapInfo.bitmap); } ImageLoader.sPendingListMap.remove(mKey); @@ -381,7 +376,7 @@ public final class ImageLoader { } } - private static final class LoadBitmapFromUriTask<T> extends LoadBitmapTask<T> { + private static final class LoadBitmapFromUriTask extends LoadBitmapTask { private LoadBitmapFromUriTask( Context context, ImageCache imageCache, @@ -400,7 +395,7 @@ public final class ImageLoader { } /** Loads and caches the logo for a given {@link TvInputInfo} */ - public static final class LoadTvInputLogoTask<T> extends LoadBitmapTask<T> { + public static final class LoadTvInputLogoTask extends LoadBitmapTask { private final TvInputInfo mInfo; public LoadTvInputLogoTask(Context context, ImageCache cache, TvInputInfo info) { @@ -419,10 +414,9 @@ public final class ImageLoader { @Override public ScaledBitmapInfo doGetBitmapInBackground() { Drawable drawable = mInfo.loadIcon(mAppContext); - Bitmap bm = - drawable instanceof BitmapDrawable - ? ((BitmapDrawable) drawable).getBitmap() - : BitmapUtils.drawableToBitmap(drawable); + Bitmap bm = drawable instanceof BitmapDrawable + ? ((BitmapDrawable) drawable).getBitmap() + : BitmapUtils.drawableToBitmap(drawable); return bm == null ? null : BitmapUtils.createScaledBitmapInfo(getKey(), bm, mMaxWidth, mMaxHeight); @@ -434,46 +428,6 @@ public final class ImageLoader { } } - /** - * Calculates Aspect Ratio of Poster Art from Uri. - * - * <p><b>Note</b> the function will check the cache before loading the bitmap - * - * @return the Aspect Ratio of the Poster Art. - */ - public static int getAspectRatioFromPosterArtUri(Context context, String uriString) { - // Check the cache before loading the bitmap. - ImageCache imageCache = ImageCache.getInstance(); - ScaledBitmapInfo bitmapInfo = imageCache.get(uriString); - int bitmapWidth; - int bitmapHeight; - float bitmapAspectRatio; - int aspectRatio; - if (bitmapInfo == null) { - bitmapInfo = - BitmapUtils.decodeSampledBitmapFromUriString( - context, uriString, Integer.MAX_VALUE, Integer.MAX_VALUE); - } - bitmapWidth = bitmapInfo.bitmap.getWidth(); - bitmapHeight = bitmapInfo.bitmap.getHeight(); - bitmapAspectRatio = (float) bitmapWidth / bitmapHeight; - /* Assign nearest aspect ratio from the defined values in Preview Programs */ - if (bitmapAspectRatio > 0 && bitmapAspectRatio <= 0.6803) { - aspectRatio = PreviewPrograms.ASPECT_RATIO_2_3; - } else if (bitmapAspectRatio > 0.6803 && bitmapAspectRatio <= 0.8469) { - aspectRatio = PreviewPrograms.ASPECT_RATIO_MOVIE_POSTER; - } else if (bitmapAspectRatio > 0.8469 && bitmapAspectRatio <= 1.1667) { - aspectRatio = PreviewPrograms.ASPECT_RATIO_1_1; - } else if (bitmapAspectRatio > 1.1667 && bitmapAspectRatio <= 1.4167) { - aspectRatio = PreviewPrograms.ASPECT_RATIO_4_3; - } else if (bitmapAspectRatio > 1.4167 && bitmapAspectRatio <= 1.6389) { - aspectRatio = PreviewPrograms.ASPECT_RATIO_3_2; - } else { - aspectRatio = PreviewPrograms.ASPECT_RATIO_16_9; - } - return aspectRatio; - } - private static synchronized Handler getMainHandler() { if (sMainHandler == null) { sMainHandler = new Handler(Looper.getMainLooper()); |