From ca3168bd9ec99668e02087f35833a4807f439c1e Mon Sep 17 00:00:00 2001 From: Matthew Ng Date: Wed, 24 May 2017 16:40:31 -0700 Subject: [PATCH] Unminimize to save divider position after rotation Holds the divider ratio in the divider state to persist after configuration change while minimized. After unminimizing past a configuration change, the previous position will estimate to the closest snap target. Test: manual - minimize, rotate, unminimize Fixes: 34395958 Change-Id: I6ceffb9f5018b8009069f0aa0085f263d8982319 --- .../systemui/stackdivider/Divider.java | 2 +- .../systemui/stackdivider/DividerState.java | 1 + .../systemui/stackdivider/DividerView.java | 36 ++++++++++--------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java index 0b09accf2db14..f750815d663f7 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java @@ -79,6 +79,7 @@ public class Divider extends SystemUI { private void addDivider(Configuration configuration) { mView = (DividerView) LayoutInflater.from(mContext).inflate(R.layout.docked_stack_divider, null); + mView.injectDependencies(mWindowManager, mDividerState); mView.setVisibility(mVisible ? View.VISIBLE : View.INVISIBLE); mView.setMinimizedDockStack(mMinimized, mHomeStackResizable); final int size = mContext.getResources().getDimensionPixelSize( @@ -87,7 +88,6 @@ public class Divider extends SystemUI { final int width = landscape ? size : MATCH_PARENT; final int height = landscape ? MATCH_PARENT : size; mWindowManager.add(mView, width, height); - mView.injectDependencies(mWindowManager, mDividerState); } private void removeDivider() { diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerState.java b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerState.java index 353a9749eb259..3a5c61e6d7f0c 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerState.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerState.java @@ -22,4 +22,5 @@ package com.android.systemui.stackdivider; public class DividerState { public boolean animateAfterRecentsDrawn; public boolean growAfterRecentsDrawn; + public float mRatioPositionBeforeMinimized; } diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java index 9e2ec571faa8b..2bda1dfb5f88d 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java @@ -364,6 +364,17 @@ public class DividerView extends FrameLayout implements OnTouchListener, public void injectDependencies(DividerWindowManager windowManager, DividerState dividerState) { mWindowManager = windowManager; mState = dividerState; + + // Set the previous position ratio before minimized state after attaching this divider + if (mStableInsets.isEmpty()) { + SystemServicesProxy.getInstance(mContext).getStableInsets(mStableInsets); + } + int position = (int) (mState.mRatioPositionBeforeMinimized * + (isHorizontalDivision() ? mDisplayHeight : mDisplayWidth)); + mSnapAlgorithm = null; + initializeSnapAlgorithm(); + mDividerPositionBeforeMinimized = mSnapAlgorithm.calculateNonDismissingSnapTarget(position) + .position; } public WindowManagerProxy getWindowManagerProxy() { @@ -719,19 +730,12 @@ public class DividerView extends FrameLayout implements OnTouchListener, mHandle.setAlpha(minimized ? 0f : 1f); mDockedStackMinimized = minimized; } else if (mDockedStackMinimized != minimized) { - if (mStableInsets.isEmpty()) { - SystemServicesProxy.getInstance(mContext).getStableInsets(mStableInsets); - } mMinimizedSnapAlgorithm = null; mDockedStackMinimized = minimized; initializeSnapAlgorithm(); if (mIsInMinimizeInteraction != minimized) { if (minimized) { mIsInMinimizeInteraction = true; - mDividerPositionBeforeMinimized = DockedDividerUtils.calculateMiddlePosition( - isHorizontalDivision(), mStableInsets, mDisplayWidth, mDisplayHeight, - mDividerSize); - int position = mMinimizedSnapAlgorithm.getMiddleTarget().position; resizeStack(position, position, mMinimizedSnapAlgorithm.getMiddleTarget()); } else { @@ -776,7 +780,7 @@ public class DividerView extends FrameLayout implements OnTouchListener, mIsInMinimizeInteraction = true; if (minimized && (mCurrentAnimator == null || !mCurrentAnimator.isRunning()) && (mDividerPositionBeforeMinimized <= 0 || !mAdjustedForIme)) { - mDividerPositionBeforeMinimized = getCurrentPosition(); + savePositionBeforeMinimized(); } mMinimizedSnapAlgorithm = null; mDockedStackMinimized = minimized; @@ -836,10 +840,16 @@ public class DividerView extends FrameLayout implements OnTouchListener, // Only get new position if home stack is resizable, ime is open and not minimized // (including the animation) if (mHomeStackResizable && adjustedForIme && !mIsInMinimizeInteraction) { - mDividerPositionBeforeMinimized = getCurrentPosition(); + savePositionBeforeMinimized(); } } + private void savePositionBeforeMinimized() { + mDividerPositionBeforeMinimized = getCurrentPosition(); + mState.mRatioPositionBeforeMinimized = (float) mDividerPositionBeforeMinimized / + (isHorizontalDivision() ? mDisplayHeight : mDisplayWidth); + } + private void resetBackground() { mBackground.setPivotX(mBackground.getWidth() / 2); mBackground.setPivotY(mBackground.getHeight() / 2); @@ -1198,14 +1208,6 @@ public class DividerView extends FrameLayout implements OnTouchListener, mDockSide, mDividerSize); mEntranceAnimationRunning = true; - // Insets might not have been fetched yet, so fetch manually if needed. - if (mStableInsets.isEmpty()) { - SystemServicesProxy.getInstance(mContext).getStableInsets(mStableInsets); - mSnapAlgorithm = null; - mMinimizedSnapAlgorithm = null; - initializeSnapAlgorithm(); - } - resizeStack(position, mSnapAlgorithm.getMiddleTarget().position, mSnapAlgorithm.getMiddleTarget()); }