Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 439365a9 authored by Yorke Lee's avatar Yorke Lee
Browse files

Simplify and rewire in-call buttons

* Fix bug where the switch camera option was never shown
* Fix bug where dialpad button was shown for video calls

* Move management of call button's actual visiblity into the
CallCardFragment. The CallCardPresenter is in charge of deciding
what functionality is available, but the CallCardFragment manages
the actual UI that is displayed.

* Simplify code that collapses call button functionality into
the overflow button. Any buttons that would cause the total number
of buttons to exceed the given threshold will be collapsed into
an overflow menu.

* Dynamically toggle the contentDescription of the hold button. This
is used for both accessibility as well as generating the menu option
if the button is collapsed into the overflow menu

* Removed some now unused strings and code.

Bug: 20127747
Bug: 20127925
Bug: 20090502

Change-Id: I33fda7ad74af926d8c3a507bff8f3c69c19ea57e
parent c6fa624f
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -68,7 +68,8 @@
        <ToggleButton android:id="@+id/audioButton"
            style="@style/InCallCompoundButton"
            android:background="@drawable/btn_compound_audio"
            android:contentDescription="@string/audio_mode_speaker" />
            android:contentDescription="@string/audio_mode_speaker"
            android:visibility="gone" />

        <!-- "Change to audio call" for video calls. -->
        <ImageButton android:id="@+id/changeToVoiceButton"
@@ -83,7 +84,8 @@
        <ToggleButton android:id="@+id/muteButton"
            style="@style/InCallCompoundButton"
            android:background="@drawable/btn_compound_mute"
            android:contentDescription="@string/onscreenMuteText" />
            android:contentDescription="@string/onscreenMuteText"
            android:visibility="gone" />

        <!-- CENTER SLOT ======================================================================= -->

@@ -91,7 +93,8 @@
        <ToggleButton android:id="@+id/dialpadButton"
            style="@style/InCallCompoundButton"
            android:background="@drawable/btn_compound_dialpad"
            android:contentDescription="@string/onscreenShowDialpadText" />
            android:contentDescription="@string/onscreenShowDialpadText"
            android:visibility="gone" />

        <!-- MIDDLE RIGHT SLOT ================================================================= -->

@@ -102,7 +105,8 @@
        <ToggleButton android:id="@+id/holdButton"
            style="@style/InCallCompoundButton"
            android:background="@drawable/btn_compound_hold"
            android:contentDescription="@string/onscreenHoldText" />
            android:contentDescription="@string/onscreenHoldText_unselected"
            android:visibility="gone" />

        <!-- "Swap" (or "Manage calls" in some CDMA states) -->
        <ImageButton android:id="@+id/swapButton"
+0 −36
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2014 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License
  -->

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/overflow_merge_menu_item"
          android:title="@string/overflowMergeMenuItemText" />

    <item android:id="@+id/overflow_add_menu_item"
          android:title="@string/overflowAddMenuItemText" />

    <item android:id="@+id/overflow_hold_menu_item"
          android:title="@string/overflowHoldMenuItemText" />

    <item android:id="@+id/overflow_resume_menu_item"
        android:title="@string/overflowResumeMenuItemText" />

    <item android:id="@+id/overflow_swap_menu_item"
          android:title="@string/overflowSwapMenuItemText" />

    <item android:id="@+id/overflow_manage_conference_menu_item"
          android:title="@string/overflowManageConferenceMenuItemText" />
</menu>
+8 −17
Original line number Diff line number Diff line
@@ -255,23 +255,14 @@
         to dial using the physical keyboard -->
    <string name="dialerKeyboardHintText">Use keyboard to dial</string>

    <!-- Text for the overflow "Hold call" menu item. -->
    <string name="overflowHoldMenuItemText">Hold call</string>
    <!-- Text for the overflow "Resume call" menu item. -->
    <string name="overflowResumeMenuItemText">Resume call</string>
    <!-- Text for the overflow "Add call" menu item. -->
    <string name="overflowAddMenuItemText">Add call</string>
    <!-- Text for the onscreen "Merge calls" menu item. -->
    <string name="overflowMergeMenuItemText">Merge calls</string>
    <!-- Text for the onscreen "Swap calls" menu item. -->
    <string name="overflowSwapMenuItemText">Swap calls</string>
    <!-- Text for the overflow "Manage Conference Video Call" menu item. -->
    <string name="overflowManageConferenceMenuItemText">Manage Conference</string>

    <!-- Text for the onscreen "Hold" button -->
    <string name="onscreenHoldText">Hold</string>
    <!-- Text for the onscreen "Hold" button when it is not selected. Pressing it will put
         the call on hold. -->
    <string name="onscreenHoldText_unselected">Hold Call</string>
    <!-- Text for the onscreen "Hold" button when it is selected. Pressing it will resume
         the call from a previously held state. -->
    <string name="onscreenHoldText_selected">Resume Call</string>
    <!-- Text for the onscreen "End call" button -->
    <string name="onscreenEndCallText">End</string>
    <string name="onscreenEndCallText">End Call</string>
    <!-- Text for the onscreen "Show Dialpad" button -->
    <string name="onscreenShowDialpadText">Dialpad</string>
    <!-- Text for the onscreen "Mute" button -->
