1 package org.robolectric.shadows; 2 3 import android.widget.AbsListView; 4 import org.robolectric.annotation.Implementation; 5 import org.robolectric.annotation.Implements; 6 7 @Implements(AbsListView.class) 8 public class ShadowAbsListView extends ShadowAdapterView { 9 private AbsListView.OnScrollListener onScrollListener; 10 private int smoothScrolledPosition; 11 private int lastSmoothScrollByDistance; 12 private int lastSmoothScrollByDuration; 13 14 @Implementation setOnScrollListener(AbsListView.OnScrollListener l)15 protected void setOnScrollListener(AbsListView.OnScrollListener l) { 16 onScrollListener = l; 17 } 18 19 @Implementation smoothScrollToPosition(int position)20 protected void smoothScrollToPosition(int position) { 21 smoothScrolledPosition = position; 22 } 23 24 @Implementation smoothScrollBy(int distance, int duration)25 protected void smoothScrollBy(int distance, int duration) { 26 this.lastSmoothScrollByDistance = distance; 27 this.lastSmoothScrollByDuration = duration; 28 } 29 30 /** 31 * Robolectric accessor for the onScrollListener 32 * 33 * @return AbsListView.OnScrollListener 34 */ getOnScrollListener()35 public AbsListView.OnScrollListener getOnScrollListener() { 36 return onScrollListener; 37 } 38 39 /** 40 * Robolectric accessor for the last smoothScrolledPosition 41 * 42 * @return int position 43 */ getSmoothScrolledPosition()44 public int getSmoothScrolledPosition() { 45 return smoothScrolledPosition; 46 } 47 48 /** 49 * Robolectric accessor for the last smoothScrollBy distance 50 * 51 * @return int distance 52 */ getLastSmoothScrollByDistance()53 public int getLastSmoothScrollByDistance() { 54 return lastSmoothScrollByDistance; 55 } 56 57 /** 58 * Robolectric accessor for the last smoothScrollBy duration 59 * 60 * @return int duration 61 */ getLastSmoothScrollByDuration()62 public int getLastSmoothScrollByDuration() { 63 return lastSmoothScrollByDuration; 64 } 65 } 66