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; |
(...skipping 28 matching lines...) Expand all Loading... | |
39 // notifyDiscoveryState(). | 39 // notifyDiscoveryState(). |
40 static final int DISCOVERY_FAILED_TO_START = 0; | 40 static final int DISCOVERY_FAILED_TO_START = 0; |
41 static final int DISCOVERING = 1; | 41 static final int DISCOVERING = 1; |
42 static final int DISCOVERY_IDLE = 2; | 42 static final int DISCOVERY_IDLE = 2; |
43 | 43 |
44 // Values passed to nativeOnDialogFinished:eventType, and only used in the n ative function. | 44 // Values passed to nativeOnDialogFinished:eventType, and only used in the n ative function. |
45 static final int DIALOG_FINISHED_DENIED_PERMISSION = 0; | 45 static final int DIALOG_FINISHED_DENIED_PERMISSION = 0; |
46 static final int DIALOG_FINISHED_CANCELLED = 1; | 46 static final int DIALOG_FINISHED_CANCELLED = 1; |
47 static final int DIALOG_FINISHED_SELECTED = 2; | 47 static final int DIALOG_FINISHED_SELECTED = 2; |
48 | 48 |
49 private static final int SIGNAL_STRENGTH_ICONS[][] = | |
50 new int[][] {{R.drawable.ic_signal_cellular_0_bar_grey600_24dp, | |
51 R.drawable.ic_signal_cellular_0_bar_white_24dp} , | |
52 {R.drawable.ic_signal_cellular_1_bar_grey600_24dp, | |
53 R.drawable.ic_signal_cellular_1_bar_white_24dp}, | |
54 {R.drawable.ic_signal_cellular_2_bar_grey600_24dp, | |
55 R.drawable.ic_signal_cellular_2_bar_white_24dp}, | |
56 {R.drawable.ic_signal_cellular_3_bar_grey600_24dp, | |
57 R.drawable.ic_signal_cellular_3_bar_white_24dp}, | |
58 {R.drawable.ic_signal_cellular_4_bar_grey600_24dp, | |
59 R.drawable.ic_signal_cellular_4_bar_white_24dp}}; | |
60 | |
49 // The window that owns this dialog. | 61 // The window that owns this dialog. |
50 final WindowAndroid mWindowAndroid; | 62 final WindowAndroid mWindowAndroid; |
51 | 63 |
52 // Always equal to mWindowAndroid.getActivity().get(), but stored separately to make sure it's | 64 // Always equal to mWindowAndroid.getActivity().get(), but stored separately to make sure it's |
53 // not GC'ed. | 65 // not GC'ed. |
54 final Activity mActivity; | 66 final Activity mActivity; |
55 | 67 |
56 // The dialog to show to let the user pick a device. | 68 // The dialog to show to let the user pick a device. |
57 ItemChooserDialog mItemChooserDialog; | 69 ItemChooserDialog mItemChooserDialog; |
58 | 70 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 return null; | 342 return null; |
331 } | 343 } |
332 BluetoothChooserDialog dialog = new BluetoothChooserDialog( | 344 BluetoothChooserDialog dialog = new BluetoothChooserDialog( |
333 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial ogPtr); | 345 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial ogPtr); |
334 dialog.show(); | 346 dialog.show(); |
335 return dialog; | 347 return dialog; |
336 } | 348 } |
337 | 349 |
338 @VisibleForTesting | 350 @VisibleForTesting |
339 @CalledByNative | 351 @CalledByNative |
340 void addOrUpdateDevice(String deviceId, String deviceName) { | 352 void addOrUpdateDevice(String deviceId, String deviceName, int signalStrengt hLevel) { |
341 mItemChooserDialog.addOrUpdateItem( | 353 ItemChooserDialog.ItemChooserRowIcon signalStrengthLevelIcon = null; |
342 new ItemChooserDialog.ItemChooserRow(deviceId, deviceName)); | 354 assert 0 <= signalStrengthLevel && signalStrengthLevel <= 4; |
juncai
2016/09/12 20:05:49
I think this assert needs to be moved inside the f
ortuno
2016/09/13 03:00:45
Made the first condition -1.
| |
355 if (signalStrengthLevel != -1) { | |
356 int iconPair[] = SIGNAL_STRENGTH_ICONS[signalStrengthLevel]; | |
357 signalStrengthLevelIcon = new ItemChooserDialog.ItemChooserRowIcon( | |
358 iconPair[0], iconPair[1], mActivity.getResources().getQuanti tyString( | |
359 R.plurals.signal_strength_ level_n_bars, | |
360 signalStrengthLevel, signa lStrengthLevel)); | |
361 } | |
362 mItemChooserDialog.addOrUpdateItem(new ItemChooserDialog.ItemChooserRow( | |
363 deviceId, deviceName, signalStrengthLevelIcon)); | |
343 } | 364 } |
344 | 365 |
345 @VisibleForTesting | 366 @VisibleForTesting |
346 @CalledByNative | 367 @CalledByNative |
347 void closeDialog() { | 368 void closeDialog() { |
348 mNativeBluetoothChooserDialogPtr = 0; | 369 mNativeBluetoothChooserDialogPtr = 0; |
349 mItemChooserDialog.dismiss(); | 370 mItemChooserDialog.dismiss(); |
350 } | 371 } |
351 | 372 |
352 @VisibleForTesting | 373 @VisibleForTesting |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 @VisibleForTesting | 424 @VisibleForTesting |
404 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); | 425 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); |
405 // Help links. | 426 // Help links. |
406 @VisibleForTesting | 427 @VisibleForTesting |
407 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro id); | 428 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro id); |
408 @VisibleForTesting | 429 @VisibleForTesting |
409 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd roid); | 430 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd roid); |
410 @VisibleForTesting | 431 @VisibleForTesting |
411 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser Android); | 432 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser Android); |
412 } | 433 } |
OLD | NEW |