From b8d0f5029ebaf8e3a0bd32c8b54b3baee6f2876a Mon Sep 17 00:00:00 2001 From: wangqi Date: Wed, 14 Mar 2018 12:12:32 -0700 Subject: Add swap call button to RTT call. Bug: 67596257 Test: manual PiperOrigin-RevId: 189064976 Change-Id: I3265881114baceb4d63fcc3d55d1c904cd3216dc --- .../android/incallui/rtt/impl/RttChatFragment.java | 50 +++++++- .../android/incallui/rtt/impl/RttOverflowMenu.java | 38 ++++++- .../incallui/rtt/impl/res/layout/frag_rtt_chat.xml | 6 +- .../incallui/rtt/impl/res/layout/overflow_menu.xml | 6 + .../incallui/rtt/impl/res/layout/rtt_banner.xml | 126 +++++++++++---------- .../android/incallui/rtt/impl/res/values/ids.xml | 19 ++++ 6 files changed, 174 insertions(+), 71 deletions(-) create mode 100644 java/com/android/incallui/rtt/impl/res/values/ids.xml (limited to 'java/com/android/incallui/rtt') diff --git a/java/com/android/incallui/rtt/impl/RttChatFragment.java b/java/com/android/incallui/rtt/impl/RttChatFragment.java index 3b943c431..c6eef9ca2 100644 --- a/java/com/android/incallui/rtt/impl/RttChatFragment.java +++ b/java/com/android/incallui/rtt/impl/RttChatFragment.java @@ -17,11 +17,13 @@ package com.android.incallui.rtt.impl; import android.app.Activity; +import android.content.Context; import android.os.Bundle; import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.OnScrollListener; @@ -49,6 +51,8 @@ import com.android.dialer.common.UiUtil; import com.android.incallui.audioroute.AudioRouteSelectorDialogFragment; import com.android.incallui.audioroute.AudioRouteSelectorDialogFragment.AudioRouteSelectorPresenter; import com.android.incallui.call.DialerCall.State; +import com.android.incallui.hold.OnHoldFragment; +import com.android.incallui.incall.protocol.InCallButtonIds; import com.android.incallui.incall.protocol.InCallButtonUi; import com.android.incallui.incall.protocol.InCallButtonUiDelegate; import com.android.incallui.incall.protocol.InCallButtonUiDelegateFactory; @@ -99,6 +103,7 @@ public class RttChatFragment extends Fragment private Chronometer chronometer; private boolean isTimerStarted; private RttOverflowMenu overflowMenu; + private SecondaryInfo savedSecondaryInfo; /** * Create a new instance of RttChatFragment. @@ -124,6 +129,9 @@ public class RttChatFragment extends Fragment if (savedInstanceState != null) { inCallButtonUiDelegate.onRestoreInstanceState(savedInstanceState); } + inCallScreenDelegate = + FragmentUtils.getParentUnsafe(this, InCallScreenDelegateFactory.class) + .newInCallScreenDelegate(); // Prevent updating local message until UI is ready. isClearingInput = true; } @@ -133,9 +141,6 @@ public class RttChatFragment extends Fragment super.onViewCreated(view, bundle); LogUtil.i("RttChatFragment.onViewCreated", null); - inCallScreenDelegate = - FragmentUtils.getParentUnsafe(this, InCallScreenDelegateFactory.class) - .newInCallScreenDelegate(); rttCallScreenDelegate = FragmentUtils.getParentUnsafe(this, RttCallScreenDelegateFactory.class) .newRttCallScreenDelegate(this); @@ -185,7 +190,7 @@ public class RttChatFragment extends Fragment inCallButtonUiDelegate.onEndCallClicked(); }); - overflowMenu = new RttOverflowMenu(getContext(), inCallButtonUiDelegate); + overflowMenu = new RttOverflowMenu(getContext(), inCallButtonUiDelegate, inCallScreenDelegate); view.findViewById(R.id.rtt_overflow_button) .setOnClickListener( v -> { @@ -311,7 +316,36 @@ public class RttChatFragment extends Fragment } @Override - public void setSecondary(@NonNull SecondaryInfo secondaryInfo) {} + public void onAttach(Context context) { + super.onAttach(context); + if (savedSecondaryInfo != null) { + setSecondary(savedSecondaryInfo); + } + } + + @Override + public void setSecondary(@NonNull SecondaryInfo secondaryInfo) { + LogUtil.i("RttChatFragment.setSecondary", secondaryInfo.toString()); + if (!isAdded()) { + savedSecondaryInfo = secondaryInfo; + return; + } + savedSecondaryInfo = null; + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + Fragment oldBanner = getChildFragmentManager().findFragmentById(R.id.rtt_on_hold_banner); + if (secondaryInfo.shouldShow()) { + OnHoldFragment onHoldFragment = OnHoldFragment.newInstance(secondaryInfo); + onHoldFragment.setPadTopInset(false); + transaction.replace(R.id.rtt_on_hold_banner, onHoldFragment); + } else { + if (oldBanner != null) { + transaction.remove(oldBanner); + } + } + transaction.setCustomAnimations(R.anim.abc_slide_in_top, R.anim.abc_slide_out_top); + transaction.commitNowAllowingStateLoss(); + overflowMenu.enableSwitchToSecondaryButton(secondaryInfo.shouldShow()); + } @Override public void setCallState(@NonNull PrimaryCallState primaryCallState) { @@ -372,7 +406,11 @@ public class RttChatFragment extends Fragment } @Override - public void showButton(int buttonId, boolean show) {} + public void showButton(int buttonId, boolean show) { + if (buttonId == InCallButtonIds.BUTTON_SWAP) { + overflowMenu.enableSwapCallButton(show); + } + } @Override public void enableButton(int buttonId, boolean enable) {} diff --git a/java/com/android/incallui/rtt/impl/RttOverflowMenu.java b/java/com/android/incallui/rtt/impl/RttOverflowMenu.java index cca36318e..2a061c546 100644 --- a/java/com/android/incallui/rtt/impl/RttOverflowMenu.java +++ b/java/com/android/incallui/rtt/impl/RttOverflowMenu.java @@ -21,6 +21,7 @@ import android.telecom.CallAudioState; import android.view.View; import android.widget.PopupWindow; import com.android.incallui.incall.protocol.InCallButtonUiDelegate; +import com.android.incallui.incall.protocol.InCallScreenDelegate; import com.android.incallui.rtt.impl.RttCheckableButton.OnCheckedChangeListener; import com.android.incallui.speakerbuttonlogic.SpeakerButtonInfo; import com.android.incallui.speakerbuttonlogic.SpeakerButtonInfo.IconSize; @@ -32,11 +33,19 @@ public class RttOverflowMenu extends PopupWindow implements OnCheckedChangeListe private final RttCheckableButton speakerButton; private final RttCheckableButton dialpadButton; private final RttCheckableButton addCallButton; + private final RttCheckableButton swapCallButton; private final InCallButtonUiDelegate inCallButtonUiDelegate; + private final InCallScreenDelegate inCallScreenDelegate; + private boolean isSwitchToSecondaryButtonEnabled; + private boolean isSwapCallButtonEnabled; - RttOverflowMenu(Context context, InCallButtonUiDelegate inCallButtonUiDelegate) { + RttOverflowMenu( + Context context, + InCallButtonUiDelegate inCallButtonUiDelegate, + InCallScreenDelegate inCallScreenDelegate) { super(context); this.inCallButtonUiDelegate = inCallButtonUiDelegate; + this.inCallScreenDelegate = inCallScreenDelegate; View view = View.inflate(context, R.layout.overflow_menu, null); setContentView(view); setOnDismissListener(this::dismiss); @@ -49,7 +58,18 @@ public class RttOverflowMenu extends PopupWindow implements OnCheckedChangeListe dialpadButton = view.findViewById(R.id.menu_keypad); dialpadButton.setOnCheckedChangeListener(this); addCallButton = view.findViewById(R.id.menu_add_call); - addCallButton.setOnCheckedChangeListener(this); + addCallButton.setOnClickListener(v -> this.inCallButtonUiDelegate.addCallClicked()); + swapCallButton = view.findViewById(R.id.menu_swap_call); + swapCallButton.setOnClickListener( + v -> { + if (isSwapCallButtonEnabled) { + this.inCallButtonUiDelegate.swapClicked(); + } + if (isSwitchToSecondaryButtonEnabled) { + this.inCallScreenDelegate.onSecondaryInfoClicked(); + } + dismiss(); + }); } @Override @@ -60,8 +80,6 @@ public class RttOverflowMenu extends PopupWindow implements OnCheckedChangeListe inCallButtonUiDelegate.toggleSpeakerphone(); } else if (button == dialpadButton) { inCallButtonUiDelegate.showDialpadClicked(isChecked); - } else if (button == addCallButton) { - inCallButtonUiDelegate.addCallClicked(); } dismiss(); } @@ -91,4 +109,16 @@ public class RttOverflowMenu extends PopupWindow implements OnCheckedChangeListe void setDialpadButtonChecked(boolean isChecked) { dialpadButton.setChecked(isChecked); } + + void enableSwapCallButton(boolean enabled) { + isSwapCallButtonEnabled = enabled; + swapCallButton.setVisibility( + isSwapCallButtonEnabled || isSwitchToSecondaryButtonEnabled ? View.VISIBLE : View.GONE); + } + + void enableSwitchToSecondaryButton(boolean enabled) { + isSwitchToSecondaryButtonEnabled = enabled; + swapCallButton.setVisibility( + isSwapCallButtonEnabled || isSwitchToSecondaryButtonEnabled ? View.VISIBLE : View.GONE); + } } diff --git a/java/com/android/incallui/rtt/impl/res/layout/frag_rtt_chat.xml b/java/com/android/incallui/rtt/impl/res/layout/frag_rtt_chat.xml index 6940569a3..753117904 100644 --- a/java/com/android/incallui/rtt/impl/res/layout/frag_rtt_chat.xml +++ b/java/com/android/incallui/rtt/impl/res/layout/frag_rtt_chat.xml @@ -19,8 +19,6 @@ android:layout_height="match_parent" android:fitsSystemWindows="true"> - - + + - \ No newline at end of file + diff --git a/java/com/android/incallui/rtt/impl/res/layout/overflow_menu.xml b/java/com/android/incallui/rtt/impl/res/layout/overflow_menu.xml index a29fad5f1..eb7e38691 100644 --- a/java/com/android/incallui/rtt/impl/res/layout/overflow_menu.xml +++ b/java/com/android/incallui/rtt/impl/res/layout/overflow_menu.xml @@ -46,4 +46,10 @@ style="@style/RttButton" android:drawableStart="@drawable/quantum_ic_add_call_vd_theme_24" android:text="@string/incall_label_add_call"/> + \ No newline at end of file diff --git a/java/com/android/incallui/rtt/impl/res/layout/rtt_banner.xml b/java/com/android/incallui/rtt/impl/res/layout/rtt_banner.xml index f1938056f..c4d3a4290 100644 --- a/java/com/android/incallui/rtt/impl/res/layout/rtt_banner.xml +++ b/java/com/android/incallui/rtt/impl/res/layout/rtt_banner.xml @@ -14,64 +14,74 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License --> - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical"> + + + + + + + - \ No newline at end of file + + + + \ No newline at end of file diff --git a/java/com/android/incallui/rtt/impl/res/values/ids.xml b/java/com/android/incallui/rtt/impl/res/values/ids.xml new file mode 100644 index 000000000..3e4755b7c --- /dev/null +++ b/java/com/android/incallui/rtt/impl/res/values/ids.xml @@ -0,0 +1,19 @@ + + + + + -- cgit v1.2.3