code: public <T> boolean waitForResource(int res, int timeout) {
          int RETRY_PERIOD = 250;
          int retryNum = timeout / RETRY_PERIOD;
          for (int i = 0; i < retryNum; i++) {
              T View = (T) this.getView(res);
              if (View != null) {
                  break;
              }
              if (i == retryNum - 1) {
                  return false;
              }
              this.sleep(RETRY_PERIOD);
          }
          return true;
      }
docs: Wait for a resource to become active
  
  @param res     - view resource
  @param timeout - timeout period to keep retrying
  @param <T>     - View type