Chromium Code Reviews| 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.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; | |
| 14 import android.graphics.drawable.Drawable; | |
| 15 import android.graphics.drawable.LevelListDrawable; | |
| 16 import android.graphics.drawable.StateListDrawable; | |
| 13 import android.location.LocationManager; | 17 import android.location.LocationManager; |
| 18 import android.support.graphics.drawable.VectorDrawableCompat; | |
| 14 import android.text.SpannableString; | 19 import android.text.SpannableString; |
| 15 import android.text.TextUtils; | 20 import android.text.TextUtils; |
| 16 import android.view.View; | 21 import android.view.View; |
| 17 | 22 |
| 23 import org.chromium.base.Log; | |
| 18 import org.chromium.base.VisibleForTesting; | 24 import org.chromium.base.VisibleForTesting; |
| 19 import org.chromium.base.annotations.CalledByNative; | 25 import org.chromium.base.annotations.CalledByNative; |
| 20 import org.chromium.chrome.R; | 26 import org.chromium.chrome.R; |
| 21 import org.chromium.chrome.browser.omnibox.OmniboxUrlEmphasizer; | 27 import org.chromium.chrome.browser.omnibox.OmniboxUrlEmphasizer; |
| 22 import org.chromium.chrome.browser.profiles.Profile; | 28 import org.chromium.chrome.browser.profiles.Profile; |
| 23 import org.chromium.components.location.LocationUtils; | 29 import org.chromium.components.location.LocationUtils; |
| 24 import org.chromium.ui.base.WindowAndroid; | 30 import org.chromium.ui.base.WindowAndroid; |
| 25 import org.chromium.ui.text.NoUnderlineClickableSpan; | 31 import org.chromium.ui.text.NoUnderlineClickableSpan; |
| 26 import org.chromium.ui.text.SpanApplier; | 32 import org.chromium.ui.text.SpanApplier; |
| 27 import org.chromium.ui.text.SpanApplier.SpanInfo; | 33 import org.chromium.ui.text.SpanApplier.SpanInfo; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 56 // The dialog to show to let the user pick a device. | 62 // The dialog to show to let the user pick a device. |
| 57 ItemChooserDialog mItemChooserDialog; | 63 ItemChooserDialog mItemChooserDialog; |
| 58 | 64 |
| 59 // The origin for the site wanting to pair with the bluetooth devices. | 65 // The origin for the site wanting to pair with the bluetooth devices. |
| 60 String mOrigin; | 66 String mOrigin; |
| 61 | 67 |
| 62 // The security level of the connection to the site wanting to pair with the | 68 // The security level of the connection to the site wanting to pair with the |
| 63 // bluetooth devices. For valid values see SecurityStateModel::SecurityLevel . | 69 // bluetooth devices. For valid values see SecurityStateModel::SecurityLevel . |
| 64 int mSecurityLevel; | 70 int mSecurityLevel; |
| 65 | 71 |
| 72 LevelListDrawable strengthSignalIcons; | |
| 73 | |
| 66 // A pointer back to the native part of the implementation for this dialog. | 74 // A pointer back to the native part of the implementation for this dialog. |
| 67 long mNativeBluetoothChooserDialogPtr; | 75 long mNativeBluetoothChooserDialogPtr; |
| 68 | 76 |
| 69 // Used to keep track of when the Mode Changed Receiver is registered. | 77 // Used to keep track of when the Mode Changed Receiver is registered. |
| 70 boolean mIsLocationModeChangedReceiverRegistered = false; | 78 boolean mIsLocationModeChangedReceiverRegistered = false; |
| 71 | 79 |
| 72 @VisibleForTesting | 80 @VisibleForTesting |
| 73 final BroadcastReceiver mLocationModeBroadcastReceiver = new BroadcastReceiv er() { | 81 final BroadcastReceiver mLocationModeBroadcastReceiver = new BroadcastReceiv er() { |
| 74 @Override | 82 @Override |
| 75 public void onReceive(Context context, Intent intent) { | 83 public void onReceive(Context context, Intent intent) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 99 */ | 107 */ |
| 100 @VisibleForTesting | 108 @VisibleForTesting |
| 101 BluetoothChooserDialog(WindowAndroid windowAndroid, String origin, int secur ityLevel, | 109 BluetoothChooserDialog(WindowAndroid windowAndroid, String origin, int secur ityLevel, |
| 102 long nativeBluetoothChooserDialogPtr) { | 110 long nativeBluetoothChooserDialogPtr) { |
| 103 mWindowAndroid = windowAndroid; | 111 mWindowAndroid = windowAndroid; |
| 104 mActivity = windowAndroid.getActivity().get(); | 112 mActivity = windowAndroid.getActivity().get(); |
| 105 assert mActivity != null; | 113 assert mActivity != null; |
| 106 mOrigin = origin; | 114 mOrigin = origin; |
| 107 mSecurityLevel = securityLevel; | 115 mSecurityLevel = securityLevel; |
| 108 mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr; | 116 mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr; |
| 117 Resources resources = mActivity.getResources(); | |
| 118 | |
| 119 StateListDrawable level0 = new StateListDrawable(); | |
| 120 level0.addState(new int[] {-android.R.attr.state_selected}, | |
| 121 VectorDrawableCompat.create( | |
| 122 resources, R.drawable.ic_signal_cellular_0_bar_grey, nul l /* theme */)); | |
|
Ian Wen
2016/10/14 01:39:51
Why not simply use mActivity.getTheme() here? Or i
| |
| 123 level0.addState(new int[] {android.R.attr.state_selected}, | |
| 124 VectorDrawableCompat.create( | |
| 125 resources, R.drawable.ic_signal_cellular_0_bar_white, nu ll /* theme */)); | |
| 126 | |
| 127 StateListDrawable level1 = new StateListDrawable(); | |
| 128 level1.addState(new int[] {-android.R.attr.state_selected}, | |
| 129 VectorDrawableCompat.create( | |
| 130 resources, R.drawable.ic_signal_cellular_1_bar_grey, nul l /* theme */)); | |
| 131 level1.addState(new int[] {android.R.attr.state_selected}, | |
| 132 VectorDrawableCompat.create( | |
| 133 resources, R.drawable.ic_signal_cellular_1_bar_white, nu ll /* theme */)); | |
| 134 | |
| 135 StateListDrawable level2 = new StateListDrawable(); | |
| 136 level2.addState(new int[] {-android.R.attr.state_selected}, | |
| 137 VectorDrawableCompat.create( | |
| 138 resources, R.drawable.ic_signal_cellular_2_bar_grey, nul l /* theme */)); | |
| 139 level2.addState(new int[] {android.R.attr.state_selected}, | |
| 140 VectorDrawableCompat.create( | |
| 141 resources, R.drawable.ic_signal_cellular_2_bar_white, nu ll /* theme */)); | |
| 142 | |
| 143 StateListDrawable level3 = new StateListDrawable(); | |
| 144 level3.addState(new int[] {-android.R.attr.state_selected}, | |
| 145 VectorDrawableCompat.create( | |
| 146 resources, R.drawable.ic_signal_cellular_3_bar_grey, nul l /* theme */)); | |
| 147 level3.addState(new int[] {android.R.attr.state_selected}, | |
| 148 VectorDrawableCompat.create( | |
| 149 resources, R.drawable.ic_signal_cellular_3_bar_white, nu ll /* theme */)); | |
| 150 | |
| 151 StateListDrawable level4 = new StateListDrawable(); | |
| 152 level4.addState(new int[] {-android.R.attr.state_selected}, | |
| 153 VectorDrawableCompat.create( | |
| 154 resources, R.drawable.ic_signal_cellular_4_bar_grey, nul l /* theme */)); | |
| 155 level4.addState(new int[] {android.R.attr.state_selected}, | |
| 156 VectorDrawableCompat.create( | |
| 157 resources, R.drawable.ic_signal_cellular_4_bar_white, nu ll /* theme */)); | |
| 158 | |
| 159 strengthSignalIcons = new LevelListDrawable(); | |
| 160 strengthSignalIcons.addLevel(0, 0, level0); | |
| 161 strengthSignalIcons.addLevel(1, 1, level1); | |
| 162 strengthSignalIcons.addLevel(2, 2, level2); | |
| 163 strengthSignalIcons.addLevel(3, 3, level3); | |
| 164 strengthSignalIcons.addLevel(4, 4, level4); | |
| 109 } | 165 } |
| 110 | 166 |
| 111 /** | 167 /** |
| 112 * Show the BluetoothChooserDialog. | 168 * Show the BluetoothChooserDialog. |
| 113 */ | 169 */ |
| 114 @VisibleForTesting | 170 @VisibleForTesting |
| 115 void show() { | 171 void show() { |
| 116 // Emphasize the origin. | 172 // Emphasize the origin. |
| 117 Profile profile = Profile.getLastUsedProfile(); | 173 Profile profile = Profile.getLastUsedProfile(); |
| 118 SpannableString origin = new SpannableString(mOrigin); | 174 SpannableString origin = new SpannableString(mOrigin); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 149 SpannableString statusIdleSomeFound = SpanApplier.applySpans( | 205 SpannableString statusIdleSomeFound = SpanApplier.applySpans( |
| 150 mActivity.getString(R.string.bluetooth_not_seeing_it_idle_some_f ound), | 206 mActivity.getString(R.string.bluetooth_not_seeing_it_idle_some_f ound), |
| 151 new SpanInfo("<link1>", "</link1>", | 207 new SpanInfo("<link1>", "</link1>", |
| 152 new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, m Activity)), | 208 new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, m Activity)), |
| 153 new SpanInfo("<link2>", "</link2>", | 209 new SpanInfo("<link2>", "</link2>", |
| 154 new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mAct ivity))); | 210 new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mAct ivity))); |
| 155 | 211 |
| 156 ItemChooserDialog.ItemChooserLabels labels = | 212 ItemChooserDialog.ItemChooserLabels labels = |
| 157 new ItemChooserDialog.ItemChooserLabels(title, searching, noneFo und, statusActive, | 213 new ItemChooserDialog.ItemChooserLabels(title, searching, noneFo und, statusActive, |
| 158 statusIdleNoneFound, statusIdleSomeFound, positiveButton ); | 214 statusIdleNoneFound, statusIdleSomeFound, positiveButton ); |
| 159 mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels); | 215 mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels, true /* usingIcon */); |
| 160 | 216 |
| 161 mActivity.registerReceiver(mLocationModeBroadcastReceiver, | 217 mActivity.registerReceiver(mLocationModeBroadcastReceiver, |
| 162 new IntentFilter(LocationManager.MODE_CHANGED_ACTION)); | 218 new IntentFilter(LocationManager.MODE_CHANGED_ACTION)); |
| 163 mIsLocationModeChangedReceiverRegistered = true; | 219 mIsLocationModeChangedReceiverRegistered = true; |
| 164 } | 220 } |
| 165 | 221 |
| 166 // Called to report the dialog's results back to native code. | 222 // Called to report the dialog's results back to native code. |
| 167 private void finishDialog(int resultCode, String id) { | 223 private void finishDialog(int resultCode, String id) { |
| 168 if (mIsLocationModeChangedReceiverRegistered) { | 224 if (mIsLocationModeChangedReceiverRegistered) { |
| 169 mActivity.unregisterReceiver(mLocationModeBroadcastReceiver); | 225 mActivity.unregisterReceiver(mLocationModeBroadcastReceiver); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 return null; | 386 return null; |
| 331 } | 387 } |
| 332 BluetoothChooserDialog dialog = new BluetoothChooserDialog( | 388 BluetoothChooserDialog dialog = new BluetoothChooserDialog( |
| 333 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial ogPtr); | 389 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial ogPtr); |
| 334 dialog.show(); | 390 dialog.show(); |
| 335 return dialog; | 391 return dialog; |
| 336 } | 392 } |
| 337 | 393 |
| 338 @VisibleForTesting | 394 @VisibleForTesting |
| 339 @CalledByNative | 395 @CalledByNative |
| 340 void addOrUpdateDevice(String deviceId, String deviceName) { | 396 void addOrUpdateDevice(String deviceId, String deviceName, int signalStrengt hLevel) { |
| 397 assert - 1 <= signalStrengthLevel && signalStrengthLevel <= 4; | |
| 398 ItemChooserDialog.ItemChooserRow row = mItemChooserDialog.getItemChooser Row(deviceId); | |
| 399 Drawable icon = null; | |
| 400 String iconDescription = null; | |
| 401 boolean didUpdateOldDrawable = false; | |
| 402 if (signalStrengthLevel != -1) { | |
| 403 if (row == null) { | |
| 404 icon = strengthSignalIcons.getConstantState().newDrawable(); | |
| 405 } else { | |
| 406 icon = row.getIcon(); | |
| 407 } | |
| 408 if (icon.setLevel(signalStrengthLevel)) { | |
| 409 icon.invalidateSelf(); | |
| 410 } | |
| 411 iconDescription = mActivity.getResources().getQuantityString( | |
| 412 R.plurals.signal_strength_level_n_bars, signalStrengthLevel, | |
| 413 signalStrengthLevel); | |
| 414 didUpdateOldDrawable = true; | |
| 415 } | |
| 341 mItemChooserDialog.addOrUpdateItem( | 416 mItemChooserDialog.addOrUpdateItem( |
| 342 new ItemChooserDialog.ItemChooserRow(deviceId, deviceName)); | 417 new ItemChooserDialog.ItemChooserRow(deviceId, deviceName, icon, ico nDescription), |
|
Ian Wen
2016/10/14 01:39:51
IIRC this method will be called more than 10 times
| |
| 418 didUpdateOldDrawable); | |
| 343 } | 419 } |
| 344 | 420 |
| 345 @VisibleForTesting | 421 @VisibleForTesting |
| 346 @CalledByNative | 422 @CalledByNative |
| 347 void closeDialog() { | 423 void closeDialog() { |
| 348 mNativeBluetoothChooserDialogPtr = 0; | 424 mNativeBluetoothChooserDialogPtr = 0; |
| 349 mItemChooserDialog.dismiss(); | 425 mItemChooserDialog.dismiss(); |
| 350 } | 426 } |
| 351 | 427 |
| 352 @VisibleForTesting | 428 @VisibleForTesting |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 @VisibleForTesting | 479 @VisibleForTesting |
| 404 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); | 480 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); |
| 405 // Help links. | 481 // Help links. |
| 406 @VisibleForTesting | 482 @VisibleForTesting |
| 407 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro id); | 483 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro id); |
| 408 @VisibleForTesting | 484 @VisibleForTesting |
| 409 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd roid); | 485 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd roid); |
| 410 @VisibleForTesting | 486 @VisibleForTesting |
| 411 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser Android); | 487 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser Android); |
| 412 } | 488 } |
| OLD | NEW |