Merge "Use device type to show corresponding icon and name" into rvc-dev am: ea93f91f2c
Change-Id: I2e11a47837e268d0955c409e7fb9e2263825fa1b
This commit is contained in:
32
packages/SettingsLib/res/drawable/ic_media_group_device.xml
Normal file
32
packages/SettingsLib/res/drawable/ic_media_group_device.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<!--
|
||||
Copyright (C) 2020 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"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:pathData="M18.2,1L9.8,1C8.81,1 8,1.81 8,2.8v14.4c0,0.99 0.81,1.79 1.8,1.79l8.4,0.01c0.99,0 1.8,-0.81 1.8,-1.8L20,2.8c0,-0.99 -0.81,-1.8 -1.8,-1.8zM14,3c1.1,0 2,0.89 2,2s-0.9,2 -2,2 -2,-0.89 -2,-2 0.9,-2 2,-2zM14,16.5c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4 4,1.79 4,4 -1.79,4 -4,4z"
|
||||
android:fillColor="#000000"/>
|
||||
<path
|
||||
android:pathData="M14,12.5m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0"
|
||||
android:fillColor="#000000"/>
|
||||
<path
|
||||
android:pathData="M6,5H4v16c0,1.1 0.89,2 2,2h10v-2H6V5z"
|
||||
android:fillColor="#000000"/>
|
||||
</vector>
|
||||
@@ -15,11 +15,17 @@
|
||||
*/
|
||||
package com.android.settingslib.media;
|
||||
|
||||
import static android.media.MediaRoute2Info.TYPE_GROUP;
|
||||
import static android.media.MediaRoute2Info.TYPE_REMOTE_SPEAKER;
|
||||
import static android.media.MediaRoute2Info.TYPE_REMOTE_TV;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.MediaRoute2Info;
|
||||
import android.media.MediaRouter2Manager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settingslib.R;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
|
||||
@@ -51,7 +57,23 @@ public class InfoMediaDevice extends MediaDevice {
|
||||
public Drawable getIcon() {
|
||||
//TODO(b/120669861): Return remote device icon uri once api is ready.
|
||||
return BluetoothUtils.buildBtRainbowDrawable(mContext,
|
||||
mContext.getDrawable(R.drawable.ic_media_device), getId().hashCode());
|
||||
mContext.getDrawable(getDrawableResId()), getId().hashCode());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getDrawableResId() {
|
||||
int resId;
|
||||
switch (mRouteInfo.getType()) {
|
||||
case TYPE_GROUP:
|
||||
resId = R.drawable.ic_media_group_device;
|
||||
break;
|
||||
case TYPE_REMOTE_TV:
|
||||
case TYPE_REMOTE_SPEAKER:
|
||||
default:
|
||||
resId = R.drawable.ic_media_device;
|
||||
break;
|
||||
}
|
||||
return resId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,11 +15,17 @@
|
||||
*/
|
||||
package com.android.settingslib.media;
|
||||
|
||||
import static android.media.MediaRoute2Info.TYPE_BUILTIN_SPEAKER;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.MediaRoute2Info;
|
||||
import android.media.MediaRouter2Manager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settingslib.R;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
|
||||
@@ -43,7 +49,18 @@ public class PhoneMediaDevice extends MediaDevice {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mContext.getString(R.string.media_transfer_this_device_name);
|
||||
CharSequence name;
|
||||
switch (mRouteInfo.getType()) {
|
||||
case TYPE_WIRED_HEADSET:
|
||||
case TYPE_WIRED_HEADPHONES:
|
||||
name = mRouteInfo.getName();
|
||||
break;
|
||||
case TYPE_BUILTIN_SPEAKER:
|
||||
default:
|
||||
name = mContext.getString(R.string.media_transfer_this_device_name);
|
||||
break;
|
||||
}
|
||||
return name.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +71,23 @@ public class PhoneMediaDevice extends MediaDevice {
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return BluetoothUtils.buildBtRainbowDrawable(mContext,
|
||||
mContext.getDrawable(R.drawable.ic_smartphone), getId().hashCode());
|
||||
mContext.getDrawable(getDrawableResId()), getId().hashCode());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getDrawableResId() {
|
||||
int resId;
|
||||
switch (mRouteInfo.getType()) {
|
||||
case TYPE_WIRED_HEADSET:
|
||||
case TYPE_WIRED_HEADPHONES:
|
||||
resId = com.android.internal.R.drawable.ic_bt_headphones_a2dp;
|
||||
break;
|
||||
case TYPE_BUILTIN_SPEAKER:
|
||||
default:
|
||||
resId = R.drawable.ic_smartphone;
|
||||
break;
|
||||
}
|
||||
return resId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.android.settingslib.media;
|
||||
|
||||
import static android.media.MediaRoute2Info.TYPE_GROUP;
|
||||
import static android.media.MediaRoute2Info.TYPE_REMOTE_SPEAKER;
|
||||
import static android.media.MediaRoute2Info.TYPE_REMOTE_TV;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -86,4 +90,19 @@ public class InfoMediaDeviceTest {
|
||||
|
||||
assertThat(mInfoMediaDevice.getId()).isEqualTo(TEST_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDrawableResId_returnCorrectResId() {
|
||||
when(mRouteInfo.getType()).thenReturn(TYPE_REMOTE_TV);
|
||||
|
||||
assertThat(mInfoMediaDevice.getDrawableResId()).isEqualTo(R.drawable.ic_media_device);
|
||||
|
||||
when(mRouteInfo.getType()).thenReturn(TYPE_REMOTE_SPEAKER);
|
||||
|
||||
assertThat(mInfoMediaDevice.getDrawableResId()).isEqualTo(R.drawable.ic_media_device);
|
||||
|
||||
when(mRouteInfo.getType()).thenReturn(TYPE_GROUP);
|
||||
|
||||
assertThat(mInfoMediaDevice.getDrawableResId()).isEqualTo(R.drawable.ic_media_group_device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,23 @@
|
||||
|
||||
package com.android.settingslib.media;
|
||||
|
||||
import static android.media.MediaRoute2Info.TYPE_BUILTIN_SPEAKER;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADPHONES;
|
||||
import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.MediaRoute2Info;
|
||||
|
||||
import com.android.settingslib.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
@@ -32,6 +40,9 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PhoneMediaDeviceTest {
|
||||
|
||||
@Mock
|
||||
private MediaRoute2Info mInfo;
|
||||
|
||||
private Context mContext;
|
||||
private PhoneMediaDevice mPhoneMediaDevice;
|
||||
|
||||
@@ -41,7 +52,7 @@ public class PhoneMediaDeviceTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mPhoneMediaDevice =
|
||||
new PhoneMediaDevice(mContext, null, null, null);
|
||||
new PhoneMediaDevice(mContext, null, mInfo, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,4 +69,42 @@ public class PhoneMediaDeviceTest {
|
||||
|
||||
assertThat(mPhoneMediaDevice.getSummary()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDrawableResId_returnCorrectResId() {
|
||||
when(mInfo.getType()).thenReturn(TYPE_WIRED_HEADPHONES);
|
||||
|
||||
assertThat(mPhoneMediaDevice.getDrawableResId())
|
||||
.isEqualTo(com.android.internal.R.drawable.ic_bt_headphones_a2dp);
|
||||
|
||||
when(mInfo.getType()).thenReturn(TYPE_WIRED_HEADSET);
|
||||
|
||||
assertThat(mPhoneMediaDevice.getDrawableResId())
|
||||
.isEqualTo(com.android.internal.R.drawable.ic_bt_headphones_a2dp);
|
||||
|
||||
when(mInfo.getType()).thenReturn(TYPE_BUILTIN_SPEAKER);
|
||||
|
||||
assertThat(mPhoneMediaDevice.getDrawableResId()).isEqualTo(R.drawable.ic_smartphone);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getName_returnCorrectName() {
|
||||
final String deviceName = "test_name";
|
||||
|
||||
when(mInfo.getType()).thenReturn(TYPE_WIRED_HEADPHONES);
|
||||
when(mInfo.getName()).thenReturn(deviceName);
|
||||
|
||||
assertThat(mPhoneMediaDevice.getName())
|
||||
.isEqualTo(deviceName);
|
||||
|
||||
when(mInfo.getType()).thenReturn(TYPE_WIRED_HEADSET);
|
||||
|
||||
assertThat(mPhoneMediaDevice.getName())
|
||||
.isEqualTo(deviceName);
|
||||
|
||||
when(mInfo.getType()).thenReturn(TYPE_BUILTIN_SPEAKER);
|
||||
|
||||
assertThat(mPhoneMediaDevice.getName())
|
||||
.isEqualTo(mContext.getString(R.string.media_transfer_this_device_name));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user