1 /* 2 * Copyright (C) 2017 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 17 package com.android.incallui.speakerbuttonlogic; 18 19 import android.support.annotation.DrawableRes; 20 import android.support.annotation.IntDef; 21 import android.support.annotation.StringRes; 22 import android.telecom.CallAudioState; 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 25 26 /** Info about how a "Speaker" button should be displayed */ 27 public class SpeakerButtonInfo { 28 29 // Testing note: most of this is exercised in ReturnToCallTest.java 30 31 /** Preferred size for icons */ 32 @Retention(RetentionPolicy.SOURCE) 33 @IntDef({IconSize.SIZE_24_DP, IconSize.SIZE_36_DP}) 34 public @interface IconSize { 35 int SIZE_24_DP = 1; 36 int SIZE_36_DP = 2; 37 } 38 39 @DrawableRes public final int icon; 40 @StringRes public final int contentDescription; 41 @StringRes public final int label; 42 public final boolean nonBluetoothMode; 43 public final boolean isChecked; 44 SpeakerButtonInfo(CallAudioState audioState)45 public SpeakerButtonInfo(CallAudioState audioState) { 46 if ((audioState.getSupportedRouteMask() & CallAudioState.ROUTE_BLUETOOTH) 47 == CallAudioState.ROUTE_BLUETOOTH) { 48 nonBluetoothMode = false; 49 label = R.string.incall_label_audio; 50 51 if ((audioState.getRoute() & CallAudioState.ROUTE_BLUETOOTH) 52 == CallAudioState.ROUTE_BLUETOOTH) { 53 icon = R.drawable.volume_bluetooth; 54 contentDescription = R.string.incall_content_description_bluetooth; 55 isChecked = true; 56 } else if ((audioState.getRoute() & CallAudioState.ROUTE_SPEAKER) 57 == CallAudioState.ROUTE_SPEAKER) { 58 icon = R.drawable.quantum_ic_volume_up_vd_theme_24; 59 contentDescription = R.string.incall_content_description_speaker; 60 isChecked = true; 61 } else if ((audioState.getRoute() & CallAudioState.ROUTE_WIRED_HEADSET) 62 == CallAudioState.ROUTE_WIRED_HEADSET) { 63 icon = R.drawable.quantum_ic_headset_vd_theme_24; 64 contentDescription = R.string.incall_content_description_headset; 65 isChecked = true; 66 } else { 67 icon = R.drawable.quantum_ic_phone_in_talk_vd_theme_24; 68 contentDescription = R.string.incall_content_description_earpiece; 69 isChecked = false; 70 } 71 } else { 72 nonBluetoothMode = true; 73 isChecked = audioState.getRoute() == CallAudioState.ROUTE_SPEAKER; 74 label = R.string.incall_label_speaker; 75 icon = R.drawable.quantum_ic_volume_up_vd_theme_24; 76 contentDescription = R.string.incall_content_description_speaker; 77 } 78 } 79 } 80