private void startRefresh(boolean isUserInitiated, boolean isSwipeInitiated) {
    if (mIsRefreshing) {
      return;
    }

    mIsRefreshing = true;
    mIsRefreshUserInitiated = isUserInitiated;

    // Clear the list adapter to trigger the empty list display.
    mAdapter.clear();

    Collection<String> urls = UrlManager.getInstance(this).getUrls(true);
    if (urls.isEmpty()) {
      finishRefresh();
    } else {
      // Show the swipe-to-refresh busy indicator for refreshes initiated by a swipe.
      if (isSwipeInitiated) {
        mSwipeRefreshWidget.setRefreshing(true);
      }

      // Update the empty list view to show a scanning animation.
      mEmptyListText.setText(R.string.physical_web_empty_list_scanning);

      mScanningImageView.setImageResource(R.drawable.physical_web_scanning_animation);
      mScanningImageView.setColorFilter(null);

      AnimationDrawable animationDrawable = (AnimationDrawable) mScanningImageView.getDrawable();
      animationDrawable.start();

      resolve(urls);
    }

    // Clear stored URLs and resubscribe to Nearby.
    PhysicalWeb.startPhysicalWeb((ChromeApplication) getApplicationContext());
  }
 /**
  * Handle a click event.
  *
  * @param adapterView The AdapterView where the click happened.
  * @param view The View that was clicked inside the AdapterView.
  * @param position The position of the clicked element in the list.
  * @param id The row id of the clicked element in the list.
  */
 @Override
 public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
   PhysicalWebUma.onUrlSelected(this);
   PwsResult pwsResult = mAdapter.getItem(position);
   Intent intent = createNavigateToUrlIntent(pwsResult);
   startActivity(intent);
 }
  private void finishRefresh() {
    // Hide the busy indicator.
    mSwipeRefreshWidget.setRefreshing(false);

    // Stop the scanning animation, show a "nothing found" message.
    mEmptyListText.setText(R.string.physical_web_empty_list);

    int tintColor = ContextCompat.getColor(this, R.color.physical_web_logo_gray_tint);
    mScanningImageView.setImageResource(R.drawable.physical_web_logo);
    mScanningImageView.setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);

    // Record refresh-related UMA.
    if (!mIsInitialDisplayRecorded) {
      mIsInitialDisplayRecorded = true;
      PhysicalWebUma.onUrlsDisplayed(this, mAdapter.getCount());
    } else if (mIsRefreshUserInitiated) {
      PhysicalWebUma.onUrlsRefreshed(this, mAdapter.getCount());
    }

    mIsRefreshing = false;
  }