private void setState(State state) {
    this.state = state;
    switch (state) {
      case PULL_TO_REFRESH:
        spinner.setVisibility(View.INVISIBLE);
        image.setVisibility(View.VISIBLE);
        text.setText(pullToRefreshText);

        if (showLastUpdatedText && lastUpdated != -1) {
          lastUpdatedTextView.setVisibility(View.VISIBLE);
          lastUpdatedTextView.setText(
              String.format(lastUpdatedText, lastUpdatedDateFormat.format(new Date(lastUpdated))));
        }

        break;

      case RELEASE_TO_REFRESH:
        spinner.setVisibility(View.INVISIBLE);
        image.setVisibility(View.VISIBLE);
        text.setText(releaseToRefreshText);
        break;

      case REFRESHING:
        setUiRefreshing();

        lastUpdated = System.currentTimeMillis();
        if (onRefreshListener == null) {
          setState(State.PULL_TO_REFRESH);
        } else {
          onRefreshListener.onRefresh();
        }

        break;
    }
  }
 private void setUiRefreshing() {
   spinner.setVisibility(View.VISIBLE);
   image.clearAnimation();
   image.setVisibility(View.INVISIBLE);
   text.setText(refreshingText);
 }