CallButtonPresenter.java revision fe09b09a955c574d1131932211a05f862ee9e50f
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
19dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordonimport com.android.incallui.AudioModeProvider.AudioModeListener;
20671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordonimport com.android.incallui.InCallPresenter.InCallState;
21671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordonimport com.android.incallui.InCallPresenter.InCallStateListener;
22dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordonimport com.android.services.telephony.common.AudioMode;
23671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordonimport com.android.services.telephony.common.Call;
24bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordonimport com.android.services.telephony.common.Call.Capabilities;
25671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon
26241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng/**
27241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng * Logic for call buttons.
28241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng */
29150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordonpublic class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButtonUi>
30dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        implements InCallStateListener, AudioModeListener {
31241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
32671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon    private Call mCall;
333c2a439eb67ec6fb89daf1914ab3ce05e8aaa428Santos Cordon    private ProximitySensor mProximitySensor;
34e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee    private boolean mAutomaticallyMuted = false;
35e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee    private boolean mPreviousMuteState = false;
36241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
379de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon    public CallButtonPresenter() {
38241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
39241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
40241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    @Override
41241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    public void onUiReady(CallButtonUi ui) {
42241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng        super.onUiReady(ui);
438b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng
44b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        mProximitySensor = InCallPresenter.getInstance().getProximitySensor();
45b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        AudioModeProvider.getInstance().addListener(this);
46b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon
47b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        // register for call state changes last
48b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        InCallPresenter.getInstance().addListener(this);
49dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
50dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
51dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    @Override
52dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void onUiUnready(CallButtonUi ui) {
5322c678c74fa38e921ea22b09962062fce6148047Christine Chen        super.onUiUnready(ui);
5422c678c74fa38e921ea22b09962062fce6148047Christine Chen
55b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        InCallPresenter.getInstance().removeListener(this);
56b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        AudioModeProvider.getInstance().removeListener(this);
57b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon
58b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        mProximitySensor = null;
59241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
60241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
61150a5c58c67f230c8fd7293b180bbf50aa761480Santos Cordon    @Override
62671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon    public void onStateChange(InCallState state, CallList callList) {
63e7be13fb0556e62b07bc271b130412d82d7f7521Santos Cordon        if (state == InCallState.OUTGOING) {
64e7be13fb0556e62b07bc271b130412d82d7f7521Santos Cordon            mCall = callList.getOutgoingCall();
65e7be13fb0556e62b07bc271b130412d82d7f7521Santos Cordon        } else if (state == InCallState.INCALL) {
66efd4282ec4221ec5eefd4155a4ad915adcedca70Santos Cordon            mCall = callList.getActiveOrBackgroundCall();
67671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon        } else {
68671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon            mCall = null;
69671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon        }
70bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon
71bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        updateUi(state, mCall);
72241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
73241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
74dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    @Override
75dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void onAudioMode(int mode) {
768b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        if (getUi() != null) {
778b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            getUi().setAudio(mode);
788b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        }
79dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
80dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
81dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    @Override
82dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void onSupportedAudioMode(int mask) {
838b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        if (getUi() != null) {
848b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng            getUi().setSupportedAudio(mask);
858b6c8d0dbfba6eabe3d835f8cdcec8a13e253d0cChiao Cheng        }
86dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
87dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
883e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon    @Override
893e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon    public void onMute(boolean muted) {
903e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon        if (getUi() != null) {
913e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon            getUi().setMute(muted);
923e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon        }
933e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon    }
943e69e4fe0e6dbce738cc6b3f9a71fc177e9fe1b6Santos Cordon
95dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public int getAudioMode() {
96b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        return AudioModeProvider.getInstance().getAudioMode();
97dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
98dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
99dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public int getSupportedAudio() {
100b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        return AudioModeProvider.getInstance().getSupportedModes();
101dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
102dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
103dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void setAudioMode(int mode) {
104dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
105dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // TODO: Set a intermediate state in this presenter until we get
106dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // an update for onAudioMode().  This will make UI response immediate
107dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // if it turns out to be slow
108dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
1091a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng        Log.d(this, "Sending new Audio Mode: " + AudioMode.toString(mode));
110dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        CallCommandClient.getInstance().setAudioMode(mode);
111dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
112dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
113dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    /**
114dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon     * Function assumes that bluetooth is not supported.
115dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon     */
116dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    public void toggleSpeakerphone() {
117dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // this function should not be called if bluetooth is available
1189de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon        if (0 != (AudioMode.BLUETOOTH & getSupportedAudio())) {
119dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
1209de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon            // It's clear the UI is wrong, so update the supported mode once again.
1211a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng            Log.e(this, "toggling speakerphone not allowed when bluetooth supported.");
1229de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon            getUi().setSupportedAudio(getSupportedAudio());
123dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon            return;
124dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        }
125dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
126dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        int newMode = AudioMode.SPEAKER;
127dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
128dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        // if speakerphone is already on, change to wired/earpiece
1299de3d7c5188c02cabf03799f87d494ee7dc702cbSantos Cordon        if (getAudioMode() == AudioMode.SPEAKER) {
130dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon            newMode = AudioMode.WIRED_OR_EARPIECE;
131dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        }
132dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
133dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        setAudioMode(newMode);
134dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon    }
135dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon
136b94803e83573734d21a32047b21f348cb2305155Chiao Cheng    public void endCallClicked() {
137e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon        if (mCall == null) {
138e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon            return;
139e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon        }
140671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon
141b94803e83573734d21a32047b21f348cb2305155Chiao Cheng        // TODO(klp): hook up call id.
142671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon        CallCommandClient.getInstance().disconnectCall(mCall.getCallId());
143b94803e83573734d21a32047b21f348cb2305155Chiao Cheng    }
144b94803e83573734d21a32047b21f348cb2305155Chiao Cheng
1450f09a02be361d5bb36fac6981649204f5d6987faChristine Chen    public void manageConferenceButtonClicked() {
1460f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        getUi().displayManageConferencePanel(true);
1470f09a02be361d5bb36fac6981649204f5d6987faChristine Chen    }
1480f09a02be361d5bb36fac6981649204f5d6987faChristine Chen
149241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    public void muteClicked(boolean checked) {
1501a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng        Log.d(this, "turning on mute: " + checked);
1513552ee4b7111b995735d330b2e89bfabc2fd9b61Chiao Cheng        CallCommandClient.getInstance().mute(checked);
152241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
153241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng
1548193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon    public void holdClicked(boolean checked) {
155e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon        if (mCall == null) {
156e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon            return;
157e286f91abd12dee037de19c3836d8002e450a9c9Santos Cordon        }
158671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon
1591a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng        Log.d(this, "holding: " + mCall.getCallId());
160efd4282ec4221ec5eefd4155a4ad915adcedca70Santos Cordon
1618193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon        // TODO(klp): use appropriate hold callId.
162671b221ccadea34fb9327ef5342b26419eb5ca99Santos Cordon        CallCommandClient.getInstance().hold(mCall.getCallId(), checked);
1638193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon        getUi().setHold(checked);
1648193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon    }
1658193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon
16661b7737bc556865097f9ca846bddb562371013fdSantos Cordon    public void mergeClicked() {
16761b7737bc556865097f9ca846bddb562371013fdSantos Cordon        CallCommandClient.getInstance().merge();
16861b7737bc556865097f9ca846bddb562371013fdSantos Cordon    }
16961b7737bc556865097f9ca846bddb562371013fdSantos Cordon
17061b7737bc556865097f9ca846bddb562371013fdSantos Cordon    public void addCallClicked() {
171e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee        // Automatically mute the current call
172e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee        mAutomaticallyMuted = true;
173b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon        mPreviousMuteState = AudioModeProvider.getInstance().getMute();
174a485665ec253f0a04cf7e411cb7acc2738196c63Yorke Lee        // Simulate a click on the mute button
175e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee        getUi().setMute(true);
176a485665ec253f0a04cf7e411cb7acc2738196c63Yorke Lee        muteClicked(true);
177e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee
17861b7737bc556865097f9ca846bddb562371013fdSantos Cordon        CallCommandClient.getInstance().addCall();
17961b7737bc556865097f9ca846bddb562371013fdSantos Cordon    }
18061b7737bc556865097f9ca846bddb562371013fdSantos Cordon
18161b7737bc556865097f9ca846bddb562371013fdSantos Cordon    public void swapClicked() {
18261b7737bc556865097f9ca846bddb562371013fdSantos Cordon        CallCommandClient.getInstance().swap();
18361b7737bc556865097f9ca846bddb562371013fdSantos Cordon    }
18461b7737bc556865097f9ca846bddb562371013fdSantos Cordon
1855b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen    public void showDialpadClicked(boolean checked) {
1861a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng        Log.v(this, "Show dialpad " + String.valueOf(checked));
1875b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen        getUi().displayDialpad(checked);
1883c2a439eb67ec6fb89daf1914ab3ce05e8aaa428Santos Cordon        mProximitySensor.onDialpadVisible(checked);
1895b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen    }
1905b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen
191bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon    private void updateUi(InCallState state, Call call) {
192bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        final CallButtonUi ui = getUi();
193bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        if (ui == null) {
194bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon            return;
195bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        }
196bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon
197bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        final boolean isVisible = state.isConnectingOrConnected() &&
198066e3c2737dcc5288fec577324eb95dd94eb826eChristine Chen                !state.isIncoming() && call != null;
199bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon
20061b7737bc556865097f9ca846bddb562371013fdSantos Cordon        ui.setVisible(isVisible);
20161b7737bc556865097f9ca846bddb562371013fdSantos Cordon
2021a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng        Log.d(this, "Updating call UI for call: ", call);
20361b7737bc556865097f9ca846bddb562371013fdSantos Cordon
204066e3c2737dcc5288fec577324eb95dd94eb826eChristine Chen        if (isVisible) {
205fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            Log.v(this, "Show hold ", call.can(Capabilities.SUPPORT_HOLD));
206fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            Log.v(this, "Enable hold", call.can(Capabilities.HOLD));
2071a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng            Log.v(this, "Show merge ", call.can(Capabilities.MERGE_CALLS));
2081a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng            Log.v(this, "Show swap ", call.can(Capabilities.SWAP_CALLS));
2091a7f2bcab2d2023f2ee4cfb0bc57bc265b5aab87Chiao Cheng            Log.v(this, "Show add call ", call.can(Capabilities.ADD_CALL));
210fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            Log.v(this, "Show mute ", call.can(Capabilities.MUTE));
211bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon
212fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            final boolean canMerge = call.can(Capabilities.MERGE_CALLS);
213fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            final boolean canAdd = call.can(Capabilities.ADD_CALL);
214fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen
215fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            if (canMerge) {
216fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen                ui.showMerge(true);
217fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen                ui.showAddCall(false);
218fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            } else {
219fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen                ui.showMerge(false);
220fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen                ui.showAddCall(true);
221fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen                ui.enableAddCall(canAdd);
222fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            }
223fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen
224fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            ui.showHold(call.can(Capabilities.SUPPORT_HOLD));
225b6ec8a55702f69c1bcb7b3eb1646c363ad9b4d10Santos Cordon            ui.setHold(call.getState() == Call.State.ONHOLD);
226fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            ui.enableHold(call.can(Capabilities.HOLD));
227b6ec8a55702f69c1bcb7b3eb1646c363ad9b4d10Santos Cordon
22861b7737bc556865097f9ca846bddb562371013fdSantos Cordon            ui.showSwap(call.can(Capabilities.SWAP_CALLS));
229e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee
230e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee            // Restore the previous mute state
231b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon            if (mAutomaticallyMuted &&
232b0d08a16da088e01f416f52a7b74ee9630c1493aSantos Cordon                    AudioModeProvider.getInstance().getMute() != mPreviousMuteState) {
233e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee                ui.setMute(mPreviousMuteState);
234e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee                mAutomaticallyMuted = false;
235e08284ea58e98666e6f1b45734d9901de91c2bb4Yorke Lee            }
236fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen            ui.enableMute(call.can(Capabilities.MUTE));
2370f09a02be361d5bb36fac6981649204f5d6987faChristine Chen
2380f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            // Finally, update the "extra button row": It's displayed above the
2390f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            // "End" button, but only if necessary.  Also, it's never displayed
2400f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            // while the dialpad is visible (since it would overlap.)
2410f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            //
2420f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            // The row contains two buttons:
2430f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            //
2440f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            // - "Manage conference" (used only on GSM devices)
2450f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            // - "Merge" button (used only on CDMA devices)
2460f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            // TODO(klp) Add cdma merge button
2470f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            final boolean showCdmaMerge = false;
2480f09a02be361d5bb36fac6981649204f5d6987faChristine Chen//                    (phoneType == PhoneConstants.PHONE_TYPE_CDMA) && inCallControlState.canMerge;
2490f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            final boolean showExtraButtonRow =
2500f09a02be361d5bb36fac6981649204f5d6987faChristine Chen                    (showCdmaMerge || call.isConferenceCall()) && !getUi().isDialpadVisible();
2510f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            if (showExtraButtonRow) {
2520f09a02be361d5bb36fac6981649204f5d6987faChristine Chen                // Need to set up mCdmaMergeButton and mManageConferenceButton if this is the first
2530f09a02be361d5bb36fac6981649204f5d6987faChristine Chen                // time they're visible.
2540f09a02be361d5bb36fac6981649204f5d6987faChristine Chen                // TODO(klp) add cdma merge button
2550f09a02be361d5bb36fac6981649204f5d6987faChristine Chen//                if (mCdmaMergeButton == null) {
2560f09a02be361d5bb36fac6981649204f5d6987faChristine Chen//                    setupExtraButtons();
2570f09a02be361d5bb36fac6981649204f5d6987faChristine Chen//                }
2580f09a02be361d5bb36fac6981649204f5d6987faChristine Chen//                mCdmaMergeButton.setVisibility(showCdmaMerge ? View.VISIBLE : View.GONE);
2590f09a02be361d5bb36fac6981649204f5d6987faChristine Chen                if (call.isConferenceCall()) {
2600f09a02be361d5bb36fac6981649204f5d6987faChristine Chen                    getUi().showManageConferenceCallButton();
2610f09a02be361d5bb36fac6981649204f5d6987faChristine Chen                }
2620f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            } else {
2630f09a02be361d5bb36fac6981649204f5d6987faChristine Chen                getUi().hideExtraRow();
2640f09a02be361d5bb36fac6981649204f5d6987faChristine Chen            }
265bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        }
266bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon    }
267bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon
268241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    public interface CallButtonUi extends Ui {
2694df10e20c8a4a5c2b6b1e9d0c895cf205929e8ddChiao Cheng        void setVisible(boolean on);
270241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng        void setMute(boolean on);
271fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen        void enableMute(boolean enabled);
2728193bc3df6b0726d36a5b7b889ec91c4d59f40c1Santos Cordon        void setHold(boolean on);
273bc168c4fb0638846c5076a5a35a2e75ee4947908Santos Cordon        void showHold(boolean show);
274fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen        void enableHold(boolean enabled);
27561b7737bc556865097f9ca846bddb562371013fdSantos Cordon        void showMerge(boolean show);
27661b7737bc556865097f9ca846bddb562371013fdSantos Cordon        void showSwap(boolean show);
27761b7737bc556865097f9ca846bddb562371013fdSantos Cordon        void showAddCall(boolean show);
278fe09b09a955c574d1131932211a05f862ee9e50fChristine Chen        void enableAddCall(boolean enabled);
2795b9034b5b1b48a4339dd2f893a851cc64d6279dfChristine Chen        void displayDialpad(boolean on);
2800f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        boolean isDialpadVisible();
281dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        void setAudio(int mode);
282dab149c9b2185be82cbca63cc3980e41444900c0Santos Cordon        void setSupportedAudio(int mask);
2830f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        void showManageConferenceCallButton();
2840f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        void showCDMAMergeButton();
2850f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        void hideExtraRow();
2860f09a02be361d5bb36fac6981649204f5d6987faChristine Chen        void displayManageConferencePanel(boolean on);
287241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng    }
288241d50d5f523eb0b644d8a9c1cf7fd2eb418ab88Chiao Cheng}
289