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
This commit is contained in:
Josh Tsuji
2021-05-26 11:33:48 -04:00
parent 09f82e22fd
commit 995553c359
6 changed files with 70 additions and 45 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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();
});
}
}