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.common.ApiHelper;
     23 import com.android.gallery3d.ui.ScreenNail;
     24 import com.android.gallery3d.util.ThreadPool.Job;
     25 
     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;
     32 
     33     public static final int CACHED_IMAGE_QUALITY = 95;
     34 
     35     public static final int IMAGE_READY = 0;
     36     public static final int IMAGE_WAIT = 1;
     37     public static final int IMAGE_ERROR = -1;
     38 
     39     public static final String MIME_TYPE_JPEG = "image/jpeg";
     40 
     41     private static final int BYTESBUFFE_POOL_SIZE = 4;
     42     private static final int BYTESBUFFER_SIZE = 200 * 1024;
     43 
     44     private static int sMicrothumbnailTargetSize = 200;
     45     private static final BytesBufferPool sMicroThumbBufferPool =
     46             new BytesBufferPool(BYTESBUFFE_POOL_SIZE, BYTESBUFFER_SIZE);
     47 
     48     private static int sThumbnailTargetSize = 640;
     49 
     50     // TODO: fix default value for latlng and change this.
     51     public static final double INVALID_LATLNG = 0f;
     52 
     53     public abstract Job<Bitmap> requestImage(int type);
     54     public abstract Job<BitmapRegionDecoder> requestLargeImage();
     55 
     56     public MediaItem(Path path, long version) {
     57         super(path, version);
     58     }
     59 
     60     public long getDateInMs() {
     61         return 0;
     62     }
     63 
     64     public String getName() {
     65         return null;
     66     }
     67 
     68     public void getLatLong(double[] latLong) {
     69         latLong[0] = INVALID_LATLNG;
     70         latLong[1] = INVALID_LATLNG;
     71     }
     72 
     73     public String[] getTags() {
     74         return null;
     75     }
     76 
     77     public Face[] getFaces() {
     78         return null;
     79     }
     80 
     81     // The rotation of the full-resolution image. By default, it returns the value of
     82     // getRotation().
     83     public int getFullImageRotation() {
     84         return getRotation();
     85     }
     86 
     87     public int getRotation() {
     88         return 0;
     89     }
     90 
     91     public long getSize() {
     92         return 0;
     93     }
     94 
     95     public abstract String getMimeType();
     96 
     97     public String getFilePath() {
     98         return "";
     99     }
    100 
    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();
    105 
    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() {
    109         return null;
    110     }
    111 
    112     public static int getTargetSize(int type) {
    113         switch (type) {
    114             case TYPE_THUMBNAIL:
    115                 return sThumbnailTargetSize;
    116             case TYPE_MICROTHUMBNAIL:
    117                 return sMicrothumbnailTargetSize;
    118             default:
    119                 throw new RuntimeException(
    120                     "should only request thumb/microthumb from cache");
    121         }
    122     }
    123 
    124     public static BytesBufferPool getBytesBufferPool() {
    125         return sMicroThumbBufferPool;
    126     }
    127 
    128     public static void setThumbnailSizes(int size, int microSize) {
    129         sThumbnailTargetSize = size;
    130         if (sMicrothumbnailTargetSize != microSize) {
    131             sMicrothumbnailTargetSize = microSize;
    132         }
    133     }
    134 }
    135