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

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

Issue 2823853004: DO NO SUMMIT: bluetooth: Use a LevelListDrawable instead of an array of drawables
Patch Set: Save icons level Created 3 years, 8 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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; 14 import android.content.res.Resources;
15 import android.graphics.drawable.Drawable; 15 import android.graphics.drawable.Drawable;
16 import android.graphics.drawable.LevelListDrawable;
16 import android.location.LocationManager; 17 import android.location.LocationManager;
17 import android.support.graphics.drawable.VectorDrawableCompat; 18 import android.support.graphics.drawable.VectorDrawableCompat;
18 import android.support.v4.graphics.drawable.DrawableCompat; 19 import android.support.v4.graphics.drawable.DrawableCompat;
19 import android.text.SpannableString; 20 import android.text.SpannableString;
20 import android.text.TextUtils; 21 import android.text.TextUtils;
21 import android.view.View; 22 import android.view.View;
22 23
23 import org.chromium.base.ApiCompatibilityUtils; 24 import org.chromium.base.ApiCompatibilityUtils;
24 import org.chromium.base.Log; 25 import org.chromium.base.Log;
25 import org.chromium.base.VisibleForTesting; 26 import org.chromium.base.VisibleForTesting;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 71
71 // The security level of the connection to the site wanting to pair with the 72 // The security level of the connection to the site wanting to pair with the
72 // bluetooth devices. For valid values see SecurityStateModel::SecurityLevel . 73 // bluetooth devices. For valid values see SecurityStateModel::SecurityLevel .
73 int mSecurityLevel; 74 int mSecurityLevel;
74 75
75 @VisibleForTesting 76 @VisibleForTesting
76 Drawable mConnectedIcon; 77 Drawable mConnectedIcon;
77 @VisibleForTesting 78 @VisibleForTesting
78 String mConnectedIconDescription; 79 String mConnectedIconDescription;
79 @VisibleForTesting 80 @VisibleForTesting
80 Drawable[] mSignalStrengthLevelIcon; 81 LevelListDrawable mSignalStrengthLevelIcon;
81 82
82 // A pointer back to the native part of the implementation for this dialog. 83 // A pointer back to the native part of the implementation for this dialog.
83 long mNativeBluetoothChooserDialogPtr; 84 long mNativeBluetoothChooserDialogPtr;
84 85
85 // Used to keep track of when the Mode Changed Receiver is registered. 86 // Used to keep track of when the Mode Changed Receiver is registered.
86 boolean mIsLocationModeChangedReceiverRegistered; 87 boolean mIsLocationModeChangedReceiverRegistered;
87 88
88 // The local device Bluetooth adapter. 89 // The local device Bluetooth adapter.
89 private final BluetoothAdapter mAdapter; 90 private final BluetoothAdapter mAdapter;
90 91
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 assert mActivity != null; 128 assert mActivity != null;
128 mOrigin = origin; 129 mOrigin = origin;
129 mSecurityLevel = securityLevel; 130 mSecurityLevel = securityLevel;
130 mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr; 131 mNativeBluetoothChooserDialogPtr = nativeBluetoothChooserDialogPtr;
131 mAdapter = BluetoothAdapter.getDefaultAdapter(); 132 mAdapter = BluetoothAdapter.getDefaultAdapter();
132 133
133 // Initialize icons. 134 // Initialize icons.
134 mConnectedIcon = getIconWithRowIconColorStateList(R.drawable.ic_bluetoot h_connected); 135 mConnectedIcon = getIconWithRowIconColorStateList(R.drawable.ic_bluetoot h_connected);
135 mConnectedIconDescription = mActivity.getString(R.string.bluetooth_devic e_connected); 136 mConnectedIconDescription = mActivity.getString(R.string.bluetooth_devic e_connected);
136 137
137 mSignalStrengthLevelIcon = new Drawable[] { 138 mSignalStrengthLevelIcon = new LevelListDrawable();
138 getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_0 _bar), 139 mSignalStrengthLevelIcon.addLevel(
139 getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_1 _bar), 140 0, 0, getIconWithRowIconColorStateList(R.drawable.ic_signal_cell ular_0_bar));
140 getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_2 _bar), 141 mSignalStrengthLevelIcon.addLevel(
141 getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_3 _bar), 142 1, 1, getIconWithRowIconColorStateList(R.drawable.ic_signal_cell ular_1_bar));
142 getIconWithRowIconColorStateList(R.drawable.ic_signal_cellular_4 _bar)}; 143 mSignalStrengthLevelIcon.addLevel(
144 2, 2, getIconWithRowIconColorStateList(R.drawable.ic_signal_cell ular_2_bar));
145 mSignalStrengthLevelIcon.addLevel(
146 3, 3, getIconWithRowIconColorStateList(R.drawable.ic_signal_cell ular_3_bar));
147 mSignalStrengthLevelIcon.addLevel(
148 4, 4, getIconWithRowIconColorStateList(R.drawable.ic_signal_cell ular_4_bar));
143 149
144 if (mAdapter == null) { 150 if (mAdapter == null) {
145 Log.i(TAG, "BluetoothChooserDialog: Default Bluetooth adapter not fo und."); 151 Log.i(TAG, "BluetoothChooserDialog: Default Bluetooth adapter not fo und.");
146 } 152 }
147 mAdapterOffStatus = 153 mAdapterOffStatus =
148 SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_ad apter_off_help), 154 SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_ad apter_off_help),
149 new SpanInfo("<link>", "</link>", 155 new SpanInfo("<link>", "</link>",
150 new BluetoothClickableSpan(LinkType.ADAPTER_OFF_ HELP, mActivity))); 156 new BluetoothClickableSpan(LinkType.ADAPTER_OFF_ HELP, mActivity)));
151 } 157 }
152 158
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 @VisibleForTesting 392 @VisibleForTesting
387 @CalledByNative 393 @CalledByNative
388 void addOrUpdateDevice( 394 void addOrUpdateDevice(
389 String deviceId, String deviceName, boolean isGATTConnected, int sig nalStrengthLevel) { 395 String deviceId, String deviceName, boolean isGATTConnected, int sig nalStrengthLevel) {
390 Drawable icon = null; 396 Drawable icon = null;
391 String iconDescription = null; 397 String iconDescription = null;
392 if (isGATTConnected) { 398 if (isGATTConnected) {
393 icon = mConnectedIcon.getConstantState().newDrawable(); 399 icon = mConnectedIcon.getConstantState().newDrawable();
394 iconDescription = mConnectedIconDescription; 400 iconDescription = mConnectedIconDescription;
395 } else if (signalStrengthLevel != -1) { 401 } else if (signalStrengthLevel != -1) {
396 icon = mSignalStrengthLevelIcon[signalStrengthLevel].getConstantStat e().newDrawable(); 402 icon = mSignalStrengthLevelIcon.getConstantState().newDrawable();
ortuno 2017/04/26 01:06:45 This line makes the dialog pretty unusable. Since
403 icon.setLevel(signalStrengthLevel);
397 iconDescription = mActivity.getResources().getQuantityString( 404 iconDescription = mActivity.getResources().getQuantityString(
398 R.plurals.signal_strength_level_n_bars, signalStrengthLevel, 405 R.plurals.signal_strength_level_n_bars, signalStrengthLevel,
399 signalStrengthLevel); 406 signalStrengthLevel);
400 } 407 }
401 408
402 mItemChooserDialog.addOrUpdateItem(deviceId, deviceName, icon, iconDescr iption); 409 mItemChooserDialog.addOrUpdateItem(deviceId, deviceName, icon, iconDescr iption);
403 } 410 }
404 411
405 @VisibleForTesting 412 @VisibleForTesting
406 @CalledByNative 413 @CalledByNative
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 @VisibleForTesting 460 @VisibleForTesting
454 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); 461 native void nativeRestartSearch(long nativeBluetoothChooserAndroid);
455 // Help links. 462 // Help links.
456 @VisibleForTesting 463 @VisibleForTesting
457 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro id); 464 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro id);
458 @VisibleForTesting 465 @VisibleForTesting
459 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd roid); 466 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd roid);
460 @VisibleForTesting 467 @VisibleForTesting
461 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser Android); 468 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser Android);
462 } 469 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698