• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.database.DataSetObserver;
4 import android.widget.BaseAdapter;
5 import com.xtremelabs.robolectric.internal.Implementation;
6 import com.xtremelabs.robolectric.internal.Implements;
7 import com.xtremelabs.robolectric.internal.RealObject;
8 
9 import java.util.ArrayList;
10 import java.util.List;
11 
12 @SuppressWarnings({"UnusedDeclaration"})
13 @Implements(BaseAdapter.class)
14 public class ShadowBaseAdapter {
15 	@RealObject private BaseAdapter realBaseAdapter;
16     private final List<DataSetObserver> dataSetObservers = new ArrayList<DataSetObserver>();
17     private boolean wasNotifyDataSetChangedCalled;
18 
19     @Implementation
isEmpty()20     public boolean isEmpty() {
21     	return realBaseAdapter.getCount() == 0;
22     }
23 
24     /**
25      * Just returns true
26      *
27      * @return true
28      */
29     @Implementation
areAllItemsEnabled()30     public boolean areAllItemsEnabled() {
31         return true;
32     }
33 
34     /**
35      * Registers the observer.
36      *
37      * @param observer observer
38      */
39     @Implementation
registerDataSetObserver(DataSetObserver observer)40     public void registerDataSetObserver(DataSetObserver observer) {
41         dataSetObservers.add(observer);
42     }
43 
44     /**
45      * Unregisters the observer if it can be found. Nothing otherwise.
46      *
47      * @param observer observer
48      */
49     @Implementation
unregisterDataSetObserver(DataSetObserver observer)50     public void unregisterDataSetObserver(DataSetObserver observer) {
51         dataSetObservers.remove(observer);
52     }
53 
54     /**
55      * Notifies the registered observers
56      */
57     @Implementation
notifyDataSetChanged()58     public void notifyDataSetChanged() {
59         wasNotifyDataSetChangedCalled = true;
60         for (DataSetObserver dataSetObserver : dataSetObservers) {
61             dataSetObserver.onChanged();
62         }
63     }
64 
65     /**
66      * Notifies the registered observers
67      */
68     @Implementation
notifyDataSetInvalidated()69     public void notifyDataSetInvalidated() {
70         for (DataSetObserver dataSetObserver : dataSetObservers) {
71             dataSetObserver.onInvalidated();
72         }
73     }
74 
clearWasDataSetChangedCalledFlag()75     public void clearWasDataSetChangedCalledFlag() {
76         wasNotifyDataSetChangedCalled = false;
77     }
78 
wasNotifyDataSetChangedCalled()79     public boolean wasNotifyDataSetChangedCalled() {
80         return wasNotifyDataSetChangedCalled;
81     }
82 }
83