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.graphics.Bitmap; 22 import android.net.Uri; 23 import android.provider.DrmStore; 24 25 /** 26 * Represents an ordered collection of Image objects from the DRM provider. 27 */ 28 public class DrmImageList extends ImageList implements IImageList { 29 30 // TODO: get other field from database too ? 31 private static final String[] DRM_IMAGE_PROJECTION = new String[] { 32 DrmStore.Images._ID, 33 DrmStore.Images.DATA, 34 DrmStore.Images.MIME_TYPE, 35 }; 36 37 private static final int INDEX_ID = 0; 38 private static final int INDEX_DATA_PATH = 1; 39 private static final int INDEX_MIME_TYPE = 2; 40 DrmImageList(ContentResolver resolver, Uri imageUri, int sort, String bucketId)41 public DrmImageList(ContentResolver resolver, Uri imageUri, int sort, 42 String bucketId) { 43 super(resolver, imageUri, sort, bucketId); 44 } 45 46 @Override sortOrder()47 protected String sortOrder() { 48 // We have no date information in DrmStore, so we just sort by _id. 49 return "_id ASC"; 50 } 51 52 @Override createCursor()53 protected Cursor createCursor() { 54 return mContentResolver.query( 55 mBaseUri, DRM_IMAGE_PROJECTION, null, null, sortOrder()); 56 } 57 58 private static class DrmImage extends Image { 59 DrmImage(BaseImageList container, ContentResolver cr, long id, int index, Uri uri, String dataPath, long miniThumbMagic, String mimeType, long dateTaken, String title, int rotation)60 protected DrmImage(BaseImageList container, ContentResolver cr, 61 long id, int index, Uri uri, String dataPath, 62 long miniThumbMagic, String mimeType, long dateTaken, 63 String title, int rotation) { 64 super(container, cr, id, index, uri, dataPath, 65 mimeType, dateTaken, title, rotation); 66 } 67 68 @Override getDegreesRotated()69 public int getDegreesRotated() { 70 return 0; 71 } 72 73 @Override isDrm()74 public boolean isDrm() { 75 return true; 76 } 77 78 @Override isReadonly()79 public boolean isReadonly() { 80 return true; 81 } 82 83 @Override miniThumbBitmap()84 public Bitmap miniThumbBitmap() { 85 return fullSizeBitmap(IImage.MINI_THUMB_TARGET_SIZE, 86 IImage.MINI_THUMB_MAX_NUM_PIXELS); 87 } 88 89 @Override thumbBitmap(boolean rotateAsNeeded)90 public Bitmap thumbBitmap(boolean rotateAsNeeded) { 91 return fullSizeBitmap(IImage.THUMBNAIL_TARGET_SIZE, 92 IImage.THUMBNAIL_MAX_NUM_PIXELS); 93 } 94 } 95 96 @Override loadImageFromCursor(Cursor cursor)97 protected BaseImage loadImageFromCursor(Cursor cursor) { 98 long id = cursor.getLong(INDEX_ID); 99 String dataPath = cursor.getString(INDEX_DATA_PATH); 100 String mimeType = cursor.getString(INDEX_MIME_TYPE); 101 return new DrmImage(this, mContentResolver, id, cursor.getPosition(), 102 contentUri(id), dataPath, 0, mimeType, 0, "DrmImage-" + id, 103 0); 104 } 105 } 106