Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.view.ViewTreeObserver;
      4 import com.xtremelabs.robolectric.internal.Implementation;
      5 import com.xtremelabs.robolectric.internal.Implements;
      6 
      7 import java.util.ArrayList;
      8 import java.util.List;
      9 
     10 @SuppressWarnings({"UnusedDeclaration"})
     11 @Implements(ViewTreeObserver.class)
     12 public class ShadowViewTreeObserver {
     13 
     14     private ArrayList<ViewTreeObserver.OnGlobalLayoutListener> globalLayoutListeners = new ArrayList<ViewTreeObserver.OnGlobalLayoutListener>();
     15 
     16     @Implementation
     17     public void addOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener listener) {
     18         this.globalLayoutListeners.add(listener);
     19     }
     20 
     21     @Implementation
     22     public void removeGlobalOnLayoutListener(ViewTreeObserver.OnGlobalLayoutListener listener) {
     23         this.globalLayoutListeners.remove(listener);
     24     }
     25 
     26     public void fireOnGlobalLayoutListeners() {
     27         for (ViewTreeObserver.OnGlobalLayoutListener listener : new ArrayList<ViewTreeObserver.OnGlobalLayoutListener>(globalLayoutListeners)) {
     28             listener.onGlobalLayout();
     29         }
     30     }
     31 
     32     public List<ViewTreeObserver.OnGlobalLayoutListener> getOnGlobalLayoutListeners() {
     33         return globalLayoutListeners;
     34     }
     35 }
     36