2 * Copyright (C) 2014 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.cyanogenmod.eleven.cache;
18 import android.content.Context;
19 import android.graphics.Bitmap;
20 import android.graphics.drawable.Drawable;
21 import android.graphics.drawable.TransitionDrawable;
22 import android.widget.ImageView;
23 import com.cyanogenmod.eleven.cache.ImageWorker.ImageType;
24 import com.cyanogenmod.eleven.utils.ImageUtils;
27 * The actual {@link android.os.AsyncTask} that will process the image.
29 public class SimpleBitmapWorkerTask extends BitmapWorkerTask<String, Void, TransitionDrawable> {
32 * Constructor of <code>BitmapWorkerTask</code>
34 * @param key the key of the image to store to
35 * @param imageView The {@link ImageView} to use.
36 * @param imageType The type of image URL to fetch for.
37 * @param fromDrawable what drawable to transition from
39 public SimpleBitmapWorkerTask(final String key, final ImageView imageView, final ImageType imageType,
40 final Drawable fromDrawable, final Context context) {
41 super(key, imageView, imageType, fromDrawable, context);
45 * Constructor of <code>BitmapWorkerTask</code>
47 * @param key the key of the image to store to
48 * @param imageView The {@link ImageView} to use.
49 * @param imageType The type of image URL to fetch for.
50 * @param fromDrawable what drawable to transition from
51 * @param scaleImgToView flag to scale the bitmap to the image view bounds
53 public SimpleBitmapWorkerTask(final String key, final ImageView imageView, final ImageType imageType,
54 final Drawable fromDrawable, final Context context, final boolean scaleImgToView) {
55 super(key, imageView, imageType, fromDrawable, context, scaleImgToView);
62 protected TransitionDrawable doInBackground(final String... params) {
67 final Bitmap bitmap = getBitmapInBackground(params);
68 if (mScaleImgToView) {
69 Bitmap scaledBitmap = ImageUtils.scaleBitmapForImageView(bitmap, getAttachedImageView());
70 return createImageTransitionDrawable(scaledBitmap);
73 return createImageTransitionDrawable(bitmap);
80 protected void onPostExecute(TransitionDrawable transitionDrawable) {
81 final ImageView imageView = getAttachedImageView();
82 if (transitionDrawable != null && imageView != null) {
83 imageView.setImageDrawable(transitionDrawable);
84 } else if (imageView != null) {
85 imageView.setImageDrawable(mFromDrawable);