Home | History | Annotate | Download | only in data
      1 /*
      2  * Copyright (C) 2012 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.gallery3d.data;
     18 
     19 import java.util.ArrayList;
     20 
     21 public class FilterEmptyPromptSet extends MediaSet implements ContentListener {
     22     @SuppressWarnings("unused")
     23     private static final String TAG = "FilterEmptyPromptSet";
     24 
     25     private ArrayList<MediaItem> mEmptyItem;
     26     private MediaSet mBaseSet;
     27 
     28     public FilterEmptyPromptSet(Path path, MediaSet baseSet, MediaItem emptyItem) {
     29         super(path, INVALID_DATA_VERSION);
     30         mEmptyItem = new ArrayList<MediaItem>(1);
     31         mEmptyItem.add(emptyItem);
     32         mBaseSet = baseSet;
     33         mBaseSet.addContentListener(this);
     34     }
     35 
     36     @Override
     37     public int getMediaItemCount() {
     38         int itemCount = mBaseSet.getMediaItemCount();
     39         if (itemCount > 0) {
     40             return itemCount;
     41         } else {
     42             return 1;
     43         }
     44     }
     45 
     46     @Override
     47     public ArrayList<MediaItem> getMediaItem(int start, int count) {
     48         int itemCount = mBaseSet.getMediaItemCount();
     49         if (itemCount > 0) {
     50             return mBaseSet.getMediaItem(start, count);
     51         } else if (start == 0 && count == 1) {
     52             return mEmptyItem;
     53         } else {
     54             throw new ArrayIndexOutOfBoundsException();
     55         }
     56     }
     57 
     58     @Override
     59     public void onContentDirty() {
     60         notifyContentChanged();
     61     }
     62 
     63     @Override
     64     public boolean isLeafAlbum() {
     65         return true;
     66     }
     67 
     68     @Override
     69     public boolean isCameraRoll() {
     70         return mBaseSet.isCameraRoll();
     71     }
     72 
     73     @Override
     74     public long reload() {
     75         return mBaseSet.reload();
     76     }
     77 
     78     @Override
     79     public String getName() {
     80         return mBaseSet.getName();
     81     }
     82 }
     83