1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.settingslib.media; 17 18 import static android.media.MediaRoute2Info.FEATURE_REMOTE_GROUP_PLAYBACK; 19 import static android.media.MediaRoute2Info.FEATURE_REMOTE_VIDEO_PLAYBACK; 20 import static android.media.MediaRoute2Info.TYPE_GROUP; 21 import static android.media.MediaRoute2Info.TYPE_REMOTE_SPEAKER; 22 import static android.media.MediaRoute2Info.TYPE_REMOTE_TV; 23 24 import android.content.Context; 25 import android.graphics.drawable.Drawable; 26 import android.media.MediaRoute2Info; 27 import android.media.MediaRouter2Manager; 28 29 import androidx.annotation.VisibleForTesting; 30 31 import com.android.settingslib.R; 32 import com.android.settingslib.bluetooth.BluetoothUtils; 33 34 import java.util.List; 35 36 /** 37 * InfoMediaDevice extends MediaDevice to represents wifi device. 38 */ 39 public class InfoMediaDevice extends MediaDevice { 40 41 private static final String TAG = "InfoMediaDevice"; 42 InfoMediaDevice(Context context, MediaRouter2Manager routerManager, MediaRoute2Info info, String packageName)43 InfoMediaDevice(Context context, MediaRouter2Manager routerManager, MediaRoute2Info info, 44 String packageName) { 45 super(context, routerManager, info, packageName); 46 initDeviceRecord(); 47 } 48 49 @Override getName()50 public String getName() { 51 return mRouteInfo.getName().toString(); 52 } 53 54 @Override getSummary()55 public String getSummary() { 56 return mRouteInfo.getClientPackageName() != null 57 ? mContext.getString(R.string.bluetooth_active_no_battery_level) : null; 58 } 59 60 @Override getIcon()61 public Drawable getIcon() { 62 final Drawable drawable = getIconWithoutBackground(); 63 setColorFilter(drawable); 64 return BluetoothUtils.buildAdvancedDrawable(mContext, drawable); 65 } 66 67 @Override getIconWithoutBackground()68 public Drawable getIconWithoutBackground() { 69 return mContext.getDrawable(getDrawableResIdByFeature()); 70 } 71 72 @VisibleForTesting getDrawableResId()73 int getDrawableResId() { 74 int resId; 75 switch (mRouteInfo.getType()) { 76 case TYPE_GROUP: 77 resId = R.drawable.ic_media_group_device; 78 break; 79 case TYPE_REMOTE_TV: 80 resId = R.drawable.ic_media_display_device; 81 break; 82 case TYPE_REMOTE_SPEAKER: 83 default: 84 resId = R.drawable.ic_media_speaker_device; 85 break; 86 } 87 return resId; 88 } 89 90 @VisibleForTesting getDrawableResIdByFeature()91 int getDrawableResIdByFeature() { 92 int resId; 93 final List<String> features = mRouteInfo.getFeatures(); 94 if (features.contains(FEATURE_REMOTE_GROUP_PLAYBACK)) { 95 resId = R.drawable.ic_media_group_device; 96 } else if (features.contains(FEATURE_REMOTE_VIDEO_PLAYBACK)) { 97 resId = R.drawable.ic_media_display_device; 98 } else { 99 resId = R.drawable.ic_media_speaker_device; 100 } 101 102 return resId; 103 } 104 105 @Override getId()106 public String getId() { 107 return MediaDeviceUtils.getId(mRouteInfo); 108 } 109 isConnected()110 public boolean isConnected() { 111 return true; 112 } 113 } 114