OLD | NEW |
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.bluetooth.BluetoothAdapter; | 9 import android.bluetooth.BluetoothAdapter; |
10 import android.content.BroadcastReceiver; | 10 import android.content.BroadcastReceiver; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 String mOrigin; | 69 String mOrigin; |
70 | 70 |
71 // The security level of the connection to the site wanting to pair with the | 71 // The security level of the connection to the site wanting to pair with the |
72 // bluetooth devices. For valid values see SecurityStateModel::SecurityLevel
. | 72 // bluetooth devices. For valid values see SecurityStateModel::SecurityLevel
. |
73 int mSecurityLevel; | 73 int mSecurityLevel; |
74 | 74 |
75 @VisibleForTesting | 75 @VisibleForTesting |
76 Drawable mConnectedIcon; | 76 Drawable mConnectedIcon; |
77 @VisibleForTesting | 77 @VisibleForTesting |
78 String mConnectedIconDescription; | 78 String mConnectedIconDescription; |
| 79 @VisibleForTesting |
| 80 Drawable[] mSignalStrengthLevelIcon; |
79 | 81 |
80 // A pointer back to the native part of the implementation for this dialog. | 82 // A pointer back to the native part of the implementation for this dialog. |
81 long mNativeBluetoothChooserDialogPtr; | 83 long mNativeBluetoothChooserDialogPtr; |
82 | 84 |
83 // Used to keep track of when the Mode Changed Receiver is registered. | 85 // Used to keep track of when the Mode Changed Receiver is registered. |
84 boolean mIsLocationModeChangedReceiverRegistered; | 86 boolean mIsLocationModeChangedReceiverRegistered; |
85 | 87 |
86 // The local device Bluetooth adapter. | 88 // The local device Bluetooth adapter. |
87 private final BluetoothAdapter mAdapter; | 89 private final BluetoothAdapter mAdapter; |
88 | 90 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 BluetoothChooserDialog(WindowAndroid windowAndroid, String origin, int secur
ityLevel, | 123 BluetoothChooserDialog(WindowAndroid windowAndroid, String origin, int secur
ityLevel, |
122 long nativeBluetoothChooserDialogPtr) { | 124 long nativeBluetoothChooserDialogPtr) { |
123 mWindowAndroid = windowAndroid; | 125 mWindowAndroid = windowAndroid; |
124 mActivity = windowAndroid.getActivity().get(); | 126 mActivity = windowAndroid.getActivity().get(); |
125 assert mActivity != null; | 127 assert mActivity != null; |
126 mOrigin = origin; | 128 mOrigin = origin; |
127 mSecurityLevel = securityLevel; | 129 mSecurityLevel = securityLevel; |
128 mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr; | 130 mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr; |
129 mAdapter = BluetoothAdapter.getDefaultAdapter(); | 131 mAdapter = BluetoothAdapter.getDefaultAdapter(); |
130 | 132 |
131 Resources res = mActivity.getResources(); | 133 // Initialize icons. |
| 134 mConnectedIcon = getIconWithRowIconColorStateList(R.drawable.ic_bluetoot
h_connected); |
| 135 mConnectedIconDescription = mActivity.getString(R.string.bluetooth_devic
e_connected); |
132 | 136 |
133 // Initialize icons. | 137 mSignalStrengthLevelIcon = new Drawable[] { |
134 mConnectedIcon = VectorDrawableCompat.create( | 138 getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_0
_bar), |
135 res, R.drawable.ic_bluetooth_connected, mActivity.getTheme()); | 139 getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_1
_bar), |
136 DrawableCompat.setTintList(mConnectedIcon, | 140 getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_2
_bar), |
137 ApiCompatibilityUtils.getColorStateList(res, R.color.item_choose
r_row_icon_color)); | 141 getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_3
_bar), |
138 | 142 getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_4
_bar)}; |
139 mConnectedIconDescription = mActivity.getString(R.string.bluetooth_devic
e_connected); | |
140 | 143 |
141 if (mAdapter == null) { | 144 if (mAdapter == null) { |
142 Log.i(TAG, "BluetoothChooserDialog: Default Bluetooth adapter not fo
und."); | 145 Log.i(TAG, "BluetoothChooserDialog: Default Bluetooth adapter not fo
und."); |
143 } | 146 } |
144 mAdapterOffStatus = | 147 mAdapterOffStatus = |
145 SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_ad
apter_off_help), | 148 SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_ad
apter_off_help), |
146 new SpanInfo("<link>", "</link>", | 149 new SpanInfo("<link>", "</link>", |
147 new BluetoothClickableSpan(LinkType.ADAPTER_OFF_
HELP, mActivity))); | 150 new BluetoothClickableSpan(LinkType.ADAPTER_OFF_
HELP, mActivity))); |
148 } | 151 } |
149 | 152 |
| 153 private Drawable getIconWithRowIconColorStateList(int icon) { |
| 154 Resources res = mActivity.getResources(); |
| 155 |
| 156 Drawable drawable = VectorDrawableCompat.create(res, icon, mActivity.get
Theme()); |
| 157 DrawableCompat.setTintList(drawable, |
| 158 ApiCompatibilityUtils.getColorStateList(res, R.color.item_choose
r_row_icon_color)); |
| 159 return drawable; |
| 160 } |
| 161 |
150 /** | 162 /** |
151 * Show the BluetoothChooserDialog. | 163 * Show the BluetoothChooserDialog. |
152 */ | 164 */ |
153 @VisibleForTesting | 165 @VisibleForTesting |
154 void show() { | 166 void show() { |
155 // Emphasize the origin. | 167 // Emphasize the origin. |
156 Profile profile = Profile.getLastUsedProfile(); | 168 Profile profile = Profile.getLastUsedProfile(); |
157 SpannableString origin = new SpannableString(mOrigin); | 169 SpannableString origin = new SpannableString(mOrigin); |
158 OmniboxUrlEmphasizer.emphasizeUrl( | 170 OmniboxUrlEmphasizer.emphasizeUrl( |
159 origin, mActivity.getResources(), profile, mSecurityLevel, false
, true, true); | 171 origin, mActivity.getResources(), profile, mSecurityLevel, false
, true, true); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 return null; | 378 return null; |
367 } | 379 } |
368 BluetoothChooserDialog dialog = new BluetoothChooserDialog( | 380 BluetoothChooserDialog dialog = new BluetoothChooserDialog( |
369 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial
ogPtr); | 381 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial
ogPtr); |
370 dialog.show(); | 382 dialog.show(); |
371 return dialog; | 383 return dialog; |
372 } | 384 } |
373 | 385 |
374 @VisibleForTesting | 386 @VisibleForTesting |
375 @CalledByNative | 387 @CalledByNative |
376 void addOrUpdateDevice(String deviceId, String deviceName, boolean isGATTCon
nected) { | 388 void addOrUpdateDevice( |
| 389 String deviceId, String deviceName, boolean isGATTConnected, int sig
nalStrengthLevel) { |
377 Drawable icon = null; | 390 Drawable icon = null; |
378 String iconDescription = null; | 391 String iconDescription = null; |
379 if (isGATTConnected) { | 392 if (isGATTConnected) { |
380 icon = mConnectedIcon.getConstantState().newDrawable(); | 393 icon = mConnectedIcon.getConstantState().newDrawable(); |
381 iconDescription = mConnectedIconDescription; | 394 iconDescription = mConnectedIconDescription; |
| 395 } else if (signalStrengthLevel != -1) { |
| 396 icon = mSignalStrengthLevelIcon[signalStrengthLevel].getConstantStat
e().newDrawable(); |
| 397 iconDescription = mActivity.getResources().getQuantityString( |
| 398 R.plurals.signal_strength_level_n_bars, signalStrengthLevel, |
| 399 signalStrengthLevel); |
382 } | 400 } |
383 | 401 |
384 mItemChooserDialog.addOrUpdateItem(deviceId, deviceName, icon, iconDescr
iption); | 402 mItemChooserDialog.addOrUpdateItem(deviceId, deviceName, icon, iconDescr
iption); |
385 } | 403 } |
386 | 404 |
387 @VisibleForTesting | 405 @VisibleForTesting |
388 @CalledByNative | 406 @CalledByNative |
389 void closeDialog() { | 407 void closeDialog() { |
390 mNativeBluetoothChooserDialogPtr = 0; | 408 mNativeBluetoothChooserDialogPtr = 0; |
391 mItemChooserDialog.dismiss(); | 409 mItemChooserDialog.dismiss(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 @VisibleForTesting | 453 @VisibleForTesting |
436 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); | 454 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); |
437 // Help links. | 455 // Help links. |
438 @VisibleForTesting | 456 @VisibleForTesting |
439 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro
id); | 457 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro
id); |
440 @VisibleForTesting | 458 @VisibleForTesting |
441 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd
roid); | 459 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd
roid); |
442 @VisibleForTesting | 460 @VisibleForTesting |
443 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser
Android); | 461 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser
Android); |
444 } | 462 } |
OLD | NEW |