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 android.database.Cursor; 20 21 import com.android.gallery3d.util.GalleryUtils; 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 public int width; 48 public int height; 49 LocalMediaItem(Path path, long version)50 public LocalMediaItem(Path path, long version) { 51 super(path, version); 52 } 53 54 @Override getDateInMs()55 public long getDateInMs() { 56 return dateTakenInMs; 57 } 58 59 @Override getName()60 public String getName() { 61 return caption; 62 } 63 64 @Override getLatLong(double[] latLong)65 public void getLatLong(double[] latLong) { 66 latLong[0] = latitude; 67 latLong[1] = longitude; 68 } 69 updateFromCursor(Cursor cursor)70 abstract protected boolean updateFromCursor(Cursor cursor); 71 getBucketId()72 public int getBucketId() { 73 return bucketId; 74 } 75 updateContent(Cursor cursor)76 protected void updateContent(Cursor cursor) { 77 if (updateFromCursor(cursor)) { 78 mDataVersion = nextVersionNumber(); 79 } 80 } 81 82 @Override getDetails()83 public MediaDetails getDetails() { 84 MediaDetails details = super.getDetails(); 85 details.addDetail(MediaDetails.INDEX_PATH, filePath); 86 details.addDetail(MediaDetails.INDEX_TITLE, caption); 87 DateFormat formater = DateFormat.getDateTimeInstance(); 88 details.addDetail(MediaDetails.INDEX_DATETIME, formater.format(new Date(dateTakenInMs))); 89 90 if (GalleryUtils.isValidLocation(latitude, longitude)) { 91 details.addDetail(MediaDetails.INDEX_LOCATION, new double[] {latitude, longitude}); 92 } 93 if (fileSize > 0) details.addDetail(MediaDetails.INDEX_SIZE, fileSize); 94 return details; 95 } 96 97 @Override getMimeType()98 public String getMimeType() { 99 return mimeType; 100 } 101 getSize()102 public long getSize() { 103 return fileSize; 104 } 105 } 106