• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 
17 package com.android.incallui.rtt.impl;
18 
19 import android.content.Context;
20 import android.telecom.CallAudioState;
21 import android.view.View;
22 import android.widget.PopupWindow;
23 import com.android.incallui.incall.protocol.InCallButtonUiDelegate;
24 
25 /** Audio select menu for RTT call. */
26 public class AudioSelectMenu extends PopupWindow {
27 
28   private final InCallButtonUiDelegate inCallButtonUiDelegate;
29   private final OnButtonClickListener onButtonClickListener;
30   private final RttCheckableButton bluetoothButton;
31   private final RttCheckableButton speakerButton;
32   private final RttCheckableButton headsetButton;
33   private final RttCheckableButton earpieceButton;
34 
35   interface OnButtonClickListener {
onBackPressed()36     void onBackPressed();
37   }
38 
AudioSelectMenu( Context context, InCallButtonUiDelegate inCallButtonUiDelegate, OnButtonClickListener onButtonClickListener)39   AudioSelectMenu(
40       Context context,
41       InCallButtonUiDelegate inCallButtonUiDelegate,
42       OnButtonClickListener onButtonClickListener) {
43     super(context, null, 0, R.style.OverflowMenu);
44     this.inCallButtonUiDelegate = inCallButtonUiDelegate;
45     this.onButtonClickListener = onButtonClickListener;
46     View view = View.inflate(context, R.layout.audio_route, null);
47     setContentView(view);
48     setOnDismissListener(this::dismiss);
49     setFocusable(true);
50     setWidth(context.getResources().getDimensionPixelSize(R.dimen.rtt_overflow_menu_width));
51     view.findViewById(R.id.audioroute_back)
52         .setOnClickListener(
53             v -> {
54               dismiss();
55               this.onButtonClickListener.onBackPressed();
56             });
57     CallAudioState audioState = inCallButtonUiDelegate.getCurrentAudioState();
58     bluetoothButton = view.findViewById(R.id.audioroute_bluetooth);
59     speakerButton = view.findViewById(R.id.audioroute_speaker);
60     headsetButton = view.findViewById(R.id.audioroute_headset);
61     earpieceButton = view.findViewById(R.id.audioroute_earpiece);
62     initItem(bluetoothButton, CallAudioState.ROUTE_BLUETOOTH, audioState);
63     initItem(speakerButton, CallAudioState.ROUTE_SPEAKER, audioState);
64     initItem(headsetButton, CallAudioState.ROUTE_WIRED_HEADSET, audioState);
65     initItem(earpieceButton, CallAudioState.ROUTE_EARPIECE, audioState);
66   }
67 
initItem(RttCheckableButton item, final int itemRoute, CallAudioState audioState)68   private void initItem(RttCheckableButton item, final int itemRoute, CallAudioState audioState) {
69     if ((audioState.getSupportedRouteMask() & itemRoute) == 0) {
70       item.setVisibility(View.GONE);
71     } else if (audioState.getRoute() == itemRoute) {
72       item.setChecked(true);
73     }
74     item.setOnClickListener(
75         (v) -> {
76           inCallButtonUiDelegate.setAudioRoute(itemRoute);
77         });
78   }
79 
setAudioState(CallAudioState audioState)80   void setAudioState(CallAudioState audioState) {
81     bluetoothButton.setChecked(audioState.getRoute() == CallAudioState.ROUTE_BLUETOOTH);
82     speakerButton.setChecked(audioState.getRoute() == CallAudioState.ROUTE_SPEAKER);
83     headsetButton.setChecked(audioState.getRoute() == CallAudioState.ROUTE_WIRED_HEADSET);
84     earpieceButton.setChecked(audioState.getRoute() == CallAudioState.ROUTE_EARPIECE);
85   }
86 }
87