+97 −81
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.Bundle;
import android.telecom.AudioState;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
import android.util.SparseIntArray;
import android.view.ContextThemeWrapper;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
@@ -57,23 +58,31 @@ public class CallButtonFragment
        implements CallButtonPresenter.CallButtonUi, OnMenuItemClickListener, OnDismissListener,
        View.OnClickListener {
    private static final int INVALID_INDEX = -1;
    private static final int BUTTON_MAX_VISIBLE = 5;
    // The button is currently visible in the UI
    private static final int BUTTON_VISIBLE = 1;
    // The button is hidden in the UI
    private static final int BUTTON_HIDDEN = 2;
    // The button has been collapsed into the overflow menu
    private static final int BUTTON_MENU = 3;

    public interface Buttons {
        public static final int BUTTON_AUDIO = 1;
        public static final int BUTTON_DOWNGRADE_TO_VOICE = 2;
        public static final int BUTTON_MUTE = 3;
        public static final int BUTTON_DIALPAD = 4;
        public static final int BUTTON_HOLD = 5;
        public static final int BUTTON_SWAP = 6;
        public static final int BUTTON_UPGRADE_TO_VIDEO = 7;
        public static final int BUTTON_SWITCH_CAMERA = 8;
        public static final int BUTTON_ADD_CALL = 9;
        public static final int BUTTON_MERGE = 10;
        public static final int BUTTON_PAUSE_VIDEO = 11;
        public static final int BUTTON_MANAGE_VIDEO_CONFERENCE = 12;
        public static final int BUTTON_OVERFLOW = 13;
    }

        public static final int BUTTON_AUDIO = 0;
        public static final int BUTTON_DOWNGRADE_TO_VOICE = 1;
        public static final int BUTTON_MUTE = 2;
        public static final int BUTTON_DIALPAD = 3;
        public static final int BUTTON_HOLD = 4;
        public static final int BUTTON_SWAP = 5;
        public static final int BUTTON_UPGRADE_TO_VIDEO = 6;
        public static final int BUTTON_SWITCH_CAMERA = 7;
        public static final int BUTTON_ADD_CALL = 8;
        public static final int BUTTON_MERGE = 9;
        public static final int BUTTON_PAUSE_VIDEO = 10;
        public static final int BUTTON_MANAGE_VIDEO_CONFERENCE = 11;
        public static final int BUTTON_COUNT = 12;
    }

    private SparseIntArray mButtonVisibilityMap = new SparseIntArray(BUTTON_COUNT);

    private CompoundButton mAudioButton;
    private ImageButton mChangeToVoiceButton;
@@ -116,6 +125,10 @@ public class CallButtonFragment
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        for (int i = 0; i < BUTTON_COUNT; i++) {
            mButtonVisibilityMap.put(i, BUTTON_HIDDEN);
        }
    }

    @Override
@@ -218,7 +231,9 @@ public class CallButtonFragment
                        !mPauseVideoButton.isSelected() /* pause */);
                break;
            case R.id.overflowButton:
                if (mOverflowPopup != null) {
                    mOverflowPopup.show();
                }
                break;
            case R.id.manageVideoCallConferenceButton:
                onManageVideoCallConferenceClicked();
@@ -240,7 +255,6 @@ public class CallButtonFragment
            return;
        }

        Resources res = getActivity().getResources();
        View[] compoundButtons = {
                mAudioButton,
                mMuteButton,
@@ -362,19 +376,9 @@ public class CallButtonFragment
        mManageVideoCallConferenceButton.setEnabled(isEnabled);
    }

    @Override
    public void setMute(boolean value) {
        if (mMuteButton.isSelected() != value) {
            mMuteButton.setSelected(value);
        }
    }

    @Override
    public void showButton(int buttonId, boolean show) {
        final View button = getButtonById(buttonId);
        if (button != null) {
            button.setVisibility(show ? View.VISIBLE : View.GONE);
        }
        mButtonVisibilityMap.put(buttonId, show ? BUTTON_VISIBLE : BUTTON_HIDDEN);
    }

    @Override
@@ -411,8 +415,6 @@ public class CallButtonFragment
                return mPauseVideoButton;
            case BUTTON_MANAGE_VIDEO_CONFERENCE:
                return mManageVideoCallConferenceButton;
            case BUTTON_OVERFLOW:
                return mOverflowButton;
            default:
                Log.w(this, "Invalid button id");
                return null;
@@ -423,6 +425,9 @@ public class CallButtonFragment
    public void setHold(boolean value) {
        if (mHoldButton.isSelected() != value) {
            mHoldButton.setSelected(value);
            mHoldButton.setContentDescription(getContext().getString(
                    value ? R.string.onscreenHoldText_selected
                            : R.string.onscreenHoldText_unselected));
        }
    }

