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

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

Issue 2271413002: bluetooth: Implement RSSI indicator on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-impl-rssi-tx-power
Patch Set: Copyright and clean up Created 4 years, 2 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; 5 package org.chromium.chrome.browser;
6 6
7 import android.Manifest; 7 import android.Manifest;
8 import android.app.Activity; 8 import android.app.Activity;
9 import android.content.BroadcastReceiver; 9 import android.content.BroadcastReceiver;
10 import android.content.Context; 10 import android.content.Context;
11 import android.content.Intent; 11 import android.content.Intent;
12 import android.content.IntentFilter; 12 import android.content.IntentFilter;
13 import android.content.res.Resources;
13 import android.location.LocationManager; 14 import android.location.LocationManager;
15 import android.support.graphics.drawable.VectorDrawableCompat;
14 import android.text.SpannableString; 16 import android.text.SpannableString;
15 import android.text.TextUtils; 17 import android.text.TextUtils;
16 import android.view.View; 18 import android.view.View;
17 19
18 import org.chromium.base.VisibleForTesting; 20 import org.chromium.base.VisibleForTesting;
19 import org.chromium.base.annotations.CalledByNative; 21 import org.chromium.base.annotations.CalledByNative;
20 import org.chromium.chrome.R; 22 import org.chromium.chrome.R;
21 import org.chromium.chrome.browser.omnibox.OmniboxUrlEmphasizer; 23 import org.chromium.chrome.browser.omnibox.OmniboxUrlEmphasizer;
22 import org.chromium.chrome.browser.profiles.Profile; 24 import org.chromium.chrome.browser.profiles.Profile;
23 import org.chromium.components.location.LocationUtils; 25 import org.chromium.components.location.LocationUtils;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // The dialog to show to let the user pick a device. 58 // The dialog to show to let the user pick a device.
57 ItemChooserDialog mItemChooserDialog; 59 ItemChooserDialog mItemChooserDialog;
58 60
59 // The origin for the site wanting to pair with the bluetooth devices. 61 // The origin for the site wanting to pair with the bluetooth devices.
60 String mOrigin; 62 String mOrigin;
61 63
62 // The security level of the connection to the site wanting to pair with the 64 // The security level of the connection to the site wanting to pair with the
63 // bluetooth devices. For valid values see SecurityStateModel::SecurityLevel . 65 // bluetooth devices. For valid values see SecurityStateModel::SecurityLevel .
64 int mSecurityLevel; 66 int mSecurityLevel;
65 67
68 ItemChooserDialog.ItemChooserRowIcon[] mSignalStrengthLevelRowIcons;
69
66 // A pointer back to the native part of the implementation for this dialog. 70 // A pointer back to the native part of the implementation for this dialog.
67 long mNativeBluetoothChooserDialogPtr; 71 long mNativeBluetoothChooserDialogPtr;
68 72
69 // Used to keep track of when the Mode Changed Receiver is registered. 73 // Used to keep track of when the Mode Changed Receiver is registered.
70 boolean mIsLocationModeChangedReceiverRegistered = false; 74 boolean mIsLocationModeChangedReceiverRegistered = false;
71 75
72 @VisibleForTesting 76 @VisibleForTesting
73 final BroadcastReceiver mLocationModeBroadcastReceiver = new BroadcastReceiv er() { 77 final BroadcastReceiver mLocationModeBroadcastReceiver = new BroadcastReceiv er() {
74 @Override 78 @Override
75 public void onReceive(Context context, Intent intent) { 79 public void onReceive(Context context, Intent intent) {
(...skipping 23 matching lines...) Expand all
99 */ 103 */
100 @VisibleForTesting 104 @VisibleForTesting
101 BluetoothChooserDialog(WindowAndroid windowAndroid, String origin, int secur ityLevel, 105 BluetoothChooserDialog(WindowAndroid windowAndroid, String origin, int secur ityLevel,
102 long nativeBluetoothChooserDialogPtr) { 106 long nativeBluetoothChooserDialogPtr) {
103 mWindowAndroid = windowAndroid; 107 mWindowAndroid = windowAndroid;
104 mActivity = windowAndroid.getActivity().get(); 108 mActivity = windowAndroid.getActivity().get();
105 assert mActivity != null; 109 assert mActivity != null;
106 mOrigin = origin; 110 mOrigin = origin;
107 mSecurityLevel = securityLevel; 111 mSecurityLevel = securityLevel;
108 mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr; 112 mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr;
113 Resources resources = mActivity.getResources();
114 mSignalStrengthLevelRowIcons = new ItemChooserDialog.ItemChooserRowIcon[ ] {
115 new ItemChooserDialog.ItemChooserRowIcon(
116 VectorDrawableCompat.create(resources,
117 R.drawable.ic_signal_cellular_0_bar_grey600_24dp , null /* theme */),
Ian Wen 2016/09/26 18:12:48 Maybe remove /* */? This comment style is not comm
ortuno 2016/10/04 07:16:18 If it's OK with you I would rather keep this. Ther
118 VectorDrawableCompat.create(resources,
119 R.drawable.ic_signal_cellular_0_bar_white_24dp, null /* theme */),
120 resources.getQuantityString(R.plurals.signal_strength_le vel_n_bars, 0, 0)),
Ian Wen 2016/09/27 04:22:41 Thanks for making our product more accessible by a
ortuno 2016/10/04 07:16:18 As mentioned offline (I think?) the image adds mor
121 new ItemChooserDialog.ItemChooserRowIcon(
122 VectorDrawableCompat.create(resources,
123 R.drawable.ic_signal_cellular_1_bar_grey600_24dp , null /* theme */),
124 VectorDrawableCompat.create(resources,
125 R.drawable.ic_signal_cellular_1_bar_white_24dp, null /* theme */),
126 resources.getQuantityString(R.plurals.signal_strength_le vel_n_bars, 1, 1)),
127 new ItemChooserDialog.ItemChooserRowIcon(
128 VectorDrawableCompat.create(resources,
129 R.drawable.ic_signal_cellular_2_bar_grey600_24dp , null /* theme */),
130 VectorDrawableCompat.create(resources,
131 R.drawable.ic_signal_cellular_2_bar_white_24dp, null /* theme */),
132 resources.getQuantityString(R.plurals.signal_strength_le vel_n_bars, 2, 2)),
133 new ItemChooserDialog.ItemChooserRowIcon(
134 VectorDrawableCompat.create(resources,
135 R.drawable.ic_signal_cellular_3_bar_grey600_24dp , null /* theme */),
136 VectorDrawableCompat.create(resources,
137 R.drawable.ic_signal_cellular_3_bar_white_24dp, null /* theme */),
138 resources.getQuantityString(R.plurals.signal_strength_le vel_n_bars, 3, 3)),
139 new ItemChooserDialog.ItemChooserRowIcon(
140 VectorDrawableCompat.create(resources,
141 R.drawable.ic_signal_cellular_4_bar_grey600_24dp , null /* theme */),
142 VectorDrawableCompat.create(resources,
143 R.drawable.ic_signal_cellular_4_bar_white_24dp, null /* theme */),
144 resources.getQuantityString(R.plurals.signal_strength_le vel_n_bars, 4, 4))};
109 } 145 }
110 146
111 /** 147 /**
112 * Show the BluetoothChooserDialog. 148 * Show the BluetoothChooserDialog.
113 */ 149 */
114 @VisibleForTesting 150 @VisibleForTesting
115 void show() { 151 void show() {
116 // Emphasize the origin. 152 // Emphasize the origin.
117 Profile profile = Profile.getLastUsedProfile(); 153 Profile profile = Profile.getLastUsedProfile();
118 SpannableString origin = new SpannableString(mOrigin); 154 SpannableString origin = new SpannableString(mOrigin);
(...skipping 30 matching lines...) Expand all
149 SpannableString statusIdleSomeFound = SpanApplier.applySpans( 185 SpannableString statusIdleSomeFound = SpanApplier.applySpans(
150 mActivity.getString(R.string.bluetooth_not_seeing_it_idle_some_f ound), 186 mActivity.getString(R.string.bluetooth_not_seeing_it_idle_some_f ound),
151 new SpanInfo("<link1>", "</link1>", 187 new SpanInfo("<link1>", "</link1>",
152 new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, m Activity)), 188 new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, m Activity)),
153 new SpanInfo("<link2>", "</link2>", 189 new SpanInfo("<link2>", "</link2>",
154 new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mAct ivity))); 190 new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mAct ivity)));
155 191
156 ItemChooserDialog.ItemChooserLabels labels = 192 ItemChooserDialog.ItemChooserLabels labels =
157 new ItemChooserDialog.ItemChooserLabels(title, searching, noneFo und, statusActive, 193 new ItemChooserDialog.ItemChooserLabels(title, searching, noneFo und, statusActive,
158 statusIdleNoneFound, statusIdleSomeFound, positiveButton ); 194 statusIdleNoneFound, statusIdleSomeFound, positiveButton );
159 mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels); 195 mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels, true /* usingIcon */);
160 196
161 mActivity.registerReceiver(mLocationModeBroadcastReceiver, 197 mActivity.registerReceiver(mLocationModeBroadcastReceiver,
162 new IntentFilter(LocationManager.MODE_CHANGED_ACTION)); 198 new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
163 mIsLocationModeChangedReceiverRegistered = true; 199 mIsLocationModeChangedReceiverRegistered = true;
164 } 200 }
165 201
202 ItemChooserDialog.ItemChooserRowIcon[] getSignalStrengthLevelRowIcons() {
203 return mSignalStrengthLevelRowIcons;
204 }
205
166 // Called to report the dialog's results back to native code. 206 // Called to report the dialog's results back to native code.
167 private void finishDialog(int resultCode, String id) { 207 private void finishDialog(int resultCode, String id) {
168 if (mIsLocationModeChangedReceiverRegistered) { 208 if (mIsLocationModeChangedReceiverRegistered) {
169 mActivity.unregisterReceiver(mLocationModeBroadcastReceiver); 209 mActivity.unregisterReceiver(mLocationModeBroadcastReceiver);
170 mIsLocationModeChangedReceiverRegistered = false; 210 mIsLocationModeChangedReceiverRegistered = false;
171 } 211 }
172 212
173 if (mNativeBluetoothChooserDialogPtr != 0) { 213 if (mNativeBluetoothChooserDialogPtr != 0) {
174 nativeOnDialogFinished(mNativeBluetoothChooserDialogPtr, resultCode, id); 214 nativeOnDialogFinished(mNativeBluetoothChooserDialogPtr, resultCode, id);
175 } 215 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 return null; 370 return null;
331 } 371 }
332 BluetoothChooserDialog dialog = new BluetoothChooserDialog( 372 BluetoothChooserDialog dialog = new BluetoothChooserDialog(
333 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial ogPtr); 373 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial ogPtr);
334 dialog.show(); 374 dialog.show();
335 return dialog; 375 return dialog;
336 } 376 }
337 377
338 @VisibleForTesting 378 @VisibleForTesting
339 @CalledByNative 379 @CalledByNative
340 void addOrUpdateDevice(String deviceId, String deviceName) { 380 void addOrUpdateDevice(String deviceId, String deviceName, int signalStrengt hLevel) {
341 mItemChooserDialog.addOrUpdateItem( 381 assert -1 <= signalStrengthLevel
342 new ItemChooserDialog.ItemChooserRow(deviceId, deviceName)); 382 && signalStrengthLevel < mSignalStrengthLevelRowIcons.length;
383 ItemChooserDialog.ItemChooserRowIcon signalStrengthLevelIcon = null;
384 if (signalStrengthLevel != -1) {
385 signalStrengthLevelIcon = mSignalStrengthLevelRowIcons[signalStrengt hLevel];
386 }
387 mItemChooserDialog.addOrUpdateItem(new ItemChooserDialog.ItemChooserRow(
388 deviceId, deviceName, signalStrengthLevelIcon));
343 } 389 }
344 390
345 @VisibleForTesting 391 @VisibleForTesting
346 @CalledByNative 392 @CalledByNative
347 void closeDialog() { 393 void closeDialog() {
348 mNativeBluetoothChooserDialogPtr = 0; 394 mNativeBluetoothChooserDialogPtr = 0;
349 mItemChooserDialog.dismiss(); 395 mItemChooserDialog.dismiss();
350 } 396 }
351 397
352 @VisibleForTesting 398 @VisibleForTesting
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 @VisibleForTesting 449 @VisibleForTesting
404 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); 450 native void nativeRestartSearch(long nativeBluetoothChooserAndroid);
405 // Help links. 451 // Help links.
406 @VisibleForTesting 452 @VisibleForTesting
407 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro id); 453 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro id);
408 @VisibleForTesting 454 @VisibleForTesting
409 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd roid); 455 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd roid);
410 @VisibleForTesting 456 @VisibleForTesting
411 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser Android); 457 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser Android);
412 } 458 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698