Home | History | Annotate | Download | only in data
      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 LocalFilmstripDataAdapter} implementation to wrap another
     29  * {@link LocalFilmstripDataAdapter}. 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 FixedFirstProxyAdapter
     34  * @see FixedLastProxyAdapter
     35  */
     36 public abstract class FilmstripDataAdapterProxy implements
     37       LocalFilmstripDataAdapter {
     38 
     39     protected final Context mContext;
     40     protected final LocalFilmstripDataAdapter mAdapter;
     41     protected int mSuggestedWidth;
     42     protected int mSuggestedHeight;
     43 
     44     /**
     45      * Constructor.
     46      *
     47      * @param context A valid Android context.
     48      * @param wrappedAdapter The {@link LocalFilmstripDataAdapter} to be wrapped.
     49      */
     50     FilmstripDataAdapterProxy(Context context,
     51           LocalFilmstripDataAdapter wrappedAdapter) {
     52         if (wrappedAdapter == null) {
     53             throw new AssertionError("data adapter is null");
     54         }
     55         mContext = context;
     56         mAdapter = wrappedAdapter;
     57     }
     58 
     59     @Override
     60     public void suggestViewSizeBound(int w, int h) {
     61         mSuggestedWidth = w;
     62         mSuggestedHeight = h;
     63         mAdapter.suggestViewSizeBound(w, h);
     64     }
     65 
     66     @Override
     67     public void setListener(Listener listener) {
     68         mAdapter.setListener(listener);
     69     }
     70 
     71     @Override
     72     public void setLocalDataListener(FilmstripItemListener listener) {
     73         mAdapter.setLocalDataListener(listener);
     74     }
     75 
     76     @Override
     77     public void requestLoad(Callback<Void> onDone) {
     78         mAdapter.requestLoad(onDone);
     79     }
     80 
     81     @Override
     82     public void requestLoadNewPhotos() {
     83         mAdapter.requestLoadNewPhotos();
     84     }
     85 
     86     @Override
     87     public boolean addOrUpdate(FilmstripItem item) {
     88         return mAdapter.addOrUpdate(item);
     89     }
     90 
     91     @Override
     92     public void clear() {
     93         mAdapter.clear();
     94     }
     95 
     96     @Override
     97     public boolean executeDeletion() {
     98         return mAdapter.executeDeletion();
     99     }
    100 
    101     @Override
    102     public boolean undoDeletion() {
    103         return mAdapter.undoDeletion();
    104     }
    105 
    106     @Override
    107     public void refresh(Uri uri) {
    108         mAdapter.refresh(uri);
    109     }
    110 
    111     @Override
    112     public AsyncTask updateMetadataAt(int index) {
    113         return mAdapter.updateMetadataAt(index);
    114     }
    115 
    116     @Override
    117     public boolean isMetadataUpdatedAt(int index) {
    118         return mAdapter.isMetadataUpdatedAt(index);
    119     }
    120 
    121     @Override
    122     public List<AsyncTask> preloadItems(List<Integer> items) {
    123         return mAdapter.preloadItems(items);
    124     }
    125 
    126     @Override
    127     public void cancelItems(List<AsyncTask> loadTokens) {
    128         mAdapter.cancelItems(loadTokens);
    129     }
    130 
    131     @Override
    132     public List<Integer> getItemsInRange(int startPosition, int endPosition) {
    133         return mAdapter.getItemsInRange(startPosition, endPosition);
    134     }
    135 
    136     @Override
    137     public int getCount() {
    138         return mAdapter.getCount();
    139     }
    140 }
    141