Show correct call buttons depending on voice/video call.

Behaviors to be implemented in separate changelist.

Renamed some of the methods to reference buttons, and rearranged the
order in which buttons are listed and dealt with to be more
consistent with the order in the layout.

Bug: 16014280
Change-Id: I40a9137d222daf6959a869c11e6ac763baa61788
diff --git a/InCallUI/res/drawable/btn_change_to_audio.xml b/InCallUI/res/drawable/btn_change_to_voice.xml
similarity index 100%
rename from InCallUI/res/drawable/btn_change_to_audio.xml
rename to InCallUI/res/drawable/btn_change_to_voice.xml
diff --git a/InCallUI/res/layout/call_button_fragment.xml b/InCallUI/res/layout/call_button_fragment.xml
index a35cc5e..6b7e17a 100644
--- a/InCallUI/res/layout/call_button_fragment.xml
+++ b/InCallUI/res/layout/call_button_fragment.xml
@@ -83,10 +83,10 @@
             android:contentDescription="@string/onscreenAudioText" />
 
         <!-- "Change to audio call" for video calls. -->
-        <ImageButton android:id="@+id/changeToAudioButton"
+        <ImageButton android:id="@+id/changeToVoiceButton"
             style="@style/InCallButton"
-            android:background="@drawable/btn_change_to_audio"
-            android:contentDescription="@string/onscreenChangeToAudioText"
+            android:background="@drawable/btn_change_to_voice"
+            android:contentDescription="@string/onscreenChangeToVoiceText"
             android:visibility="gone" />
 
         <!-- MIDDLE LEFT SLOT ================================================================== -->
diff --git a/InCallUI/res/values/strings.xml b/InCallUI/res/values/strings.xml
index 3795aa5..dbbfc12 100644
--- a/InCallUI/res/values/strings.xml
+++ b/InCallUI/res/values/strings.xml
@@ -303,9 +303,9 @@
     <!-- Text for the onscreen "Video call" button used to change a voice call
          to a video call. [CHAR LIMIT=10] -->
     <string name="onscreenVideoCallText">Video call</string>
-    <!-- Text for the onscreen "Change to audio" button. When clicked, this downgrades a video call
-         to an audio call. -->
-    <string name="onscreenChangeToAudioText">Change to audio call</string>
+    <!-- Text for the onscreen "Change to voice" button. When clicked, this downgrades a video call
+         to a voice call. -->
+    <string name="onscreenChangeToVoiceText">Change to voice call</string>
     <!-- Text for the onscreen "Switch camera" button. When clicked, this switches the user's camera
          for video calling between the front-facing camera and the back-facing camera. -->
     <string name="onscreenSwitchCameraText">Switch camera</string>
diff --git a/InCallUI/src/com/android/incallui/CallButtonFragment.java b/InCallUI/src/com/android/incallui/CallButtonFragment.java
index 3b06f1a..93bb001 100644
--- a/InCallUI/src/com/android/incallui/CallButtonFragment.java
+++ b/InCallUI/src/com/android/incallui/CallButtonFragment.java
@@ -40,13 +40,18 @@
         implements CallButtonPresenter.CallButtonUi, OnMenuItemClickListener, OnDismissListener,
         View.OnClickListener, CompoundButton.OnCheckedChangeListener {
 
-    private ImageButton mMuteButton;
     private ImageButton mAudioButton;
-    private ImageButton mHoldButton;
+    private ImageButton mChangeToVoiceButton;
+    private ImageButton mMuteButton;
     private ImageButton mShowDialpadButton;
-    private ImageButton mMergeButton;
-    private ImageButton mAddCallButton;
+    private ImageButton mHoldButton;
     private ImageButton mSwapButton;
+    private ImageButton mChangeToVideoButton;
+    private ImageButton mSwitchCameraButton;
+    private ImageButton mAddCallButton;
+    private ImageButton mMergeButton;
+    private ImageButton mPauseVideoButton;
+    private ImageButton mOverflowButton;
 
     private PopupMenu mAudioModePopup;
     private boolean mAudioModePopupVisible;
@@ -125,14 +130,24 @@
             }
         });
 
+        mChangeToVoiceButton = (ImageButton) parent.findViewById(R.id.changeToVoiceButton);
+        mChangeToVoiceButton. setOnClickListener(this);
         mShowDialpadButton = (ImageButton) parent.findViewById(R.id.dialpadButton);
         mShowDialpadButton.setOnClickListener(this);
