1 /* 2 * Copyright (C) 2010 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.gallery3d.data; 18 19 import com.android.gallery3d.util.GalleryUtils; 20 21 import android.database.Cursor; 22 23 import java.text.DateFormat; 24 import java.util.Date; 25 26 // 27 // LocalMediaItem is an abstract class captures those common fields 28 // in LocalImage and LocalVideo. 29 // 30 public abstract class LocalMediaItem extends MediaItem { 31 32 @SuppressWarnings("unused") 33 private static final String TAG = "LocalMediaItem"; 34 35 // database fields 36 public int id; 37 public String caption; 38 public String mimeType; 39 public long fileSize; 40 public double latitude = INVALID_LATLNG; 41 public double longitude = INVALID_LATLNG; 42 public long dateTakenInMs; 43 public long dateAddedInSec; 44 public long dateModifiedInSec; 45 public String filePath; 46 public int bucketId; 47 48 public LocalMediaItem(Path path, long version) { 49 super(path, version); 50 } 51 52 @Override 53 public long getDateInMs() { 54 return dateTakenInMs; 55 } 56 57 @Override 58 public String getName() { 59 return caption; 60 } 61 62 @Override 63 public void getLatLong(double[] latLong) { 64 latLong[0] = latitude; 65 latLong[1] = longitude; 66 } 67 68 abstract protected boolean updateFromCursor(Cursor cursor); 69 70 public int getBucketId() { 71 return bucketId; 72 } 73 74 protected void updateContent(Cursor cursor) { 75 if (updateFromCursor(cursor)) { 76 mDataVersion = nextVersionNumber(); 77 } 78 } 79 80 @Override 81 public MediaDetails getDetails() { 82 MediaDetails details = super.getDetails(); 83 details.addDetail(MediaDetails.INDEX_PATH, filePath); 84 details.addDetail(MediaDetails.INDEX_TITLE, caption); 85 DateFormat formater = DateFormat.getDateTimeInstance(); 86 details.addDetail(MediaDetails.INDEX_DATETIME, formater.format(new Date(dateTakenInMs))); 87 88 if (GalleryUtils.isValidLocation(latitude, longitude)) { 89 details.addDetail(MediaDetails.INDEX_LOCATION, new double[] {latitude, longitude}); 90 } 91 if (fileSize > 0) details.addDetail(MediaDetails.INDEX_SIZE, fileSize); 92 return details; 93 } 94 95 @Override 96 public String getMimeType() { 97 return mimeType; 98 } 99 100 public long getSize() { 101 return fileSize; 102 } 103 } 104