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()); }
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; }