Allow quick scrub/switch from minus one
Launcher's window doesn't have focus when on minus one. In this case, we tell the minus one overlay to hide and add a window focused callback to start quick scrub/switch after launcher regains focus. Since the transition from minus one takes longer than for launcher to get window focus, we also defer until the overlay is completely hidden before starting the quick scrub transition. Bug: 70180755 Change-Id: Ifcf85aaf1942b51394e68e209b89807fa4007afe
This commit is contained in:
1 parent
aefd062125
commit
618a5044cf
2 files changed
+71
-5
No files matched your search
@@ -52,6 +52,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.launcher3.Launcher.LauncherOverlay;
|
||||
@@ -235,6 +236,7 @@ public class Workspace extends PagedView
|
||||
boolean mStartedSendingScrollEvents;
|
||||
float mLastOverlayScroll = 0;
|
||||
boolean mOverlayShown = false;
|
||||
private Runnable mOnOverlayHiddenCallback;
|
||||
|
||||
private boolean mForceDrawAdjacentPages = false;
|
||||
private boolean mPageRearrangeEnabled = false;
|
||||
@@ -1163,6 +1165,10 @@ public class Workspace extends PagedView
|
||||
if (mOverlayShown) {
|
||||
mLauncher.getUserEventDispatcher().logActionOnContainer(Action.Touch.SWIPE,
|
||||
Action.Direction.RIGHT, ContainerType.WORKSPACE, -1);
|
||||
if (mOnOverlayHiddenCallback != null) {
|
||||
mOnOverlayHiddenCallback.run();
|
||||
mOnOverlayHiddenCallback = null;
|
||||
}
|
||||
}
|
||||
mOverlayShown = false;
|
||||
}
|
||||
@@ -1188,6 +1194,59 @@ public class Workspace extends PagedView
|
||||
mLauncher.getDragLayer().setAlpha(alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the given callback when the minus one overlay is hidden. Specifically, it is run
|
||||
* when launcher's window has focus and the overlay is no longer being shown. If a callback
|
||||
* is already present, the new callback will chain off it so both are run.
|
||||
*
|
||||
* @return Whether the callback was deferred.
|
||||
*/
|
||||
public boolean runOnOverlayHidden(Runnable callback) {
|
||||
View rootView = getRootView();
|
||||
if (rootView.hasWindowFocus()) {
|
||||
if (mOverlayShown) {
|
||||
chainOverlayHiddenCallback(callback);
|
||||
return true;
|
||||
} else {
|
||||
callback.run();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ViewTreeObserver observer = rootView.getViewTreeObserver();
|
||||
if (observer != null && observer.isAlive()) {
|
||||
observer.addOnWindowFocusChangeListener(
|
||||
new ViewTreeObserver.OnWindowFocusChangeListener() {
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
if (hasFocus) {
|
||||
// Defer further if the minus one overlay is still showing.
|
||||
if (mOverlayShown) {
|
||||
chainOverlayHiddenCallback(callback);
|
||||
} else {
|
||||
callback.run();
|
||||
}
|
||||
observer.removeOnWindowFocusChangeListener(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void chainOverlayHiddenCallback(Runnable callback) {
|
||||
if (mOnOverlayHiddenCallback == null) {
|
||||
mOnOverlayHiddenCallback = callback;
|
||||
} else {
|
||||
// Chain the new callback onto the previous callback(s).
|
||||
Runnable oldCallback = mOnOverlayHiddenCallback;
|
||||
mOnOverlayHiddenCallback = () -> {
|
||||
oldCallback.run();
|
||||
callback.run();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyPageSwitchListener(int prevPage) {
|
||||
super.notifyPageSwitchListener(prevPage);
|
||||
|
||||
Reference in new issue
Block a user