1241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng/*
2241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * Copyright (C) 2013 The Android Open Source Project
3241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng *
4241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * Licensed under the Apache License, Version 2.0 (the "License");
5241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * you may not use this file except in compliance with the License.
6241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * You may obtain a copy of the License at
7241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng *
8241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng *      http://www.apache.org/licenses/LICENSE-2.0
9241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng *
10241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * Unless required by applicable law or agreed to in writing, software
11241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * distributed under the License is distributed on an "AS IS" BASIS,
12241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * See the License for the specific language governing permissions and
14241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * limitations under the License
15241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng */
16241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
17241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Chengpackage com.android.incallui;
18241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
1935224e8ff0e3707b92626767f048f1bf83352a2dTyler Gunnimport android.content.Context;
206cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Leeimport android.os.Bundle;
216cddf46812634fadc194830774110780f14e9462Tyler Gunnimport android.telecom.AudioState;
226cddf46812634fadc194830774110780f14e9462Tyler Gunnimport android.telecom.InCallService.VideoCall;
236cddf46812634fadc194830774110780f14e9462Tyler Gunnimport android.telecom.VideoProfile;
245bcdca79b692712ff8a5a7e3e1c282f4d73cdf1cSailesh Nepal
25dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordonimport com.android.incallui.AudioModeProvider.AudioModeListener;
26ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordonimport com.android.incallui.InCallPresenter.CanAddCallListener;
27671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordonimport com.android.incallui.InCallPresenter.InCallState;
28671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordonimport com.android.incallui.InCallPresenter.InCallStateListener;
29c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chenimport com.android.incallui.InCallPresenter.IncomingCallListener;
30eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunnimport com.android.incallui.InCallPresenter.InCallDetailsListener;
31671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon
32eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunnimport java.util.Objects;
33eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn
34241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng/**
35241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * Logic for call buttons.
36241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng */
37150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordonpublic class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButtonUi>
38eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn        implements InCallStateListener, AudioModeListener, IncomingCallListener,
39ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon        InCallDetailsListener, CanAddCallListener {
40241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
416cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee    private static final String KEY_AUTOMATICALLY_MUTED = "incall_key_automatically_muted";
426cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee    private static final String KEY_PREVIOUS_MUTE_STATE = "incall_key_previous_mute_state";
436cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee
44671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon    private Call mCall;
45e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee    private boolean mAutomaticallyMuted = false;
46e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee    private boolean mPreviousMuteState = false;
472ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki
489de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon    public CallButtonPresenter() {
49241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
50241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
51241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    @Override
52241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    public void onUiReady(CallButtonUi ui) {
53241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng        super.onUiReady(ui);
548b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng
55b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        AudioModeProvider.getInstance().addListener(this);
56b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon
57b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        // register for call state changes last
58b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        InCallPresenter.getInstance().addListener(this);
59c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen        InCallPresenter.getInstance().addIncomingCallListener(this);
60eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn        InCallPresenter.getInstance().addDetailsListener(this);
61ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon        InCallPresenter.getInstance().addCanAddCallListener(this);
62dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
63dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
64dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    @Override
65dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void onUiUnready(CallButtonUi ui) {
6622c678c74fa38e921ea22b09962062fce6148047Christine Chen        super.onUiUnready(ui);
6722c678c74fa38e921ea22b09962062fce6148047Christine Chen
68b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        InCallPresenter.getInstance().removeListener(this);
69b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        AudioModeProvider.getInstance().removeListener(this);
70c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen        InCallPresenter.getInstance().removeIncomingCallListener(this);
71eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn        InCallPresenter.getInstance().removeDetailsListener(this);
72241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
73241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
74150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon    @Override
75f3d0654f2b6d77b7eef8bdcb4c39ee59e55017deNancy Chen    public void onStateChange(InCallState oldState, InCallState newState, CallList callList) {
7655e998472730cae27a82eed49cf7b020699b9286Christine Chen        CallButtonUi ui = getUi();
779be240faad1857e122614a70fd6e632b143ddc41Christine Chen
78f3d0654f2b6d77b7eef8bdcb4c39ee59e55017deNancy Chen        if (newState == InCallState.OUTGOING) {
79e7be13fb0556e62b07bc271b130412d82d7f7521Santos Cordon            mCall = callList.getOutgoingCall();
80f3d0654f2b6d77b7eef8bdcb4c39ee59e55017deNancy Chen        } else if (newState == InCallState.INCALL) {
81efd4282ec4221ec5eefd4155a4ad915adcedca70Santos Cordon            mCall = callList.getActiveOrBackgroundCall();
822ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki
832ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki            // When connected to voice mail, automatically shows the dialpad.
842ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki            // (On previous releases we showed it when in-call shows up, before waiting for
852ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki            // OUTGOING.  We may want to do that once we start showing "Voice mail" label on
862ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki            // the dialpad too.)
8755e998472730cae27a82eed49cf7b020699b9286Christine Chen            if (ui != null) {
8804318a393b5492fb72d6edafca588e6b25ad752cNancy Chen                if (oldState == InCallState.OUTGOING && mCall != null) {
8904318a393b5492fb72d6edafca588e6b25ad752cNancy Chen                    if (CallerInfoUtils.isVoiceMailNumber(ui.getContext(), mCall)) {
9004318a393b5492fb72d6edafca588e6b25ad752cNancy Chen                        ui.displayDialpad(true /* show */, true /* animate */);
9104318a393b5492fb72d6edafca588e6b25ad752cNancy Chen                    }
9255e998472730cae27a82eed49cf7b020699b9286Christine Chen                }
932ce872d6f7dd8a7eb0275b4195336f779972f698Makoto Onuki            }
94f3d0654f2b6d77b7eef8bdcb4c39ee59e55017deNancy Chen        } else if (newState == InCallState.INCOMING) {
9555e998472730cae27a82eed49cf7b020699b9286Christine Chen            if (ui != null) {
9681bcf2a2e1c197655cf4a3aaf7d9af8088cf102eSai Cheemalapati                ui.displayDialpad(false /* show */, true /* animate */);
9755e998472730cae27a82eed49cf7b020699b9286Christine Chen            }
98c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen            mCall = null;
99671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon        } else {
100671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon            mCall = null;
101671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon        }
102f3d0654f2b6d77b7eef8bdcb4c39ee59e55017deNancy Chen        updateUi(newState, mCall);
103241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
104241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
105eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn    /**
106eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     * Updates the user interface in response to a change in the details of a call.
107eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     * Currently handles changes to the call buttons in response to a change in the details for a
108eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     * call.  This is important to ensure changes to the active call are reflected in the available
109eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     * buttons.
110eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     *
111eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     * @param call The active call.
112eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     * @param details The call details.
113eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     */
114eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn    @Override
115eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn    public void onDetailsChanged(Call call, android.telecom.Call.Details details) {
116cbaa95b644b24c57ad998e4c3296815de58060d5Santos Cordon        if (getUi() != null && Objects.equals(call, mCall)) {
117cbaa95b644b24c57ad998e4c3296815de58060d5Santos Cordon            updateCallButtons(call, getUi().getContext());
118eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn        }
119eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn    }
120eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn
121dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    @Override
122f3d0654f2b6d77b7eef8bdcb4c39ee59e55017deNancy Chen    public void onIncomingCall(InCallState oldState, InCallState newState, Call call) {
123f3d0654f2b6d77b7eef8bdcb4c39ee59e55017deNancy Chen        onStateChange(oldState, newState, CallList.getInstance());
124c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen    }
125c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen
126c155f799fc0d4a2c9577f1e0688a3f1f5b436aefChristine Chen    @Override
127ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon    public void onCanAddCallChanged(boolean canAddCall) {
128cbaa95b644b24c57ad998e4c3296815de58060d5Santos Cordon        if (getUi() != null && mCall != null) {
129ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon            updateCallButtons(mCall, getUi().getContext());
130ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon        }
131ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon    }
132ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon
133ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon    @Override
134dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void onAudioMode(int mode) {
1358b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        if (getUi() != null) {
1368b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            getUi().setAudio(mode);
1378b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        }
138dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
139dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
140dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    @Override
141dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void onSupportedAudioMode(int mask) {
1428b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        if (getUi() != null) {
1438b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            getUi().setSupportedAudio(mask);
1448b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        }
145dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
146dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
1473e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon    @Override
1483e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon    public void onMute(boolean muted) {
1497154c3df1cd121a61b8fdd51f6e936be735c4e2bAndrew Lee        if (getUi() != null && !mAutomaticallyMuted) {
1503e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon            getUi().setMute(muted);
1513e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon        }
1523e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon    }
1533e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon
154dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public int getAudioMode() {
155b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        return AudioModeProvider.getInstance().getAudioMode();
156dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
157dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
158dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public int getSupportedAudio() {
159b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        return AudioModeProvider.getInstance().getSupportedModes();
160dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
161dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
162dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void setAudioMode(int mode) {
163dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
164dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // TODO: Set a intermediate state in this presenter until we get
165dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // an update for onAudioMode().  This will make UI response immediate
166dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // if it turns out to be slow
167dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
16843f3e6e0760ea774e479935733d8a30b724457cdIhab Awad        Log.d(this, "Sending new Audio Mode: " + AudioState.audioRouteToString(mode));
1696cddf46812634fadc194830774110780f14e9462Tyler Gunn        TelecomAdapter.getInstance().setAudioRoute(mode);
170dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
171dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
172dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    /**
173dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon     * Function assumes that bluetooth is not supported.
174dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon     */
175dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void toggleSpeakerphone() {
176dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // this function should not be called if bluetooth is available
17743f3e6e0760ea774e479935733d8a30b724457cdIhab Awad        if (0 != (AudioState.ROUTE_BLUETOOTH & getSupportedAudio())) {
178dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
1799de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon            // It's clear the UI is wrong, so update the supported mode once again.
1801a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng            Log.e(this, "toggling speakerphone not allowed when bluetooth supported.");
1819de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon            getUi().setSupportedAudio(getSupportedAudio());
182dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon            return;
183dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        }
184dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
18543f3e6e0760ea774e479935733d8a30b724457cdIhab Awad        int newMode = AudioState.ROUTE_SPEAKER;
186dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
187dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // if speakerphone is already on, change to wired/earpiece
18843f3e6e0760ea774e479935733d8a30b724457cdIhab Awad        if (getAudioMode() == AudioState.ROUTE_SPEAKER) {
18943f3e6e0760ea774e479935733d8a30b724457cdIhab Awad            newMode = AudioState.ROUTE_WIRED_OR_EARPIECE;
190dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        }
191dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
192dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        setAudioMode(newMode);
193dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
194dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
195241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    public void muteClicked(boolean checked) {
1961a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng        Log.d(this, "turning on mute: " + checked);
1976cddf46812634fadc194830774110780f14e9462Tyler Gunn        TelecomAdapter.getInstance().mute(checked);
198241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
199241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
2008193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon    public void holdClicked(boolean checked) {
201e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon        if (mCall == null) {
202e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon            return;
203e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon        }
204fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal        if (checked) {
205fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal            Log.i(this, "Putting the call on hold: " + mCall);
2066cddf46812634fadc194830774110780f14e9462Tyler Gunn            TelecomAdapter.getInstance().holdCall(mCall.getId());
207fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal        } else {
208fc22ba88566ef70e202128335231c367de6c52afSailesh Nepal            Log.i(this, "Removing the call from hold: " + mCall);
2096cddf46812634fadc194830774110780f14e9462Tyler Gunn            TelecomAdapter.getInstance().unholdCall(mCall.getId());
2100e7d8b3f2a18171087b3fe4aa9cc3bf4449ad5b3Yorke Lee        }
2118193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon    }
2128193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon
21352c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon    public void swapClicked() {
21452c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon        if (mCall == null) {
21552c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon            return;
21652c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon        }
21752c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon
21852c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon        Log.i(this, "Swapping the call: " + mCall);
2196cddf46812634fadc194830774110780f14e9462Tyler Gunn        TelecomAdapter.getInstance().swap(mCall.getId());
22052c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon    }
22152c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon
22261b7737bc556865097f9ca846bddb562371013fdSantos Cordon    public void mergeClicked() {
2236cddf46812634fadc194830774110780f14e9462Tyler Gunn        TelecomAdapter.getInstance().merge(mCall.getId());
22461b7737bc556865097f9ca846bddb562371013fdSantos Cordon    }
22561b7737bc556865097f9ca846bddb562371013fdSantos Cordon
22661b7737bc556865097f9ca846bddb562371013fdSantos Cordon    public void addCallClicked() {
227e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee        // Automatically mute the current call
228e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee        mAutomaticallyMuted = true;
229b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        mPreviousMuteState = AudioModeProvider.getInstance().getMute();
230a485665ec253f0a04cf7e411cb7acc2738196c63Yorke Lee        // Simulate a click on the mute button
231a485665ec253f0a04cf7e411cb7acc2738196c63Yorke Lee        muteClicked(true);
2326cddf46812634fadc194830774110780f14e9462Tyler Gunn        TelecomAdapter.getInstance().addCall();
23361b7737bc556865097f9ca846bddb562371013fdSantos Cordon    }
23461b7737bc556865097f9ca846bddb562371013fdSantos Cordon
235746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    public void changeToVoiceClicked() {
236230f77ec8e790f70b0c4a475e69566c049c97a06Andrew Lee        VideoCall videoCall = mCall.getVideoCall();
237230f77ec8e790f70b0c4a475e69566c049c97a06Andrew Lee        if (videoCall == null) {
238746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            return;
239746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
240746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
24143f3e6e0760ea774e479935733d8a30b724457cdIhab Awad        VideoProfile videoProfile = new VideoProfile(
24243f3e6e0760ea774e479935733d8a30b724457cdIhab Awad                VideoProfile.VideoState.AUDIO_ONLY, VideoProfile.QUALITY_DEFAULT);
24343f3e6e0760ea774e479935733d8a30b724457cdIhab Awad        videoCall.sendSessionModifyRequest(videoProfile);
244746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    }
245746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
2465b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen    public void showDialpadClicked(boolean checked) {
2471a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng        Log.v(this, "Show dialpad " + String.valueOf(checked));
24881bcf2a2e1c197655cf4a3aaf7d9af8088cf102eSai Cheemalapati        getUi().displayDialpad(checked /* show */, true /* animate */);
2495b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen    }
2505b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen
251746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    public void changeToVideoClicked() {
252230f77ec8e790f70b0c4a475e69566c049c97a06Andrew Lee        VideoCall videoCall = mCall.getVideoCall();
253230f77ec8e790f70b0c4a475e69566c049c97a06Andrew Lee        if (videoCall == null) {
254746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            return;
255746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
256746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
25743f3e6e0760ea774e479935733d8a30b724457cdIhab Awad        VideoProfile videoProfile =
25843f3e6e0760ea774e479935733d8a30b724457cdIhab Awad                new VideoProfile(VideoProfile.VideoState.BIDIRECTIONAL);
25943f3e6e0760ea774e479935733d8a30b724457cdIhab Awad        videoCall.sendSessionModifyRequest(videoProfile);
260aed98fccfc2af12f8c24f93242fecdab23758c8dAndrew Lee
261aed98fccfc2af12f8c24f93242fecdab23758c8dAndrew Lee        mCall.setSessionModificationState(Call.SessionModificationState.REQUEST_FAILED);
262746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    }
263746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
264746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    /**
265746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     * Switches the camera between the front-facing and back-facing camera.
266746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     * @param useFrontFacingCamera True if we should switch to using the front-facing camera, or
267746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     *     false if we should switch to using the back-facing camera.
268746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     */
269746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    public void switchCameraClicked(boolean useFrontFacingCamera) {
2700455402172610400a220a95e3ad8a93302a80f15Tyler Gunn        InCallCameraManager cameraManager = InCallPresenter.getInstance().getInCallCameraManager();
2710455402172610400a220a95e3ad8a93302a80f15Tyler Gunn        cameraManager.setUseFrontFacingCamera(useFrontFacingCamera);
272746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
273230f77ec8e790f70b0c4a475e69566c049c97a06Andrew Lee        VideoCall videoCall = mCall.getVideoCall();
274230f77ec8e790f70b0c4a475e69566c049c97a06Andrew Lee        if (videoCall == null) {
275746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            return;
276746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
277746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
2780455402172610400a220a95e3ad8a93302a80f15Tyler Gunn        String cameraId = cameraManager.getActiveCameraId();
279746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        if (cameraId != null) {
280230f77ec8e790f70b0c4a475e69566c049c97a06Andrew Lee            videoCall.setCamera(cameraId);
281181c11e0668ac892df10a897cd05505b342dcdc3Tyler Gunn            videoCall.requestCameraCapabilities();
282746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
283746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        getUi().setSwitchCameraButton(!useFrontFacingCamera);
284746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    }
285746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
286746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    /**
287746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     * Stop or start client's video transmission.
288746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     * @param pause True if pausing the local user's video, or false if starting the local user's
289746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     *    video.
290746ee736f255772f7da308765fab22ba7512a10eAndrew Lee     */
291746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    public void pauseVideoClicked(boolean pause) {
292230f77ec8e790f70b0c4a475e69566c049c97a06Andrew Lee        VideoCall videoCall = mCall.getVideoCall();
293230f77ec8e790f70b0c4a475e69566c049c97a06Andrew Lee        if (videoCall == null) {
294746ee736f255772f7da308765fab22ba7512a10eAndrew Lee            return;
295746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
296746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
297746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        if (pause) {
298230f77ec8e790f70b0c4a475e69566c049c97a06Andrew Lee            videoCall.setCamera(null);
29943f3e6e0760ea774e479935733d8a30b724457cdIhab Awad            VideoProfile videoProfile = new VideoProfile(
30043f3e6e0760ea774e479935733d8a30b724457cdIhab Awad                    mCall.getVideoState() | VideoProfile.VideoState.PAUSED);
30143f3e6e0760ea774e479935733d8a30b724457cdIhab Awad            videoCall.sendSessionModifyRequest(videoProfile);
302746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        } else {
3030455402172610400a220a95e3ad8a93302a80f15Tyler Gunn            InCallCameraManager cameraManager = InCallPresenter.getInstance().
3040455402172610400a220a95e3ad8a93302a80f15Tyler Gunn                    getInCallCameraManager();
3050455402172610400a220a95e3ad8a93302a80f15Tyler Gunn            videoCall.setCamera(cameraManager.getActiveCameraId());
30643f3e6e0760ea774e479935733d8a30b724457cdIhab Awad            VideoProfile videoProfile = new VideoProfile(
30743f3e6e0760ea774e479935733d8a30b724457cdIhab Awad                    mCall.getVideoState() & ~VideoProfile.VideoState.PAUSED);
30843f3e6e0760ea774e479935733d8a30b724457cdIhab Awad            videoCall.sendSessionModifyRequest(videoProfile);
309746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        }
310746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        getUi().setPauseVideoButton(pause);
311746ee736f255772f7da308765fab22ba7512a10eAndrew Lee    }
312746ee736f255772f7da308765fab22ba7512a10eAndrew Lee
313bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon    private void updateUi(InCallState state, Call call) {
31489fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        Log.d(this, "Updating call UI for call: ", call);
31589fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
316bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        final CallButtonUi ui = getUi();
317bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        if (ui == null) {
318bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon            return;
319bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        }
320bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon
32189fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        final boolean isEnabled =
32289fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee                state.isConnectingOrConnected() &&!state.isIncoming() && call != null;
32318db3795cd475434ee28841de75b3d85eab5fa57Ben Gilad        ui.setEnabled(isEnabled);
32461b7737bc556865097f9ca846bddb562371013fdSantos Cordon
32589fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee        if (!isEnabled) {
32689fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee            return;
32746c57f18a63d5923b0b93f1988a56bb4beb9cc5dChristine Chen        }
32889fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
329eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn        updateCallButtons(call, ui.getContext());
330eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn
331737f56760b617688aac7218021a5e615ed750810Ihab Awad        ui.enableMute(call.can(android.telecom.Call.Details.CAPABILITY_MUTE));
332eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn    }
333eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn
334eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn    /**
335eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     * Updates the buttons applicable for the UI.
336eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     *
337eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     * @param call The active call.
338eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     * @param context The context.
339eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn     */
340eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn    private void updateCallButtons(Call call, Context context) {
341eb36b967255d32039b769ba0c78e982e988f7c1dTyler Gunn        if (call.isVideoCall(context)) {
3425532000faea55ee01145ec7535c5e0b68c0f7286Andrew Lee            updateVideoCallButtons(call);
3432b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        } else {
3442b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            updateVoiceCallButtons(call);
3452b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        }
3462b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee    }
3472b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3485532000faea55ee01145ec7535c5e0b68c0f7286Andrew Lee    private void updateVideoCallButtons(Call call) {
3492b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        Log.v(this, "Showing buttons for video call.");
3502b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        final CallButtonUi ui = getUi();
3512b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3522b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // Hide all voice-call-related buttons.
3532b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showAudioButton(false);
3542b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showDialpadButton(false);
3552b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showHoldButton(false);
3562b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showSwapButton(false);
3572b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showChangeToVideoButton(false);
3582b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showAddCallButton(false);
3592b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showMergeButton(false);
3602b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showOverflowButton(false);
3612b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3622b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // Show all video-call-related buttons.
3632b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showChangeToVoiceButton(true);
3642b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showSwitchCameraButton(true);
3652b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showPauseVideoButton(true);
3665532000faea55ee01145ec7535c5e0b68c0f7286Andrew Lee
367737f56760b617688aac7218021a5e615ed750810Ihab Awad        final boolean supportHold = call.can(android.telecom.Call.Details.CAPABILITY_SUPPORT_HOLD);
368737f56760b617688aac7218021a5e615ed750810Ihab Awad        final boolean enableHoldOption = call.can(android.telecom.Call.Details.CAPABILITY_HOLD);
3695532000faea55ee01145ec7535c5e0b68c0f7286Andrew Lee        ui.showHoldButton(supportHold);
3705532000faea55ee01145ec7535c5e0b68c0f7286Andrew Lee        ui.enableHold(enableHoldOption);
3715532000faea55ee01145ec7535c5e0b68c0f7286Andrew Lee        ui.setHold(call.getState() == Call.State.ONHOLD);
3722b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee    }
3732b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3742b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee    private void updateVoiceCallButtons(Call call) {
3752b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        Log.v(this, "Showing buttons for voice call.");
3762b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        final CallButtonUi ui = getUi();
3772b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3782b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // Hide all video-call-related buttons.
3792b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showChangeToVoiceButton(false);
3802b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showSwitchCameraButton(false);
3812b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showPauseVideoButton(false);
3822b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
3832b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        // Show all voice-call-related buttons.
3842b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showAudioButton(true);
3852b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showDialpadButton(true);
3862b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee
387737f56760b617688aac7218021a5e615ed750810Ihab Awad        Log.v(this, "Show hold ", call.can(android.telecom.Call.Details.CAPABILITY_SUPPORT_HOLD));
388737f56760b617688aac7218021a5e615ed750810Ihab Awad        Log.v(this, "Enable hold", call.can(android.telecom.Call.Details.CAPABILITY_HOLD));
389737f56760b617688aac7218021a5e615ed750810Ihab Awad        Log.v(this, "Show merge ", call.can(
390737f56760b617688aac7218021a5e615ed750810Ihab Awad                android.telecom.Call.Details.CAPABILITY_MERGE_CONFERENCE));
391737f56760b617688aac7218021a5e615ed750810Ihab Awad        Log.v(this, "Show swap ", call.can(
392737f56760b617688aac7218021a5e615ed750810Ihab Awad                android.telecom.Call.Details.CAPABILITY_SWAP_CONFERENCE));
393ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon        Log.v(this, "Show add call ", TelecomAdapter.getInstance().canAddCall());
394737f56760b617688aac7218021a5e615ed750810Ihab Awad        Log.v(this, "Show mute ", call.can(android.telecom.Call.Details.CAPABILITY_MUTE));
39543f3e6e0760ea774e479935733d8a30b724457cdIhab Awad
396ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon        final boolean canAdd = TelecomAdapter.getInstance().canAddCall();
397737f56760b617688aac7218021a5e615ed750810Ihab Awad        final boolean enableHoldOption = call.can(android.telecom.Call.Details.CAPABILITY_HOLD);
398737f56760b617688aac7218021a5e615ed750810Ihab Awad        final boolean supportHold = call.can(android.telecom.Call.Details.CAPABILITY_SUPPORT_HOLD);
399e1d1225e90cb9f7f62c837baa1b2aa17f5fab119Andrew Lee        final boolean isCallOnHold = call.getState() == Call.State.ONHOLD;
40016e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee
401737f56760b617688aac7218021a5e615ed750810Ihab Awad        boolean canVideoCall = call.can(android.telecom.Call.Details.CAPABILITY_SUPPORTS_VT_LOCAL)
402737f56760b617688aac7218021a5e615ed750810Ihab Awad                && call.can(android.telecom.Call.Details.CAPABILITY_SUPPORTS_VT_REMOTE);
4032b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        ui.showChangeToVideoButton(canVideoCall);
404e1d1225e90cb9f7f62c837baa1b2aa17f5fab119Andrew Lee        ui.enableChangeToVideoButton(!isCallOnHold);
40589fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
406737f56760b617688aac7218021a5e615ed750810Ihab Awad        final boolean showMergeOption = call.can(
407737f56760b617688aac7218021a5e615ed750810Ihab Awad                android.telecom.Call.Details.CAPABILITY_MERGE_CONFERENCE);
40852c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon        final boolean showAddCallOption = canAdd;
40952c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon
410b07ea6f65496c02b693bcc71524decc2011807d2Andrew Lee        // Show either HOLD or SWAP, but not both. If neither HOLD or SWAP is available:
411b07ea6f65496c02b693bcc71524decc2011807d2Andrew Lee        //     (1) If the device normally can hold, show HOLD in a disabled state.
412ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        //     (2) If the device doesn't have the concept of hold/swap, remove the button.
413737f56760b617688aac7218021a5e615ed750810Ihab Awad        final boolean showSwapOption = call.can(
414737f56760b617688aac7218021a5e615ed750810Ihab Awad                android.telecom.Call.Details.CAPABILITY_SWAP_CONFERENCE);
415b07ea6f65496c02b693bcc71524decc2011807d2Andrew Lee        final boolean showHoldOption = !showSwapOption && (enableHoldOption || supportHold);
416ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee
417e1d1225e90cb9f7f62c837baa1b2aa17f5fab119Andrew Lee        ui.setHold(isCallOnHold);
41816e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee        // If we show video upgrade and add/merge and hold/swap, the overflow menu is needed.
41916e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee        final boolean isVideoOverflowScenario = canVideoCall
42016e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee                && (showAddCallOption || showMergeOption) && (showHoldOption || showSwapOption);
42116e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee        // If we show hold/swap, add, and merge simultaneously, the overflow menu is needed.
422ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon        final boolean isOverflowScenario =
42316e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee                (showHoldOption || showSwapOption) && showMergeOption && showAddCallOption;
42416e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee
42516e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee        if (isVideoOverflowScenario) {
4262b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            ui.showHoldButton(false);
4272b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            ui.showSwapButton(false);
4282b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            ui.showAddCallButton(false);
4292b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee            ui.showMergeButton(false);
43089fbf5c95d0f0ed345c5e5b251ead1c519144c88Andrew Lee
431ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.configureOverflowMenu(
432ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee                    showMergeOption,
43352c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon                    showAddCallOption /* showAddMenuOption */,
434ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee                    showHoldOption && enableHoldOption /* showHoldMenuOption */,
435ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee                    showSwapOption);
436ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon            ui.showOverflowButton(true);
4372b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        } else {
438ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon            if (isOverflowScenario) {
43916e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee                ui.showAddCallButton(false);
44016e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee                ui.showMergeButton(false);
44116e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee
44216e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee                ui.configureOverflowMenu(
44316e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee                        showMergeOption,
44452c30ebe11e132c5b00a15aabdf4a411355bf0f4Santos Cordon                        showAddCallOption /* showAddMenuOption */,
44516e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee                        false /* showHoldMenuOption */,
44616e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee                        false /* showSwapMenuOption */);
44716e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee            } else {
44816e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee                ui.showMergeButton(showMergeOption);
44916e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee                ui.showAddCallButton(showAddCallOption);
45016e71a4f2c283f94ca54c070dcc284f8f43e6eb4Andrew Lee            }
451ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee
452ba4e858e872fe446f3a7a17321289d025a40a847Santos Cordon            ui.showOverflowButton(isOverflowScenario);
453ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.showHoldButton(showHoldOption);
454ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.enableHold(enableHoldOption);
455ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee            ui.showSwapButton(showSwapOption);
4562b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        }
457bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon    }
458bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon
459eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen    public void refreshMuteState() {
460eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen        // Restore the previous mute state
461eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen        if (mAutomaticallyMuted &&
462eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen                AudioModeProvider.getInstance().getMute() != mPreviousMuteState) {
463eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen            if (getUi() == null) {
464eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen                return;
465eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen            }
466eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen            muteClicked(mPreviousMuteState);
467eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen        }
468eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen        mAutomaticallyMuted = false;
469eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen    }
470eb7244f3001ca3b001b17bda99ab5c790eb1b2d3Christine Chen
4716cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee    @Override
4726cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee    public void onSaveInstanceState(Bundle outState) {
4736cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee        super.onSaveInstanceState(outState);
4746cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee        outState.putBoolean(KEY_AUTOMATICALLY_MUTED, mAutomaticallyMuted);
4756cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee        outState.putBoolean(KEY_PREVIOUS_MUTE_STATE, mPreviousMuteState);
4766cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee    }
4776cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee
4786cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee    @Override
4796cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee    public void onRestoreInstanceState(Bundle savedInstanceState) {
4806cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee        mAutomaticallyMuted =
4816cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee                savedInstanceState.getBoolean(KEY_AUTOMATICALLY_MUTED, mAutomaticallyMuted);
4826cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee        mPreviousMuteState =
4836cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee                savedInstanceState.getBoolean(KEY_PREVIOUS_MUTE_STATE, mPreviousMuteState);
4846cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee        super.onRestoreInstanceState(savedInstanceState);
4856cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee    }
4866cc6c432d98d552913862a6b663dc4d5dad5c145Yorke Lee
487241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    public interface CallButtonUi extends Ui {
48818db3795cd475434ee28841de75b3d85eab5fa57Ben Gilad        void setEnabled(boolean on);
489241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng        void setMute(boolean on);
490fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen        void enableMute(boolean enabled);
4912b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showAudioButton(boolean show);
4922b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showChangeToVoiceButton(boolean show);
4932b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showDialpadButton(boolean show);
4948193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon        void setHold(boolean on);
4952b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showHoldButton(boolean show);
496fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen        void enableHold(boolean enabled);
4972b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showSwapButton(boolean show);
4982b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showChangeToVideoButton(boolean show);
499e1d1225e90cb9f7f62c837baa1b2aa17f5fab119Andrew Lee        void enableChangeToVideoButton(boolean enable);
5002b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showSwitchCameraButton(boolean show);
501746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        void setSwitchCameraButton(boolean isBackFacingCamera);
5022b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showAddCallButton(boolean show);
5032b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showMergeButton(boolean show);
5042b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showPauseVideoButton(boolean show);
505746ee736f255772f7da308765fab22ba7512a10eAndrew Lee        void setPauseVideoButton(boolean isPaused);
5062b138f87f439c7fbc45e8e9e760af187e22725bcAndrew Lee        void showOverflowButton(boolean show);
50781bcf2a2e1c197655cf4a3aaf7d9af8088cf102eSai Cheemalapati        void displayDialpad(boolean on, boolean animate);
5080f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        boolean isDialpadVisible();
509dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        void setAudio(int mode);
510dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        void setSupportedAudio(int mask);
511ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee        void configureOverflowMenu(boolean showMergeMenuOption, boolean showAddMenuOption,
512ddb824ecb3f052551b3ea97d5f5cb3037ec4c683Andrew Lee                boolean showHoldMenuOption, boolean showSwapMenuOption);
51335224e8ff0e3707b92626767f048f1bf83352a2dTyler Gunn        Context getContext();
514241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
515241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng}
516