Home | History | Annotate | Download | only in data
      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_IMPORT = 1 << 11;
     39     public static final int SUPPORT_ALL = 0xffffffff;
     40 
     41     // These are the bits returned from getMediaType():
     42     public static final int MEDIA_TYPE_UNKNOWN = 1;
     43     public static final int MEDIA_TYPE_IMAGE = 2;
     44     public static final int MEDIA_TYPE_VIDEO = 4;
     45     public static final int MEDIA_TYPE_ALL = MEDIA_TYPE_IMAGE | MEDIA_TYPE_VIDEO;
     46 
     47     public static final String MEDIA_TYPE_IMAGE_STRING = "image";
     48     public static final String MEDIA_TYPE_VIDEO_STRING = "video";
     49     public static final String MEDIA_TYPE_ALL_STRING = "all";
     50 
     51     // These are flags for cache() and return values for getCacheFlag():
     52     public static final int CACHE_FLAG_NO = 0;
     53     public static final int CACHE_FLAG_SCREENNAIL = 1;
     54     public static final int CACHE_FLAG_FULL = 2;
     55 
     56     // These are return values for getCacheStatus():
     57     public static final int CACHE_STATUS_NOT_CACHED = 0;
     58     public static final int CACHE_STATUS_CACHING = 1;
     59     public static final int CACHE_STATUS_CACHED_SCREENNAIL = 2;
     60     public static final int CACHE_STATUS_CACHED_FULL = 3;
     61 
     62     private static long sVersionSerial = 0;
     63 
     64     protected long mDataVersion;
     65 
     66     protected final Path mPath;
     67 
     68     public MediaObject(Path path, long version) {
     69         path.setObject(this);
     70         mPath = path;
     71         mDataVersion = version;
     72     }
     73 
     74     public Path getPath() {
     75         return mPath;
     76     }
     77 
     78     public int getSupportedOperations() {
     79         return 0;
     80     }
     81 
     82     public void delete() {
     83         throw new UnsupportedOperationException();
     84     }
     85 
     86     public void rotate(int degrees) {
     87         throw new UnsupportedOperationException();
     88     }
     89 
     90     public Uri getContentUri() {
     91         throw new UnsupportedOperationException();
     92     }
     93 
     94     public Uri getPlayUri() {
     95         throw new UnsupportedOperationException();
     96     }
     97 
     98     public int getMediaType() {
     99         return MEDIA_TYPE_UNKNOWN;
    100     }
    101 
    102     public boolean Import() {
    103         throw new UnsupportedOperationException();
    104     }
    105 
    106     public MediaDetails getDetails() {
    107         MediaDetails details = new MediaDetails();
    108         return details;
    109     }
    110 
    111     public long getDataVersion() {
    112         return mDataVersion;
    113     }
    114 
    115     public int getCacheFlag() {
    116         return CACHE_FLAG_NO;
    117     }
    118 
    119     public int getCacheStatus() {
    120         throw new UnsupportedOperationException();
    121     }
    122 
    123     public long getCacheSize() {
    124         throw new UnsupportedOperationException();
    125     }
    126 
    127     public void cache(int flag) {
    128         throw new UnsupportedOperationException();
    129     }
    130 
    131     public static synchronized long nextVersionNumber() {
    132         return ++MediaObject.sVersionSerial;
    133     }
    134 
    135     public static int getTypeFromString(String s) {
    136         if (MEDIA_TYPE_ALL_STRING.equals(s)) return MediaObject.MEDIA_TYPE_ALL;
    137         if (MEDIA_TYPE_IMAGE_STRING.equals(s)) return MediaObject.MEDIA_TYPE_IMAGE;
    138         if (MEDIA_TYPE_VIDEO_STRING.equals(s)) return MediaObject.MEDIA_TYPE_VIDEO;
    139         throw new IllegalArgumentException(s);
    140     }
    141 
    142     public static String getTypeString(int type) {
    143         switch (type) {
    144             case MEDIA_TYPE_IMAGE: return MEDIA_TYPE_IMAGE_STRING;
    145             case MEDIA_TYPE_VIDEO: return MEDIA_TYPE_VIDEO_STRING;
    146             case MEDIA_TYPE_ALL: return MEDIA_TYPE_ALL_STRING;
    147         }
    148         throw new IllegalArgumentException();
    149     }
    150 }
    151