Skip to content

Instantly share code, notes, and snippets.

@rpgobjects
Last active April 6, 2018 03:54
Show Gist options
  • Select an option

  • Save rpgobjects/ed023abb8e00d000fa3e to your computer and use it in GitHub Desktop.

Select an option

Save rpgobjects/ed023abb8e00d000fa3e to your computer and use it in GitHub Desktop.

Revisions

  1. rpgobjects renamed this gist May 24, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. rpgobjects renamed this gist May 24, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. rpgobjects created this gist May 24, 2014.
    40 changes: 40 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    /**
    * Espresso IdlingResource for Ion
    * https://github.com/koush/ion
    * https://code.google.com/p/android-test-kit/
    * Because you can't deregister an IdlingResource, you have to create a new one per test.
    * You need to use a unique resourceName each test.
    */
    public final class IonIdlingResource implements IdlingResource {

    private static final String TAG = "IonIdlingResource";
    private final String resourceName;
    private Context context;
    private volatile ResourceCallback resourceCallback;


    public IonIdlingResource(String resourceName, Context context) {
    this.resourceName = resourceName;
    this.context = context;
    }

    @Override
    public String getName() {
    return resourceName;
    }

    @Override
    public boolean isIdleNow() {
    int count = Ion.getDefault(context).getPendingRequestCount(context);
    if(count == 0) {
    resourceCallback.onTransitionToIdle();
    }
    Log.d(TAG,resourceName + " count=" + count);
    return count == 0;
    }

    @Override
    public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
    this.resourceCallback = resourceCallback;
    }
    }