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.Context;
20 import android.net.Uri;
21 import android.os.AsyncTask;
22 import android.view.View;
24 import com.android.camera.debug.Log;
25 import com.android.camera.filmstrip.DataAdapter;
26 import com.android.camera.filmstrip.ImageData;
29 * A {@link LocalDataAdapter} which puts a {@link LocalData} fixed at the first
30 * position. It's done by combining a {@link LocalData} and another
31 * {@link LocalDataAdapter}.
33 public class FixedFirstDataAdapter extends AbstractLocalDataAdapterWrapper
34 implements DataAdapter.Listener {
36 @SuppressWarnings("unused")
37 private static final Log.Tag TAG = new Log.Tag("FixedFirstDataAdpt");
39 private LocalData mFirstData;
40 private Listener mListener;
45 * @param context Valid Android context.
46 * @param wrappedAdapter The {@link LocalDataAdapter} to be wrapped.
47 * @param firstData The {@link LocalData} to be placed at the first
50 public FixedFirstDataAdapter(
52 LocalDataAdapter wrappedAdapter,
53 LocalData firstData) {
54 super(context, wrappedAdapter);
55 if (firstData == null) {
56 throw new AssertionError("data is null");
58 mFirstData = firstData;
62 public LocalData getLocalData(int dataID) {
66 return mAdapter.getLocalData(dataID - 1);
70 public void removeData(int dataID) {
72 mAdapter.removeData(dataID - 1);
77 public int findDataByContentUri(Uri uri) {
78 int pos = mAdapter.findDataByContentUri(uri);
86 public void updateData(int pos, LocalData data) {
89 if (mListener != null) {
90 mListener.onDataUpdated(new UpdateReporter() {
92 public boolean isDataRemoved(int dataID) {
97 public boolean isDataUpdated(int dataID) {
103 mAdapter.updateData(pos - 1, data);
108 public int getTotalNumber() {
109 return (mAdapter.getTotalNumber() + 1);
113 public View getView(Context context, View recycled, int dataID) {
115 return mFirstData.getView(
116 context, recycled, mSuggestedWidth, mSuggestedHeight, 0, null, false);
118 return mAdapter.getView(context, recycled, dataID - 1);
122 public int getItemViewType(int dataId) {
124 return mFirstData.getItemViewType().ordinal();
126 return mAdapter.getItemViewType(dataId);
130 public void resizeView(Context context, int dataID, View view, int w, int h) {
135 public ImageData getImageData(int dataID) {
139 return mAdapter.getImageData(dataID - 1);
143 public void setListener(Listener listener) {
144 mListener = listener;
145 mAdapter.setListener((listener == null) ? null : this);
146 // The first data is always there. Thus, When the listener is set,
147 // we should call listener.onDataLoaded().
148 if (mListener != null) {
149 mListener.onDataLoaded();
154 public boolean canSwipeInFullScreen(int dataID) {
156 return mFirstData.canSwipeInFullScreen();
158 return mAdapter.canSwipeInFullScreen(dataID - 1);
162 public void onDataLoaded() {
163 if (mListener == null) {
166 mListener.onDataUpdated(new UpdateReporter() {
168 public boolean isDataRemoved(int dataID) {
173 public boolean isDataUpdated(int dataID) {
174 return (dataID != 0);
180 public void onDataUpdated(final UpdateReporter reporter) {
181 mListener.onDataUpdated(new UpdateReporter() {
183 public boolean isDataRemoved(int dataID) {
184 return (dataID != 0) && reporter.isDataRemoved(dataID - 1);
188 public boolean isDataUpdated(int dataID) {
189 return (dataID != 0) && reporter.isDataUpdated(dataID - 1);
195 public void onDataInserted(int dataID, ImageData data) {
196 mListener.onDataInserted(dataID + 1, data);
200 public void onDataRemoved(int dataID, ImageData data) {
201 mListener.onDataRemoved(dataID + 1, data);
205 public AsyncTask updateMetadata(int dataId) {
207 return mAdapter.updateMetadata(dataId - 1);
209 MetadataLoader.loadMetadata(mContext, mFirstData);
215 public boolean isMetadataUpdated(int dataId) {
217 return mAdapter.isMetadataUpdated(dataId - 1);
219 return mFirstData.isMetadataUpdated();