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.filmstrip; 18 19 import android.content.Context; 20 import android.view.View; 21 22 /** 23 * An interface which defines the interactions between the 24 * {@link ImageData} and the 25 * {@link com.android.camera.widget.FilmstripView}. 26 */ 27 public interface DataAdapter { 28 /** 29 * An interface which defines the update reporter used to return to the 30 * {@link com.android.camera.filmstrip.FilmstripController.FilmstripListener}. 31 */ 32 public interface UpdateReporter { 33 /** Checks if the data of dataID is removed. */ 34 public boolean isDataRemoved(int dataID); 35 36 /** Checks if the data of dataID is updated. */ 37 public boolean isDataUpdated(int dataID); 38 } 39 40 /** 41 * An interface which defines the listener for data events over 42 * {@link ImageData}. Usually 43 * {@link com.android.camera.widget.FilmstripView} itself. 44 */ 45 public interface Listener { 46 /** 47 * Called when the whole data loading is done. There is not any 48 * assumption on the previous data. 49 */ 50 public void onDataLoaded(); 51 52 /** 53 * Called when some of the data is updated. 54 * 55 * @param reporter Use this reporter to know what happened. 56 */ 57 public void onDataUpdated(UpdateReporter reporter); 58 59 /** 60 * Called when a new data item is inserted. 61 * 62 * @param dataID The ID of the inserted data. 63 * @param data The inserted data. 64 */ 65 public void onDataInserted(int dataID, ImageData data); 66 67 /** 68 * Called when a data item is removed. 69 * 70 * @param dataID The ID of the removed data. 71 * @param data The data. 72 */ 73 public void onDataRemoved(int dataID, ImageData data); 74 } 75 76 /** Returns the total number of image data. */ 77 public int getTotalNumber(); 78 79 /** 80 * Returns the view to visually present the image data. 81 * 82 * @param context The {@link android.content.Context} to create the view. 83 * @param recycled A view that can be reused if one is available, or null. 84 * @param dataID The ID of the image data to be presented. 85 * @return The view representing the image data. Null if unavailable or 86 * the {@code dataID} is out of range. 87 */ 88 public View getView(Context context, View recycled, int dataID); 89 90 /** Returns a unique identifier for the view created by this data so that the view 91 * can be reused. 92 * 93 * @see android.widget.BaseAdapter#getItemViewType(int) 94 */ 95 public int getItemViewType(int dataId); 96 97 /** 98 * Resizes the view used to visually present the image data. This is 99 * useful when the view contains a bitmap. 100 * 101 * @param context The {@link android.content.Context} to create the view. 102 * @param dataID The ID of the resize data to be presented. 103 * @param view The view to update that was created by getView(). 104 * @param w Width in pixels of rendered view. 105 * @param h Height in pixels of rendered view. 106 */ 107 public void resizeView(Context context, int dataID, View view, int w, int h); 108 109 /** 110 * Returns the {@link ImageData} specified by the ID. 111 * 112 * @param dataID The ID of the {@link ImageData}. 113 * @return The specified {@link ImageData}. Null if not available. 114 */ 115 public ImageData getImageData(int dataID); 116 117 /** 118 * Suggests the data adapter the maximum possible size of the layout so 119 * the {@link DataAdapter} can optimize the view returned for the 120 * {@link ImageData}. 121 * 122 * @param widthPixels Width in pixels of rendered view. 123 * @param heightPixels Height in pixels of rendered view. 124 */ 125 public void suggestViewSizeBound(int widthPixels, int heightPixels); 126 127 /** 128 * Sets the listener for data events over the ImageData. Replaces the 129 * previous listener if it exists. 130 * 131 * @param listener The listener to use. 132 */ 133 public void setListener(Listener listener); 134 135 /** 136 * Returns whether the view of the data can be moved by swipe 137 * gesture when in full-screen. 138 * 139 * @param dataID The ID of the data. 140 * @return Whether the view can be moved. 141 */ 142 public boolean canSwipeInFullScreen(int dataID); 143 } 144