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

@@ -1,26 +0,0 @@
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M20,18c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2H4c-1.1,0
-2,0.9 -2,2v10c0,1.1 0.9,2 2,2H0v2h24v-2h-4zM4,6h16v10H4V6z"/>
</vector>

View File

@@ -1,25 +0,0 @@
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M13.5,12l3.8,-3.7c0.4,-0.4 0.4,-1.1 0,-1.5l-4.5,-4.5c-0.4,-0.4 -1.1,-0.4 -1.5,0.1C11.1,2.5 11,2.8 11,3v6.4L6.9,5.4C6.5,5 5.9,5 5.5,5.4s-0.4,1.1 0,1.5l5.1,5.1l-5.1,5.1c-0.4,0.4 -0.4,1.1 0,1.5s1.1,0.4 1.5,0l4.1,-4V21c0,0.6 0.5,1 1,1c0.3,0 0.5,-0.1 0.7,-0.3l0.1,0l4.5,-4.5c0.4,-0.4 0.4,-1.1 0,-1.5L13.5,12zM13,9.7V5.4l2.1,2.2L13,9.7zM13,18.6v-4.3l2.1,2.2L13,18.6z"/>
</vector>

View File

@@ -1,28 +0,0 @@
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19,8H5c-1.66,0-3,1.34-3,3v5c0,0.55,0.45,1,1,1h3v3c0,0.55,0.45,1,1,1h10c0.55,0,1-0.45,1-1v-3h3c0.55,0,1-0.45,1-1v-5
C22,9.34,20.66,8,19,8z M16,19H8v-5h8V19z
M19,12c-0.55,0-1-0.45-1-1s0.45-1,1-1s1,0.45,1,1S19.55,12,19,12z M17,3H7
C6.45,3,6,3.45,6,4v3h12V4C18,3.45,17.55,3,17,3z"/>
</vector>

View File

@@ -8673,27 +8673,6 @@
<!-- Estimated wait time range for real time supports -->
<string name="support_estimated_wait_time">~<xliff:g id="ESTIMATE" example="2 minutes">%1$s</xliff:g> wait</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_computer">Computer</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_headset">Headset</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_phone">Phone</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_imaging">Imaging</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_headphone">Headphone</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_input_peripheral">Input Peripheral</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_bluetooth">Bluetooth</string>
<!-- Used as title on the automatic storage manager settings. [CHAR LIMIT=60] -->
<string name="automatic_storage_manager_settings">Manage storage</string>

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
@@ -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;
}
}
}

View File

@@ -15,21 +15,15 @@
*/
package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.graph.BluetoothDeviceLayerDrawable;
import org.junit.Before;
import org.junit.Test;
@@ -37,7 +31,6 @@ import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static org.mockito.Matchers.anyInt;
@@ -76,20 +69,4 @@ public class UtilsTest {
verify(mMetricsFeatureProvider).visible(eq(mContext), anyInt(),
eq(MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR));
}
@Test
public void testGetBluetoothDrawable_noBatteryLevel_returnSimpleDrawable() {
final Drawable drawable = Utils.getBluetoothDrawable(RuntimeEnvironment.application,
R.drawable.ic_bt_laptop, BluetoothDevice.BATTERY_LEVEL_UNKNOWN, 1 /* iconScale */);
assertThat(drawable).isNotInstanceOf(BluetoothDeviceLayerDrawable.class);
}
@Test
public void testGetBluetoothDrawable_hasBatteryLevel_returnLayerDrawable() {
final Drawable drawable = Utils.getBluetoothDrawable(RuntimeEnvironment.application,
R.drawable.ic_bt_laptop, 10 /* batteryLevel */, 1 /* iconScale */);
assertThat(drawable).isInstanceOf(BluetoothDeviceLayerDrawable.class);
}
}