+        mSwapButton = (ImageButton) parent.findViewById(R.id.swapButton);
+        mSwapButton.setOnClickListener(this);
+        mChangeToVideoButton = (ImageButton) parent.findViewById(R.id.changeToVideoButton);
+        mChangeToVideoButton.setOnClickListener(this);
+        mSwitchCameraButton = (ImageButton) parent.findViewById(R.id.switchCameraButton);
+        mSwitchCameraButton.setOnClickListener(this);
         mAddCallButton = (ImageButton) parent.findViewById(R.id.addButton);
         mAddCallButton.setOnClickListener(this);
         mMergeButton = (ImageButton) parent.findViewById(R.id.mergeButton);
         mMergeButton.setOnClickListener(this);
-        mSwapButton = (ImageButton) parent.findViewById(R.id.swapButton);
-        mSwapButton.setOnClickListener(this);
+        mPauseVideoButton = (ImageButton) parent.findViewById(R.id.pauseVideoButton);
+        mPauseVideoButton.setOnClickListener(this);
+        mOverflowButton = (ImageButton) parent.findViewById(R.id.overflowButton);
+        mOverflowButton.setOnClickListener(this);
 
         return parent;
     }
@@ -175,6 +190,13 @@
             case R.id.dialpadButton:
                 getPresenter().showDialpadClicked(!mShowDialpadButton.isSelected());
                 break;
+            case R.id.changeToVoiceButton:
+            case R.id.changeToVideoButton:
+            case R.id.switchCameraButton:
+            case R.id.pauseVideoButton:
+            case R.id.overflowButton:
+                // TODO: Implement these button behaviors.
+                break;
             default:
                 Log.wtf(this, "onClick: unexpected");
                 break;
@@ -189,14 +211,18 @@
             view.setVisibility(View.VISIBLE);
         }
 
-        // The smaller buttons laid out horizontally just below the end-call button.
-        mMuteButton.setEnabled(isEnabled);
         mAudioButton.setEnabled(isEnabled);
-        mHoldButton.setEnabled(isEnabled);
+        mChangeToVoiceButton.setEnabled(isEnabled);
+        mMuteButton.setEnabled(isEnabled);
         mShowDialpadButton.setEnabled(isEnabled);
-        mMergeButton.setEnabled(isEnabled);
-        mAddCallButton.setEnabled(isEnabled);
+        mHoldButton.setEnabled(isEnabled);
         mSwapButton.setEnabled(isEnabled);
+        mChangeToVideoButton.setEnabled(isEnabled);
+        mSwitchCameraButton.setEnabled(isEnabled);
+        mAddCallButton.setEnabled(isEnabled);
+        mMergeButton.setEnabled(isEnabled);
+        mPauseVideoButton.setEnabled(isEnabled);
+        mOverflowButton.setEnabled(isEnabled);
     }
 
     @Override
@@ -205,17 +231,32 @@
     }
 
     @Override
+    public void showAudioButton(boolean show) {
+        mAudioButton.setVisibility(show ? View.VISIBLE : View.GONE);
+    }
+
+    @Override
+    public void showChangeToVoiceButton(boolean show) {
+        mChangeToVoiceButton.setVisibility(show ? View.VISIBLE : View.GONE);
+    }
+
+    @Override
     public void enableMute(boolean enabled) {
         mMuteButton.setEnabled(enabled);
     }
 
     @Override
+    public void showDialpadButton(boolean show) {
+        mShowDialpadButton.setVisibility(show ? View.VISIBLE : View.GONE);
+    }
+
+    @Override
     public void setHold(boolean value) {
         mHoldButton.setSelected(value);
     }
 
     @Override
-    public void showHold(boolean show) {
+    public void showHoldButton(boolean show) {
         mHoldButton.setVisibility(show ? View.VISIBLE : View.GONE);
     }
 
@@ -225,17 +266,22 @@
     }
 
     @Override
