From 3e64e959ea6cf13c27b8ba3b583d25f0f9bb9ea8 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 6 Aug 2020 10:33:03 -0700 Subject: [PATCH] Also factor the floating rotation button into the active touch region - The floating rotation button sits in the gesture region and touches over the button should not start the recents animation. Add a visibility callback to the floating rotation button in addition to the existing contextual button listener and update when needed. Bug: 162775448 Bug: 161921293 Test: Repeatedly rotate with floating button Test: atest SystemUITests:NavigationBarRotationContextTest Change-Id: I798370b41041e4f02bb82f5aeb20b9ccc1d2a4e8 --- .../phone/FloatingRotationButton.java | 21 ++++++++++++++ .../phone/NavigationBarFragment.java | 12 +------- .../statusbar/phone/NavigationBarView.java | 28 +++++++++++++++++-- .../statusbar/phone/RotationButton.java | 3 ++ .../phone/RotationButtonController.java | 4 ++- .../phone/RotationContextButton.java | 14 ++++++++++ .../NavigationBarRotationContextTest.java | 2 +- 7 files changed, 69 insertions(+), 15 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/FloatingRotationButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/FloatingRotationButton.java index 687f5f15a78cb..8a85f7d6a2c5f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/FloatingRotationButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/FloatingRotationButton.java @@ -30,6 +30,8 @@ import com.android.systemui.R; import com.android.systemui.statusbar.policy.KeyButtonDrawable; import com.android.systemui.statusbar.policy.KeyButtonView; +import java.util.function.Consumer; + /** Containing logic for the rotation button on the physical left bottom corner of the screen. */ public class FloatingRotationButton implements RotationButton { @@ -45,6 +47,7 @@ public class FloatingRotationButton implements RotationButton { private boolean mCanShow = true; private RotationButtonController mRotationButtonController; + private Consumer mVisibilityChangedCallback; FloatingRotationButton(Context context) { mContext = context; @@ -66,6 +69,11 @@ public class FloatingRotationButton implements RotationButton { mRotationButtonController.getDarkIconColor()); } + @Override + public void setVisibilityChangedCallback(Consumer visibilityChangedCallback) { + mVisibilityChangedCallback = visibilityChangedCallback; + } + @Override public View getCurrentView() { return mKeyButtonView; @@ -105,6 +113,16 @@ public class FloatingRotationButton implements RotationButton { mKeyButtonDrawable.resetAnimation(); mKeyButtonDrawable.startAnimation(); } + mKeyButtonView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + @Override + public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, + int i6, int i7) { + if (mIsShowing && mVisibilityChangedCallback != null) { + mVisibilityChangedCallback.accept(true); + } + mKeyButtonView.removeOnLayoutChangeListener(this); + } + }); return true; } @@ -115,6 +133,9 @@ public class FloatingRotationButton implements RotationButton { } mWindowManager.removeViewImmediate(mKeyButtonView); mIsShowing = false; + if (mVisibilityChangedCallback != null) { + mVisibilityChangedCallback.accept(false); + } return true; } 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 6297052550c31..5c466bfef9a40 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java @@ -351,15 +351,6 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback } }; - private final ContextButtonListener mRotationButtonListener = (button, visible) -> { - if (visible) { - // If the button will actually become visible and the navbar is about to hide, - // tell the statusbar to keep it around for longer - mAutoHideController.touchAutoHide(); - mNavigationBarView.notifyActiveTouchRegions(); - } - }; - private final Runnable mAutoDim = () -> getBarTransitions().setAutoDim(true); private final ContentObserver mAssistContentObserver = new ContentObserver( @@ -507,8 +498,6 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback // Currently there is no accelerometer sensor on non-default display. if (mIsOnDefaultDisplay) { - mNavigationBarView.getRotateSuggestionButton().setListener(mRotationButtonListener); - final RotationButtonController rotationButtonController = mNavigationBarView.getRotationButtonController(); rotationButtonController.addRotationCallback(mRotationWatcher); @@ -1312,6 +1301,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback if (mAutoHideController != null) { mAutoHideController.setNavigationBar(mAutoHideUiElement); } + mNavigationBarView.setAutoHideController(autoHideController); } private boolean isTransientShown() { 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 84512ac85fa97..6475c985cea2e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -131,6 +131,7 @@ public class NavigationBarView extends FrameLayout implements private boolean mDeadZoneConsuming = false; private final NavigationBarTransitions mBarTransitions; private final OverviewProxyService mOverviewProxyService; + private AutoHideController mAutoHideController; // performs manual animation in sync with layout transitions private final NavTransitionListener mTransitionListener = new NavTransitionListener(); @@ -276,6 +277,15 @@ public class NavigationBarView extends FrameLayout implements info.touchableRegion.setEmpty(); }; + private final Consumer mRotationButtonListener = (visible) -> { + if (visible) { + // If the button will actually become visible and the navbar is about to hide, + // tell the statusbar to keep it around for longer + mAutoHideController.touchAutoHide(); + } + notifyActiveTouchRegions(); + }; + public NavigationBarView(Context context, AttributeSet attrs) { super(context, attrs); @@ -312,7 +322,8 @@ public class NavigationBarView extends FrameLayout implements mFloatingRotationButton = new FloatingRotationButton(context); mRotationButtonController = new RotationButtonController(mLightContext, mLightIconColor, mDarkIconColor, - isGesturalMode ? mFloatingRotationButton : rotateSuggestionButton); + isGesturalMode ? mFloatingRotationButton : rotateSuggestionButton, + mRotationButtonListener); mConfiguration = new Configuration(); mTmpLastConfiguration = new Configuration(); @@ -360,6 +371,10 @@ public class NavigationBarView extends FrameLayout implements }); } + public void setAutoHideController(AutoHideController autoHideController) { + mAutoHideController = autoHideController; + } + public NavigationBarTransitions getBarTransitions() { return mBarTransitions; } @@ -938,7 +953,15 @@ public class NavigationBarView extends FrameLayout implements updateButtonLocation(getBackButton()); updateButtonLocation(getHomeButton()); updateButtonLocation(getRecentsButton()); - updateButtonLocation(getRotateSuggestionButton()); + updateButtonLocation(getImeSwitchButton()); + updateButtonLocation(getAccessibilityButton()); + if (mFloatingRotationButton.isVisible()) { + View floatingRotationView = mFloatingRotationButton.getCurrentView(); + floatingRotationView.getBoundsOnScreen(mTmpBounds); + mActiveRegion.op(mTmpBounds, Op.UNION); + } else { + updateButtonLocation(getRotateSuggestionButton()); + } mOverviewProxyService.onActiveNavBarRegionChanges(mActiveRegion); } @@ -1210,6 +1233,7 @@ public class NavigationBarView extends FrameLayout implements dumpButton(pw, "rcnt", getRecentsButton()); dumpButton(pw, "rota", getRotateSuggestionButton()); dumpButton(pw, "a11y", getAccessibilityButton()); + dumpButton(pw, "ime", getImeSwitchButton()); pw.println(" }"); pw.println(" mScreenOn: " + mScreenOn); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButton.java index 687efd34ee30b..74d4eb175ac49 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButton.java @@ -20,9 +20,12 @@ import android.view.View; import com.android.systemui.statusbar.policy.KeyButtonDrawable; +import java.util.function.Consumer; + /** Interface of a rotation button that interacts {@link RotationButtonController}. */ interface RotationButton { void setRotationButtonController(RotationButtonController rotationButtonController); + void setVisibilityChangedCallback(Consumer visibilityChangedCallback); View getCurrentView(); boolean show(); boolean hide(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java index f83cdd488c041..9309d044fc254 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java @@ -124,7 +124,8 @@ public class RotationButtonController { } RotationButtonController(Context context, @ColorInt int lightIconColor, - @ColorInt int darkIconColor, RotationButton rotationButton) { + @ColorInt int darkIconColor, RotationButton rotationButton, + Consumer visibilityChangedCallback) { mContext = context; mLightIconColor = lightIconColor; mDarkIconColor = darkIconColor; @@ -139,6 +140,7 @@ public class RotationButtonController { mTaskStackListener = new TaskStackListenerImpl(); mRotationButton.setOnClickListener(this::onRotateSuggestionClick); mRotationButton.setOnHoverListener(this::onRotateSuggestionHover); + mRotationButton.setVisibilityChangedCallback(visibilityChangedCallback); } void registerListeners() { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationContextButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationContextButton.java index d7e95e43ea8f7..b7900ba0a4d24 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationContextButton.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationContextButton.java @@ -22,6 +22,8 @@ import android.view.View; import com.android.systemui.statusbar.policy.KeyButtonDrawable; +import java.util.function.Consumer; + /** Containing logic for the rotation button in nav bar. */ public class RotationContextButton extends ContextualButton implements RotationButton { public static final boolean DEBUG_ROTATION = false; @@ -37,6 +39,18 @@ public class RotationContextButton extends ContextualButton implements RotationB mRotationButtonController = rotationButtonController; } + @Override + public void setVisibilityChangedCallback(Consumer visibilityChangedCallback) { + setListener(new ContextButtonListener() { + @Override + public void onVisibilityChanged(ContextualButton button, boolean visible) { + if (visibilityChangedCallback != null) { + visibilityChangedCallback.accept(visible); + } + } + }); + } + @Override public void setVisibility(int visibility) { super.setVisibility(visibility); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarRotationContextTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarRotationContextTest.java index f21235c12cde5..f665241142929 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarRotationContextTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarRotationContextTest.java @@ -60,7 +60,7 @@ public class NavigationBarRotationContextTest extends SysuiTestCase { final View view = new View(mContext); mRotationButton = mock(RotationButton.class); mRotationButtonController = spy(new RotationButtonController(mContext, 0, 0, - mRotationButton)); + mRotationButton, (visibility) -> {})); final KeyButtonDrawable kbd = mock(KeyButtonDrawable.class); doReturn(view).when(mRotationButton).getCurrentView(); doReturn(true).when(mRotationButton).acceptRotationProposal();