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.net.Uri; 20 21 import com.android.camera.util.Size; 22 23 import java.util.Date; 24 25 /** 26 * Represents an immutable set of backing data. No object or value 27 * returned from this object should be mutable. 28 */ 29 public class FilmstripItemData { 30 // TODO Make these enum values. 31 public static final String MIME_TYPE_JPEG = "image/jpeg"; 32 public static final String MIME_TYPE_GIF = "image/gif"; 33 public static final String MIME_TYPE_PHOTOSPHERE = "application/vnd.google.panorama360+jpg"; 34 public static final String MIME_TYPE_MP4 = "video/mp4"; 35 36 private final long mContentId; 37 private final String mTitle; 38 private final String mMimeType; 39 private final Date mCreationDate; 40 private final Date mLastModifiedDate; 41 private final String mFilePath; 42 private final Uri mUri; 43 private final Size mDimensions; 44 private final long mSizeInBytes; 45 private final int mOrientation; 46 private final Location mLocation; 47 FilmstripItemData( long contentId, String title, String mimeType, Date creationDate, Date lastModifiedDate, String filePath, Uri uri, Size dimensions, long sizeInBytes, int orientation, Location location)48 public FilmstripItemData( 49 long contentId, 50 String title, 51 String mimeType, 52 Date creationDate, 53 Date lastModifiedDate, 54 String filePath, 55 Uri uri, 56 Size dimensions, 57 long sizeInBytes, 58 int orientation, 59 Location location) { 60 mContentId = contentId; 61 mTitle = title; 62 mMimeType = mimeType; 63 mCreationDate = creationDate; 64 mLastModifiedDate = lastModifiedDate; 65 mFilePath = filePath; 66 mUri = uri; 67 mDimensions = dimensions; 68 mSizeInBytes = sizeInBytes; 69 mOrientation = orientation; 70 mLocation = location; 71 } 72 getContentId()73 public long getContentId() { 74 return mContentId; 75 } 76 77 /** 78 * Gets the string title of this item. May be used for sorting. 79 */ getTitle()80 public String getTitle() { 81 return mTitle; 82 } 83 84 /** 85 * @return The mimetype of this data item, or null, if this item has no 86 * mimetype associated with it. 87 */ getMimeType()88 public String getMimeType() { 89 return mMimeType; 90 } 91 92 /** 93 * Gets the date when this item was created. The returned date may be used 94 * for sorting. 95 */ getCreationDate()96 public Date getCreationDate() { 97 return mCreationDate; 98 } 99 100 /** 101 * Gets the date when this item was last modified. The returned date may 102 * be used for sorting. 103 */ getLastModifiedDate()104 public Date getLastModifiedDate() { 105 return mLastModifiedDate; 106 } 107 108 /** 109 * Returns the path to the data on the storage. 110 */ getFilePath()111 public String getFilePath() { 112 return mFilePath; 113 } 114 115 /** 116 * @return The URI of this data. Must be a unique one and not null. 117 */ getUri()118 public Uri getUri() { 119 return mUri; 120 } 121 122 /** 123 * Dimensions of this item. 124 * 125 * @return physical width and height in pixels. 126 */ getDimensions()127 /* package */ Size getDimensions() { 128 return mDimensions; 129 } 130 131 /** 132 * @return total number of bytes that represent this item. 133 */ getSizeInBytes()134 public long getSizeInBytes() { 135 return mSizeInBytes; 136 } 137 138 /** 139 * Returns the rotation of the image in degrees clockwise. The valid values 140 * are 0, 90, 180, and 270. 141 */ getOrientation()142 /* package */ int getOrientation() { 143 return mOrientation; 144 } 145 getLocation()146 public Location getLocation() { 147 return mLocation; 148 } 149 150 @Override toString()151 public String toString() { 152 StringBuilder sb = new StringBuilder(); 153 sb.append("FilmstripItemData {"); 154 sb.append("id:"); 155 sb.append(mContentId); 156 sb.append(",title:"); 157 sb.append(mTitle); 158 sb.append(",mimeType:"); 159 sb.append(mMimeType); 160 sb.append(",creationDate:"); 161 sb.append(mCreationDate); 162 sb.append(",lastModifiedDate:"); 163 sb.append(mLastModifiedDate); 164 sb.append(",filePath:"); 165 sb.append(mFilePath); 166 sb.append(",uri:"); 167 sb.append(mUri); 168 sb.append(",dimensions:"); 169 sb.append(mDimensions); 170 sb.append(",sizeInBytes:"); 171 sb.append(mSizeInBytes); 172 sb.append(",orientation:"); 173 sb.append(mOrientation); 174 sb.append(",location:"); 175 sb.append(mLocation); 176 sb.append("}"); 177 return sb.toString(); 178 } 179 180 public static class Builder { 181 public static final Date EMPTY = new Date(0); 182 public static final Size ZERO = new Size(0, 0); 183 184 private long mContentId = -1; 185 private String mTitle = ""; 186 private String mMimeType = ""; 187 private Date mCreationDate = EMPTY; 188 private Date mLastModifiedDate = EMPTY; 189 private String mFilePath = ""; 190 private final Uri mUri; 191 private Size mDimensions = ZERO; 192 private long mSizeInBytes = 0; 193 private int mOrientation = 0; 194 private Location mLocation = Location.UNKNOWN; 195 Builder(Uri uri)196 public Builder(Uri uri) { 197 mUri = uri; 198 } 199 build()200 public FilmstripItemData build() { 201 return new FilmstripItemData( 202 mContentId, 203 mTitle, 204 mMimeType, 205 mCreationDate, 206 mLastModifiedDate, 207 mFilePath, 208 mUri, 209 mDimensions, 210 mSizeInBytes, 211 mOrientation, 212 mLocation 213 ); 214 } 215 from(FilmstripItemData data)216 public static Builder from(FilmstripItemData data) { 217 Builder builder = new Builder(data.getUri()); 218 builder.mContentId = data.getContentId(); 219 builder.mTitle = data.getTitle(); 220 builder.mMimeType = data.getMimeType(); 221 builder.mCreationDate = data.getCreationDate(); 222 builder.mLastModifiedDate = data.getLastModifiedDate(); 223 builder.mFilePath = data.getFilePath(); 224 builder.mDimensions = data.getDimensions(); 225 builder.mSizeInBytes = data.getSizeInBytes(); 226 builder.mOrientation = data.getOrientation(); 227 builder.mLocation = data.getLocation(); 228 return builder; 229 } 230 withContentId(long contentId)231 public Builder withContentId(long contentId) { 232 mContentId = contentId; 233 return this; 234 } 235 withTitle(String title)236 public Builder withTitle(String title) { 237 mTitle = title; 238 return this; 239 } 240 withMimeType(String mimeType)241 public Builder withMimeType(String mimeType) { 242 mMimeType = mimeType; 243 return this; 244 } 245 withCreationDate(Date creationDate)246 public Builder withCreationDate(Date creationDate) { 247 mCreationDate = creationDate; 248 return this; 249 } 250 withLastModifiedDate(Date lastModifiedDate)251 public Builder withLastModifiedDate(Date lastModifiedDate) { 252 mLastModifiedDate = lastModifiedDate; 253 return this; 254 } 255 withFilePath(String filePath)256 public Builder withFilePath(String filePath) { 257 mFilePath = filePath; 258 return this; 259 } 260 withDimensions(Size dimensions)261 public Builder withDimensions(Size dimensions) { 262 mDimensions = dimensions; 263 return this; 264 } 265 withSizeInBytes(long sizeInBytes)266 public Builder withSizeInBytes(long sizeInBytes) { 267 mSizeInBytes = sizeInBytes; 268 return this; 269 } 270 withOrientation(int orientation)271 public Builder withOrientation(int orientation) { 272 mOrientation = orientation; 273 return this; 274 } 275 withLocation(Location location)276 public Builder withLocation(Location location) { 277 mLocation = location; 278 return this; 279 } 280 } 281 } 282