VideoObject.java revision 9a4cece52995545c210d2e6bf7eb4748caa184ec
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 17package com.android.camera.gallery; 18 19import com.android.camera.BitmapManager; 20 21import android.content.ContentResolver; 22import android.graphics.Bitmap; 23import android.media.ThumbnailUtils; 24import android.net.Uri; 25import android.provider.MediaStore.Images; 26import android.provider.MediaStore.Video; 27import android.util.Log; 28 29import java.io.IOException; 30import java.io.InputStream; 31 32/** 33 * Represents a particular video and provides access to the underlying data and 34 * two thumbnail bitmaps as well as other information such as the id, and the 35 * path to the actual video data. 36 */ 37public class VideoObject extends BaseImage implements IImage { 38 private static final String TAG = "VideoObject"; 39 /** 40 * Constructor. 41 * 42 * @param id the image id of the image 43 * @param cr the content resolver 44 */ 45 protected VideoObject(BaseImageList container, ContentResolver cr, 46 long id, int index, Uri uri, String dataPath, 47 String mimeType, long dateTaken, String title) { 48 super(container, cr, id, index, uri, dataPath, 49 mimeType, dateTaken, title); 50 } 51 52 @Override 53 public boolean equals(Object other) { 54 if (other == null || !(other instanceof VideoObject)) return false; 55 return fullSizeImageUri().equals( 56 ((VideoObject) other).fullSizeImageUri()); 57 } 58 59 @Override 60 public int hashCode() { 61 return fullSizeImageUri().toString().hashCode(); 62 } 63 64 @Override 65 public Bitmap fullSizeBitmap(int minSideLength, int maxNumberOfPixels, 66 boolean rotateAsNeeded, boolean useNative) { 67 return ThumbnailUtils.createVideoThumbnail(mDataPath, 68 Video.Thumbnails.MINI_KIND); 69 } 70 71 @Override 72 public InputStream fullSizeImageData() { 73 try { 74 InputStream input = mContentResolver.openInputStream( 75 fullSizeImageUri()); 76 return input; 77 } catch (IOException ex) { 78 return null; 79 } 80 } 81 82 @Override 83 public int getHeight() { 84 return 0; 85 } 86 87 @Override 88 public int getWidth() { 89 return 0; 90 } 91 92 public boolean isReadonly() { 93 return false; 94 } 95 96 public boolean isDrm() { 97 return false; 98 } 99 100 public boolean rotateImageBy(int degrees) { 101 return false; 102 } 103 104 public Bitmap thumbBitmap(boolean rotateAsNeeded) { 105 return fullSizeBitmap(THUMBNAIL_TARGET_SIZE, THUMBNAIL_MAX_NUM_PIXELS); 106 } 107 108 @Override 109 public Bitmap miniThumbBitmap() { 110 try { 111 long id = mId; 112 return BitmapManager.instance().getThumbnail(mContentResolver, 113 id, Images.Thumbnails.MICRO_KIND, null, true); 114 } catch (Throwable ex) { 115 Log.e(TAG, "miniThumbBitmap got exception", ex); 116 return null; 117 } 118 } 119 120 @Override 121 public String toString() { 122 return new StringBuilder("VideoObject").append(mId).toString(); 123 } 124} 125