Home | History | Annotate | Download | only in gallery
      1 /*
      2  * Copyright (C) 2009 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.camera.gallery;
     18 
     19 import com.android.camera.BitmapManager;
     20 import com.android.camera.Util;
     21 
     22 import android.content.ContentResolver;
     23 import android.graphics.Bitmap;
     24 import android.net.Uri;
     25 import android.provider.MediaStore.Images;
     26 import android.util.Log;
     27 
     28 /**
     29  * Represents a particular image and provides access to the underlying bitmap
     30  * and two thumbnail bitmaps as well as other information such as the id, and
     31  * the path to the actual image data.
     32  */
     33 public abstract class BaseImage implements IImage {
     34     private static final String TAG = "BaseImage";
     35     protected ContentResolver mContentResolver;
     36 
     37     // Database field
     38     protected Uri mUri;
     39     protected long mId;
     40     private final long mDateTaken;
     41 
     42     protected BaseImage(ContentResolver cr,
     43             long id, Uri uri, long miniThumbMagic,
     44             long dateTaken) {
     45         mContentResolver = cr;
     46         mId = id;
     47         mUri = uri;
     48         mDateTaken = dateTaken;
     49     }
     50 
     51     @Override
     52     public boolean equals(Object other) {
     53         if (other == null || !(other instanceof Image)) return false;
     54         return mUri.equals(((Image) other).mUri);
     55     }
     56 
     57     @Override
     58     public int hashCode() {
     59         return mUri.hashCode();
     60     }
     61 
     62     public Uri fullSizeImageUri() {
     63         return mUri;
     64     }
     65 
     66     public long getDateTaken() {
     67         return mDateTaken;
     68     }
     69 
     70     public int getDegreesRotated() {
     71         return 0;
     72     }
     73 
     74     public Bitmap miniThumbBitmap() {
     75         Bitmap b = null;
     76         try {
     77             long id = mId;
     78             b = BitmapManager.instance().getThumbnail(mContentResolver, id,
     79                     Images.Thumbnails.MICRO_KIND, null, false);
     80         } catch (Throwable ex) {
     81             Log.e(TAG, "miniThumbBitmap got exception", ex);
     82             return null;
     83         }
     84         if (b != null) {
     85             b = Util.rotate(b, getDegreesRotated());
     86         }
     87         return b;
     88     }
     89 
     90     @Override
     91     public String toString() {
     92         return mUri.toString();
     93     }
     94 }
     95