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.content.Context; 20 import android.net.Uri; 21 import android.os.AsyncTask; 22 23 import com.android.camera.util.Callback; 24 25 import java.util.List; 26 27 /** 28 * An abstract {@link LocalDataAdapter} implementation to wrap another 29 * {@link LocalDataAdapter}. All implementations related to data id is not 30 * addressed in this abstract class since wrapping another data adapter 31 * surely makes things different for data id. 32 * 33 * @see FixedFirstDataAdapter 34 * @see FixedLastDataAdapter 35 */ 36 public abstract class AbstractLocalDataAdapterWrapper implements LocalDataAdapter { 37 38 protected final Context mContext; 39 protected final LocalDataAdapter mAdapter; 40 protected int mSuggestedWidth; 41 protected int mSuggestedHeight; 42 43 /** 44 * Constructor. 45 * 46 * @param context A valid Android context. 47 * @param wrappedAdapter The {@link LocalDataAdapter} to be wrapped. 48 */ 49 AbstractLocalDataAdapterWrapper(Context context, LocalDataAdapter wrappedAdapter) { 50 if (wrappedAdapter == null) { 51 throw new AssertionError("data adapter is null"); 52 } 53 mContext = context; 54 mAdapter = wrappedAdapter; 55 } 56 57 @Override 58 public void suggestViewSizeBound(int w, int h) { 59 mSuggestedWidth = w; 60 mSuggestedHeight = h; 61 mAdapter.suggestViewSizeBound(w, h); 62 } 63 64 @Override 65 public void setListener(Listener listener) { 66 mAdapter.setListener(listener); 67 } 68 69 @Override 70 public void setLocalDataListener(LocalDataListener listener) { 71 mAdapter.setLocalDataListener(listener); 72 } 73 74 @Override 75 public void requestLoad(Callback<Void> doneCallback) { 76 mAdapter.requestLoad(doneCallback); 77 } 78 79 @Override 80 public void requestLoadNewPhotos() { 81 mAdapter.requestLoadNewPhotos(); 82 } 83 84 @Override 85 public boolean addData(LocalData data) { 86 return mAdapter.addData(data); 87 } 88 89 @Override 90 public void flush() { 91 mAdapter.flush(); 92 } 93 94 @Override 95 public boolean executeDeletion() { 96 return mAdapter.executeDeletion(); 97 } 98 99 @Override 100 public boolean undoDataRemoval() { 101 return mAdapter.undoDataRemoval(); 102 } 103 104 @Override 105 public void refresh(Uri uri) { 106 mAdapter.refresh(uri); 107 } 108 109 @Override 110 public AsyncTask updateMetadata(int dataId) { 111 return mAdapter.updateMetadata(dataId); 112 } 113 114 @Override 115 public boolean isMetadataUpdated(int dataId) { 116 return mAdapter.isMetadataUpdated(dataId); 117 } 118 119 @Override 120 public List<AsyncTask> preloadItems(List<Integer> items) { 121 return mAdapter.preloadItems(items); 122 } 123 124 @Override 125 public void cancelItems(List<AsyncTask> loadTokens) { 126 mAdapter.cancelItems(loadTokens); 127 } 128 129 @Override 130 public List<Integer> getItemsInRange(int startPosition, int endPosition) { 131 return mAdapter.getItemsInRange(startPosition, endPosition); 132 } 133 134 @Override 135 public int getCount() { 136 return mAdapter.getCount(); 137 } 138 } 139