2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.camera.data;
19 import android.content.ContentResolver;
20 import android.content.Context;
21 import android.database.Cursor;
22 import android.net.Uri;
23 import android.provider.MediaStore;
25 import com.android.camera.data.FilmstripContentQueries.CursorToFilmstripItemFactory;
26 import com.android.camera.debug.Log;
28 import java.util.List;
30 public class VideoItemFactory implements CursorToFilmstripItemFactory<VideoItem> {
31 private static final Log.Tag TAG = new Log.Tag("VideoItemFact");
32 private static final String QUERY_ORDER = MediaStore.Video.VideoColumns.DATE_TAKEN
33 + " DESC, " + MediaStore.Video.VideoColumns._ID + " DESC";
35 private final Context mContext;
36 private final ContentResolver mContentResolver;
37 private final VideoDataFactory mVideoDataFactory;
39 public VideoItemFactory(Context context, ContentResolver contentResolver,
40 VideoDataFactory videoDataFactory) {
42 mContentResolver = contentResolver;
43 mVideoDataFactory = videoDataFactory;
47 public VideoItem get(Cursor c) {
48 VideoItemData data = mVideoDataFactory.fromCursor(c);
50 return new VideoItem(mContext, data, this);
52 Log.w(TAG, "skipping item with null data, returning null for item");
57 /** Query for a single video data item */
58 public VideoItem get(Uri uri) {
59 VideoItem newData = null;
60 Cursor c = mContext.getContentResolver().query(uri, VideoDataQuery.QUERY_PROJECTION, null,
63 if (c.moveToFirst()) {
72 /** Query for all the video data items */
73 public List<VideoItem> queryAll() {
74 return queryAll(VideoDataQuery.CONTENT_URI,
75 FilmstripItemBase.QUERY_ALL_MEDIA_ID);
78 /** Query for all the video data items */
79 public List<VideoItem> queryAll(Uri uri, long lastId) {
80 return FilmstripContentQueries
81 .forCameraPath(mContentResolver, uri, VideoDataQuery.QUERY_PROJECTION, lastId,
85 /** Query for a single data item */
86 public VideoItem queryContentUri(Uri uri) {
87 // TODO: Consider refactoring this, this approach may be slow.
88 List<VideoItem> videos = queryAll(uri,
89 FilmstripItemBase.QUERY_ALL_MEDIA_ID);
90 if (videos.isEmpty()) {