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.TYPE_GROUP; 19 import static android.media.MediaRoute2Info.TYPE_REMOTE_CAR; 20 import static android.media.MediaRoute2Info.TYPE_REMOTE_COMPUTER; 21 import static android.media.MediaRoute2Info.TYPE_REMOTE_GAME_CONSOLE; 22 import static android.media.MediaRoute2Info.TYPE_REMOTE_SMARTPHONE; 23 import static android.media.MediaRoute2Info.TYPE_REMOTE_SMARTWATCH; 24 import static android.media.MediaRoute2Info.TYPE_REMOTE_SPEAKER; 25 import static android.media.MediaRoute2Info.TYPE_REMOTE_TABLET; 26 import static android.media.MediaRoute2Info.TYPE_REMOTE_TABLET_DOCKED; 27 import static android.media.MediaRoute2Info.TYPE_REMOTE_TV; 28 29 import android.annotation.NonNull; 30 import android.annotation.Nullable; 31 import android.content.Context; 32 import android.graphics.drawable.Drawable; 33 import android.media.MediaRoute2Info; 34 import android.media.RouteListingPreference; 35 36 import androidx.annotation.VisibleForTesting; 37 38 import com.android.settingslib.R; 39 40 /** 41 * InfoMediaDevice extends MediaDevice to represents wifi device. 42 */ 43 public class InfoMediaDevice extends MediaDevice { 44 45 private static final String TAG = "InfoMediaDevice"; 46 InfoMediaDevice( @onNull Context context, @NonNull MediaRoute2Info info, @Nullable RouteListingPreference.Item item)47 InfoMediaDevice( 48 @NonNull Context context, 49 @NonNull MediaRoute2Info info, 50 @Nullable RouteListingPreference.Item item) { 51 super(context, info, item); 52 initDeviceRecord(); 53 } 54 55 @Override getName()56 public String getName() { 57 return mRouteInfo.getName().toString(); 58 } 59 60 @Override getSummary()61 public String getSummary() { 62 return mRouteInfo.getClientPackageName() != null 63 ? mContext.getString(R.string.bluetooth_active_no_battery_level) : null; 64 } 65 66 @Override getIcon()67 public Drawable getIcon() { 68 return getIconWithoutBackground(); 69 } 70 71 @Override getIconWithoutBackground()72 public Drawable getIconWithoutBackground() { 73 return mContext.getDrawable(getDrawableResIdByType()); 74 } 75 76 @VisibleForTesting 77 @SuppressWarnings("NewApi") getDrawableResIdByType()78 int getDrawableResIdByType() { 79 int resId; 80 switch (mRouteInfo.getType()) { 81 case TYPE_GROUP: 82 resId = R.drawable.ic_media_group_device; 83 break; 84 case TYPE_REMOTE_TV: 85 resId = R.drawable.ic_media_display_device; 86 break; 87 case TYPE_REMOTE_TABLET: 88 resId = R.drawable.ic_media_tablet; 89 break; 90 case TYPE_REMOTE_TABLET_DOCKED: 91 resId = R.drawable.ic_dock_device; 92 break; 93 case TYPE_REMOTE_COMPUTER: 94 resId = R.drawable.ic_media_computer; 95 break; 96 case TYPE_REMOTE_GAME_CONSOLE: 97 resId = R.drawable.ic_media_game_console; 98 break; 99 case TYPE_REMOTE_CAR: 100 resId = R.drawable.ic_media_car; 101 break; 102 case TYPE_REMOTE_SMARTWATCH: 103 resId = R.drawable.ic_media_smartwatch; 104 break; 105 case TYPE_REMOTE_SMARTPHONE: 106 resId = R.drawable.ic_smartphone; 107 break; 108 case TYPE_REMOTE_SPEAKER: 109 default: 110 resId = R.drawable.ic_media_speaker_device; 111 break; 112 } 113 return resId; 114 } 115 116 @Override getId()117 public String getId() { 118 return mRouteInfo.getId(); 119 } 120 isConnected()121 public boolean isConnected() { 122 return true; 123 } 124 } 125