Merge "Fixing the menu overlap with the system bars under half oval type." into sc-dev

This commit is contained in:
PETER LIANG
2021-06-24 00:27:21 +00:00
committed by Android (Google) Code Review

View File

@@ -16,6 +16,7 @@
package com.android.systemui.accessibility.floatingmenu; package com.android.systemui.accessibility.floatingmenu;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.util.MathUtils.constrain; import static android.util.MathUtils.constrain;
import static android.util.MathUtils.sq; import static android.util.MathUtils.sq;
import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.ime;
@@ -200,6 +201,7 @@ public class AccessibilityFloatingMenuView extends FrameLayout
mListView = listView; mListView = listView;
mWindowManager = context.getSystemService(WindowManager.class); mWindowManager = context.getSystemService(WindowManager.class);
mLastConfiguration = new Configuration(getResources().getConfiguration());
mAdapter = new AccessibilityTargetAdapter(mTargets); mAdapter = new AccessibilityTargetAdapter(mTargets);
mUiHandler = createUiHandler(); mUiHandler = createUiHandler();
mPosition = position; mPosition = position;
@@ -243,7 +245,6 @@ public class AccessibilityFloatingMenuView extends FrameLayout
} }
}); });
mLastConfiguration = new Configuration(getResources().getConfiguration());
initListView(); initListView();
updateStrokeWith(getResources().getConfiguration().uiMode, mAlignment); updateStrokeWith(getResources().getConfiguration().uiMode, mAlignment);
@@ -567,8 +568,10 @@ public class AccessibilityFloatingMenuView extends FrameLayout
final int currentX = (int) event.getX(); final int currentX = (int) event.getX();
final int currentY = (int) event.getY(); final int currentY = (int) event.getY();
final int marginStartEnd = getMarginStartEndWith(mLastConfiguration);
final Rect touchDelegateBounds = final Rect touchDelegateBounds =
new Rect(mMargin, mMargin, mMargin + getLayoutWidth(), mMargin + getLayoutHeight()); new Rect(marginStartEnd, mMargin, marginStartEnd + getLayoutWidth(),
mMargin + getLayoutHeight());
if (action == MotionEvent.ACTION_DOWN if (action == MotionEvent.ACTION_DOWN
&& touchDelegateBounds.contains(currentX, currentY)) { && touchDelegateBounds.contains(currentX, currentY)) {
mIsDownInEnlargedTouchArea = true; mIsDownInEnlargedTouchArea = true;
@@ -682,15 +685,13 @@ public class AccessibilityFloatingMenuView extends FrameLayout
mListView.setLayoutManager(layoutManager); mListView.setLayoutManager(layoutManager);
mListView.addOnItemTouchListener(this); mListView.addOnItemTouchListener(this);
mListView.animate().setInterpolator(new OvershootInterpolator()); mListView.animate().setInterpolator(new OvershootInterpolator());
updateListView(); updateListViewWith(mLastConfiguration);
addView(mListView); addView(mListView);
} }
private void updateListView() { private void updateListViewWith(Configuration configuration) {
final LayoutParams layoutParams = (FrameLayout.LayoutParams) mListView.getLayoutParams(); updateMarginWith(configuration);
layoutParams.setMargins(mMargin, mMargin, mMargin, mMargin);
mListView.setLayoutParams(layoutParams);
final int elevation = final int elevation =
getResources().getDimensionPixelSize(R.dimen.accessibility_floating_menu_elevation); getResources().getDimensionPixelSize(R.dimen.accessibility_floating_menu_elevation);
@@ -719,13 +720,15 @@ public class AccessibilityFloatingMenuView extends FrameLayout
@Override @Override
protected void onConfigurationChanged(Configuration newConfig) { protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
mLastConfiguration.setTo(newConfig);
final int diff = newConfig.diff(mLastConfiguration); final int diff = newConfig.diff(mLastConfiguration);
if ((diff & ActivityInfo.CONFIG_LOCALE) != 0) { if ((diff & ActivityInfo.CONFIG_LOCALE) != 0) {
updateAccessibilityTitle(mCurrentLayoutParams); updateAccessibilityTitle(mCurrentLayoutParams);
} }
updateDimensions(); updateDimensions();
updateListView(); updateListViewWith(newConfig);
updateItemViewWith(mSizeType); updateItemViewWith(mSizeType);
updateColor(); updateColor();
updateStrokeWith(newConfig.uiMode, mAlignment); updateStrokeWith(newConfig.uiMode, mAlignment);
@@ -733,8 +736,6 @@ public class AccessibilityFloatingMenuView extends FrameLayout
updateRadiusWith(mSizeType, mRadiusType, mTargets.size()); updateRadiusWith(mSizeType, mRadiusType, mTargets.size());
updateScrollModeWith(hasExceededMaxLayoutHeight()); updateScrollModeWith(hasExceededMaxLayoutHeight());
setSystemGestureExclusion(); setSystemGestureExclusion();
mLastConfiguration.setTo(newConfig);
} }
@VisibleForTesting @VisibleForTesting
@@ -756,11 +757,11 @@ public class AccessibilityFloatingMenuView extends FrameLayout
} }
private int getMinWindowX() { private int getMinWindowX() {
return -mMargin; return -getMarginStartEndWith(mLastConfiguration);
} }
private int getMaxWindowX() { private int getMaxWindowX() {
return mScreenWidth - mMargin - getLayoutWidth(); return mScreenWidth - getMarginStartEndWith(mLastConfiguration) - getLayoutWidth();
} }
private int getMaxWindowY() { private int getMaxWindowY() {
@@ -805,6 +806,15 @@ public class AccessibilityFloatingMenuView extends FrameLayout
return layoutBottomY > imeY ? (layoutBottomY - imeY) : 0; return layoutBottomY > imeY ? (layoutBottomY - imeY) : 0;
} }
private void updateMarginWith(Configuration configuration) {
// Avoid overlapping with system bars under landscape mode, update the margins of the menu
// to align the edge of system bars.
final int marginStartEnd = getMarginStartEndWith(configuration);
final LayoutParams layoutParams = (FrameLayout.LayoutParams) mListView.getLayoutParams();
layoutParams.setMargins(marginStartEnd, mMargin, marginStartEnd, mMargin);
mListView.setLayoutParams(layoutParams);
}
private void updateOffsetWith(@ShapeType int shapeType, @Alignment int side) { private void updateOffsetWith(@ShapeType int shapeType, @Alignment int side) {
final float halfWidth = getLayoutWidth() / 2.0f; final float halfWidth = getLayoutWidth() / 2.0f;
final float offset = (shapeType == ShapeType.OVAL) ? 0 : halfWidth; final float offset = (shapeType == ShapeType.OVAL) ? 0 : halfWidth;
@@ -896,6 +906,12 @@ public class AccessibilityFloatingMenuView extends FrameLayout
return (mPadding + mIconHeight) * mTargets.size() + mPadding; return (mPadding + mIconHeight) * mTargets.size() + mPadding;
} }
private int getMarginStartEndWith(Configuration configuration) {
return configuration != null
&& configuration.orientation == ORIENTATION_PORTRAIT
? mMargin : 0;
}
private @DimenRes int getRadiusResId(@SizeType int sizeType, int itemCount) { private @DimenRes int getRadiusResId(@SizeType int sizeType, int itemCount) {
return sizeType == SizeType.SMALL return sizeType == SizeType.SMALL
? getSmallSizeResIdWith(itemCount) ? getSmallSizeResIdWith(itemCount)
@@ -932,7 +948,7 @@ public class AccessibilityFloatingMenuView extends FrameLayout
} }
private int getWindowWidth() { private int getWindowWidth() {
return mMargin * 2 + getLayoutWidth(); return getMarginStartEndWith(mLastConfiguration) * 2 + getLayoutWidth();
} }
private int getWindowHeight() { private int getWindowHeight() {