@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.physical_web_list_urls_activity); mAdapter = new NearbyUrlsAdapter(this); View emptyView = findViewById(R.id.physical_web_empty); mListView = (ListView) findViewById(R.id.physical_web_urls_list); mListView.setEmptyView(emptyView); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(this); mEmptyListText = (TextView) findViewById(R.id.physical_web_empty_list_text); mScanningImageView = (ImageView) findViewById(R.id.physical_web_logo); mSwipeRefreshWidget = (SwipeRefreshWidget) findViewById(R.id.physical_web_swipe_refresh_widget); mSwipeRefreshWidget.setOnRefreshListener(this); mPwsClient = new PwsClientImpl(); int referer = getIntent().getIntExtra(REFERER_KEY, 0); if (savedInstanceState == null // Ensure this is a newly-created activity. && referer == NOTIFICATION_REFERER) { PhysicalWebUma.onNotificationPressed(this); } mIsInitialDisplayRecorded = false; mIsRefreshing = false; mIsRefreshUserInitiated = false; }
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; }