-    public void showMerge(boolean show) {
-        mMergeButton.setVisibility(show ? View.VISIBLE : View.GONE);
-    }
-
-    @Override
-    public void showSwap(boolean show) {
+    public void showSwapButton(boolean show) {
         mSwapButton.setVisibility(show ? View.VISIBLE : View.GONE);
     }
 
     @Override
-    public void showAddCall(boolean show) {
+    public void showChangeToVideoButton(boolean show) {
+        mChangeToVideoButton.setVisibility(show ? View.VISIBLE : View.GONE);
+    }
+
+    @Override
+    public void showSwitchCameraButton(boolean show) {
+        mSwitchCameraButton.setVisibility(show ? View.VISIBLE : View.GONE);
+    }
+
+    @Override
+    public void showAddCallButton(boolean show) {
         mAddCallButton.setVisibility(show ? View.VISIBLE : View.GONE);
     }
 
@@ -245,6 +291,21 @@
     }
 
     @Override
+    public void showMergeButton(boolean show) {
+        mMergeButton.setVisibility(show ? View.VISIBLE : View.GONE);
+    }
+
+    @Override
+    public void showPauseVideoButton(boolean show) {
+        mPauseVideoButton.setVisibility(show ? View.VISIBLE : View.GONE);
+    }
+
+    @Override
+    public void showOverflowButton(boolean show) {
+        mOverflowButton.setVisibility(show ? View.VISIBLE : View.GONE);
+    }
+
+    @Override
     public void setAudio(int mode) {
         updateAudioButtons(getPresenter().getSupportedAudio());
         refreshAudioModePopup();
diff --git a/InCallUI/src/com/android/incallui/CallButtonPresenter.java b/InCallUI/src/com/android/incallui/CallButtonPresenter.java
index 7867f43..4f457b8 100644
--- a/InCallUI/src/com/android/incallui/CallButtonPresenter.java
+++ b/InCallUI/src/com/android/incallui/CallButtonPresenter.java
@@ -16,7 +16,6 @@
 
 package com.android.incallui;
 
-import android.content.Context;
 import android.telecomm.CallCapabilities;
 
 import com.android.contacts.common.util.PhoneNumberHelper;
@@ -27,7 +26,6 @@
 import com.android.incallui.InCallPresenter.IncomingCallListener;
 import com.android.services.telephony.common.AudioMode;
 
-import android.app.Fragment;
 import android.telephony.PhoneNumberUtils;
 
 /**
@@ -229,6 +227,60 @@
             return;
         }
 
+        if (call.isVideoCall()) {
+            updateVideoCallButtons(call);
+        } else {
+            updateVoiceCallButtons(call);
+        }
+
+        ui.enableMute(call.can(CallCapabilities.MUTE));
+
+        // Finally, update the "extra button row": It's displayed above the "End" button, but only
+        // if necessary. It's never displayed while the dialpad is visible since it would overlap.
+        //
+        // The row contains two buttons:
+        //     - "Manage conference" (used only on GSM devices)
+        //     - "Merge" button (used only on CDMA devices)
+        final boolean canMerge = call.can(CallCapabilities.MERGE_CALLS);
+        final boolean isGenericConference = call.can(CallCapabilities.GENERIC_CONFERENCE);
+        mShowGenericMerge = isGenericConference && canMerge;
+        mShowManageConference = (call.isConferenceCall() && !isGenericConference);
+        updateExtraButtonRow();
+    }
+
+    private void updateVideoCallButtons(Call call) {
+        Log.v(this, "Showing buttons for video call.");
+        final CallButtonUi ui = getUi();
+
+        // Hide all voice-call-related buttons.
+        ui.showAudioButton(false);
+        ui.showDialpadButton(false);
+        ui.showHoldButton(false);
+        ui.showSwapButton(false);
+        ui.showChangeToVideoButton(false);
+        ui.showAddCallButton(false);
+        ui.showMergeButton(false);
+        ui.showOverflowButton(false);
+
+        // Show all video-call-related buttons.
+        ui.showChangeToVoiceButton(true);
+        ui.showSwitchCameraButton(true);
+        ui.showPauseVideoButton(true);
+    }
+
+    private void updateVoiceCallButtons(Call call) {
+        Log.v(this, "Showing buttons for voice call.");
+        final CallButtonUi ui = getUi();
+
+        // Hide all video-call-related buttons.
+        ui.showChangeToVoiceButton(false);
+        ui.showSwitchCameraButton(false);
+        ui.showPauseVideoButton(false);
+
+        // Show all voice-call-related buttons.
+        ui.showAudioButton(true);
+        ui.showDialpadButton(true);
+
         Log.v(this, "Show hold ", call.can(CallCapabilities.SUPPORT_HOLD));
         Log.v(this, "Enable hold", call.can(CallCapabilities.HOLD));
         Log.v(this, "Show merge ", call.can(CallCapabilities.MERGE_CALLS));
@@ -242,37 +294,35 @@
         final boolean canHold = call.can(CallCapabilities.HOLD);
         final boolean canSwap = call.can(CallCapabilities.SWAP_CALLS);
         final boolean supportHold = call.can(CallCapabilities.SUPPORT_HOLD);
+        boolean canVideoCall = call.can(CallCapabilities.SUPPORTS_VT_LOCAL)
+                && call.can(CallCapabilities.SUPPORTS_VT_REMOTE);
 
         final boolean showMerge = !isGenericConference && canMerge;
 
-        // Show either MERGE or ADD button, but not both.
-        ui.showMerge(showMerge);
-        ui.showAddCall(!showMerge);
-        ui.enableAddCall(!showMerge && canAdd);
+        ui.showChangeToVideoButton(canVideoCall);
 
-        // Show either HOLD or SWAP button, but not both.
-        // If neither HOLD or SWAP is available:
-        //     (1) If the device normally can hold/swap, show HOLD in a disabled state.
-        //     (2) If the device doesn't have the concept of hold/swap, remove the button.
-        ui.showHold(canHold || (!canSwap && supportHold));
-        ui.showSwap(!canHold && canSwap);
-        ui.setHold(call.getState() == Call.State.ONHOLD);
-        ui.enableHold(canHold);
+        if (canVideoCall && (canHold || canSwap || supportHold)) {
+            ui.showHoldButton(false);
+            ui.showSwapButton(false);
+            ui.showAddCallButton(false);
+            ui.showMergeButton(false);
 
-        ui.enableMute(call.can(CallCapabilities.MUTE));
+            ui.showOverflowButton(true);
+        } else {
+            // Show either MERGE or ADD button, but not both.
+            ui.showMergeButton(showMerge);
+            ui.showAddCallButton(!showMerge);
+            ui.enableAddCall(!showMerge && canAdd);
 
-        // Finally, update the "extra button row": It's displayed above the
-        // "End" button, but only if necessary.  Also, it's never displayed
-        // while the dialpad is visible (since it would overlap.)
-        //
-        // The row contains two buttons:
-        //
-        // - "Manage conference" (used only on GSM devices)
-        // - "Merge" button (used only on CDMA devices)
-
-        mShowGenericMerge = isGenericConference && canMerge;
-        mShowManageConference = (call.isConferenceCall() && !isGenericConference);
-        updateExtraButtonRow();
+            // Show either HOLD or SWAP button, but not both.
+            // If neither HOLD or SWAP is available:
+            //     (1) If the device normally can hold/swap, show HOLD in a disabled state.
+            //     (2) If the device doesn't have the concept of hold/swap, remove the button.
+            ui.showHoldButton(canHold || (!canSwap && supportHold));
+            ui.showSwapButton(!canHold && canSwap);
+            ui.setHold(call.getState() == Call.State.ONHOLD);
+            ui.enableHold(canHold);
+        }
     }
 
     private void updateExtraButtonRow() {
@@ -309,13 +359,20 @@
         void setEnabled(boolean on);
         void setMute(boolean on);
         void enableMute(boolean enabled);
+        void showAudioButton(boolean show);
+        void showChangeToVoiceButton(boolean show);
+        void showDialpadButton(boolean show);
         void setHold(boolean on);
-        void showHold(boolean show);
+        void showHoldButton(boolean show);
         void enableHold(boolean enabled);
-        void showMerge(boolean show);
-        void showSwap(boolean show);
-        void showAddCall(boolean show);
+        void showSwapButton(boolean show);
+        void showChangeToVideoButton(boolean show);
+        void showSwitchCameraButton(boolean show);
+        void showAddCallButton(boolean show);
         void enableAddCall(boolean enabled);
+        void showMergeButton(boolean show);
+        void showPauseVideoButton(boolean show);
+        void showOverflowButton(boolean show);
         void displayDialpad(boolean on, boolean animate);
         boolean isDialpadVisible();
         void setAudio(int mode);