Merge "Fix a couple of rotation bugs" into qt-dev

This commit is contained in:
Tracy Zhou
2019-06-19 17:43:47 +00:00
committed by Android (Google) Code Review
5 changed files with 43 additions and 56 deletions

View File

@@ -115,7 +115,6 @@ public class FloatingRotationButton implements RotationButton {
return false; return false;
} }
mWindowManager.removeViewImmediate(mKeyButtonView); mWindowManager.removeViewImmediate(mKeyButtonView);
mRotationButtonController.cleanUp();
mIsShowing = false; mIsShowing = false;
return true; return true;
} }
@@ -141,10 +140,7 @@ public class FloatingRotationButton implements RotationButton {
@Override @Override
public void setOnClickListener(View.OnClickListener onClickListener) { public void setOnClickListener(View.OnClickListener onClickListener) {
mKeyButtonView.setOnClickListener(view -> { mKeyButtonView.setOnClickListener(onClickListener);
hide();
onClickListener.onClick(view);
});
} }
@Override @Override

View File

@@ -871,9 +871,6 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
boolean[] feedbackEnabled = new boolean[1]; boolean[] feedbackEnabled = new boolean[1];
int a11yFlags = getA11yButtonState(feedbackEnabled); int a11yFlags = getA11yButtonState(feedbackEnabled);
mNavigationBarView.getRotationButtonController().setAccessibilityFeedbackEnabled(
feedbackEnabled[0]);
boolean clickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0; boolean clickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0;
boolean longClickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0; boolean longClickable = (a11yFlags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0;
mNavigationBarView.setAccessibilityButtonState(clickable, longClickable); mNavigationBarView.setAccessibilityButtonState(clickable, longClickable);

View File

@@ -1040,6 +1040,9 @@ public class NavigationBarView extends FrameLayout implements
reorient(); reorient();
onNavigationModeChanged(mNavBarMode); onNavigationModeChanged(mNavBarMode);
setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled()); setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled());
if (mRotationButtonController != null) {
mRotationButtonController.registerListeners();
}
mEdgeBackGestureHandler.onNavBarAttached(); mEdgeBackGestureHandler.onNavBarAttached();
getViewTreeObserver().addOnComputeInternalInsetsListener(mOnComputeInternalInsetsListener); getViewTreeObserver().addOnComputeInternalInsetsListener(mOnComputeInternalInsetsListener);
@@ -1053,6 +1056,10 @@ public class NavigationBarView extends FrameLayout implements
for (int i = 0; i < mButtonDispatchers.size(); ++i) { for (int i = 0; i < mButtonDispatchers.size(); ++i) {
mButtonDispatchers.valueAt(i).onDestroy(); mButtonDispatchers.valueAt(i).onDestroy();
} }
if (mRotationButtonController != null) {
mRotationButtonController.unregisterListeners();
}
mEdgeBackGestureHandler.onNavBarDetached(); mEdgeBackGestureHandler.onNavBarDetached();
getViewTreeObserver().removeOnComputeInternalInsetsListener( getViewTreeObserver().removeOnComputeInternalInsetsListener(
mOnComputeInternalInsetsListener); mOnComputeInternalInsetsListener);

View File

