1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.gallery3d.data; 18 19 import android.graphics.Bitmap; 20 import android.graphics.BitmapFactory; 21 import android.graphics.BitmapRegionDecoder; 22 import android.net.Uri; 23 24 import com.android.gallery3d.app.GalleryApp; 25 import com.android.gallery3d.common.BitmapUtils; 26 import com.android.gallery3d.common.Utils; 27 import com.android.gallery3d.util.ThreadPool.Job; 28 import com.android.gallery3d.util.ThreadPool.JobContext; 29 30 public class ActionImage extends MediaItem { 31 @SuppressWarnings("unused") 32 private static final String TAG = "ActionImage"; 33 private GalleryApp mApplication; 34 private int mResourceId; 35 36 public ActionImage(Path path, GalleryApp application, int resourceId) { 37 super(path, nextVersionNumber()); 38 mApplication = Utils.checkNotNull(application); 39 mResourceId = resourceId; 40 } 41 42 @Override 43 public Job<Bitmap> requestImage(int type) { 44 return new BitmapJob(type); 45 } 46 47 @Override 48 public Job<BitmapRegionDecoder> requestLargeImage() { 49 return null; 50 } 51 52 private class BitmapJob implements Job<Bitmap> { 53 private int mType; 54 55 protected BitmapJob(int type) { 56 mType = type; 57 } 58 59 @Override 60 public Bitmap run(JobContext jc) { 61 int targetSize = MediaItem.getTargetSize(mType); 62 Bitmap bitmap = BitmapFactory.decodeResource(mApplication.getResources(), 63 mResourceId); 64 65 if (mType == MediaItem.TYPE_MICROTHUMBNAIL) { 66 bitmap = BitmapUtils.resizeAndCropCenter(bitmap, targetSize, true); 67 } else { 68 bitmap = BitmapUtils.resizeDownBySideLength(bitmap, targetSize, true); 69 } 70 return bitmap; 71 } 72 } 73 74 @Override 75 public int getSupportedOperations() { 76 return SUPPORT_ACTION; 77 } 78 79 @Override 80 public int getMediaType() { 81 return MEDIA_TYPE_UNKNOWN; 82 } 83 84 @Override 85 public Uri getContentUri() { 86 return null; 87 } 88 89 @Override 90 public String getMimeType() { 91 return ""; 92 } 93 94 @Override 95 public int getWidth() { 96 return 0; 97 } 98 99 @Override 100 public int getHeight() { 101 return 0; 102 } 103 } 104