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.net.Uri; 20 21 public abstract class MediaObject { 22 @SuppressWarnings("unused") 23 private static final String TAG = "MediaObject"; 24 public static final long INVALID_DATA_VERSION = -1; 25 26 // These are the bits returned from getSupportedOperations(): 27 public static final int SUPPORT_DELETE = 1 << 0; 28 public static final int SUPPORT_ROTATE = 1 << 1; 29 public static final int SUPPORT_SHARE = 1 << 2; 30 public static final int SUPPORT_CROP = 1 << 3; 31 public static final int SUPPORT_SHOW_ON_MAP = 1 << 4; 32 public static final int SUPPORT_SETAS = 1 << 5; 33 public static final int SUPPORT_FULL_IMAGE = 1 << 6; 34 public static final int SUPPORT_PLAY = 1 << 7; 35 public static final int SUPPORT_CACHE = 1 << 8; 36 public static final int SUPPORT_EDIT = 1 << 9; 37 public static final int SUPPORT_INFO = 1 << 10; 38 public static final int SUPPORT_TRIM = 1 << 11; 39 public static final int SUPPORT_UNLOCK = 1 << 12; 40 public static final int SUPPORT_BACK = 1 << 13; 41 public static final int SUPPORT_ACTION = 1 << 14; 42 public static final int SUPPORT_CAMERA_SHORTCUT = 1 << 15; 43 public static final int SUPPORT_MUTE = 1 << 16; 44 public static final int SUPPORT_PRINT = 1 << 17; 45 public static final int SUPPORT_ALL = 0xffffffff; 46 47 // These are the bits returned from getMediaType(): 48 public static final int MEDIA_TYPE_UNKNOWN = 1; 49 public static final int MEDIA_TYPE_IMAGE = 2; 50 public static final int MEDIA_TYPE_VIDEO = 4; 51 public static final int MEDIA_TYPE_ALL = MEDIA_TYPE_IMAGE | MEDIA_TYPE_VIDEO; 52 53 public static final String MEDIA_TYPE_IMAGE_STRING = "image"; 54 public static final String MEDIA_TYPE_VIDEO_STRING = "video"; 55 public static final String MEDIA_TYPE_ALL_STRING = "all"; 56 57 // These are flags for cache() and return values for getCacheFlag(): 58 public static final int CACHE_FLAG_NO = 0; 59 public static final int CACHE_FLAG_SCREENNAIL = 1; 60 public static final int CACHE_FLAG_FULL = 2; 61 62 // These are return values for getCacheStatus(): 63 public static final int CACHE_STATUS_NOT_CACHED = 0; 64 public static final int CACHE_STATUS_CACHING = 1; 65 public static final int CACHE_STATUS_CACHED_SCREENNAIL = 2; 66 public static final int CACHE_STATUS_CACHED_FULL = 3; 67 68 private static long sVersionSerial = 0; 69 70 protected long mDataVersion; 71 72 protected final Path mPath; 73 74 public interface PanoramaSupportCallback { 75 void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama, 76 boolean isPanorama360); 77 } 78 79 public MediaObject(Path path, long version) { 80 path.setObject(this); 81 mPath = path; 82 mDataVersion = version; 83 } 84 85 public Path getPath() { 86 return mPath; 87 } 88 89 public int getSupportedOperations() { 90 return 0; 91 } 92 93 public void getPanoramaSupport(PanoramaSupportCallback callback) { 94 callback.panoramaInfoAvailable(this, false, false); 95 } 96 97 public void clearCachedPanoramaSupport() { 98 } 99 100 public void delete() { 101 throw new UnsupportedOperationException(); 102 } 103 104 public void rotate(int degrees) { 105 throw new UnsupportedOperationException(); 106 } 107 108 public Uri getContentUri() { 109 String className = getClass().getName(); 110 Log.e(TAG, "Class " + className + "should implement getContentUri."); 111 Log.e(TAG, "The object was created from path: " + getPath()); 112 throw new UnsupportedOperationException(); 113 } 114 115 public Uri getPlayUri() { 116 throw new UnsupportedOperationException(); 117 } 118 119 public int getMediaType() { 120 return MEDIA_TYPE_UNKNOWN; 121 } 122 123 public MediaDetails getDetails() { 124 MediaDetails details = new MediaDetails(); 125 return details; 126 } 127 128 public long getDataVersion() { 129 return mDataVersion; 130 } 131 132 public int getCacheFlag() { 133 return CACHE_FLAG_NO; 134 } 135 136 public int getCacheStatus() { 137 throw new UnsupportedOperationException(); 138 } 139 140 public long getCacheSize() { 141 throw new UnsupportedOperationException(); 142 } 143 144 public void cache(int flag) { 145 throw new UnsupportedOperationException(); 146 } 147 148 public static synchronized long nextVersionNumber() { 149 return ++MediaObject.sVersionSerial; 150 } 151 152 public static int getTypeFromString(String s) { 153 if (MEDIA_TYPE_ALL_STRING.equals(s)) return MediaObject.MEDIA_TYPE_ALL; 154 if (MEDIA_TYPE_IMAGE_STRING.equals(s)) return MediaObject.MEDIA_TYPE_IMAGE; 155 if (MEDIA_TYPE_VIDEO_STRING.equals(s)) return MediaObject.MEDIA_TYPE_VIDEO; 156 throw new IllegalArgumentException(s); 157 } 158 159 public static String getTypeString(int type) { 160 switch (type) { 161 case MEDIA_TYPE_IMAGE: return MEDIA_TYPE_IMAGE_STRING; 162 case MEDIA_TYPE_VIDEO: return MEDIA_TYPE_VIDEO_STRING; 163 case MEDIA_TYPE_ALL: return MEDIA_TYPE_ALL_STRING; 164 } 165 throw new IllegalArgumentException(); 166 } 167 } 168