Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java

Issue 2108983002: Use ContextUtils in PhysicalWeb (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update tests to use new methods Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.physicalweb; 5 package org.chromium.chrome.browser.physicalweb;
6 6
7 import android.animation.Animator; 7 import android.animation.Animator;
8 import android.animation.AnimatorListenerAdapter; 8 import android.animation.AnimatorListenerAdapter;
9 import android.animation.ObjectAnimator; 9 import android.animation.ObjectAnimator;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 14 matching lines...) Expand all
25 import android.widget.AdapterView; 25 import android.widget.AdapterView;
26 import android.widget.ImageView; 26 import android.widget.ImageView;
27 import android.widget.ListView; 27 import android.widget.ListView;
28 import android.widget.TextView; 28 import android.widget.TextView;
29 29
30 import org.chromium.base.ApiCompatibilityUtils; 30 import org.chromium.base.ApiCompatibilityUtils;
31 import org.chromium.base.ContextUtils; 31 import org.chromium.base.ContextUtils;
32 import org.chromium.base.Log; 32 import org.chromium.base.Log;
33 import org.chromium.base.VisibleForTesting; 33 import org.chromium.base.VisibleForTesting;
34 import org.chromium.chrome.R; 34 import org.chromium.chrome.R;
35 import org.chromium.chrome.browser.ChromeApplication;
36 import org.chromium.chrome.browser.widget.FadingShadow; 35 import org.chromium.chrome.browser.widget.FadingShadow;
37 import org.chromium.chrome.browser.widget.FadingShadowView; 36 import org.chromium.chrome.browser.widget.FadingShadowView;
38 37
39 import java.util.Collection; 38 import java.util.Collection;
40 39
41 /** 40 /**
42 * This activity displays a list of nearby URLs as stored in the {@link UrlManag er}. 41 * This activity displays a list of nearby URLs as stored in the {@link UrlManag er}.
43 * This activity does not and should not rely directly or indirectly on the nati ve library. 42 * This activity does not and should not rely directly or indirectly on the nati ve library.
44 */ 43 */
45 public class ListUrlsActivity extends AppCompatActivity implements AdapterView.O nItemClickListener, 44 public class ListUrlsActivity extends AppCompatActivity implements AdapterView.O nItemClickListener,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 }); 114 });
116 115
117 mPwsClient = new PwsClientImpl(this); 116 mPwsClient = new PwsClientImpl(this);
118 int referer = getIntent().getIntExtra(REFERER_KEY, 0); 117 int referer = getIntent().getIntExtra(REFERER_KEY, 0);
119 if (savedInstanceState == null) { // Ensure this is a newly-created act ivity. 118 if (savedInstanceState == null) { // Ensure this is a newly-created act ivity.
120 PhysicalWebUma.onActivityReferral(this, referer); 119 PhysicalWebUma.onActivityReferral(this, referer);
121 } 120 }
122 mIsInitialDisplayRecorded = false; 121 mIsInitialDisplayRecorded = false;
123 mIsRefreshing = false; 122 mIsRefreshing = false;
124 mIsRefreshUserInitiated = false; 123 mIsRefreshUserInitiated = false;
125 mPhysicalWebBleClient = 124 mPhysicalWebBleClient = PhysicalWebBleClient.getInstance();
126 PhysicalWebBleClient.getInstance((ChromeApplication) getApplicationC ontext());
127 } 125 }
128 126
129 @Override 127 @Override
130 public boolean onCreateOptionsMenu(Menu menu) { 128 public boolean onCreateOptionsMenu(Menu menu) {
131 int tintColor = ContextCompat.getColor(this, R.color.light_normal_color) ; 129 int tintColor = ContextCompat.getColor(this, R.color.light_normal_color) ;
132 130
133 Drawable tintedRefresh = ContextCompat.getDrawable(this, R.drawable.btn_ toolbar_reload); 131 Drawable tintedRefresh = ContextCompat.getDrawable(this, R.drawable.btn_ toolbar_reload);
134 tintedRefresh.setColorFilter(tintColor, PorterDuff.Mode.SRC_IN); 132 tintedRefresh.setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);
135 menu.add(0, R.id.menu_id_refresh, 1, R.string.physical_web_refresh) 133 menu.add(0, R.id.menu_id_refresh, 1, R.string.physical_web_refresh)
136 .setIcon(tintedRefresh) 134 .setIcon(tintedRefresh)
(...skipping 25 matching lines...) Expand all
162 mPhysicalWebBleClient.foregroundSubscribe(this); 160 mPhysicalWebBleClient.foregroundSubscribe(this);
163 } 161 }
164 162
165 private void foregroundUnsubscribe() { 163 private void foregroundUnsubscribe() {
166 mPhysicalWebBleClient.foregroundUnsubscribe(); 164 mPhysicalWebBleClient.foregroundUnsubscribe();
167 } 165 }
168 166
169 @Override 167 @Override
170 protected void onStart() { 168 protected void onStart() {
171 super.onStart(); 169 super.onStart();
172 UrlManager.getInstance(this).addObserver(this); 170 UrlManager.getInstance().addObserver(this);
173 } 171 }
174 172
175 @Override 173 @Override
176 protected void onResume() { 174 protected void onResume() {
177 super.onResume(); 175 super.onResume();
178 foregroundSubscribe(); 176 foregroundSubscribe();
179 startRefresh(false, false); 177 startRefresh(false, false);
180 178
181 int bottomBarDisplayCount = getBottomBarDisplayCount(); 179 int bottomBarDisplayCount = getBottomBarDisplayCount();
182 if (bottomBarDisplayCount < BOTTOM_BAR_DISPLAY_LIMIT) { 180 if (bottomBarDisplayCount < BOTTOM_BAR_DISPLAY_LIMIT) {
183 showBottomBar(); 181 showBottomBar();
184 setBottomBarDisplayCount(bottomBarDisplayCount + 1); 182 setBottomBarDisplayCount(bottomBarDisplayCount + 1);
185 } 183 }
186 } 184 }
187 185
188 @Override 186 @Override
189 protected void onPause() { 187 protected void onPause() {
190 foregroundUnsubscribe(); 188 foregroundUnsubscribe();
191 super.onPause(); 189 super.onPause();
192 } 190 }
193 191
194 @Override 192 @Override
195 public void onRefresh() { 193 public void onRefresh() {
196 startRefresh(true, true); 194 startRefresh(true, true);
197 } 195 }
198 196
199 @Override 197 @Override
200 protected void onStop() { 198 protected void onStop() {
201 UrlManager.getInstance(this).removeObserver(this); 199 UrlManager.getInstance().removeObserver(this);
202 super.onStop(); 200 super.onStop();
203 } 201 }
204 202
205 private void resolve(Collection<UrlInfo> urls, final boolean isUserInitiated ) { 203 private void resolve(Collection<UrlInfo> urls, final boolean isUserInitiated ) {
206 final long timestamp = SystemClock.elapsedRealtime(); 204 final long timestamp = SystemClock.elapsedRealtime();
207 mPwsClient.resolve(urls, new PwsClient.ResolveScanCallback() { 205 mPwsClient.resolve(urls, new PwsClient.ResolveScanCallback() {
208 @Override 206 @Override
209 public void onPwsResults(Collection<PwsResult> pwsResults) { 207 public void onPwsResults(Collection<PwsResult> pwsResults) {
210 long duration = SystemClock.elapsedRealtime() - timestamp; 208 long duration = SystemClock.elapsedRealtime() - timestamp;
211 if (isUserInitiated) { 209 if (isUserInitiated) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 if (mIsRefreshing) { 258 if (mIsRefreshing) {
261 return; 259 return;
262 } 260 }
263 261
264 mIsRefreshing = true; 262 mIsRefreshing = true;
265 mIsRefreshUserInitiated = isUserInitiated; 263 mIsRefreshUserInitiated = isUserInitiated;
266 264
267 // Clear the list adapter to trigger the empty list display. 265 // Clear the list adapter to trigger the empty list display.
268 mAdapter.clear(); 266 mAdapter.clear();
269 267
270 Collection<UrlInfo> urls = UrlManager.getInstance(this).getUrls(true); 268 Collection<UrlInfo> urls = UrlManager.getInstance().getUrls(true);
271 269
272 // Check the Physical Web preference to ensure we do not resolve URLs wh en Physical Web is 270 // Check the Physical Web preference to ensure we do not resolve URLs wh en Physical Web is
273 // off or onboarding. Normally the user will not reach this activity unl ess the preference 271 // off or onboarding. Normally the user will not reach this activity unl ess the preference
274 // is explicitly enabled, but there is a button on the diagnostics page that launches into 272 // is explicitly enabled, but there is a button on the diagnostics page that launches into
275 // the activity without checking the preference state. 273 // the activity without checking the preference state.
276 if (urls.isEmpty() || !PhysicalWeb.isPhysicalWebPreferenceEnabled(this)) { 274 if (urls.isEmpty() || !PhysicalWeb.isPhysicalWebPreferenceEnabled()) {
277 finishRefresh(); 275 finishRefresh();
278 } else { 276 } else {
279 // Show the swipe-to-refresh busy indicator for refreshes initiated by a swipe. 277 // Show the swipe-to-refresh busy indicator for refreshes initiated by a swipe.
280 if (isSwipeInitiated) { 278 if (isSwipeInitiated) {
281 mSwipeRefreshWidget.setRefreshing(true); 279 mSwipeRefreshWidget.setRefreshing(true);
282 } 280 }
283 281
284 // Update the empty list view to show a scanning animation. 282 // Update the empty list view to show a scanning animation.
285 mEmptyListText.setText(R.string.physical_web_empty_list_scanning); 283 mEmptyListText.setText(R.string.physical_web_empty_list_scanning);
286 284
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 @VisibleForTesting 388 @VisibleForTesting
391 void overridePwsClientForTesting(PwsClient pwsClient) { 389 void overridePwsClientForTesting(PwsClient pwsClient) {
392 mPwsClient = pwsClient; 390 mPwsClient = pwsClient;
393 } 391 }
394 392
395 @VisibleForTesting 393 @VisibleForTesting
396 void overrideContextForTesting(Context context) { 394 void overrideContextForTesting(Context context) {
397 mContext = context; 395 mContext = context;
398 } 396 }
399 } 397 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698