| 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; |
| 11 import android.content.Context; | 11 import android.content.Context; |
| 12 import android.content.Intent; | 12 import android.content.Intent; |
| 13 import android.content.IntentFilter; | 13 import android.content.IntentFilter; |
| 14 import android.content.res.Resources; |
| 15 import android.graphics.drawable.Drawable; |
| 14 import android.location.LocationManager; | 16 import android.location.LocationManager; |
| 17 import android.support.graphics.drawable.VectorDrawableCompat; |
| 18 import android.support.v4.graphics.drawable.DrawableCompat; |
| 15 import android.text.SpannableString; | 19 import android.text.SpannableString; |
| 16 import android.text.TextUtils; | 20 import android.text.TextUtils; |
| 17 import android.view.View; | 21 import android.view.View; |
| 18 | 22 |
| 23 import org.chromium.base.ApiCompatibilityUtils; |
| 19 import org.chromium.base.Log; | 24 import org.chromium.base.Log; |
| 20 import org.chromium.base.VisibleForTesting; | 25 import org.chromium.base.VisibleForTesting; |
| 21 import org.chromium.base.annotations.CalledByNative; | 26 import org.chromium.base.annotations.CalledByNative; |
| 22 import org.chromium.chrome.R; | 27 import org.chromium.chrome.R; |
| 23 import org.chromium.chrome.browser.omnibox.OmniboxUrlEmphasizer; | 28 import org.chromium.chrome.browser.omnibox.OmniboxUrlEmphasizer; |
| 24 import org.chromium.chrome.browser.profiles.Profile; | 29 import org.chromium.chrome.browser.profiles.Profile; |
| 25 import org.chromium.components.location.LocationUtils; | 30 import org.chromium.components.location.LocationUtils; |
| 26 import org.chromium.ui.base.WindowAndroid; | 31 import org.chromium.ui.base.WindowAndroid; |
| 27 import org.chromium.ui.text.NoUnderlineClickableSpan; | 32 import org.chromium.ui.text.NoUnderlineClickableSpan; |
| 28 import org.chromium.ui.text.SpanApplier; | 33 import org.chromium.ui.text.SpanApplier; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // The dialog to show to let the user pick a device. | 65 // The dialog to show to let the user pick a device. |
| 61 ItemChooserDialog mItemChooserDialog; | 66 ItemChooserDialog mItemChooserDialog; |
| 62 | 67 |
| 63 // The origin for the site wanting to pair with the bluetooth devices. | 68 // The origin for the site wanting to pair with the bluetooth devices. |
| 64 String mOrigin; | 69 String mOrigin; |
| 65 | 70 |
| 66 // 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 |
| 67 // bluetooth devices. For valid values see SecurityStateModel::SecurityLevel
. | 72 // bluetooth devices. For valid values see SecurityStateModel::SecurityLevel
. |
| 68 int mSecurityLevel; | 73 int mSecurityLevel; |
| 69 | 74 |
| 75 @VisibleForTesting |
| 76 Drawable mConnectedIcon; |
| 77 @VisibleForTesting |
| 78 String mConnectedIconDescription; |
| 79 |
| 70 // A pointer back to the native part of the implementation for this dialog. | 80 // A pointer back to the native part of the implementation for this dialog. |
| 71 long mNativeBluetoothChooserDialogPtr; | 81 long mNativeBluetoothChooserDialogPtr; |
| 72 | 82 |
| 73 // Used to keep track of when the Mode Changed Receiver is registered. | 83 // Used to keep track of when the Mode Changed Receiver is registered. |
| 74 boolean mIsLocationModeChangedReceiverRegistered; | 84 boolean mIsLocationModeChangedReceiverRegistered; |
| 75 | 85 |
| 76 // The local device Bluetooth adapter. | 86 // The local device Bluetooth adapter. |
| 77 private final BluetoothAdapter mAdapter; | 87 private final BluetoothAdapter mAdapter; |
| 78 | 88 |
| 79 // The status message to show when the bluetooth adapter is turned off. | 89 // The status message to show when the bluetooth adapter is turned off. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 110 @VisibleForTesting | 120 @VisibleForTesting |
| 111 BluetoothChooserDialog(WindowAndroid windowAndroid, String origin, int secur
ityLevel, | 121 BluetoothChooserDialog(WindowAndroid windowAndroid, String origin, int secur
ityLevel, |
| 112 long nativeBluetoothChooserDialogPtr) { | 122 long nativeBluetoothChooserDialogPtr) { |
| 113 mWindowAndroid = windowAndroid; | 123 mWindowAndroid = windowAndroid; |
| 114 mActivity = windowAndroid.getActivity().get(); | 124 mActivity = windowAndroid.getActivity().get(); |
| 115 assert mActivity != null; | 125 assert mActivity != null; |
| 116 mOrigin = origin; | 126 mOrigin = origin; |
| 117 mSecurityLevel = securityLevel; | 127 mSecurityLevel = securityLevel; |
| 118 mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr; | 128 mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr; |
| 119 mAdapter = BluetoothAdapter.getDefaultAdapter(); | 129 mAdapter = BluetoothAdapter.getDefaultAdapter(); |
| 130 |
| 131 Resources res = mActivity.getResources(); |
| 132 |
| 133 // Initialize icons. |
| 134 mConnectedIcon = VectorDrawableCompat.create( |
| 135 res, R.drawable.ic_bluetooth_connected, mActivity.getTheme()); |
| 136 DrawableCompat.setTintList(mConnectedIcon, |
| 137 ApiCompatibilityUtils.getColorStateList(res, R.color.item_choose
r_row_icon_color)); |
| 138 |
| 139 mConnectedIconDescription = mActivity.getString(R.string.bluetooth_devic
e_connected); |
| 140 |
| 120 if (mAdapter == null) { | 141 if (mAdapter == null) { |
| 121 Log.i(TAG, "BluetoothChooserDialog: Default Bluetooth adapter not fo
und."); | 142 Log.i(TAG, "BluetoothChooserDialog: Default Bluetooth adapter not fo
und."); |
| 122 } | 143 } |
| 123 mAdapterOffStatus = | 144 mAdapterOffStatus = |
| 124 SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_ad
apter_off_help), | 145 SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_ad
apter_off_help), |
| 125 new SpanInfo("<link>", "</link>", | 146 new SpanInfo("<link>", "</link>", |
| 126 new BluetoothClickableSpan(LinkType.ADAPTER_OFF_
HELP, mActivity))); | 147 new BluetoothClickableSpan(LinkType.ADAPTER_OFF_
HELP, mActivity))); |
| 127 } | 148 } |
| 128 | 149 |
| 129 /** | 150 /** |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // the dialog. | 365 // the dialog. |
| 345 return null; | 366 return null; |
| 346 } | 367 } |
| 347 BluetoothChooserDialog dialog = new BluetoothChooserDialog( | 368 BluetoothChooserDialog dialog = new BluetoothChooserDialog( |
| 348 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial
ogPtr); | 369 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial
ogPtr); |
| 349 dialog.show(); | 370 dialog.show(); |
| 350 return dialog; | 371 return dialog; |
| 351 } | 372 } |
| 352 | 373 |
| 353 @VisibleForTesting | 374 @VisibleForTesting |
| 375 Drawable getConnectedIcon() { |
| 376 return mConnectedIcon.getConstantState().newDrawable().mutate(); |
| 377 } |
| 378 |
| 379 @VisibleForTesting |
| 354 @CalledByNative | 380 @CalledByNative |
| 355 void addOrUpdateDevice(String deviceId, String deviceName) { | 381 void addOrUpdateDevice(String deviceId, String deviceName, boolean isGATTCon
nected) { |
| 356 mItemChooserDialog.addOrUpdateItem(deviceId, deviceName); | 382 Drawable icon = null; |
| 383 String iconDescription = null; |
| 384 if (isGATTConnected) { |
| 385 icon = getConnectedIcon(); |
| 386 iconDescription = mConnectedIconDescription; |
| 387 } |
| 388 |
| 389 mItemChooserDialog.addOrUpdateItem(deviceId, deviceName, icon, iconDescr
iption); |
| 357 } | 390 } |
| 358 | 391 |
| 359 @VisibleForTesting | 392 @VisibleForTesting |
| 360 @CalledByNative | 393 @CalledByNative |
| 361 void closeDialog() { | 394 void closeDialog() { |
| 362 mNativeBluetoothChooserDialogPtr = 0; | 395 mNativeBluetoothChooserDialogPtr = 0; |
| 363 mItemChooserDialog.dismiss(); | 396 mItemChooserDialog.dismiss(); |
| 364 } | 397 } |
| 365 | 398 |
| 366 @VisibleForTesting | 399 @VisibleForTesting |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 @VisibleForTesting | 440 @VisibleForTesting |
| 408 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); | 441 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); |
| 409 // Help links. | 442 // Help links. |
| 410 @VisibleForTesting | 443 @VisibleForTesting |
| 411 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro
id); | 444 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro
id); |
| 412 @VisibleForTesting | 445 @VisibleForTesting |
| 413 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd
roid); | 446 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd
roid); |
| 414 @VisibleForTesting | 447 @VisibleForTesting |
| 415 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser
Android); | 448 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser
Android); |
| 416 } | 449 } |
| OLD | NEW |