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
17package com.android.gallery3d.data;
18
19import android.database.Cursor;
20
21import com.android.gallery3d.util.GalleryUtils;
22
23import java.text.DateFormat;
24import java.util.Date;
25
26//
27// LocalMediaItem is an abstract class captures those common fields
28// in LocalImage and LocalVideo.
29//
30public 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
50    public LocalMediaItem(Path path, long version) {
51        super(path, version);
52    }
53
54    @Override
55    public long getDateInMs() {
56        return dateTakenInMs;
57    }
58
59    @Override
60    public String getName() {
61        return caption;
62    }
63
64    @Override
65    public void getLatLong(double[] latLong) {
66        latLong[0] = latitude;
67        latLong[1] = longitude;
68    }
69
70    abstract protected boolean updateFromCursor(Cursor cursor);
71
72    public int getBucketId() {
73        return bucketId;
74    }
75
76    protected void updateContent(Cursor cursor) {
77        if (updateFromCursor(cursor)) {
78            mDataVersion = nextVersionNumber();
79        }
80    }
81
82    @Override
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,
89                formater.format(new Date(dateModifiedInSec * 1000)));
90        details.addDetail(MediaDetails.INDEX_WIDTH, width);
91        details.addDetail(MediaDetails.INDEX_HEIGHT, height);
92
93        if (GalleryUtils.isValidLocation(latitude, longitude)) {
94            details.addDetail(MediaDetails.INDEX_LOCATION, new double[] {latitude, longitude});
95        }
96        if (fileSize > 0) details.addDetail(MediaDetails.INDEX_SIZE, fileSize);
97        return details;
98    }
99
100    @Override
101    public String getMimeType() {
102        return mimeType;
103    }
104
105    @Override
106    public long getSize() {
107        return fileSize;
108    }
109}
110