Home | History | Annotate | Download | only in data
      1 /*
      2  * Copyright (C) 2010 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.BitmapRegionDecoder;
     21 
     22 import com.android.gallery3d.ui.ScreenNail;
     23 import com.android.gallery3d.util.ThreadPool.Job;
     24 
     25 // MediaItem represents an image or a video item.
     26 public abstract class MediaItem extends MediaObject {
     27     // NOTE: These type numbers are stored in the image cache, so it should not
     28     // not be changed without resetting the cache.
     29     public static final int TYPE_THUMBNAIL = 1;
     30     public static final int TYPE_MICROTHUMBNAIL = 2;
     31 
     32     public static final int THUMBNAIL_TARGET_SIZE = 640;
     33     public static final int MICROTHUMBNAIL_TARGET_SIZE = 200;
     34     public static final int CACHED_IMAGE_QUALITY = 95;
     35 
     36     public static final int IMAGE_READY = 0;
     37     public static final int IMAGE_WAIT = 1;
     38     public static final int IMAGE_ERROR = -1;
     39 
     40     public static final String MIME_TYPE_JPEG = "image/jpeg";
     41 
     42     private static final int BYTESBUFFE_POOL_SIZE = 4;
     43     private static final int BYTESBUFFER_SIZE = 200 * 1024;
     44 
     45     private static final BitmapPool sMicroThumbPool = new BitmapPool(
     46             MICROTHUMBNAIL_TARGET_SIZE, MICROTHUMBNAIL_TARGET_SIZE, 16);
     47     private static final BitmapPool sThumbPool = new BitmapPool(4);
     48     private static final BytesBufferPool sMicroThumbBufferPool =
     49             new BytesBufferPool(BYTESBUFFE_POOL_SIZE, BYTESBUFFER_SIZE);
     50 
     51     // TODO: fix default value for latlng and change this.
     52     public static final double INVALID_LATLNG = 0f;
     53 
     54     public abstract Job<Bitmap> requestImage(int type);
     55     public abstract Job<BitmapRegionDecoder> requestLargeImage();
     56 
     57     public MediaItem(Path path, long version) {
     58         super(path, version);
     59     }
     60 
     61     public long getDateInMs() {
     62         return 0;
     63     }
     64 
     65     public String getName() {
     66         return null;
     67     }
     68 
     69     public void getLatLong(double[] latLong) {
     70         latLong[0] = INVALID_LATLNG;
     71         latLong[1] = INVALID_LATLNG;
     72     }
     73 
     74     public String[] getTags() {
     75         return null;
     76     }
     77 
     78     public Face[] getFaces() {
     79         return null;
     80     }
     81 
     82     // The rotation of the full-resolution image. By default, it returns the value of
     83     // getRotation().
     84     public int getFullImageRotation() {
     85         return getRotation();
     86     }
     87 
     88     public int getRotation() {
     89         return 0;
     90     }
     91 
     92     public long getSize() {
     93         return 0;
     94     }
     95 
     96     public abstract String getMimeType();
     97 
     98     // Returns width and height of the media item.
     99     // Returns 0, 0 if the information is not available.
    100     public abstract int getWidth();
    101     public abstract int getHeight();
    102 
    103     // This is an alternative for requestImage() in PhotoPage. If this
    104     // is implemented, you don't need to implement requestImage().
    105     public ScreenNail getScreenNail() {
    106         return null;
    107     }
    108 
    109     public static int getTargetSize(int type) {
    110         switch (type) {
    111             case TYPE_THUMBNAIL:
    112                 return THUMBNAIL_TARGET_SIZE;
    113             case TYPE_MICROTHUMBNAIL:
    114                 return MICROTHUMBNAIL_TARGET_SIZE;
    115             default:
    116                 throw new RuntimeException(
    117                     "should only request thumb/microthumb from cache");
    118         }
    119     }
    120 
    121     public static BitmapPool getMicroThumbPool() {
    122         return sMicroThumbPool;
    123     }
    124 
    125     public static BitmapPool getThumbPool() {
    126         return sThumbPool;
    127     }
    128 
    129     public static BytesBufferPool getBytesBufferPool() {
    130         return sMicroThumbBufferPool;
    131     }
    132 }
    133