• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.content.ContentResolver;
20 import android.database.Cursor;
21 import android.net.Uri;
22 import android.provider.MediaStore.Images.Media;
23 
24 /**
25  * Represents an ordered collection of Image objects. Provides an API to add
26  * and remove an image.
27  */
28 public class ImageList extends BaseImageList implements IImageList {
29 
30     @SuppressWarnings("unused")
31     private static final String TAG = "ImageList";
32 
33     private static final String[] ACCEPTABLE_IMAGE_TYPES =
34             new String[] { "image/jpeg", "image/png", "image/gif" };
35 
36     /**
37      * ImageList constructor.
38      */
ImageList(ContentResolver resolver, Uri imageUri, int sort, String bucketId)39     public ImageList(ContentResolver resolver, Uri imageUri,
40             int sort, String bucketId) {
41         super(resolver, imageUri, sort, bucketId);
42     }
43 
44     private static final String WHERE_CLAUSE =
45             "(" + Media.MIME_TYPE + " in (?, ?, ?))";
46     private static final String WHERE_CLAUSE_WITH_BUCKET_ID =
47             WHERE_CLAUSE + " AND " + Media.BUCKET_ID + " = ?";
48 
whereClause()49     protected String whereClause() {
50         return mBucketId == null ? WHERE_CLAUSE : WHERE_CLAUSE_WITH_BUCKET_ID;
51     }
52 
whereClauseArgs()53     protected String[] whereClauseArgs() {
54         // TODO: Since mBucketId won't change, we should keep the array.
55         if (mBucketId != null) {
56             int count = ACCEPTABLE_IMAGE_TYPES.length;
57             String[] result = new String[count + 1];
58             System.arraycopy(ACCEPTABLE_IMAGE_TYPES, 0, result, 0, count);
59             result[count] = mBucketId;
60             return result;
61         }
62         return ACCEPTABLE_IMAGE_TYPES;
63     }
64 
65     @Override
createCursor()66     protected Cursor createCursor() {
67         Cursor c = Media.query(
68                 mContentResolver, mBaseUri, IMAGE_PROJECTION,
69                 whereClause(), whereClauseArgs(), sortOrder());
70         return c;
71     }
72 
73     static final String[] IMAGE_PROJECTION = new String[] {
74             Media._ID,
75             Media.DATE_TAKEN,
76             Media.MINI_THUMB_MAGIC,
77             Media.ORIENTATION,
78             Media.DATE_MODIFIED};
79 
80     private static final int INDEX_ID = 0;
81     private static final int INDEX_DATE_TAKEN = 1;
82     private static final int INDEX_MINI_THUMB_MAGIC = 2;
83     private static final int INDEX_ORIENTATION = 3;
84     private static final int INDEX_DATE_MODIFIED = 4;
85 
86     @Override
loadImageFromCursor(Cursor cursor)87     protected BaseImage loadImageFromCursor(Cursor cursor) {
88         long id = cursor.getLong(INDEX_ID);
89         long dateTaken = cursor.getLong(INDEX_DATE_TAKEN);
90         if (dateTaken == 0) {
91             dateTaken = cursor.getLong(INDEX_DATE_MODIFIED) * 1000;
92         }
93         long miniThumbMagic = cursor.getLong(INDEX_MINI_THUMB_MAGIC);
94         int orientation = cursor.getInt(INDEX_ORIENTATION);
95         return new Image(mContentResolver, id,
96                 contentUri(id), miniThumbMagic, dateTaken,
97                 orientation);
98     }
99 }
100