Move the bluetooth icon logic to settingslib

This cl contains the moving about:
1. Several methods in Bluetooth/Utils.java
2. Bluetooth icon drawables
3. Bluetooth strings
4. Tests

Bug: 65488978
Test: RunSettingslibRoboTests

Change-Id: I682daa3eeb5022beb90a95763c70d19d32d54915
This commit is contained in:
jackqdyulei
2017-09-18 13:43:43 -07:00
parent 9d31fa4c8f
commit 88a4b0b0e5
8 changed files with 14 additions and 226 deletions

View File

@@ -51,8 +51,8 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
}
protected void setHeaderProperties() {
final Pair<Drawable, String> pair = Utils.getBtClassDrawableWithDescription(
mContext, mCachedDevice,
final Pair<Drawable, String> pair = com.android.settingslib.bluetooth.Utils
.getBtClassDrawableWithDescription(mContext, mCachedDevice,
mContext.getResources().getFraction(R.fraction.bt_battery_scale_fraction, 1, 1));
String summaryText = mCachedDevice.getConnectionSummary();
mHeaderController.setLabel(mCachedDevice.getName());

View File

@@ -122,8 +122,8 @@ public final class BluetoothDevicePreference extends GearPreference implements
// Null check is done at the framework
setSummary(mCachedDevice.getConnectionSummary());
final Pair<Drawable, String> pair = Utils.getBtClassDrawableWithDescription(getContext(),
mCachedDevice);
final Pair<Drawable, String> pair = com.android.settingslib.bluetooth.Utils
.getBtClassDrawableWithDescription(getContext(), mCachedDevice);
if (pair.first != null) {
setIcon(pair.first);
contentDescription = pair.second;

View File

@@ -17,31 +17,19 @@
package com.android.settings.bluetooth;
import android.app.AlertDialog;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.annotation.VisibleForTesting;
import android.util.Pair;
import android.widget.Toast;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
import com.android.settingslib.bluetooth.Utils.ErrorListener;
import com.android.settingslib.graph.BluetoothDeviceLayerDrawable;
import java.util.List;
/**
* Utils is a helper class that contains constants for various
@@ -57,16 +45,16 @@ public final class Utils {
public static int getConnectionStateSummary(int connectionState) {
switch (connectionState) {
case BluetoothProfile.STATE_CONNECTED:
return R.string.bluetooth_connected;
case BluetoothProfile.STATE_CONNECTING:
return R.string.bluetooth_connecting;
case BluetoothProfile.STATE_DISCONNECTED:
return R.string.bluetooth_disconnected;
case BluetoothProfile.STATE_DISCONNECTING:
return R.string.bluetooth_disconnecting;
default:
return 0;
case BluetoothProfile.STATE_CONNECTED:
return R.string.bluetooth_connected;
case BluetoothProfile.STATE_CONNECTING:
return R.string.bluetooth_connecting;
case BluetoothProfile.STATE_DISCONNECTED:
return R.string.bluetooth_disconnected;
case BluetoothProfile.STATE_DISCONNECTING:
return R.string.bluetooth_disconnecting;
default:
return 0;
}
}
@@ -154,81 +142,4 @@ public final class Utils {
}
};
static Pair<Drawable, String> getBtClassDrawableWithDescription(Context context,
CachedBluetoothDevice cachedDevice) {
return getBtClassDrawableWithDescription(context, cachedDevice, 1 /* iconScale */);
}
static Pair<Drawable, String> getBtClassDrawableWithDescription(Context context,
CachedBluetoothDevice cachedDevice, float iconScale) {
BluetoothClass btClass = cachedDevice.getBtClass();
final int level = cachedDevice.getBatteryLevel();
if (btClass != null) {
switch (btClass.getMajorDeviceClass()) {
case BluetoothClass.Device.Major.COMPUTER:
return new Pair<>(getBluetoothDrawable(context, R.drawable.ic_bt_laptop, level,
iconScale),
context.getString(R.string.bluetooth_talkback_computer));
case BluetoothClass.Device.Major.PHONE:
return new Pair<>(
getBluetoothDrawable(context, R.drawable.ic_bt_cellphone, level,
iconScale),
context.getString(R.string.bluetooth_talkback_phone));
case BluetoothClass.Device.Major.PERIPHERAL:
return new Pair<>(
getBluetoothDrawable(context, HidProfile.getHidClassDrawable(btClass),
level, iconScale),
context.getString(R.string.bluetooth_talkback_input_peripheral));
case BluetoothClass.Device.Major.IMAGING:
return new Pair<>(
getBluetoothDrawable(context, R.drawable.ic_settings_print, level,
iconScale),
context.getString(R.string.bluetooth_talkback_imaging));
default:
// unrecognized device class; continue
}
}
List<LocalBluetoothProfile> profiles = cachedDevice.getProfiles();
for (LocalBluetoothProfile profile : profiles) {
int resId = profile.getDrawableResource(btClass);
if (resId != 0) {
return new Pair<>(getBluetoothDrawable(context, resId, level, iconScale), null);
}
}
if (btClass != null) {
if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
return new Pair<>(
getBluetoothDrawable(context, R.drawable.ic_bt_headset_hfp, level,
iconScale),
context.getString(R.string.bluetooth_talkback_headset));
}
if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
return new Pair<>(
getBluetoothDrawable(context, R.drawable.ic_bt_headphones_a2dp, level,
iconScale),
context.getString(R.string.bluetooth_talkback_headphone));
}
}
return new Pair<>(
getBluetoothDrawable(context, R.drawable.ic_settings_bluetooth, level, iconScale),
context.getString(R.string.bluetooth_talkback_bluetooth));
}
@VisibleForTesting
static Drawable getBluetoothDrawable(Context context, @DrawableRes int resId,
int batteryLevel, float iconScale) {
if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) {
return BluetoothDeviceLayerDrawable.createLayerDrawable(context, resId, batteryLevel,
iconScale);
} else if (resId != 0) {
return context.getDrawable(resId);
} else {
return null;
}
}
}