From 995553c35986f22637abe4d86f47bb5ba6b7bd06 Mon Sep 17 00:00:00 2001 From: Josh Tsuji Date: Wed, 26 May 2021 11:33:48 -0400 Subject: [PATCH] Fix the live caption tooltip, which was sad and broken. - Position it correctly using getLocationOnScreen since the dialog height is now variable. - Update colors so it's readable in dark mode. - Make it touchable so it can be dismissed without dismissing the entire volume dialog. Fixes: 184624161 Test: commented out setting tooltip seen so I could experiment with it Change-Id: I44ba0f9a5488edf88a63ff4842e9abc27e1ce408 --- .../res/layout-land/volume_dialog.xml | 3 +- .../SystemUI/res/layout/volume_dialog.xml | 3 +- .../res/layout/volume_tool_tip_view.xml | 5 +- .../res/values-land-television/dimens.xml | 1 + packages/SystemUI/res/values-land/dimens.xml | 1 - .../systemui/volume/VolumeDialogImpl.java | 102 +++++++++++------- 6 files changed, 70 insertions(+), 45 deletions(-) diff --git a/packages/SystemUI/res/layout-land/volume_dialog.xml b/packages/SystemUI/res/layout-land/volume_dialog.xml index 7a03172c69dbb..f1cda277f0451 100644 --- a/packages/SystemUI/res/layout-land/volume_dialog.xml +++ b/packages/SystemUI/res/layout-land/volume_dialog.xml @@ -147,6 +147,7 @@ android:layout="@layout/volume_tool_tip_view" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="bottom | right"/> + android:layout_gravity="bottom | right" + android:layout_marginRight="@dimen/volume_tool_tip_right_margin"/> \ No newline at end of file diff --git a/packages/SystemUI/res/layout/volume_dialog.xml b/packages/SystemUI/res/layout/volume_dialog.xml index 6aaa54afd1586..51718d9af0543 100644 --- a/packages/SystemUI/res/layout/volume_dialog.xml +++ b/packages/SystemUI/res/layout/volume_dialog.xml @@ -147,7 +147,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom | right" - android:layout_marginRight="@dimen/volume_tool_tip_right_margin" - android:layout_marginBottom="@dimen/volume_tool_tip_bottom_margin"/> + android:layout_marginRight="@dimen/volume_tool_tip_right_margin"/> \ No newline at end of file diff --git a/packages/SystemUI/res/layout/volume_tool_tip_view.xml b/packages/SystemUI/res/layout/volume_tool_tip_view.xml index 9fe885ebefc72..ee24969487524 100644 --- a/packages/SystemUI/res/layout/volume_tool_tip_view.xml +++ b/packages/SystemUI/res/layout/volume_tool_tip_view.xml @@ -17,6 +17,7 @@ diff --git a/packages/SystemUI/res/values-land-television/dimens.xml b/packages/SystemUI/res/values-land-television/dimens.xml index 220ed5cce83e0..a9bc9e5cd6389 100644 --- a/packages/SystemUI/res/values-land-television/dimens.xml +++ b/packages/SystemUI/res/values-land-television/dimens.xml @@ -23,6 +23,7 @@ 4dp @dimen/volume_dialog_slider_width 100dp + 136dp 36dp 6dp diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml index 215698dd1884a..9df9db607b9fc 100644 --- a/packages/SystemUI/res/values-land/dimens.xml +++ b/packages/SystemUI/res/values-land/dimens.xml @@ -43,7 +43,6 @@ 14dp - 136dp 12dp 128dp diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java index 50b885815e099..961822a598e72 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java @@ -337,37 +337,44 @@ public class VolumeDialogImpl implements VolumeDialog, mTouchableRegion.setEmpty(); - // Set the touchable region to the union of all child view bounds. We don't use touches on - // the volume dialog container itself, so this is fine. + // Set the touchable region to the union of all child view bounds and the live caption + // tooltip. We don't use touches on the volume dialog container itself, so this is fine. for (int i = 0; i < mDialogView.getChildCount(); i++) { - final View view = mDialogView.getChildAt(i); - final int[] locInWindow = new int[2]; - view.getLocationInWindow(locInWindow); + unionViewBoundstoTouchableRegion(mDialogView.getChildAt(i)); + } - float x = locInWindow[0]; - float y = locInWindow[1]; - - // The ringer and rows container has extra height at the top to fit the expanded ringer - // drawer. This area should not be touchable unless the ringer drawer is open. - if (view == mTopContainer && !mIsRingerDrawerOpen) { - if (!isLandscape()) { - y += getRingerDrawerOpenExtraSize(); - } else { - x += getRingerDrawerOpenExtraSize(); - } - } - - mTouchableRegion.op( - (int) x, - (int) y, - locInWindow[0] + view.getWidth(), - locInWindow[1] + view.getHeight(), - Region.Op.UNION); + if (mODICaptionsTooltipView != null && mODICaptionsTooltipView.getVisibility() == VISIBLE) { + unionViewBoundstoTouchableRegion(mODICaptionsTooltipView); } internalInsetsInfo.touchableRegion.set(mTouchableRegion); } + private void unionViewBoundstoTouchableRegion(final View view) { + final int[] locInWindow = new int[2]; + view.getLocationInWindow(locInWindow); + + float x = locInWindow[0]; + float y = locInWindow[1]; + + // The ringer and rows container has extra height at the top to fit the expanded ringer + // drawer. This area should not be touchable unless the ringer drawer is open. + if (view == mTopContainer && !mIsRingerDrawerOpen) { + if (!isLandscape()) { + y += getRingerDrawerOpenExtraSize(); + } else { + x += getRingerDrawerOpenExtraSize(); + } + } + + mTouchableRegion.op( + (int) x, + (int) y, + locInWindow[0] + view.getWidth(), + locInWindow[1] + view.getHeight(), + Region.Op.UNION); + } + private void initDialog() { mDialog = new CustomDialog(mContext); @@ -1058,21 +1065,38 @@ public class VolumeDialogImpl implements VolumeDialog, } if (mODICaptionsTooltipView != null) { - mODICaptionsTooltipView.setAlpha(0.f); - mODICaptionsTooltipView.animate() - .alpha(1.f) - .setStartDelay(mDialogShowAnimationDurationMs) - .withEndAction(() -> { - if (D.BUG) Log.d(TAG, "tool:checkODICaptionsTooltip() putBoolean true"); - Prefs.putBoolean(mContext, - Prefs.Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP, true); - mHasSeenODICaptionsTooltip = true; - if (mODICaptionsIcon != null) { - mODICaptionsIcon - .postOnAnimation(getSinglePressFor(mODICaptionsIcon)); - } - }) - .start(); + mODICaptionsTooltipView.setAlpha(0.0f); + + // We need to wait for layout and then center the caption view. Since the height of the + // dialog is now dynamic (with the variable ringer drawer height changing the height of + // the dialog), we need to do this here in code vs. in XML. + mHandler.post(() -> { + final int[] odiTooltipLocation = mODICaptionsTooltipView.getLocationOnScreen(); + final int[] odiButtonLocation = mODICaptionsIcon.getLocationOnScreen(); + + final float heightDiffForCentering = + (mODICaptionsTooltipView.getHeight() - mODICaptionsIcon.getHeight()) / 2f; + + mODICaptionsTooltipView.setTranslationY( + odiButtonLocation[1] - odiTooltipLocation[1] - heightDiffForCentering); + + mODICaptionsTooltipView.animate() + .alpha(1.0f) + .setStartDelay(mDialogShowAnimationDurationMs) + .withEndAction(() -> { + if (D.BUG) { + Log.d(TAG, "tool:checkODICaptionsTooltip() putBoolean true"); + } + Prefs.putBoolean(mContext, + Prefs.Key.HAS_SEEN_ODI_CAPTIONS_TOOLTIP, true); + mHasSeenODICaptionsTooltip = true; + if (mODICaptionsIcon != null) { + mODICaptionsIcon + .postOnAnimation(getSinglePressFor(mODICaptionsIcon)); + } + }) + .start(); + }); } }