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 checkable; 43 public final boolean isChecked; 44 45 public SpeakerButtonInfo(CallAudioState audioState, @IconSize int iconSize) { 46 if ((audioState.getSupportedRouteMask() & CallAudioState.ROUTE_BLUETOOTH) 47 == CallAudioState.ROUTE_BLUETOOTH) { 48 checkable = false; 49 isChecked = false; 50 label = R.string.incall_label_audio; 51 52 if ((audioState.getRoute() & CallAudioState.ROUTE_BLUETOOTH) 53 == CallAudioState.ROUTE_BLUETOOTH) { 54 icon = 55 iconSize == IconSize.SIZE_36_DP 56 ? R.drawable.quantum_ic_bluetooth_audio_white_36 57 : R.drawable.quantum_ic_bluetooth_audio_white_24; 58 contentDescription = R.string.incall_content_description_bluetooth; 59 } else if ((audioState.getRoute() & CallAudioState.ROUTE_SPEAKER) 60 == CallAudioState.ROUTE_SPEAKER) { 61 icon = 62 iconSize == IconSize.SIZE_36_DP 63 ? R.drawable.quantum_ic_volume_up_white_36 64 : R.drawable.quantum_ic_volume_up_white_24; 65 contentDescription = R.string.incall_content_description_speaker; 66 } else if ((audioState.getRoute() & CallAudioState.ROUTE_WIRED_HEADSET) 67 == CallAudioState.ROUTE_WIRED_HEADSET) { 68 icon = 69 iconSize == IconSize.SIZE_36_DP 70 ? R.drawable.quantum_ic_headset_white_36 71 : R.drawable.quantum_ic_headset_white_24; 72 contentDescription = R.string.incall_content_description_headset; 73 } else { 74 icon = 75 iconSize == IconSize.SIZE_36_DP 76 ? R.drawable.quantum_ic_phone_in_talk_white_36 77 : R.drawable.quantum_ic_phone_in_talk_white_24; 78 contentDescription = R.string.incall_content_description_earpiece; 79 } 80 } else { 81 checkable = true; 82 isChecked = audioState.getRoute() == CallAudioState.ROUTE_SPEAKER; 83 label = R.string.incall_label_speaker; 84 icon = 85 iconSize == IconSize.SIZE_36_DP 86 ? R.drawable.quantum_ic_volume_up_white_36 87 : R.drawable.quantum_ic_volume_up_white_24; 88 contentDescription = R.string.incall_content_description_speaker; 89 } 90 } 91 } 92