2 * Copyright (C) 2010 The Android Open Source 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.
17 package com.android.gallery3d.data;
19 import android.graphics.Bitmap;
20 import android.graphics.BitmapRegionDecoder;
22 import com.android.gallery3d.common.ApiHelper;
23 import com.android.gallery3d.ui.ScreenNail;
24 import com.android.gallery3d.util.ThreadPool.Job;
26 // MediaItem represents an image or a video item.
27 public abstract class MediaItem extends MediaObject {
28 // NOTE: These type numbers are stored in the image cache, so it should not
29 // not be changed without resetting the cache.
30 public static final int TYPE_THUMBNAIL = 1;
31 public static final int TYPE_MICROTHUMBNAIL = 2;
33 public static final int CACHED_IMAGE_QUALITY = 95;
35 public static final int IMAGE_READY = 0;
36 public static final int IMAGE_WAIT = 1;
37 public static final int IMAGE_ERROR = -1;
39 public static final String MIME_TYPE_JPEG = "image/jpeg";
41 private static final int BYTESBUFFE_POOL_SIZE = 4;
42 private static final int BYTESBUFFER_SIZE = 200 * 1024;
44 private static int sMicrothumbnailTargetSize = 200;
45 private static final BytesBufferPool sMicroThumbBufferPool =
46 new BytesBufferPool(BYTESBUFFE_POOL_SIZE, BYTESBUFFER_SIZE);
48 private static int sThumbnailTargetSize = 640;
50 // TODO: fix default value for latlng and change this.
51 public static final double INVALID_LATLNG = 0f;
53 public abstract Job<Bitmap> requestImage(int type);
54 public abstract Job<BitmapRegionDecoder> requestLargeImage();
56 public MediaItem(Path path, long version) {
60 public long getDateInMs() {
64 public String getName() {
68 public void getLatLong(double[] latLong) {
69 latLong[0] = INVALID_LATLNG;
70 latLong[1] = INVALID_LATLNG;
73 public String[] getTags() {
77 public Face[] getFaces() {
81 // The rotation of the full-resolution image. By default, it returns the value of
83 public int getFullImageRotation() {
87 public int getRotation() {
91 public long getSize() {
95 public abstract String getMimeType();
97 public String getFilePath() {
101 // Returns width and height of the media item.
102 // Returns 0, 0 if the information is not available.
103 public abstract int getWidth();
104 public abstract int getHeight();
106 // This is an alternative for requestImage() in PhotoPage. If this
107 // is implemented, you don't need to implement requestImage().
108 public ScreenNail getScreenNail() {
112 public static int getTargetSize(int type) {
115 return sThumbnailTargetSize;
116 case TYPE_MICROTHUMBNAIL:
117 return sMicrothumbnailTargetSize;
119 throw new RuntimeException(
120 "should only request thumb/microthumb from cache");
124 public static BytesBufferPool getBytesBufferPool() {
125 return sMicroThumbBufferPool;
128 public static void setThumbnailSizes(int size, int microSize) {
129 sThumbnailTargetSize = size;
130 if (sMicrothumbnailTargetSize != microSize) {
131 sMicrothumbnailTargetSize = microSize;