content: package com.github.aakira.expandablelayout.uitest.utils;
  
  import android.support.test.espresso.IdlingResource;
  
  /**
   * Referenced from stack over flow.
   * http://stackoverflow.com/questions/30155227/espresso-how-to-wait-for-some-time1-hour
   */
  public class ElapsedIdLingResource implements IdlingResource {
      private final long startTime;
      private final long waitingTime;
      private ResourceCallback resourceCallback;
  
      public ElapsedIdLingResource(long waitingTime) {
          this.startTime = System.currentTimeMillis();
          this.waitingTime = waitingTime;
      }
  
      @Override
      public String getName() {
          return ElapsedIdLingResource.class.getName() + ":" + waitingTime;
      }
  
      @Override
      public boolean isIdleNow() {
          long elapsed = System.currentTimeMillis() - startTime;
          boolean idle = (elapsed >= waitingTime);
          if (idle) {
              resourceCallback.onTransitionToIdle();
          }
          return idle;
      }
  
      @Override
      public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
          this.resourceCallback = resourceCallback;
      }
  }