1 /* 2 * Copyright (C) 2009 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.cooliris.media; 18 19 import java.util.Date; 20 21 public final class MediaItem { 22 public static final int MEDIA_TYPE_IMAGE = 0; 23 public static final int MEDIA_TYPE_VIDEO = 1; 24 // Approximately the year 1975 in milliseconds and seconds. Serves as a min 25 // cutoff for bad times. 26 public static final long MIN_VALID_DATE_IN_MS = 157680000000L; 27 public static final long MIN_VALID_DATE_IN_SEC = 157680000L; 28 // Approximately the year 2035 in milliseconds ans seconds. Serves as a max 29 // cutoff for bad time. 30 public static final long MAX_VALID_DATE_IN_MS = 2049840000000L; 31 public static final long MAX_VALID_DATE_IN_SEC = 2049840000L; 32 33 // mId is not a unique identifier of the item mId is initialized to -1 in 34 // some cases. 35 public static final String ID = new String("id"); 36 public long mId; 37 38 public String mGuid; 39 public String mCaption; 40 public String mEditUri; 41 public String mContentUri; 42 public String mThumbnailUri; 43 public String mScreennailUri; 44 public String mMicroThumbnailUri; 45 public String mWeblink; 46 public String mMimeType; 47 private String mDisplayMimeType; 48 private int mMediaType = -1; 49 public String mRole; 50 public String mDescription; 51 52 // Location-based properties of the item. 53 public double mLatitude; 54 public double mLongitude; 55 public String mReverseGeocodedLocation; 56 57 public long mDateTakenInMs = 0; 58 public Date mLocaltime; 59 public boolean mTriedRetrievingExifDateTaken = false; 60 public long mDateModifiedInSec = 0; 61 public long mDateAddedInSec = 0; 62 public int mDurationInSec; 63 64 public int mPrimingState = 0; 65 public static final int NOT_PRIMED = 0; 66 public static final int STARTED_PRIMING = 1; 67 public static final int PRIMED = 2; 68 69 public int mClusteringState = 0; 70 public static final int NOT_CLUSTERED = 0; 71 public static final int CLUSTERED = 1; 72 73 public float mRotation; 74 75 public long mThumbnailId; 76 public int mThumbnailFocusX; 77 public int mThumbnailFocusY; 78 79 public String mFilePath; 80 81 public MediaSet mParentMediaSet; 82 public boolean mFlagForDelete; 83 84 public MediaItem() { 85 mCaption = ""; 86 } 87 88 public boolean isWellFormed() { 89 return true; 90 } 91 92 @Override 93 public String toString() { 94 return mCaption; 95 } 96 97 public boolean isLatLongValid() { 98 return (mLatitude != 0.0 || mLongitude != 0.0); 99 } 100 101 // Serves as a sanity check cutoff for bad exif information. 102 public boolean isDateTakenValid() { 103 return (mDateTakenInMs > MIN_VALID_DATE_IN_MS && mDateTakenInMs < MAX_VALID_DATE_IN_MS); 104 } 105 106 public boolean isDateModifiedValid() { 107 return (mDateModifiedInSec > MIN_VALID_DATE_IN_SEC && mDateModifiedInSec < MAX_VALID_DATE_IN_SEC); 108 } 109 110 public boolean isDateAddedValid() { 111 return (mDateAddedInSec > MIN_VALID_DATE_IN_SEC && mDateAddedInSec < MAX_VALID_DATE_IN_SEC); 112 } 113 114 public boolean isPicassaItem() { 115 return (mParentMediaSet != null && mParentMediaSet.isPicassaAlbum()); 116 } 117 118 private static final String VIDEO = "video/"; 119 120 public int getMediaType() { 121 if (mMediaType == -1) { 122 // Default to image if mMimetype is null or not video. 123 mMediaType = (mMimeType != null && mMimeType.startsWith(VIDEO)) ? MediaItem.MEDIA_TYPE_VIDEO 124 : MediaItem.MEDIA_TYPE_IMAGE; 125 } 126 return mMediaType; 127 } 128 129 public void setMediaType(int mediaType) { 130 mMediaType = mediaType; 131 } 132 133 public String getDisplayMimeType() { 134 if (mDisplayMimeType == null && mMimeType != null) { 135 int slashPos = mMimeType.indexOf('/'); 136 if (slashPos != -1 && slashPos + 1 < mMimeType.length()) { 137 mDisplayMimeType = mMimeType.substring(slashPos + 1).toUpperCase(); 138 } else { 139 mDisplayMimeType = mMimeType.toUpperCase(); 140 } 141 } 142 return (mDisplayMimeType == null) ? "" : mDisplayMimeType; 143 } 144 145 public void setDisplayMimeType(final String displayMimeType) { 146 mDisplayMimeType = displayMimeType; 147 } 148 149 public String getReverseGeocodedLocation(ReverseGeocoder reverseGeocoder) { 150 if (mReverseGeocodedLocation != null) { 151 return mReverseGeocodedLocation; 152 } 153 if (reverseGeocoder == null || !isLatLongValid()) { 154 return null; 155 } 156 // Get the 2 most granular details available. 157 mReverseGeocodedLocation = reverseGeocoder.getReverseGeocodedLocation(mLatitude, mLongitude, 2); 158 return mReverseGeocodedLocation; 159 } 160 } 161