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