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

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

Issue 2548353004: Include BT addresses in Intents from Physical Web (Closed)
Patch Set: Rebase Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivityTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java
index b588b0f6cf0113c6b887770141400761dbc07272..6e80ab607eb9b7303c1e627b215feb6d9c6e5701 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java
@@ -7,6 +7,8 @@ package org.chromium.chrome.browser.physicalweb;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
@@ -240,22 +242,24 @@ public class ListUrlsActivity extends AppCompatActivity implements AdapterView.O
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
PhysicalWebUma.onUrlSelected(this);
- PwsResult minPwsResult = mAdapter.getItem(position);
- String groupId = minPwsResult.groupId;
+ UrlInfo nearestUrlInfo = null;
+ PwsResult nearestPwsResult = mAdapter.getItem(position);
+ String groupId = nearestPwsResult.groupId;
// Make sure the PwsResult corresponds to the closest UrlDevice in the group.
double minDistance = Double.MAX_VALUE;
for (PwsResult pwsResult : mPwsResults) {
if (pwsResult.groupId.equals(groupId)) {
- double distance = UrlManager.getInstance()
- .getUrlInfoByUrl(pwsResult.requestUrl).getDistance();
+ UrlInfo urlInfo = UrlManager.getInstance().getUrlInfoByUrl(pwsResult.requestUrl);
+ double distance = urlInfo.getDistance();
if (distance < minDistance) {
minDistance = distance;
- minPwsResult = pwsResult;
+ nearestPwsResult = pwsResult;
+ nearestUrlInfo = urlInfo;
}
}
}
- Intent intent = createNavigateToUrlIntent(minPwsResult);
+ Intent intent = createNavigateToUrlIntent(nearestPwsResult, nearestUrlInfo);
mContext.startActivity(intent);
}
@@ -385,16 +389,28 @@ public class ListUrlsActivity extends AppCompatActivity implements AdapterView.O
.apply();
}
- private static Intent createNavigateToUrlIntent(PwsResult pwsResult) {
+ private static Intent createNavigateToUrlIntent(PwsResult pwsResult, UrlInfo urlInfo) {
String url = pwsResult.siteUrl;
if (url == null) {
url = pwsResult.requestUrl;
}
- return new Intent(Intent.ACTION_VIEW)
+ Intent intent = new Intent(Intent.ACTION_VIEW)
.addCategory(Intent.CATEGORY_BROWSABLE)
.setData(Uri.parse(url))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ if (urlInfo != null && urlInfo.getDeviceAddress() != null) {
+ BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ if (bluetoothAdapter != null) {
+ try {
+ intent.putExtra(BluetoothDevice.EXTRA_DEVICE,
+ bluetoothAdapter.getRemoteDevice(urlInfo.getDeviceAddress()));
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Invalid device address: " + urlInfo.getDeviceAddress(), e);
+ }
+ }
+ }
+ return intent;
}
@VisibleForTesting
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivityTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698