Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 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.content.Context; |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 20 | import android.graphics.drawable.Drawable; |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 21 | import android.os.Bundle; |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 22 | import android.view.View; |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 23 | |
Angus Kong | 01054e9 | 2013-12-10 11:06:18 -0800 | [diff] [blame] | 24 | import com.android.camera.filmstrip.ImageData; |
Angus Kong | bd26069 | 2013-08-07 14:52:56 -0700 | [diff] [blame] | 25 | |
| 26 | import java.util.Comparator; |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 27 | |
Sascha Haeberling | f1f5186 | 2013-07-31 11:28:21 -0700 | [diff] [blame] | 28 | /** |
| 29 | * An abstract interface that represents the local media data. Also implements |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 30 | * Comparable interface so we can sort in DataAdapter. |
ztenghui | a16e7b5 | 2013-08-23 11:47:56 -0700 | [diff] [blame] | 31 | * 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 Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 34 | */ |
Angus Kong | 01054e9 | 2013-12-10 11:06:18 -0800 | [diff] [blame] | 35 | public interface LocalData extends ImageData { |
Sascha Haeberling | 5850115 | 2014-01-06 11:02:35 -0800 | [diff] [blame] | 36 | static final String TAG = "LocalData"; |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 37 | |
ztenghui | a16e7b5 | 2013-08-23 11:47:56 -0700 | [diff] [blame] | 38 | public static final String MIME_TYPE_JPEG = "image/jpeg"; |
| 39 | |
Angus Kong | 740cbee | 2013-12-11 15:46:16 -0800 | [diff] [blame] | 40 | // 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 Kong | e0aff89 | 2013-12-11 20:51:01 -0800 | [diff] [blame] | 45 | public static final int DATA_ACTION_SHARE = (1 << 3); |
Angus Kong | 0822103 | 2013-06-14 14:50:31 -0700 | [diff] [blame] | 46 | |
Angus Kong | c27d21b | 2013-08-12 15:03:45 -0700 | [diff] [blame] | 47 | // Local data types. Returned by getLocalDataType(). |
Mangesh Ghiware | cd2eeb0 | 2013-08-23 13:28:21 -0700 | [diff] [blame] | 48 | /** |
| 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 Kong | 3250987 | 2013-10-02 16:53:40 -0700 | [diff] [blame] | 65 | * 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 Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 69 | public static final int LOCAL_IN_PROGRESS_DATA = 5; |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 70 | |
Sascha Haeberling | c67c07b | 2013-12-13 18:48:54 -0800 | [diff] [blame] | 71 | // 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 Huibers | caca8c7 | 2013-12-13 15:53:43 -0800 | [diff] [blame] | 73 | |
| 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 Judd | 4021c89 | 2014-03-17 12:57:50 -0700 | [diff] [blame] | 82 | View getView(Context context, View recycled, int width, int height, int placeHolderResourceId, |
Sascha Haeberling | 14ff6c8 | 2013-12-13 13:29:58 -0800 | [diff] [blame] | 83 | LocalDataAdapter adapter, boolean isInProgress); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 84 | |
Sam Judd | 43bf03f | 2014-03-17 11:27:03 -0700 | [diff] [blame] | 85 | /** 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 Huibers | caca8c7 | 2013-12-13 15:53:43 -0800 | [diff] [blame] | 92 | /** |
| 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 Judd | 4021c89 | 2014-03-17 12:57:50 -0700 | [diff] [blame] | 101 | public void loadFullImage(Context context, int width, int height, View view, LocalDataAdapter adapter); |
Andy Huibers | caca8c7 | 2013-12-13 15:53:43 -0800 | [diff] [blame] | 102 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 103 | /** |
| 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 Kong | 0822103 | 2013-06-14 14:50:31 -0700 | [diff] [blame] | 110 | long getDateTaken(); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 111 | |
| 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 Kong | 0822103 | 2013-06-14 14:50:31 -0700 | [diff] [blame] | 119 | long getDateModified(); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 120 | |
| 121 | /** Gets the title of this data */ |
Angus Kong | 0822103 | 2013-06-14 14:50:31 -0700 | [diff] [blame] | 122 | String getTitle(); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 123 | |
| 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 Kong | 4ff5a1a | 2013-08-14 16:07:54 -0700 | [diff] [blame] | 132 | /** Removes the data from the storage if possible. */ |
Angus Kong | 0822103 | 2013-06-14 14:50:31 -0700 | [diff] [blame] | 133 | boolean delete(Context c); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 134 | |
Angus Kong | 8e5e4ee | 2013-07-30 11:36:00 -0700 | [diff] [blame] | 135 | void onFullScreen(boolean fullScreen); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 136 | |
| 137 | /** Returns {@code true} if it allows swipe to filmstrip in full screen. */ |
Angus Kong | 8e5e4ee | 2013-07-30 11:36:00 -0700 | [diff] [blame] | 138 | boolean canSwipeInFullScreen(); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Returns the path to the data on the storage. |
| 142 | * |
| 143 | * @return Empty path if there's none. |
| 144 | */ |
Angus Kong | 8e5e4ee | 2013-07-30 11:36:00 -0700 | [diff] [blame] | 145 | String getPath(); |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 146 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 147 | /** |
Sascha Haeberling | 88ef766 | 2013-08-15 17:19:22 -0700 | [diff] [blame] | 148 | * @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 Kong | 26795a9 | 2014-02-20 09:18:09 -0800 | [diff] [blame] | 154 | * @return The media details (such as EXIF) for the data. {@code null} if |
| 155 | * not available for the data. |
Sascha Haeberling | 6f64b50 | 2013-08-14 16:23:18 -0700 | [diff] [blame] | 156 | */ |
| 157 | MediaDetails getMediaDetails(Context context); |
| 158 | |
| 159 | /** |
Angus Kong | c27d21b | 2013-08-12 15:03:45 -0700 | [diff] [blame] | 160 | * Returns the type of the local data defined by {@link LocalData}. |
| 161 | * |
Angus Kong | c27d21b | 2013-08-12 15:03:45 -0700 | [diff] [blame] | 162 | * @return The local data type. Could be one of the following: |
| 163 | * {@code LOCAL_CAMERA_PREVIEW}, {@code LOCAL_VIEW}, {@code LOCAL_IMAGE}, |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 164 | * {@code LOCAL_VIDEO}, {@code LOCAL_PHOTO_SPHERE}, |
| 165 | * {@code LOCAL_360_PHOTO_SPHERE}, and {@code LOCAL_RGBZ} |
Angus Kong | c27d21b | 2013-08-12 15:03:45 -0700 | [diff] [blame] | 166 | */ |
Sascha Haeberling | fae11a1 | 2013-08-15 14:29:49 -0700 | [diff] [blame] | 167 | int getLocalDataType(); |
Angus Kong | c27d21b | 2013-08-12 15:03:45 -0700 | [diff] [blame] | 168 | |
| 169 | /** |
ztenghui | a16e7b5 | 2013-08-23 11:47:56 -0700 | [diff] [blame] | 170 | * @return The size of the data in bytes |
| 171 | */ |
| 172 | long getSizeInBytes(); |
| 173 | |
| 174 | /** |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 175 | * Refresh the data content. |
| 176 | * |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 177 | * @param context The Android {@link android.content.Context}. |
ztenghui | a16e7b5 | 2013-08-23 11:47:56 -0700 | [diff] [blame] | 178 | * @return A new LocalData object if success, null otherwise. |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 179 | */ |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 180 | LocalData refresh(Context context); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 181 | |
Angus Kong | 740cbee | 2013-12-11 15:46:16 -0800 | [diff] [blame] | 182 | /** |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 183 | * @return the {@link android.content.ContentResolver} Id of the data. |
Angus Kong | 740cbee | 2013-12-11 15:46:16 -0800 | [diff] [blame] | 184 | */ |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 185 | long getContentId(); |
Angus Kong | 740cbee | 2013-12-11 15:46:16 -0800 | [diff] [blame] | 186 | |
| 187 | /** |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 188 | * @return the metadata. Should never be {@code null}. |
Angus Kong | 740cbee | 2013-12-11 15:46:16 -0800 | [diff] [blame] | 189 | */ |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 190 | Bundle getMetadata(); |
Angus Kong | 740cbee | 2013-12-11 15:46:16 -0800 | [diff] [blame] | 191 | |
Angus Kong | e2f4c03 | 2013-12-19 10:24:33 -0800 | [diff] [blame] | 192 | /** |
Sam Judd | 4021c89 | 2014-03-17 12:57:50 -0700 | [diff] [blame] | 193 | * 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 Kong | e2f4c03 | 2013-12-19 10:24:33 -0800 | [diff] [blame] | 202 | * @return whether the metadata is updated. |
| 203 | */ |
| 204 | public boolean isMetadataUpdated(); |
| 205 | |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 206 | static class NewestFirstComparator implements Comparator<LocalData> { |
| 207 | |
Angus Kong | 8e5e4ee | 2013-07-30 11:36:00 -0700 | [diff] [blame] | 208 | /** 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 Kong | dff672d | 2013-05-22 17:30:56 -0700 | [diff] [blame] | 213 | private static int compareDate(long v1, long v2) { |
| 214 | if (v1 >= 0 && v2 >= 0) { |
Angus Kong | 7283c60 | 2013-05-29 17:06:04 -0700 | [diff] [blame] | 215 | return ((v1 < v2) ? 1 : ((v1 > v2) ? -1 : 0)); |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 216 | } |
Angus Kong | 7283c60 | 2013-05-29 17:06:04 -0700 | [diff] [blame] | 217 | return ((v2 < v1) ? 1 : ((v2 > v1) ? -1 : 0)); |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | @Override |
| 221 | public int compare(LocalData d1, LocalData d2) { |
Angus Kong | dff672d | 2013-05-22 17:30:56 -0700 | [diff] [blame] | 222 | int cmp = compareDate(d1.getDateTaken(), d2.getDateTaken()); |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 223 | if (cmp == 0) { |
Angus Kong | dff672d | 2013-05-22 17:30:56 -0700 | [diff] [blame] | 224 | cmp = compareDate(d1.getDateModified(), d2.getDateModified()); |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 225 | } |
| 226 | if (cmp == 0) { |
| 227 | cmp = d1.getTitle().compareTo(d2.getTitle()); |
| 228 | } |
| 229 | return cmp; |
| 230 | } |
| 231 | } |
Angus Kong | 750e8ec | 2013-05-06 10:42:28 -0700 | [diff] [blame] | 232 | } |