Home | History | Annotate | Download | only in data
      1 /*
      2  * Copyright (C) 2010 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 MockSet extends MediaSet {
     22     ArrayList<MediaItem> mItems = new ArrayList<MediaItem>();
     23     ArrayList<MediaSet> mSets = new ArrayList<MediaSet>();
     24     Path mItemPath;
     25 
     26     public MockSet(Path path, DataManager dataManager) {
     27         super(path, nextVersionNumber());
     28         mItemPath = Path.fromString("/mock/item");
     29     }
     30 
     31     public MockSet(Path path, DataManager dataManager,
     32             int items, int item_id_start) {
     33         this(path, dataManager);
     34         for (int i = 0; i < items; i++) {
     35             Path childPath = mItemPath.getChild(item_id_start + i);
     36             mItems.add(new MockItem(childPath));
     37         }
     38     }
     39 
     40     public void addMediaSet(MediaSet sub) {
     41         mSets.add(sub);
     42     }
     43 
     44     @Override
     45     public int getMediaItemCount() {
     46         return mItems.size();
     47     }
     48 
     49     @Override
     50     public ArrayList<MediaItem> getMediaItem(int start, int count) {
     51         ArrayList<MediaItem> result = new ArrayList<MediaItem>();
     52         int end = Math.min(start + count, mItems.size());
     53 
     54         for (int i = start; i < end; i++) {
     55             result.add(mItems.get(i));
     56         }
     57         return result;
     58     }
     59 
     60     @Override
     61     public int getSubMediaSetCount() {
     62         return mSets.size();
     63     }
     64 
     65     @Override
     66     public MediaSet getSubMediaSet(int index) {
     67         return mSets.get(index);
     68     }
     69 
     70     @Override
     71     public int getTotalMediaItemCount() {
     72         int result = mItems.size();
     73         for (MediaSet s : mSets) {
     74             result += s.getTotalMediaItemCount();
     75         }
     76         return result;
     77     }
     78 
     79     @Override
     80     public String getName() {
     81         return "Set " + mPath;
     82     }
     83 
     84     @Override
     85     public long reload() {
     86         return 0;
     87     }
     88 }
     89