package org.robolectric.shadows;

import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.AbsListView;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;

import static org.robolectric.Robolectric.directlyOn;

@Implements(AbsListView.class)
public class ShadowAbsListView extends ShadowAdapterView {
  @RealObject private AbsListView realAbsListView;
  private AbsListView.OnScrollListener onScrollListener;
  private int smoothScrolledPosition;
  private int lastSmoothScrollByDistance;
  private int lastSmoothScrollByDuration;

  @Implementation
  public void setOnScrollListener(AbsListView.OnScrollListener l) {
    onScrollListener = l;
  }

  @Implementation
  public void smoothScrollToPosition(int position) {
    smoothScrolledPosition = position;
  }

  @Implementation
  public void smoothScrollBy(int distance, int duration) {
    this.lastSmoothScrollByDistance = distance;
    this.lastSmoothScrollByDuration = duration;
  }

  @Implementation
  public boolean performItemClick(View view, int position, long id) {
    return ((Boolean) directlyOn(realAbsListView, AbsListView.class, "performItemClick", View.class, int.class, long.class).invoke(view, position, id));
  }

  @Implementation
  public int getCheckedItemPosition() {
    return ((Integer) directlyOn(realAbsListView, AbsListView.class, "getCheckedItemPosition").invoke());
  }

  @Implementation
  public int getCheckedItemCount() {
    return ((Integer) directlyOn(realAbsListView, AbsListView.class, "getCheckedItemCount").invoke());
  }

  @Implementation
  public void setItemChecked(int position, boolean value) {
    directlyOn(realAbsListView, AbsListView.class, "setItemChecked", int.class, boolean.class).invoke(position, value);
  }

  @Implementation
  public int getChoiceMode() {
    return (Integer) directlyOn(realAbsListView, AbsListView.class, "getChoiceMode").invoke();
  }

  @Implementation
  public void setChoiceMode(int choiceMode) {
    directlyOn(realAbsListView, AbsListView.class, "setChoiceMode", int.class).invoke(choiceMode);
  }

  @Implementation
  public SparseBooleanArray getCheckedItemPositions() {
    return (SparseBooleanArray) directlyOn(realAbsListView, AbsListView.class, "getCheckedItemPositions").invoke();
  }

  @Implementation
  public long[] getCheckedItemIds() {
    return (long[]) directlyOn(realAbsListView, AbsListView.class, "getCheckedItemIds").invoke();
  }

  /**
   * Robolectric accessor for the onScrollListener
   *
   * @return AbsListView.OnScrollListener
   */
  public AbsListView.OnScrollListener getOnScrollListener() {
    return onScrollListener;
  }

  /**
   * Robolectric accessor for the last smoothScrolledPosition
   *
   * @return int position
   */
  public int getSmoothScrolledPosition() {
    return smoothScrolledPosition;
  }

  /**
   * Robolectric accessor for the last smoothScrollBy distance
   *
   * @return int distance
   */
  public int getLastSmoothScrollByDistance() {
    return lastSmoothScrollByDistance;
  }

  /**
   * Robolectric accessor for the last smoothScrollBy duration
   *
   * @return int duration
   */
  public int getLastSmoothScrollByDuration() {
    return lastSmoothScrollByDuration;
  }
}

@@ -31,74 +31,8 @@
 s;%0A%0A
-import android.util.SparseBooleanArray;%0Aimport android.view.View;%0A
 impo
@@ -62,16 +62,17 @@
 stView;%0A
+%0A
 import o
@@ -162,109 +162,8 @@
 nts;
-%0Aimport org.robolectric.annotation.RealObject;%0A%0Aimport static org.robolectric.Robolectric.directlyOn;
 %0A%0A@I
@@ -254,59 +254,8 @@
 w %7B%0A
-  @RealObject private AbsListView realAbsListView;%0A
   pr
@@ -787,16 +787,16 @@
 stance;%0A
+
     this
@@ -844,1460 +844,8 @@
  %7D%0A%0A
-  @Implementation%0A  public boolean performItemClick(View view, int position, long id) %7B%0A    return ((Boolean) directlyOn(realAbsListView, AbsListView.class, %22performItemClick%22, View.class, int.class, long.class).invoke(view, position, id));%0A  %7D%0A%0A  @Implementation%0A  public int getCheckedItemPosition() %7B%0A    return ((Integer) directlyOn(realAbsListView, AbsListView.class, %22getCheckedItemPosition%22).invoke());%0A  %7D%0A%0A  @Implementation%0A  public int getCheckedItemCount() %7B%0A    return ((Integer) directlyOn(realAbsListView, AbsListView.class, %22getCheckedItemCount%22).invoke());%0A  %7D%0A%0A  @Implementation%0A  public void setItemChecked(int position, boolean value) %7B%0A    directlyOn(realAbsListView, AbsListView.class, %22setItemChecked%22, int.class, boolean.class).invoke(position, value);%0A  %7D%0A%0A  @Implementation%0A  public int getChoiceMode() %7B%0A    return (Integer) directlyOn(realAbsListView, AbsListView.class, %22getChoiceMode%22).invoke();%0A  %7D%0A%0A  @Implementation%0A  public void setChoiceMode(int choiceMode) %7B%0A    directlyOn(realAbsListView, AbsListView.class, %22setChoiceMode%22, int.class).invoke(choiceMode);%0A  %7D%0A%0A  @Implementation%0A  public SparseBooleanArray getCheckedItemPositions() %7B%0A    return (SparseBooleanArray) directlyOn(realAbsListView, AbsListView.class, %22getCheckedItemPositions%22).invoke();%0A  %7D%0A%0A  @Implementation%0A  public long%5B%5D getCheckedItemIds() %7B%0A    return (long%5B%5D) directlyOn(realAbsListView, AbsListView.class, %22getCheckedItemIds%22).invoke();%0A  %7D%0A%0A
   /*

Delete trivial wrapper methods in ShadowAbsListView