diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java index 26e80adafd3d27604e5018a0645db8c2416cedc6..bf53a2f113e9b73dc6f9546badc237bca67fe007 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java @@ -59,6 +59,7 @@ import android.content.res.Configuration; import android.database.ContentObserver; import android.graphics.PixelFormat; import android.graphics.Rect; +import android.graphics.RectF; import android.hardware.display.DisplayManager; import android.inputmethodservice.InputMethodService; import android.net.Uri; @@ -83,6 +84,7 @@ import android.view.MotionEvent; import android.view.Surface; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.view.WindowInsetsController.Appearance; import android.view.WindowManager; import android.view.WindowManager.LayoutParams; @@ -217,11 +219,12 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback * original handle hidden and we'll flip the visibilities once the * {@link #mTasksFrozenListener} fires */ - private NavigationHandle mOrientationHandle; + private VerticalNavigationHandle mOrientationHandle; private WindowManager.LayoutParams mOrientationParams; private int mStartingQuickSwitchRotation; private int mCurrentRotation; private boolean mFixedRotationEnabled; + private ViewTreeObserver.OnGlobalLayoutListener mOrientationHandleGlobalLayoutListener; /** Only for default display */ @Nullable @@ -519,6 +522,8 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback getContext().getSystemService(DisplayManager.class).unregisterDisplayListener(this); getBarTransitions().removeDarkIntensityListener(mOrientationHandleIntensityListener); mWindowManager.removeView(mOrientationHandle); + mOrientationHandle.getViewTreeObserver().removeOnGlobalLayoutListener( + mOrientationHandleGlobalLayoutListener); } } @@ -573,6 +578,20 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback PixelFormat.TRANSLUCENT); mWindowManager.addView(mOrientationHandle, mOrientationParams); mOrientationHandle.setVisibility(View.GONE); + mOrientationHandleGlobalLayoutListener = + () -> { + if (mStartingQuickSwitchRotation == -1) { + return; + } + + RectF boundsOnScreen = mOrientationHandle.computeHomeHandleBounds(); + mOrientationHandle.mapRectFromViewToScreenCoords(boundsOnScreen, true); + Rect boundsRounded = new Rect(); + boundsOnScreen.roundOut(boundsRounded); + mNavigationBarView.setOrientedHandleSamplingRegion(boundsRounded); + }; + mOrientationHandle.getViewTreeObserver().addOnGlobalLayoutListener( + mOrientationHandleGlobalLayoutListener); } private void orientSecondaryHomeHandle() { @@ -621,6 +640,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback } if (mNavigationBarView != null) { mNavigationBarView.setVisibility(View.VISIBLE); + mNavigationBarView.setOrientedHandleSamplingRegion(null); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java index 6b37ac317cddc48f4b37f1433e9565a565fc584a..4821d8c46ed442c98378d3ffe580bb24ae574fd0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -35,6 +35,7 @@ import android.animation.PropertyValuesHolder; import android.animation.TimeInterpolator; import android.animation.ValueAnimator; import android.annotation.DrawableRes; +import android.annotation.Nullable; import android.app.StatusBarManager; import android.content.Context; import android.content.res.Configuration; @@ -158,6 +159,14 @@ public class NavigationBarView extends FrameLayout implements */ private ScreenPinningNotify mScreenPinningNotify; private Rect mSamplingBounds = new Rect(); + /** + * When quickswitching between apps of different orientations, we draw a secondary home handle + * in the position of the first app's orientation. This rect represents the region of that + * home handle so we can apply the correct light/dark luma on that. + * @see {@link NavigationBarFragment#mOrientationHandle} + */ + @Nullable + private Rect mOrientedHandleSamplingRegion; private class NavTransitionListener implements TransitionListener { private boolean mBackTransitioning; @@ -327,6 +336,10 @@ public class NavigationBarView extends FrameLayout implements @Override public Rect getSampledRegion(View sampledView) { + if (mOrientedHandleSamplingRegion != null) { + return mOrientedHandleSamplingRegion; + } + updateSamplingRect(); return mSamplingBounds; } @@ -897,6 +910,11 @@ public class NavigationBarView extends FrameLayout implements } } + void setOrientedHandleSamplingRegion(Rect orientedHandleSamplingRegion) { + mOrientedHandleSamplingRegion = orientedHandleSamplingRegion; + mRegionSamplingHelper.updateSamplingRect(); + } + @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); @@ -1190,6 +1208,8 @@ public class NavigationBarView extends FrameLayout implements mIsVertical ? "true" : "false", getLightTransitionsController().getCurrentDarkIntensity())); + pw.println(" mOrientedHandleSamplingRegion: " + mOrientedHandleSamplingRegion); + dumpButton(pw, "back", getBackButton()); dumpButton(pw, "home", getHomeButton()); dumpButton(pw, "rcnt", getRecentsButton()); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/VerticalNavigationHandle.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/VerticalNavigationHandle.java index a15ca9532a88ec95f530a38885094cda3e73dd04..0cdf1d32d6a0ac08219f22db0162ab5f80503d5e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/VerticalNavigationHandle.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/VerticalNavigationHandle.java @@ -18,12 +18,14 @@ package com.android.systemui.statusbar.phone; import android.content.Context; import android.graphics.Canvas; +import android.graphics.RectF; import com.android.systemui.R; /** Temporarily shown view when using QuickSwitch to switch between apps of different rotations */ public class VerticalNavigationHandle extends NavigationHandle { private final int mWidth; + private final RectF mTmpBoundsRectF = new RectF(); public VerticalNavigationHandle(Context context) { super(context); @@ -32,16 +34,21 @@ public class VerticalNavigationHandle extends NavigationHandle { @Override protected void onDraw(Canvas canvas) { + canvas.drawRoundRect(computeHomeHandleBounds(), mRadius, mRadius, mPaint); + } + + RectF computeHomeHandleBounds() { int left; int top; int bottom; int right; - + int topStart = getLocationOnScreen()[1]; int radiusOffset = mRadius * 2; right = getWidth() - mBottom; - top = getHeight() / 2 - (mWidth / 2); /* (height of screen / 2) - (height of bar / 2) */ + top = getHeight() / 2 - (mWidth / 2) - (topStart / 2); left = getWidth() - mBottom - radiusOffset; - bottom = getHeight() / 2 + (mWidth / 2); - canvas.drawRoundRect(left, top, right, bottom, mRadius, mRadius, mPaint); + bottom = top + mWidth; + mTmpBoundsRectF.set(left, top, right, bottom); + return mTmpBoundsRectF; } }