@@ -26,7 +26,7 @@ import android.app.StatusBarManager;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Looper;
import android.os.RemoteException; import android.os.RemoteException;
import android.provider.Settings; import android.provider.Settings;
import android.view.IRotationWatcher.Stub; import android.view.IRotationWatcher.Stub;
@@ -34,6 +34,7 @@ import android.view.MotionEvent;
import android.view.Surface; import android.view.Surface;
import android.view.View; import android.view.View;
import android.view.WindowManagerGlobal; import android.view.WindowManagerGlobal;
import android.view.accessibility.AccessibilityManager;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -42,6 +43,7 @@ import com.android.systemui.Interpolators;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.TaskStackChangeListener; import com.android.systemui.shared.system.TaskStackChangeListener;
import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
import com.android.systemui.statusbar.policy.KeyButtonDrawable; import com.android.systemui.statusbar.policy.KeyButtonDrawable;
import com.android.systemui.statusbar.policy.RotationLockController; import com.android.systemui.statusbar.policy.RotationLockController;
@@ -64,8 +66,10 @@ public class RotationButtonController {
private boolean mPendingRotationSuggestion; private boolean mPendingRotationSuggestion;
private boolean mHoveringRotationSuggestion; private boolean mHoveringRotationSuggestion;
private RotationLockController mRotationLockController; private RotationLockController mRotationLockController;
private AccessibilityManagerWrapper mAccessibilityManagerWrapper;
private TaskStackListenerImpl mTaskStackListener; private TaskStackListenerImpl mTaskStackListener;
private Consumer<Integer> mRotWatcherListener; private Consumer<Integer> mRotWatcherListener;
private boolean mListenersRegistered = false;
private boolean mIsNavigationBarShowing; private boolean mIsNavigationBarShowing;
private final Runnable mRemoveRotationProposal = private final Runnable mRemoveRotationProposal =
@@ -73,22 +77,17 @@ public class RotationButtonController {
private final Runnable mCancelPendingRotationProposal = private final Runnable mCancelPendingRotationProposal =
() -> mPendingRotationSuggestion = false; () -> mPendingRotationSuggestion = false;
private Animator mRotateHideAnimator; private Animator mRotateHideAnimator;
private boolean mAccessibilityFeedbackEnabled;
private final Context mContext; private final Context mContext;
private final RotationButton mRotationButton; private final RotationButton mRotationButton;
private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());
private final Stub mRotationWatcher = new Stub() { private final Stub mRotationWatcher = new Stub() {
@Override @Override
public void onRotationChanged(final int rotation) throws RemoteException { public void onRotationChanged(final int rotation) throws RemoteException {
if (mRotationButton.getCurrentView() == null) {
return;
}
// We need this to be scheduled as early as possible to beat the redrawing of // We need this to be scheduled as early as possible to beat the redrawing of
// window in response to the orientation change. // window in response to the orientation change.
Handler h = mRotationButton.getCurrentView().getHandler(); mMainThreadHandler.postAtFrontOfQueue(() -> {
Message msg = Message.obtain(h, () -> {
// If the screen rotation changes while locked, potentially update lock to flow with // If the screen rotation changes while locked, potentially update lock to flow with
// new screen rotation and hide any showing suggestions. // new screen rotation and hide any showing suggestions.
if (mRotationLockController.isRotationLocked()) { if (mRotationLockController.isRotationLocked()) {
@@ -102,8 +101,6 @@ public class RotationButtonController {
mRotWatcherListener.accept(rotation); mRotWatcherListener.accept(rotation);
} }
}); });
msg.setAsynchronous(true);
h.sendMessageAtFrontOfQueue(msg);
} }
}; };
@@ -124,40 +121,49 @@ public class RotationButtonController {
mStyleRes = style; mStyleRes = style;
mIsNavigationBarShowing = true; mIsNavigationBarShowing = true;
mRotationLockController = Dependency.get(RotationLockController.class); mRotationLockController = Dependency.get(RotationLockController.class);
mAccessibilityManagerWrapper = Dependency.get(AccessibilityManagerWrapper.class);
// Register the task stack listener // Register the task stack listener
mTaskStackListener = new TaskStackListenerImpl(); mTaskStackListener = new TaskStackListenerImpl();
ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
mRotationButton.setOnClickListener(this::onRotateSuggestionClick); mRotationButton.setOnClickListener(this::onRotateSuggestionClick);
mRotationButton.setOnHoverListener(this::onRotateSuggestionHover); mRotationButton.setOnHoverListener(this::onRotateSuggestionHover);
}
void registerListeners() {
if (mListenersRegistered) {
return;
}
mListenersRegistered = true;
try { try {
WindowManagerGlobal.getWindowManagerService() WindowManagerGlobal.getWindowManagerService()
.watchRotation(mRotationWatcher, mContext.getDisplay().getDisplayId()); .watchRotation(mRotationWatcher, mContext.getDisplay().getDisplayId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
} }
void cleanUp() { void unregisterListeners() {
// Unregister the task stack listener if (!mListenersRegistered) {
ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener); return;
}
mListenersRegistered = false;
try { try {
WindowManagerGlobal.getWindowManagerService().removeRotationWatcher(mRotationWatcher); WindowManagerGlobal.getWindowManagerService().removeRotationWatcher(mRotationWatcher);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener);
} }
void addRotationCallback(Consumer<Integer> watcher) { void addRotationCallback(Consumer<Integer> watcher) {
mRotWatcherListener = watcher; mRotWatcherListener = watcher;
} }
void setAccessibilityFeedbackEnabled(boolean flag) {
mAccessibilityFeedbackEnabled = flag;
}
void setRotationLockedAtAngle(int rotationSuggestion) { void setRotationLockedAtAngle(int rotationSuggestion) {
mRotationLockController.setRotationLockedAtAngle(true /* locked */, rotationSuggestion); mRotationLockController.setRotationLockedAtAngle(true /* locked */, rotationSuggestion);
} }
@@ -185,7 +191,7 @@ public class RotationButtonController {
// Clear any pending suggestion flag as it has either been nullified or is being shown // Clear any pending suggestion flag as it has either been nullified or is being shown
mPendingRotationSuggestion = false; mPendingRotationSuggestion = false;
view.removeCallbacks(mCancelPendingRotationProposal); mMainThreadHandler.removeCallbacks(mCancelPendingRotationProposal);
// Handle the visibility change and animation // Handle the visibility change and animation
if (visible) { // Appear and change (cannot force) if (visible) { // Appear and change (cannot force)
@@ -255,13 +261,9 @@ public class RotationButtonController {
return; return;
} }
final View currentView = mRotationButton.getCurrentView();
// If window rotation matches suggested rotation, remove any current suggestions // If window rotation matches suggested rotation, remove any current suggestions
if (rotation == windowRotation) { if (rotation == windowRotation) {
if (currentView != null) { mMainThreadHandler.removeCallbacks(mRemoveRotationProposal);
currentView.removeCallbacks(mRemoveRotationProposal);
}
setRotateSuggestionButtonState(false /* visible */); setRotateSuggestionButtonState(false /* visible */);
return; return;
} }
@@ -285,13 +287,11 @@ public class RotationButtonController {
// If the navbar isn't shown, flag the rotate icon to be shown should the navbar become // If the navbar isn't shown, flag the rotate icon to be shown should the navbar become
// visible given some time limit. // visible given some time limit.
mPendingRotationSuggestion = true; mPendingRotationSuggestion = true;
if (currentView != null) { mMainThreadHandler.removeCallbacks(mCancelPendingRotationProposal);
currentView.removeCallbacks(mCancelPendingRotationProposal); mMainThreadHandler.postDelayed(mCancelPendingRotationProposal,
currentView.postDelayed(mCancelPendingRotationProposal,
NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS); NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS);
} }
} }
}
void onDisable2FlagChanged(int state2) { void onDisable2FlagChanged(int state2) {
final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(state2); final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(state2);
@@ -334,9 +334,7 @@ public class RotationButtonController {
private void onRotationSuggestionsDisabled() { private void onRotationSuggestionsDisabled() {
// Immediately hide the rotate button and clear any planned removal // Immediately hide the rotate button and clear any planned removal
setRotateSuggestionButtonState(false /* visible */, true /* force */); setRotateSuggestionButtonState(false /* visible */, true /* force */);
if (mRotationButton.getCurrentView() != null) { mMainThreadHandler.removeCallbacks(mRemoveRotationProposal);
mRotationButton.getCurrentView().removeCallbacks(mRemoveRotationProposal);
}
} }
private void showAndLogRotationSuggestion() { private void showAndLogRotationSuggestion() {
@@ -369,10 +367,6 @@ public class RotationButtonController {
} }
private void rescheduleRotationTimeout(final boolean reasonHover) { private void rescheduleRotationTimeout(final boolean reasonHover) {
if (mRotationButton.getCurrentView() == null) {
return;
}
// May be called due to a new rotation proposal or a change in hover state // May be called due to a new rotation proposal or a change in hover state
if (reasonHover) { if (reasonHover) {
// Don't reschedule if a hide animator is running // Don't reschedule if a hide animator is running
@@ -382,16 +376,16 @@ public class RotationButtonController {
} }
// Stop any pending removal // Stop any pending removal
mRotationButton.getCurrentView().removeCallbacks(mRemoveRotationProposal); mMainThreadHandler.removeCallbacks(mRemoveRotationProposal);
// Schedule timeout // Schedule timeout
mRotationButton.getCurrentView().postDelayed(mRemoveRotationProposal, mMainThreadHandler.postDelayed(mRemoveRotationProposal,
computeRotationProposalTimeout()); computeRotationProposalTimeout());
} }
private int computeRotationProposalTimeout() { private int computeRotationProposalTimeout() {
if (mAccessibilityFeedbackEnabled) return 10000; return mAccessibilityManagerWrapper.getRecommendedTimeoutMillis(
if (mHoveringRotationSuggestion) return 8000; mHoveringRotationSuggestion ? 16000 : 5000,
return 5000; AccessibilityManager.FLAG_CONTENT_CONTROLS);
} }
private boolean isRotateSuggestionIntroduced() { private boolean isRotateSuggestionIntroduced() {

View File

@@ -63,13 +63,6 @@ public class RotationContextButton extends ContextualButton implements
null /* ovalBackgroundColor */); null /* ovalBackgroundColor */);
} }
@Override
public void onDestroy() {
if (mRotationButtonController != null) {
mRotationButtonController.cleanUp();
}
}
@Override @Override
public void onNavigationModeChanged(int mode) { public void onNavigationModeChanged(int mode) {
mNavBarMode = mode; mNavBarMode = mode;