Home | History | Annotate | Download | only in data
      1 /*
      2  * Copyright (C) 2013 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.data;
     18 
     19 import android.app.Activity;
     20 import android.content.ContentResolver;
     21 import android.content.Context;
     22 import android.graphics.drawable.Drawable;
     23 import android.view.View;
     24 
     25 import com.android.camera.ui.FilmStripView;
     26 
     27 import java.util.Comparator;
     28 
     29 /**
     30  * An abstract interface that represents the local media data. Also implements
     31  * Comparable interface so we can sort in DataAdapter.
     32  * Note that all the sub-class of LocalData are designed to be immutable, i.e:
     33  * all the members need to be final, and there is no setter. In this way, we
     34  * can guarantee thread safety for LocalData.
     35  */
     36 public interface LocalData extends FilmStripView.ImageData {
     37     static final String TAG = "CAM_LocalData";
     38 
     39     public static final String MIME_TYPE_JPEG = "image/jpeg";
     40 
     41     public static final int ACTION_NONE = 0;
     42     public static final int ACTION_PLAY = 1;
     43     public static final int ACTION_DELETE = (1 << 1);
     44 
     45     // Local data types. Returned by getLocalDataType().
     46     /**
     47      * Constant for denoting a camera preview.
     48      */
     49     public static final int LOCAL_CAMERA_PREVIEW   = 1;
     50     /**
     51      * Constant for denoting an arbitrary view.
     52      */
     53     public static final int LOCAL_VIEW             = 2;
     54     /**
     55      * Constant for denoting a still image.
     56      */
     57     public static final int LOCAL_IMAGE            = 3;
     58     /**
     59      * Constant for denoting a video.
     60      */
     61     public static final int LOCAL_VIDEO            = 4;
     62     /**
     63      * Constant for denoting a still image, with valid PhotoSphere metadata.
     64      */
     65     public static final int LOCAL_PHOTO_SPHERE     = 5;
     66     /**
     67      * Constant for denoting a still image, with valid 360 PhotoSphere metadata.
     68      */
     69     public static final int LOCAL_360_PHOTO_SPHERE = 6;
     70     /**
     71      * Constant for denoting an in-progress item which should not be touched
     72      * before the related task is done. Data of this type should not support
     73      * any actions like sharing, editing, etc.
     74      */
     75     public static final int LOCAL_IN_PROGRESS_DATA = 7;
     76 
     77     View getView(Activity a, int width, int height, Drawable placeHolder,
     78             LocalDataAdapter adapter);
     79 
     80     /**
     81      * Gets the date when this data is created. The returned date is also used
     82      * for sorting data.
     83      *
     84      * @return The date when this data is created.
     85      * @see {@link NewestFirstComparator}
     86      */
     87     long getDateTaken();
     88 
     89     /**
     90      * Gets the date when this data is modified. The returned date is also used
     91      * for sorting data.
     92      *
     93      * @return The date when this data is modified.
     94      * @see {@link NewestFirstComparator}
     95      */
     96     long getDateModified();
     97 
     98     /** Gets the title of this data */
     99     String getTitle();
    100 
    101     /**
    102      * Checks if the data actions (delete/play ...) can be applied on this data.
    103      *
    104      * @param actions The actions to check.
    105      * @return Whether all the actions are supported.
    106      */
    107     boolean isDataActionSupported(int actions);
    108 
    109     /** Removes the data from the storage if possible. */
    110     boolean delete(Context c);
    111 
    112     /**
    113      * Rotate the image in 90 degrees. This is a no-op for non-image.
    114      *
    115      * @param context Used to update the content provider when rotation is done.
    116      * @param adapter Used to update the view.
    117      * @param currentDataId Used to update the view.
    118      * @param clockwise True if the rotation goes clockwise.
    119      *
    120      * @return Whether the rotation is supported.
    121      */
    122     boolean rotate90Degrees(Context context, LocalDataAdapter adapter,
    123             int currentDataId, boolean clockwise);
    124 
    125     void onFullScreen(boolean fullScreen);
    126 
    127     /** Returns {@code true} if it allows swipe to filmstrip in full screen. */
    128     boolean canSwipeInFullScreen();
    129 
    130     /**
    131      * Returns the path to the data on the storage.
    132      *
    133      * @return Empty path if there's none.
    134      */
    135     String getPath();
    136 
    137     /**
    138      * @return The mimetype of this data item, or null, if this item has no
    139      *         mimetype associated with it.
    140      */
    141     String getMimeType();
    142 
    143     /**
    144      * Return media data (such as EXIF) for the item.
    145      */
    146     MediaDetails getMediaDetails(Context context);
    147 
    148     /**
    149      * Returns the type of the local data defined by {@link LocalData}.
    150      *
    151      * @return The local data type. Could be one of the following:
    152      * {@code LOCAL_CAMERA_PREVIEW}, {@code LOCAL_VIEW}, {@code LOCAL_IMAGE},
    153      * {@code LOCAL_VIDEO}, {@code LOCAL_PHOTO_SPHERE}, and {@code LOCAL_360_PHOTO_SPHERE}
    154      */
    155     int getLocalDataType();
    156 
    157     /**
    158      * @return The size of the data in bytes
    159      */
    160     long getSizeInBytes();
    161 
    162     /**
    163      * Refresh the data content.
    164      *
    165      * @param resolver {@link ContentResolver} to refresh the data.
    166      * @return A new LocalData object if success, null otherwise.
    167      */
    168     LocalData refresh(ContentResolver resolver);
    169 
    170     static class NewestFirstComparator implements Comparator<LocalData> {
    171 
    172         /** Compare taken/modified date of LocalData in descent order to make
    173          newer data in the front.
    174          The negative numbers here are always considered "bigger" than
    175          positive ones. Thus, if any one of the numbers is negative, the logic
    176          is reversed. */
    177         private static int compareDate(long v1, long v2) {
    178             if (v1 >= 0 && v2 >= 0) {
    179                 return ((v1 < v2) ? 1 : ((v1 > v2) ? -1 : 0));
    180             }
    181             return ((v2 < v1) ? 1 : ((v2 > v1) ? -1 : 0));
    182         }
    183 
    184         @Override
    185         public int compare(LocalData d1, LocalData d2) {
    186             int cmp = compareDate(d1.getDateTaken(), d2.getDateTaken());
    187             if (cmp == 0) {
    188                 cmp = compareDate(d1.getDateModified(), d2.getDateModified());
    189             }
    190             if (cmp == 0) {
    191                 cmp = d1.getTitle().compareTo(d2.getTitle());
    192             }
    193             return cmp;
    194         }
    195     }
    196 
    197     /**
    198      * @return the {@link android.content.ContentResolver} Id of the data.
    199      */
    200     long getContentId();
    201 }
    202 
    203