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 import java.util.concurrent.atomic.AtomicBoolean; 21 22 // This is a simple MediaSet which contains only one MediaItem -- a SnailItem. 23 public class SnailAlbum extends MediaSet { 24 private static final String TAG = "SnailAlbum"; 25 private SnailItem mItem; 26 private AtomicBoolean mDirty = new AtomicBoolean(false); 27 28 public SnailAlbum(Path path, MediaItem item) { 29 super(path, nextVersionNumber()); 30 mItem = (SnailItem) item; 31 } 32 33 @Override 34 public int getMediaItemCount() { 35 return 1; 36 } 37 38 @Override 39 public ArrayList<MediaItem> getMediaItem(int start, int count) { 40 ArrayList<MediaItem> result = new ArrayList<MediaItem>(); 41 42 // If [start, start+count) contains the index 0, return the item. 43 if (start <= 0 && start + count > 0) { 44 result.add(mItem); 45 } 46 47 return result; 48 } 49 50 @Override 51 public boolean isLeafAlbum() { 52 return true; 53 } 54 55 @Override 56 public String getName() { 57 return "SnailAlbum"; 58 } 59 60 @Override 61 public long reload() { 62 if (mDirty.compareAndSet(true, false)) { 63 mItem.updateVersion(); 64 mDataVersion = nextVersionNumber(); 65 } 66 return mDataVersion; 67 } 68 69 public void notifyChange() { 70 mDirty.set(true); 71 notifyContentChanged(); 72 } 73 } 74