blob: b434f70e500cc8a27cd37c7f63b1878d197fd8fd [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 Kong01054e92013-12-10 11:06:18 -080024import com.android.camera.filmstrip.ImageData;
Angus Kongbd260692013-08-07 14:52:56 -070025
26import java.util.Comparator;
Angus Kong750e8ec2013-05-06 10:42:28 -070027
Sascha Haeberlingf1f51862013-07-31 11:28:21 -070028/**
29 * An abstract interface that represents the local media data. Also implements
Angus Kong750e8ec2013-05-06 10:42:28 -070030 * Comparable interface so we can sort in DataAdapter.
ztenghuia16e7b52013-08-23 11:47:56 -070031 * Note that all the sub-class of LocalData are designed to be immutable, i.e:
32 * all the members need to be final, and there is no setter. In this way, we
33 * can guarantee thread safety for LocalData.
Angus Kong750e8ec2013-05-06 10:42:28 -070034 */
Angus Kong01054e92013-12-10 11:06:18 -080035public interface LocalData extends ImageData {
Sascha Haeberling58501152014-01-06 11:02:35 -080036 static final String TAG = "LocalData";
Angus Kong750e8ec2013-05-06 10:42:28 -070037
ztenghuia16e7b52013-08-23 11:47:56 -070038 public static final String MIME_TYPE_JPEG = "image/jpeg";
39
Angus Kong740cbee2013-12-11 15:46:16 -080040 // Data actions.
41 public static final int DATA_ACTION_NONE = 0;
42 public static final int DATA_ACTION_PLAY = 1;
43 public static final int DATA_ACTION_DELETE = (1 << 1);
44 public static final int DATA_ACTION_EDIT = (1 << 2);
Angus Konge0aff892013-12-11 20:51:01 -080045 public static final int DATA_ACTION_SHARE = (1 << 3);
Angus Kong08221032013-06-14 14:50:31 -070046
Angus Kongc27d21b2013-08-12 15:03:45 -070047 // Local data types. Returned by getLocalDataType().
Mangesh Ghiwarecd2eeb02013-08-23 13:28:21 -070048 /**
49 * Constant for denoting a camera preview.
50 */
51 public static final int LOCAL_CAMERA_PREVIEW = 1;
52 /**
53 * Constant for denoting an arbitrary view.
54 */
55 public static final int LOCAL_VIEW = 2;
56 /**
57 * Constant for denoting a still image.
58 */
59 public static final int LOCAL_IMAGE = 3;
60 /**
61 * Constant for denoting a video.
62 */
63 public static final int LOCAL_VIDEO = 4;
64 /**
Angus Kong32509872013-10-02 16:53:40 -070065 * Constant for denoting an in-progress item which should not be touched
66 * before the related task is done. Data of this type should not support
67 * any actions like sharing, editing, etc.
68 */
Angus Kong8a2350a2013-12-16 15:02:34 -080069 public static final int LOCAL_IN_PROGRESS_DATA = 5;
Sascha Haeberling280fd3e2013-11-21 13:52:15 -080070
Sascha Haeberlingc67c07b2013-12-13 18:48:54 -080071 // TODO: Re-think how the in-progress logic works. We shouldn't need to pass
72 // in the information about whether this session is in progress.
Andy Huiberscaca8c72013-12-13 15:53:43 -080073
74 /**
75 * Creates View to represent media.
76 *
77 * @param context The {@link android.content.Context} to create the view.
78 * @param width Width in pixels of rendered view.
79 * @param height Height in pixels of rendered view.
80 * @param adapter Data adapter for this data item.
81 */
Sam Judd4021c892014-03-17 12:57:50 -070082 View getView(Context context, View recycled, int width, int height, int placeHolderResourceId,
Sascha Haeberling14ff6c82013-12-13 13:29:58 -080083 LocalDataAdapter adapter, boolean isInProgress);
Sascha Haeberling37f36112013-08-06 14:31:52 -070084
Sam Judd43bf03f2014-03-17 11:27:03 -070085 /** Returns a unique identifier for the view created by this data so that the view
86 * can be reused.
87 *
88 * @see android.widget.BaseAdapter#getItemViewType(int)
89 */
90 LocalDataViewType getItemViewType();
91
Andy Huiberscaca8c72013-12-13 15:53:43 -080092 /**
93 * Request resize of View created by getView().
94 *
95 * @param context The {@link android.content.Context} to create the view.
96 * @param width Width in pixels of rendered view.
97 * @param height Height in pixels of rendered view.
98 * @param view View created by getView();
99 * @param adapter Data adapter for this data item.
100 */
Sam Judd4021c892014-03-17 12:57:50 -0700101 public void loadFullImage(Context context, int width, int height, View view, LocalDataAdapter adapter);
Andy Huiberscaca8c72013-12-13 15:53:43 -0800102
Sascha Haeberling37f36112013-08-06 14:31:52 -0700103 /**
104 * Gets the date when this data is created. The returned date is also used
105 * for sorting data.
106 *
107 * @return The date when this data is created.
108 * @see {@link NewestFirstComparator}
109 */
Angus Kong08221032013-06-14 14:50:31 -0700110 long getDateTaken();
Sascha Haeberling37f36112013-08-06 14:31:52 -0700111
112 /**
113 * Gets the date when this data is modified. The returned date is also used
114 * for sorting data.
115 *
116 * @return The date when this data is modified.
117 * @see {@link NewestFirstComparator}
118 */
Angus Kong08221032013-06-14 14:50:31 -0700119 long getDateModified();
Sascha Haeberling37f36112013-08-06 14:31:52 -0700120
121 /** Gets the title of this data */
Angus Kong08221032013-06-14 14:50:31 -0700122 String getTitle();
Sascha Haeberling37f36112013-08-06 14:31:52 -0700123
124 /**
125 * Checks if the data actions (delete/play ...) can be applied on this data.
126 *
127 * @param actions The actions to check.
128 * @return Whether all the actions are supported.
129 */
130 boolean isDataActionSupported(int actions);
131
Angus Kong4ff5a1a2013-08-14 16:07:54 -0700132 /** Removes the data from the storage if possible. */
Angus Kong08221032013-06-14 14:50:31 -0700133 boolean delete(Context c);
Sascha Haeberling37f36112013-08-06 14:31:52 -0700134
Angus Kong8e5e4ee2013-07-30 11:36:00 -0700135 void onFullScreen(boolean fullScreen);
Sascha Haeberling37f36112013-08-06 14:31:52 -0700136
137 /** Returns {@code true} if it allows swipe to filmstrip in full screen. */
Angus Kong8e5e4ee2013-07-30 11:36:00 -0700138 boolean canSwipeInFullScreen();
Sascha Haeberling37f36112013-08-06 14:31:52 -0700139
140 /**
141 * Returns the path to the data on the storage.
142 *
143 * @return Empty path if there's none.
144 */
Angus Kong8e5e4ee2013-07-30 11:36:00 -0700145 String getPath();
Angus Kong750e8ec2013-05-06 10:42:28 -0700146
Sascha Haeberling37f36112013-08-06 14:31:52 -0700147 /**
Sascha Haeberling88ef7662013-08-15 17:19:22 -0700148 * @return The mimetype of this data item, or null, if this item has no
149 * mimetype associated with it.
150 */
151 String getMimeType();
152
153 /**
Angus Kong26795a92014-02-20 09:18:09 -0800154 * @return The media details (such as EXIF) for the data. {@code null} if
155 * not available for the data.
Sascha Haeberling6f64b502013-08-14 16:23:18 -0700156 */
157 MediaDetails getMediaDetails(Context context);
158
159 /**
Angus Kongc27d21b2013-08-12 15:03:45 -0700160 * Returns the type of the local data defined by {@link LocalData}.
161 *
Angus Kongc27d21b2013-08-12 15:03:45 -0700162 * @return The local data type. Could be one of the following:
163 * {@code LOCAL_CAMERA_PREVIEW}, {@code LOCAL_VIEW}, {@code LOCAL_IMAGE},
Sascha Haeberling280fd3e2013-11-21 13:52:15 -0800164 * {@code LOCAL_VIDEO}, {@code LOCAL_PHOTO_SPHERE},
165 * {@code LOCAL_360_PHOTO_SPHERE}, and {@code LOCAL_RGBZ}
Angus Kongc27d21b2013-08-12 15:03:45 -0700166 */
Sascha Haeberlingfae11a12013-08-15 14:29:49 -0700167 int getLocalDataType();
Angus Kongc27d21b2013-08-12 15:03:45 -0700168
169 /**
ztenghuia16e7b52013-08-23 11:47:56 -0700170 * @return The size of the data in bytes
171 */
172 long getSizeInBytes();
173
174 /**
Sascha Haeberling37f36112013-08-06 14:31:52 -0700175 * Refresh the data content.
176 *
Angus Kong8a2350a2013-12-16 15:02:34 -0800177 * @param context The Android {@link android.content.Context}.
ztenghuia16e7b52013-08-23 11:47:56 -0700178 * @return A new LocalData object if success, null otherwise.
Sascha Haeberling37f36112013-08-06 14:31:52 -0700179 */
Angus Kong8a2350a2013-12-16 15:02:34 -0800180 LocalData refresh(Context context);
Sascha Haeberling37f36112013-08-06 14:31:52 -0700181
Angus Kong740cbee2013-12-11 15:46:16 -0800182 /**
Angus Kong8a2350a2013-12-16 15:02:34 -0800183 * @return the {@link android.content.ContentResolver} Id of the data.
Angus Kong740cbee2013-12-11 15:46:16 -0800184 */
Angus Kong8a2350a2013-12-16 15:02:34 -0800185 long getContentId();
Angus Kong740cbee2013-12-11 15:46:16 -0800186
187 /**
Angus Kong8a2350a2013-12-16 15:02:34 -0800188 * @return the metadata. Should never be {@code null}.
Angus Kong740cbee2013-12-11 15:46:16 -0800189 */
Angus Kong8a2350a2013-12-16 15:02:34 -0800190 Bundle getMetadata();
Angus Kong740cbee2013-12-11 15:46:16 -0800191
Angus Konge2f4c032013-12-19 10:24:33 -0800192 /**
Sam Judd4021c892014-03-17 12:57:50 -0700193 * Any media store attribute that can potentially change the local data
194 * should be included in this signature, primarily oriented at detecting
195 * edits.
196 *
197 * @return A string identifying the set of changeable attributes.
198 */
199 String getSignature();
200
201 /**
Angus Konge2f4c032013-12-19 10:24:33 -0800202 * @return whether the metadata is updated.
203 */
204 public boolean isMetadataUpdated();
205
Angus Kong750e8ec2013-05-06 10:42:28 -0700206 static class NewestFirstComparator implements Comparator<LocalData> {
207
Angus Kong8e5e4ee2013-07-30 11:36:00 -0700208 /** Compare taken/modified date of LocalData in descent order to make
209 newer data in the front.
210 The negative numbers here are always considered "bigger" than
211 positive ones. Thus, if any one of the numbers is negative, the logic
212 is reversed. */
Angus Kongdff672d2013-05-22 17:30:56 -0700213 private static int compareDate(long v1, long v2) {
214 if (v1 >= 0 && v2 >= 0) {
Angus Kong7283c602013-05-29 17:06:04 -0700215 return ((v1 < v2) ? 1 : ((v1 > v2) ? -1 : 0));
Angus Kong750e8ec2013-05-06 10:42:28 -0700216 }
Angus Kong7283c602013-05-29 17:06:04 -0700217 return ((v2 < v1) ? 1 : ((v2 > v1) ? -1 : 0));
Angus Kong750e8ec2013-05-06 10:42:28 -0700218 }
219
220 @Override
221 public int compare(LocalData d1, LocalData d2) {
Angus Kongdff672d2013-05-22 17:30:56 -0700222 int cmp = compareDate(d1.getDateTaken(), d2.getDateTaken());
Angus Kong750e8ec2013-05-06 10:42:28 -0700223 if (cmp == 0) {
Angus Kongdff672d2013-05-22 17:30:56 -0700224 cmp = compareDate(d1.getDateModified(), d2.getDateModified());
Angus Kong750e8ec2013-05-06 10:42:28 -0700225 }
226 if (cmp == 0) {
227 cmp = d1.getTitle().compareTo(d2.getTitle());
228 }
229 return cmp;
230 }
231 }
Angus Kong750e8ec2013-05-06 10:42:28 -0700232}