blob: eb3a092ad0f5947f46818afc757a50edb3104b8d [file] [log] [blame]
Angus Kong750e8ec2013-05-06 10:42:28 -07001/*
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
17package com.android.camera.data;
18
19import android.content.Context;
Angus Kong750e8ec2013-05-06 10:42:28 -070020import android.graphics.drawable.Drawable;
Angus Kong8a2350a2013-12-16 15:02:34 -080021import android.os.Bundle;
Angus Kong750e8ec2013-05-06 10:42:28 -070022import android.view.View;
Angus Kong750e8ec2013-05-06 10:42:28 -070023
Angus Kong2bca2102014-03-11 16:27:30 -070024import com.android.camera.debug.Log;
Angus Kong01054e92013-12-10 11:06:18 -080025import com.android.camera.filmstrip.ImageData;
Angus Kongbd260692013-08-07 14:52:56 -070026
27import java.util.Comparator;
Angus Kong750e8ec2013-05-06 10:42:28 -070028
Sascha Haeberlingf1f51862013-07-31 11:28:21 -070029/**
30 * An abstract interface that represents the local media data. Also implements
Angus Kong750e8ec2013-05-06 10:42:28 -070031 * Comparable interface so we can sort in DataAdapter.
ztenghuia16e7b52013-08-23 11:47:56 -070032 * 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.
Angus Kong750e8ec2013-05-06 10:42:28 -070035 */
Angus Kong01054e92013-12-10 11:06:18 -080036public interface LocalData extends ImageData {
Angus Kong2bca2102014-03-11 16:27:30 -070037 static final Log.Tag TAG = new Log.Tag("LocalData");
Angus Kong750e8ec2013-05-06 10:42:28 -070038
ztenghuia16e7b52013-08-23 11:47:56 -070039 public static final String MIME_TYPE_JPEG = "image/jpeg";
40
Angus Kong740cbee2013-12-11 15:46:16 -080041 // Data actions.
42 public static final int DATA_ACTION_NONE = 0;
43 public static final int DATA_ACTION_PLAY = 1;
44 public static final int DATA_ACTION_DELETE = (1 << 1);
45 public static final int DATA_ACTION_EDIT = (1 << 2);
Angus Konge0aff892013-12-11 20:51:01 -080046 public static final int DATA_ACTION_SHARE = (1 << 3);
Angus Kong08221032013-06-14 14:50:31 -070047
Angus Kongc27d21b2013-08-12 15:03:45 -070048 // Local data types. Returned by getLocalDataType().
Mangesh Ghiwarecd2eeb02013-08-23 13:28:21 -070049 /**
50 * Constant for denoting a camera preview.
51 */
52 public static final int LOCAL_CAMERA_PREVIEW = 1;
53 /**
54 * Constant for denoting an arbitrary view.
55 */
56 public static final int LOCAL_VIEW = 2;
57 /**
58 * Constant for denoting a still image.
59 */
60 public static final int LOCAL_IMAGE = 3;
61 /**
62 * Constant for denoting a video.
63 */
64 public static final int LOCAL_VIDEO = 4;
65 /**
Angus Kong32509872013-10-02 16:53:40 -070066 * Constant for denoting an in-progress item which should not be touched
67 * before the related task is done. Data of this type should not support
68 * any actions like sharing, editing, etc.
69 */
Angus Kong8a2350a2013-12-16 15:02:34 -080070 public static final int LOCAL_IN_PROGRESS_DATA = 5;
Sascha Haeberling280fd3e2013-11-21 13:52:15 -080071
Sascha Haeberlingc67c07b2013-12-13 18:48:54 -080072 // TODO: Re-think how the in-progress logic works. We shouldn't need to pass
73 // in the information about whether this session is in progress.
Andy Huiberscaca8c72013-12-13 15:53:43 -080074
75 /**
76 * Creates View to represent media.
77 *
78 * @param context The {@link android.content.Context} to create the view.
79 * @param width Width in pixels of rendered view.
80 * @param height Height in pixels of rendered view.
81 * @param adapter Data adapter for this data item.
82 */
Sam Judd4021c892014-03-17 12:57:50 -070083 View getView(Context context, View recycled, int width, int height, int placeHolderResourceId,
Sascha Haeberling14ff6c82013-12-13 13:29:58 -080084 LocalDataAdapter adapter, boolean isInProgress);
Sascha Haeberling37f36112013-08-06 14:31:52 -070085
Sam Judd43bf03f2014-03-17 11:27:03 -070086 /** Returns a unique identifier for the view created by this data so that the view
87 * can be reused.
88 *
89 * @see android.widget.BaseAdapter#getItemViewType(int)
90 */
91 LocalDataViewType getItemViewType();
92
Andy Huiberscaca8c72013-12-13 15:53:43 -080093 /**
94 * Request resize of View created by getView().
95 *
96 * @param context The {@link android.content.Context} to create the view.
97 * @param width Width in pixels of rendered view.
98 * @param height Height in pixels of rendered view.
99 * @param view View created by getView();
100 * @param adapter Data adapter for this data item.
101 */
Sam Judd4021c892014-03-17 12:57:50 -0700102 public void loadFullImage(Context context, int width, int height, View view, LocalDataAdapter adapter);
Andy Huiberscaca8c72013-12-13 15:53:43 -0800103
Sascha Haeberling37f36112013-08-06 14:31:52 -0700104 /**
105 * Gets the date when this data is created. The returned date is also used
106 * for sorting data.
107 *
108 * @return The date when this data is created.
109 * @see {@link NewestFirstComparator}
110 */
Angus Kong08221032013-06-14 14:50:31 -0700111 long getDateTaken();
Sascha Haeberling37f36112013-08-06 14:31:52 -0700112
113 /**
114 * Gets the date when this data is modified. The returned date is also used
115 * for sorting data.
116 *
117 * @return The date when this data is modified.
118 * @see {@link NewestFirstComparator}
119 */
Angus Kong08221032013-06-14 14:50:31 -0700120 long getDateModified();
Sascha Haeberling37f36112013-08-06 14:31:52 -0700121
122 /** Gets the title of this data */
Angus Kong08221032013-06-14 14:50:31 -0700123 String getTitle();
Sascha Haeberling37f36112013-08-06 14:31:52 -0700124
125 /**
126 * Checks if the data actions (delete/play ...) can be applied on this data.
127 *
128 * @param actions The actions to check.
129 * @return Whether all the actions are supported.
130 */
131 boolean isDataActionSupported(int actions);
132
Angus Kong4ff5a1a2013-08-14 16:07:54 -0700133 /** Removes the data from the storage if possible. */
Angus Kong08221032013-06-14 14:50:31 -0700134 boolean delete(Context c);
Sascha Haeberling37f36112013-08-06 14:31:52 -0700135
Angus Kong8e5e4ee2013-07-30 11:36:00 -0700136 void onFullScreen(boolean fullScreen);
Sascha Haeberling37f36112013-08-06 14:31:52 -0700137
138 /** Returns {@code true} if it allows swipe to filmstrip in full screen. */
Angus Kong8e5e4ee2013-07-30 11:36:00 -0700139 boolean canSwipeInFullScreen();
Sascha Haeberling37f36112013-08-06 14:31:52 -0700140
141 /**
142 * Returns the path to the data on the storage.
143 *
144 * @return Empty path if there's none.
145 */
Angus Kong8e5e4ee2013-07-30 11:36:00 -0700146 String getPath();
Angus Kong750e8ec2013-05-06 10:42:28 -0700147
Sascha Haeberling37f36112013-08-06 14:31:52 -0700148 /**
Sascha Haeberling88ef7662013-08-15 17:19:22 -0700149 * @return The mimetype of this data item, or null, if this item has no
150 * mimetype associated with it.
151 */
152 String getMimeType();
153
154 /**
Angus Kong26795a92014-02-20 09:18:09 -0800155 * @return The media details (such as EXIF) for the data. {@code null} if
156 * not available for the data.
Sascha Haeberling6f64b502013-08-14 16:23:18 -0700157 */
158 MediaDetails getMediaDetails(Context context);
159
160 /**
Angus Kongc27d21b2013-08-12 15:03:45 -0700161 * Returns the type of the local data defined by {@link LocalData}.
162 *
Angus Kongc27d21b2013-08-12 15:03:45 -0700163 * @return The local data type. Could be one of the following:
164 * {@code LOCAL_CAMERA_PREVIEW}, {@code LOCAL_VIEW}, {@code LOCAL_IMAGE},
Sascha Haeberling280fd3e2013-11-21 13:52:15 -0800165 * {@code LOCAL_VIDEO}, {@code LOCAL_PHOTO_SPHERE},
166 * {@code LOCAL_360_PHOTO_SPHERE}, and {@code LOCAL_RGBZ}
Angus Kongc27d21b2013-08-12 15:03:45 -0700167 */
Sascha Haeberlingfae11a12013-08-15 14:29:49 -0700168 int getLocalDataType();
Angus Kongc27d21b2013-08-12 15:03:45 -0700169
170 /**
ztenghuia16e7b52013-08-23 11:47:56 -0700171 * @return The size of the data in bytes
172 */
173 long getSizeInBytes();
174
175 /**
Sascha Haeberling37f36112013-08-06 14:31:52 -0700176 * Refresh the data content.
177 *
Angus Kong8a2350a2013-12-16 15:02:34 -0800178 * @param context The Android {@link android.content.Context}.
ztenghuia16e7b52013-08-23 11:47:56 -0700179 * @return A new LocalData object if success, null otherwise.
Sascha Haeberling37f36112013-08-06 14:31:52 -0700180 */
Angus Kong8a2350a2013-12-16 15:02:34 -0800181 LocalData refresh(Context context);
Sascha Haeberling37f36112013-08-06 14:31:52 -0700182
Angus Kong740cbee2013-12-11 15:46:16 -0800183 /**
Angus Kong8a2350a2013-12-16 15:02:34 -0800184 * @return the {@link android.content.ContentResolver} Id of the data.
Angus Kong740cbee2013-12-11 15:46:16 -0800185 */
Angus Kong8a2350a2013-12-16 15:02:34 -0800186 long getContentId();
Angus Kong740cbee2013-12-11 15:46:16 -0800187
188 /**
Angus Kong8a2350a2013-12-16 15:02:34 -0800189 * @return the metadata. Should never be {@code null}.
Angus Kong740cbee2013-12-11 15:46:16 -0800190 */
Angus Kong8a2350a2013-12-16 15:02:34 -0800191 Bundle getMetadata();
Angus Kong740cbee2013-12-11 15:46:16 -0800192
Angus Konge2f4c032013-12-19 10:24:33 -0800193 /**
Sam Judd4021c892014-03-17 12:57:50 -0700194 * Any media store attribute that can potentially change the local data
195 * should be included in this signature, primarily oriented at detecting
196 * edits.
197 *
198 * @return A string identifying the set of changeable attributes.
199 */
200 String getSignature();
201
202 /**
Angus Konge2f4c032013-12-19 10:24:33 -0800203 * @return whether the metadata is updated.
204 */
205 public boolean isMetadataUpdated();
206
Angus Kong750e8ec2013-05-06 10:42:28 -0700207 static class NewestFirstComparator implements Comparator<LocalData> {
208
Angus Kong8e5e4ee2013-07-30 11:36:00 -0700209 /** Compare taken/modified date of LocalData in descent order to make
210 newer data in the front.
211 The negative numbers here are always considered "bigger" than
212 positive ones. Thus, if any one of the numbers is negative, the logic
213 is reversed. */
Angus Kongdff672d2013-05-22 17:30:56 -0700214 private static int compareDate(long v1, long v2) {
215 if (v1 >= 0 && v2 >= 0) {
Angus Kong7283c602013-05-29 17:06:04 -0700216 return ((v1 < v2) ? 1 : ((v1 > v2) ? -1 : 0));
Angus Kong750e8ec2013-05-06 10:42:28 -0700217 }
Angus Kong7283c602013-05-29 17:06:04 -0700218 return ((v2 < v1) ? 1 : ((v2 > v1) ? -1 : 0));
Angus Kong750e8ec2013-05-06 10:42:28 -0700219 }
220
221 @Override
222 public int compare(LocalData d1, LocalData d2) {
Angus Kongdff672d2013-05-22 17:30:56 -0700223 int cmp = compareDate(d1.getDateTaken(), d2.getDateTaken());
Angus Kong750e8ec2013-05-06 10:42:28 -0700224 if (cmp == 0) {
Angus Kongdff672d2013-05-22 17:30:56 -0700225 cmp = compareDate(d1.getDateModified(), d2.getDateModified());
Angus Kong750e8ec2013-05-06 10:42:28 -0700226 }
227 if (cmp == 0) {
228 cmp = d1.getTitle().compareTo(d2.getTitle());
229 }
230 return cmp;
231 }
232 }
Angus Kong750e8ec2013-05-06 10:42:28 -0700233}