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_ALL = 0xffffffff; 45 46 // These are the bits returned from getMediaType(): 47 public static final int MEDIA_TYPE_UNKNOWN = 1; 48 public static final int MEDIA_TYPE_IMAGE = 2; 49 public static final int MEDIA_TYPE_VIDEO = 4; 50 public static final int MEDIA_TYPE_ALL = MEDIA_TYPE_IMAGE | MEDIA_TYPE_VIDEO; 51 52 public static final String MEDIA_TYPE_IMAGE_STRING = "image"; 53 public static final String MEDIA_TYPE_VIDEO_STRING = "video"; 54 public static final String MEDIA_TYPE_ALL_STRING = "all"; 55 56 // These are flags for cache() and return values for getCacheFlag(): 57 public static final int CACHE_FLAG_NO = 0; 58 public static final int CACHE_FLAG_SCREENNAIL = 1; 59 public static final int CACHE_FLAG_FULL = 2; 60 61 // These are return values for getCacheStatus(): 62 public static final int CACHE_STATUS_NOT_CACHED = 0; 63 public static final int CACHE_STATUS_CACHING = 1; 64 public static final int CACHE_STATUS_CACHED_SCREENNAIL = 2; 65 public static final int CACHE_STATUS_CACHED_FULL = 3; 66 67 private static long sVersionSerial = 0; 68 69 protected long mDataVersion; 70 71 protected final Path mPath; 72 73 public interface PanoramaSupportCallback { 74 void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama, 75 boolean isPanorama360); 76 } 77 78 public MediaObject(Path path, long version) { 79 path.setObject(this); 80 mPath = path; 81 mDataVersion = version; 82 } 83 84 public Path getPath() { 85 return mPath; 86 } 87 88 public int getSupportedOperations() { 89 return 0; 90 } 91 92 public void getPanoramaSupport(PanoramaSupportCallback callback) { 93 callback.panoramaInfoAvailable(this, false, false); 94 } 95 96 public void clearCachedPanoramaSupport() { 97 } 98 99 public void delete() { 100 throw new UnsupportedOperationException(); 101 } 102 103 public void rotate(int degrees) { 104 throw new UnsupportedOperationException(); 105 } 106 107 public Uri getContentUri() { 108 String className = getClass().getName(); 109 Log.e(TAG, "Class " + className + "should implement getContentUri."); 110 Log.e(TAG, "The object was created from path: " + getPath()); 111 throw new UnsupportedOperationException(); 112 } 113 114 public Uri getPlayUri() { 115 throw new UnsupportedOperationException(); 116 } 117 118 public int getMediaType() { 119 return MEDIA_TYPE_UNKNOWN; 120 } 121 122 public MediaDetails getDetails() { 123 MediaDetails details = new MediaDetails(); 124 return details; 125 } 126 127 public long getDataVersion() { 128 return mDataVersion; 129 } 130 131 public int getCacheFlag() { 132 return CACHE_FLAG_NO; 133 } 134 135 public int getCacheStatus() { 136 throw new UnsupportedOperationException(); 137 } 138 139 public long getCacheSize() { 140 throw new UnsupportedOperationException(); 141 } 142 143 public void cache(int flag) { 144 throw new UnsupportedOperationException(); 145 } 146 147 public static synchronized long nextVersionNumber() { 148 return ++MediaObject.sVersionSerial; 149 } 150 151 public static int getTypeFromString(String s) { 152 if (MEDIA_TYPE_ALL_STRING.equals(s)) return MediaObject.MEDIA_TYPE_ALL; 153 if (MEDIA_TYPE_IMAGE_STRING.equals(s)) return MediaObject.MEDIA_TYPE_IMAGE; 154 if (MEDIA_TYPE_VIDEO_STRING.equals(s)) return MediaObject.MEDIA_TYPE_VIDEO; 155 throw new IllegalArgumentException(s); 156 } 157 158 public static String getTypeString(int type) { 159 switch (type) { 160 case MEDIA_TYPE_IMAGE: return MEDIA_TYPE_IMAGE_STRING; 161 case MEDIA_TYPE_VIDEO: return MEDIA_TYPE_VIDEO_STRING; 162 case MEDIA_TYPE_ALL: return MEDIA_TYPE_ALL_STRING; 163 } 164 throw new IllegalArgumentException(); 165 } 166 } 167