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
diff --git a/packages/SystemUI/res/layout-land/volume_dialog.xml b/packages/SystemUI/res/layout-land/volume_dialog.xml
index 7a03172..f1cda27 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"/>
</FrameLayout>
\ 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 6aaa54a..51718d9 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"/>
</FrameLayout>
\ 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 9fe885e..ee24969 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 @@
<com.android.systemui.volume.VolumeToolTipView
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:id="@+id/tooltip_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
@@ -35,7 +36,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
- android:textColor="@android:color/white"
+ android:textColor="?android:attr/textColorPrimaryInverse"
android:text="@string/volume_odi_captions_tip"
android:textSize="14sp"/>
<ImageView
@@ -48,7 +49,7 @@
android:layout_marginEnd="2dp"
android:alpha="0.7"
android:src="@drawable/ic_remove_no_shadow"
- android:tint="@android:color/white"
+ android:tint="?android:attr/textColorPrimaryInverse"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/accessibility_volume_close_odi_captions_tip"/>
</LinearLayout>
diff --git a/packages/SystemUI/res/values-land-television/dimens.xml b/packages/SystemUI/res/values-land-television/dimens.xml
index 220ed5c..a9bc9e5 100644
--- a/packages/SystemUI/res/values-land-television/dimens.xml
+++ b/packages/SystemUI/res/values-land-television/dimens.xml
@@ -23,6 +23,7 @@
<dimen name="volume_dialog_slider_width">4dp</dimen>
<dimen name="volume_dialog_slider_corner_radius">@dimen/volume_dialog_slider_width</dimen>
<dimen name="volume_dialog_background_blur_radius">100dp</dimen>
+ <dimen name="volume_tool_tip_right_margin">136dp</dimen>
<dimen name="tv_volume_dialog_bubble_size">36dp</dimen>
<dimen name="tv_volume_dialog_row_padding">6dp</dimen>
diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml
index 215698d..9df9db6 100644
--- a/packages/SystemUI/res/values-land/dimens.xml
+++ b/packages/SystemUI/res/values-land/dimens.xml
@@ -43,7 +43,6 @@
<dimen name="qs_detail_margin_top">14dp</dimen>
- <dimen name="volume_tool_tip_right_margin">136dp</dimen>
<dimen name="volume_tool_tip_top_margin">12dp</dimen>
<dimen name="volume_row_slider_height">128dp</dimen>
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
index 50b8858..961822a5 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 @@
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 @@
}
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();
+ });
}
}