1 /* 2 * Copyright (C) 2013 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.camera.data; 18 19 import android.net.Uri; 20 import android.os.AsyncTask; 21 22 import com.android.camera.filmstrip.DataAdapter; 23 import com.android.camera.util.Callback; 24 import com.android.camera.widget.Preloader; 25 26 import java.util.List; 27 28 /** 29 * An interface which extends {@link com.android.camera.filmstrip.DataAdapter} 30 * and defines operations on the data in the local camera folder. 31 */ 32 public interface LocalDataAdapter extends DataAdapter, 33 Preloader.ItemLoader<Integer, AsyncTask>, Preloader.ItemSource<Integer> { 34 35 public interface LocalDataListener { 36 /** 37 * Metadata of a {@link com.android.camera.data.LocalData} is loaded on 38 * demand. Once the metadata is loaded this listener is notified. 39 * 40 * @param updatedData The IDs of the data whose metadata has been 41 * updated. 42 */ 43 public void onMetadataUpdated(List<Integer> updatedData); 44 } 45 46 /** 47 * Request for loading any photos that may have been added to the 48 * media store since the last update. 49 */ 50 public void requestLoadNewPhotos(); 51 52 /** 53 * Request for loading the local data. 54 */ 55 public void requestLoad(Callback<Void> doneCallback); 56 57 /** 58 * Returns the specified {@link LocalData}. 59 * 60 * @param dataID The ID of the {@link LocalData} to get. 61 * @return The {@link LocalData} to get. {@code null} if not available. 62 */ 63 public LocalData getLocalData(int dataID); 64 65 /** 66 * Remove the data in the local camera folder. 67 * 68 * @param dataID ID of data to be deleted. 69 */ 70 public void removeData(int dataID); 71 72 /** 73 * Adds new local data. The data is either inserted or updated, depending 74 * on the existence of the Uri. 75 * 76 * @param data The new data. 77 * @return Whether the data is newly inserted. 78 */ 79 public boolean addData(LocalData data); 80 81 /** 82 * Refresh the data by {@link Uri}. 83 * 84 * @param uri The {@link Uri} of the data to refresh. 85 */ 86 public void refresh(Uri uri); 87 88 /** 89 * Finds the {@link LocalData} of the specified content Uri. 90 * 91 * @param uri The content Uri of the {@link LocalData}. 92 * @return The index of the data. {@code -1} if not found. 93 */ 94 public int findDataByContentUri(Uri uri); 95 96 /** 97 * Clears all the data currently loaded. 98 */ 99 public void flush(); 100 101 /** 102 * Executes the deletion task. Delete the data waiting in the deletion 103 * queue. 104 * 105 * @return Whether the task has been executed 106 */ 107 public boolean executeDeletion(); 108 109 /** 110 * Undo a deletion. If there is any data waiting to be deleted in the queue, 111 * move it out of the deletion queue. 112 * 113 * @return Whether there are items in the queue. 114 */ 115 public boolean undoDataRemoval(); 116 117 /** 118 * Update the data in a specific position. 119 * 120 * @param pos The position of the data to be updated. 121 * @param data The new data. 122 */ 123 public void updateData(int pos, LocalData data); 124 125 /** Sets the listener for the LocalData change. */ 126 public void setLocalDataListener(LocalDataListener listener); 127 128 /** 129 * Updates the metadata in the background. The completion of the updating 130 * will be notified through 131 * {@link com.android.camera.data.LocalDataAdapter.LocalDataListener}. 132 * 133 * @param dataId The ID of the data to update the metadata for. 134 * @return An {@link android.os.AsyncTask} performing the background load 135 * that can be used to cancel the load if it's no longer needed. 136 */ 137 public AsyncTask updateMetadata(int dataId); 138 139 /** 140 * @return whether the metadata is already updated. 141 */ 142 public boolean isMetadataUpdated(int dataId); 143 } 144