@@ -436,9 +441,17 @@ public class CallButtonFragment
        mPauseVideoButton.setSelected(isPaused);
    }

    @Override
    public void setMute(boolean value) {
        if (mMuteButton.isSelected() != value) {
            mMuteButton.setSelected(value);
        }
    }

    /**The function is called when Modify Call button gets pressed. The function creates and
     * displays modify call options.
     */
    @Override
    public void displayModifyCallOptions() {
        CallButtonPresenter.CallButtonUi ui = getUi();
        if (ui == null) {
@@ -509,65 +522,68 @@ public class CallButtonFragment
        return "";
    }

    private void addToOverflowMenu(int id, View button, PopupMenu menu) {
        button.setVisibility(View.GONE);
        menu.getMenu().add(Menu.NONE, id, Menu.NONE, button.getContentDescription());
        mButtonVisibilityMap.put(id, BUTTON_MENU);
    }

    private PopupMenu getPopupMenu() {
        return new PopupMenu(new ContextThemeWrapper(getActivity(), R.style.InCallPopupMenuStyle),
                mOverflowButton);
    }

    /**
     * Iterates through the list of buttons and toggles their visibility depending on the
     * setting configured by the CallButtonPresenter. If there are more visible buttons than
     * the allowed maximum, the excess buttons are collapsed into a single overflow menu.
     */
    @Override
    public void configureOverflowMenu(boolean showMergeMenuOption, boolean showAddMenuOption,
            boolean showHoldMenuOption, boolean showSwapMenuOption,
            boolean showManageConferenceVideoCallOption) {
        if (mOverflowPopup == null) {
            final ContextThemeWrapper contextWrapper = new ContextThemeWrapper(getActivity(),
                    R.style.InCallPopupMenuStyle);
            mOverflowPopup = new PopupMenu(contextWrapper, mOverflowButton);
            mOverflowPopup.getMenuInflater().inflate(R.menu.incall_overflow_menu,
                    mOverflowPopup.getMenu());
    public void updateButtonStates() {
        View prevVisibleButton = null;
        int prevVisibleId = -1;
        PopupMenu menu = null;
        int visibleCount = 0;
        for (int i = 0; i < BUTTON_COUNT; i++) {
            final int visibility = mButtonVisibilityMap.get(i);
            final View button = getButtonById(i);
            if (visibility == BUTTON_VISIBLE) {
                visibleCount++;
                if (visibleCount <= BUTTON_MAX_VISIBLE) {
                    button.setVisibility(View.VISIBLE);
                    prevVisibleButton = button;
                    prevVisibleId = i;
                } else {
                    if (menu == null) {
                        menu = getPopupMenu();
                    }
                    // Collapse the current button into the overflow menu. If is the first visible
                    // button that exceeds the threshold, also collapse the previous visible button
                    // so that the total number of visible buttons will never exceed the threshold.
                    if (prevVisibleButton != null) {
                        addToOverflowMenu(prevVisibleId, prevVisibleButton, menu);
                        prevVisibleButton = null;
                        prevVisibleId = -1;
                    }
                    addToOverflowMenu(i, button, menu);
                }
            } else if (visibility == BUTTON_HIDDEN){
                button.setVisibility(View.GONE);
            }
        }

        mOverflowButton.setVisibility(menu != null ? View.VISIBLE : View.GONE);
        if (menu != null) {
            mOverflowPopup = menu;
            mOverflowPopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                        case R.id.overflow_merge_menu_item:
                            getPresenter().mergeClicked();
                            break;
                        case R.id.overflow_add_menu_item:
                            getPresenter().addCallClicked();
                            break;
                        case R.id.overflow_hold_menu_item:
                            getPresenter().holdClicked(true /* checked */);
                            break;
                        case R.id.overflow_resume_menu_item:
                            getPresenter().holdClicked(false /* checked */);
                            break;
                        case R.id.overflow_swap_menu_item:
                            getPresenter().addCallClicked();
                            break;
                        case R.id.overflow_manage_conference_menu_item:
                            onManageVideoCallConferenceClicked();
                            break;
                        default:
                            Log.wtf(this, "onMenuItemClick: unexpected overflow menu click");
                            break;
                    }
                    final int id = item.getItemId();
                    getButtonById(id).performClick();
                    return true;
                }
            });
            mOverflowPopup.setOnDismissListener(new OnDismissListener() {
                @Override
                public void onDismiss(PopupMenu popupMenu) {
                    popupMenu.dismiss();
        }
            });
        }

        final Menu menu = mOverflowPopup.getMenu();
        menu.findItem(R.id.overflow_merge_menu_item).setVisible(showMergeMenuOption);
        menu.findItem(R.id.overflow_add_menu_item).setVisible(showAddMenuOption);
        menu.findItem(R.id.overflow_hold_menu_item).setVisible(
                showHoldMenuOption && !mHoldButton.isSelected());
        menu.findItem(R.id.overflow_resume_menu_item).setVisible(
                showHoldMenuOption && mHoldButton.isSelected());
        menu.findItem(R.id.overflow_swap_menu_item).setVisible(showSwapMenuOption);
        menu.findItem(R.id.overflow_manage_conference_menu_item).setVisible(
            showManageConferenceVideoCallOption);

        mOverflowButton.setEnabled(menu.hasVisibleItems());
    }

    @Override
+40 −126

File changed.

Preview size limit exceeded, changes collapsed.