Merge "Do not show PipMenuActivity during expansion" into rvc-dev am: e63217a7b9
Change-Id: I6203214a70082f32da61ade82c977b0fb0c69f4a
This commit is contained in:
@@ -27,7 +27,7 @@ import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_ALL
|
|||||||
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_CONTROLLER_MESSENGER;
|
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_CONTROLLER_MESSENGER;
|
||||||
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_DISMISS_FRACTION;
|
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_DISMISS_FRACTION;
|
||||||
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_MENU_STATE;
|
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_MENU_STATE;
|
||||||
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_MOVEMENT_BOUNDS;
|
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_SHOW_MENU_WITH_DELAY;
|
||||||
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_STACK_BOUNDS;
|
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_STACK_BOUNDS;
|
||||||
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_WILL_RESIZE_MENU;
|
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_WILL_RESIZE_MENU;
|
||||||
import static com.android.systemui.pip.phone.PipMenuActivityController.MENU_STATE_CLOSE;
|
import static com.android.systemui.pip.phone.PipMenuActivityController.MENU_STATE_CLOSE;
|
||||||
@@ -138,9 +138,9 @@ public class PipMenuActivity extends Activity {
|
|||||||
final Bundle data = (Bundle) msg.obj;
|
final Bundle data = (Bundle) msg.obj;
|
||||||
showMenu(data.getInt(EXTRA_MENU_STATE),
|
showMenu(data.getInt(EXTRA_MENU_STATE),
|
||||||
data.getParcelable(EXTRA_STACK_BOUNDS),
|
data.getParcelable(EXTRA_STACK_BOUNDS),
|
||||||
data.getParcelable(EXTRA_MOVEMENT_BOUNDS),
|
|
||||||
data.getBoolean(EXTRA_ALLOW_TIMEOUT),
|
data.getBoolean(EXTRA_ALLOW_TIMEOUT),
|
||||||
data.getBoolean(EXTRA_WILL_RESIZE_MENU));
|
data.getBoolean(EXTRA_WILL_RESIZE_MENU),
|
||||||
|
data.getBoolean(EXTRA_SHOW_MENU_WITH_DELAY));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_POKE_MENU:
|
case MESSAGE_POKE_MENU:
|
||||||
@@ -177,12 +177,7 @@ public class PipMenuActivity extends Activity {
|
|||||||
private Messenger mToControllerMessenger;
|
private Messenger mToControllerMessenger;
|
||||||
private Messenger mMessenger = new Messenger(mHandler);
|
private Messenger mMessenger = new Messenger(mHandler);
|
||||||
|
|
||||||
private final Runnable mFinishRunnable = new Runnable() {
|
private final Runnable mFinishRunnable = this::hideMenu;
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
hideMenu();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@@ -321,8 +316,8 @@ public class PipMenuActivity extends Activity {
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showMenu(int menuState, Rect stackBounds, Rect movementBounds,
|
private void showMenu(int menuState, Rect stackBounds, boolean allowMenuTimeout,
|
||||||
boolean allowMenuTimeout, boolean resizeMenuOnShow) {
|
boolean resizeMenuOnShow, boolean withDelay) {
|
||||||
mAllowMenuTimeout = allowMenuTimeout;
|
mAllowMenuTimeout = allowMenuTimeout;
|
||||||
if (mMenuState != menuState) {
|
if (mMenuState != menuState) {
|
||||||
// Disallow touches if the menu needs to resize while showing, and we are transitioning
|
// Disallow touches if the menu needs to resize while showing, and we are transitioning
|
||||||
@@ -335,7 +330,6 @@ public class PipMenuActivity extends Activity {
|
|||||||
if (mMenuContainerAnimator != null) {
|
if (mMenuContainerAnimator != null) {
|
||||||
mMenuContainerAnimator.cancel();
|
mMenuContainerAnimator.cancel();
|
||||||
}
|
}
|
||||||
notifyMenuStateChange(menuState, resizeMenuOnShow);
|
|
||||||
mMenuContainerAnimator = new AnimatorSet();
|
mMenuContainerAnimator = new AnimatorSet();
|
||||||
ObjectAnimator menuAnim = ObjectAnimator.ofFloat(mMenuContainer, View.ALPHA,
|
ObjectAnimator menuAnim = ObjectAnimator.ofFloat(mMenuContainer, View.ALPHA,
|
||||||
mMenuContainer.getAlpha(), 1f);
|
mMenuContainer.getAlpha(), 1f);
|
||||||
@@ -359,7 +353,13 @@ public class PipMenuActivity extends Activity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
mMenuContainerAnimator.start();
|
if (withDelay) {
|
||||||
|
// starts the menu container animation after window expansion is completed
|
||||||
|
notifyMenuStateChange(menuState, resizeMenuOnShow, mMenuContainerAnimator::start);
|
||||||
|
} else {
|
||||||
|
notifyMenuStateChange(menuState, resizeMenuOnShow, null /* callback */);
|
||||||
|
mMenuContainerAnimator.start();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// If we are already visible, then just start the delayed dismiss and unregister any
|
// If we are already visible, then just start the delayed dismiss and unregister any
|
||||||
// existing input consumers from the previous drag
|
// existing input consumers from the previous drag
|
||||||
@@ -382,7 +382,7 @@ public class PipMenuActivity extends Activity {
|
|||||||
if (mMenuState != MENU_STATE_NONE) {
|
if (mMenuState != MENU_STATE_NONE) {
|
||||||
cancelDelayedFinish();
|
cancelDelayedFinish();
|
||||||
if (notifyMenuVisibility) {
|
if (notifyMenuVisibility) {
|
||||||
notifyMenuStateChange(MENU_STATE_NONE, mResize);
|
notifyMenuStateChange(MENU_STATE_NONE, mResize, null /* callback */);
|
||||||
}
|
}
|
||||||
mMenuContainerAnimator = new AnimatorSet();
|
mMenuContainerAnimator = new AnimatorSet();
|
||||||
ObjectAnimator menuAnim = ObjectAnimator.ofFloat(mMenuContainer, View.ALPHA,
|
ObjectAnimator menuAnim = ObjectAnimator.ofFloat(mMenuContainer, View.ALPHA,
|
||||||
@@ -434,10 +434,10 @@ public class PipMenuActivity extends Activity {
|
|||||||
final int menuState = intent.getIntExtra(EXTRA_MENU_STATE, MENU_STATE_NONE);
|
final int menuState = intent.getIntExtra(EXTRA_MENU_STATE, MENU_STATE_NONE);
|
||||||
if (menuState != MENU_STATE_NONE) {
|
if (menuState != MENU_STATE_NONE) {
|
||||||
Rect stackBounds = intent.getParcelableExtra(EXTRA_STACK_BOUNDS);
|
Rect stackBounds = intent.getParcelableExtra(EXTRA_STACK_BOUNDS);
|
||||||
Rect movementBounds = intent.getParcelableExtra(EXTRA_MOVEMENT_BOUNDS);
|
|
||||||
boolean allowMenuTimeout = intent.getBooleanExtra(EXTRA_ALLOW_TIMEOUT, true);
|
boolean allowMenuTimeout = intent.getBooleanExtra(EXTRA_ALLOW_TIMEOUT, true);
|
||||||
boolean willResizeMenu = intent.getBooleanExtra(EXTRA_WILL_RESIZE_MENU, false);
|
boolean willResizeMenu = intent.getBooleanExtra(EXTRA_WILL_RESIZE_MENU, false);
|
||||||
showMenu(menuState, stackBounds, movementBounds, allowMenuTimeout, willResizeMenu);
|
boolean withDelay = intent.getBooleanExtra(EXTRA_SHOW_MENU_WITH_DELAY, false);
|
||||||
|
showMenu(menuState, stackBounds, allowMenuTimeout, willResizeMenu, withDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,13 +540,14 @@ public class PipMenuActivity extends Activity {
|
|||||||
mBackgroundDrawable.setAlpha(alpha);
|
mBackgroundDrawable.setAlpha(alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyMenuStateChange(int menuState, boolean resize) {
|
private void notifyMenuStateChange(int menuState, boolean resize, Runnable callback) {
|
||||||
mMenuState = menuState;
|
mMenuState = menuState;
|
||||||
mResize = resize;
|
mResize = resize;
|
||||||
Message m = Message.obtain();
|
Message m = Message.obtain();
|
||||||
m.what = PipMenuActivityController.MESSAGE_MENU_STATE_CHANGED;
|
m.what = PipMenuActivityController.MESSAGE_MENU_STATE_CHANGED;
|
||||||
m.arg1 = menuState;
|
m.arg1 = menuState;
|
||||||
m.arg2 = resize ? 1 : 0;
|
m.arg2 = resize ? 1 : 0;
|
||||||
|
m.obj = callback;
|
||||||
sendMessage(m, "Could not notify controller of PIP menu visibility");
|
sendMessage(m, "Could not notify controller of PIP menu visibility");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ public class PipMenuActivityController {
|
|||||||
public static final String EXTRA_CONTROLLER_MESSENGER = "messenger";
|
public static final String EXTRA_CONTROLLER_MESSENGER = "messenger";
|
||||||
public static final String EXTRA_ACTIONS = "actions";
|
public static final String EXTRA_ACTIONS = "actions";
|
||||||
public static final String EXTRA_STACK_BOUNDS = "stack_bounds";
|
public static final String EXTRA_STACK_BOUNDS = "stack_bounds";
|
||||||
public static final String EXTRA_MOVEMENT_BOUNDS = "movement_bounds";
|
|
||||||
public static final String EXTRA_ALLOW_TIMEOUT = "allow_timeout";
|
public static final String EXTRA_ALLOW_TIMEOUT = "allow_timeout";
|
||||||
public static final String EXTRA_WILL_RESIZE_MENU = "resize_menu_on_show";
|
public static final String EXTRA_WILL_RESIZE_MENU = "resize_menu_on_show";
|
||||||
public static final String EXTRA_DISMISS_FRACTION = "dismiss_fraction";
|
public static final String EXTRA_DISMISS_FRACTION = "dismiss_fraction";
|
||||||
public static final String EXTRA_MENU_STATE = "menu_state";
|
public static final String EXTRA_MENU_STATE = "menu_state";
|
||||||
|
public static final String EXTRA_SHOW_MENU_WITH_DELAY = "show_menu_with_delay";
|
||||||
|
|
||||||
public static final int MESSAGE_MENU_STATE_CHANGED = 100;
|
public static final int MESSAGE_MENU_STATE_CHANGED = 100;
|
||||||
public static final int MESSAGE_EXPAND_PIP = 101;
|
public static final int MESSAGE_EXPAND_PIP = 101;
|
||||||
@@ -89,7 +89,7 @@ public class PipMenuActivityController {
|
|||||||
* @param menuState the current state of the menu
|
* @param menuState the current state of the menu
|
||||||
* @param resize whether or not to resize the PiP with the state change
|
* @param resize whether or not to resize the PiP with the state change
|
||||||
*/
|
*/
|
||||||
void onPipMenuStateChanged(int menuState, boolean resize);
|
void onPipMenuStateChanged(int menuState, boolean resize, Runnable callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the PIP requested to be expanded.
|
* Called when the PIP requested to be expanded.
|
||||||
@@ -130,7 +130,7 @@ public class PipMenuActivityController {
|
|||||||
case MESSAGE_MENU_STATE_CHANGED: {
|
case MESSAGE_MENU_STATE_CHANGED: {
|
||||||
int menuState = msg.arg1;
|
int menuState = msg.arg1;
|
||||||
boolean resize = msg.arg2 != 0;
|
boolean resize = msg.arg2 != 0;
|
||||||
onMenuStateChanged(menuState, resize);
|
onMenuStateChanged(menuState, resize, (Runnable) msg.obj);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_EXPAND_PIP: {
|
case MESSAGE_EXPAND_PIP: {
|
||||||
@@ -155,7 +155,7 @@ public class PipMenuActivityController {
|
|||||||
// Mark the menu as invisible once the activity finishes as well
|
// Mark the menu as invisible once the activity finishes as well
|
||||||
if (mToActivityMessenger == null) {
|
if (mToActivityMessenger == null) {
|
||||||
final boolean resize = msg.arg1 != 0;
|
final boolean resize = msg.arg1 != 0;
|
||||||
onMenuStateChanged(MENU_STATE_NONE, resize);
|
onMenuStateChanged(MENU_STATE_NONE, resize, null /* callback */);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -247,21 +247,38 @@ public class PipMenuActivityController {
|
|||||||
// If we haven't requested the start activity, or if it previously took too long to
|
// If we haven't requested the start activity, or if it previously took too long to
|
||||||
// start, then start it
|
// start, then start it
|
||||||
startMenuActivity(MENU_STATE_NONE, null /* stackBounds */,
|
startMenuActivity(MENU_STATE_NONE, null /* stackBounds */,
|
||||||
null /* movementBounds */, false /* allowMenuTimeout */,
|
false /* allowMenuTimeout */, false /* resizeMenuOnShow */,
|
||||||
false /* resizeMenuOnShow */);
|
false /* withDelay */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the menu activity.
|
* Similar to {@link #showMenu(int, Rect, boolean, boolean)} but only show the menu upon
|
||||||
|
* PiP window transition is finished.
|
||||||
*/
|
*/
|
||||||
public void showMenu(int menuState, Rect stackBounds, Rect movementBounds,
|
public void showMenuWithDelay(int menuState, Rect stackBounds, boolean allowMenuTimeout,
|
||||||
boolean allowMenuTimeout, boolean willResizeMenu) {
|
boolean willResizeMenu) {
|
||||||
|
showMenuInternal(menuState, stackBounds, allowMenuTimeout, willResizeMenu,
|
||||||
|
true /* withDelay */);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the menu activity immediately.
|
||||||
|
*/
|
||||||
|
public void showMenu(int menuState, Rect stackBounds, boolean allowMenuTimeout,
|
||||||
|
boolean willResizeMenu) {
|
||||||
|
showMenuInternal(menuState, stackBounds, allowMenuTimeout, willResizeMenu,
|
||||||
|
false /* withDelay */);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showMenuInternal(int menuState, Rect stackBounds, boolean allowMenuTimeout,
|
||||||
|
boolean willResizeMenu, boolean withDelay) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "showMenu() state=" + menuState
|
Log.d(TAG, "showMenu() state=" + menuState
|
||||||
+ " hasActivity=" + (mToActivityMessenger != null)
|
+ " hasActivity=" + (mToActivityMessenger != null)
|
||||||
+ " allowMenuTimeout=" + allowMenuTimeout
|
+ " allowMenuTimeout=" + allowMenuTimeout
|
||||||
+ " willResizeMenu=" + willResizeMenu
|
+ " willResizeMenu=" + willResizeMenu
|
||||||
|
+ " withDelay=" + withDelay
|
||||||
+ " callers=\n" + Debug.getCallers(5, " "));
|
+ " callers=\n" + Debug.getCallers(5, " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,9 +288,9 @@ public class PipMenuActivityController {
|
|||||||
if (stackBounds != null) {
|
if (stackBounds != null) {
|
||||||
data.putParcelable(EXTRA_STACK_BOUNDS, stackBounds);
|
data.putParcelable(EXTRA_STACK_BOUNDS, stackBounds);
|
||||||
}
|
}
|
||||||
data.putParcelable(EXTRA_MOVEMENT_BOUNDS, movementBounds);
|
|
||||||
data.putBoolean(EXTRA_ALLOW_TIMEOUT, allowMenuTimeout);
|
data.putBoolean(EXTRA_ALLOW_TIMEOUT, allowMenuTimeout);
|
||||||
data.putBoolean(EXTRA_WILL_RESIZE_MENU, willResizeMenu);
|
data.putBoolean(EXTRA_WILL_RESIZE_MENU, willResizeMenu);
|
||||||
|
data.putBoolean(EXTRA_SHOW_MENU_WITH_DELAY, withDelay);
|
||||||
Message m = Message.obtain();
|
Message m = Message.obtain();
|
||||||
m.what = PipMenuActivity.MESSAGE_SHOW_MENU;
|
m.what = PipMenuActivity.MESSAGE_SHOW_MENU;
|
||||||
m.obj = data;
|
m.obj = data;
|
||||||
@@ -285,8 +302,7 @@ public class PipMenuActivityController {
|
|||||||
} else if (!mStartActivityRequested || isStartActivityRequestedElapsed()) {
|
} else if (!mStartActivityRequested || isStartActivityRequestedElapsed()) {
|
||||||
// If we haven't requested the start activity, or if it previously took too long to
|
// If we haven't requested the start activity, or if it previously took too long to
|
||||||
// start, then start it
|
// start, then start it
|
||||||
startMenuActivity(menuState, stackBounds, movementBounds, allowMenuTimeout,
|
startMenuActivity(menuState, stackBounds, allowMenuTimeout, willResizeMenu, withDelay);
|
||||||
willResizeMenu);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +380,7 @@ public class PipMenuActivityController {
|
|||||||
* (ie. when manually expanding or dismissing).
|
* (ie. when manually expanding or dismissing).
|
||||||
*/
|
*/
|
||||||
public void hideMenuWithoutResize() {
|
public void hideMenuWithoutResize() {
|
||||||
onMenuStateChanged(MENU_STATE_NONE, false /* resize */);
|
onMenuStateChanged(MENU_STATE_NONE, false /* resize */, null /* callback */);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -388,8 +404,8 @@ public class PipMenuActivityController {
|
|||||||
/**
|
/**
|
||||||
* Starts the menu activity on the top task of the pinned stack.
|
* Starts the menu activity on the top task of the pinned stack.
|
||||||
*/
|
*/
|
||||||
private void startMenuActivity(int menuState, Rect stackBounds, Rect movementBounds,
|
private void startMenuActivity(int menuState, Rect stackBounds, boolean allowMenuTimeout,
|
||||||
boolean allowMenuTimeout, boolean willResizeMenu) {
|
boolean willResizeMenu, boolean withDelay) {
|
||||||
try {
|
try {
|
||||||
StackInfo pinnedStackInfo = ActivityTaskManager.getService().getStackInfo(
|
StackInfo pinnedStackInfo = ActivityTaskManager.getService().getStackInfo(
|
||||||
WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED);
|
WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED);
|
||||||
@@ -402,12 +418,10 @@ public class PipMenuActivityController {
|
|||||||
if (stackBounds != null) {
|
if (stackBounds != null) {
|
||||||
intent.putExtra(EXTRA_STACK_BOUNDS, stackBounds);
|
intent.putExtra(EXTRA_STACK_BOUNDS, stackBounds);
|
||||||
}
|
}
|
||||||
if (movementBounds != null) {
|
|
||||||
intent.putExtra(EXTRA_MOVEMENT_BOUNDS, movementBounds);
|
|
||||||
}
|
|
||||||
intent.putExtra(EXTRA_MENU_STATE, menuState);
|
intent.putExtra(EXTRA_MENU_STATE, menuState);
|
||||||
intent.putExtra(EXTRA_ALLOW_TIMEOUT, allowMenuTimeout);
|
intent.putExtra(EXTRA_ALLOW_TIMEOUT, allowMenuTimeout);
|
||||||
intent.putExtra(EXTRA_WILL_RESIZE_MENU, willResizeMenu);
|
intent.putExtra(EXTRA_WILL_RESIZE_MENU, willResizeMenu);
|
||||||
|
intent.putExtra(EXTRA_SHOW_MENU_WITH_DELAY, withDelay);
|
||||||
ActivityOptions options = ActivityOptions.makeCustomAnimation(mContext, 0, 0);
|
ActivityOptions options = ActivityOptions.makeCustomAnimation(mContext, 0, 0);
|
||||||
options.setLaunchTaskId(
|
options.setLaunchTaskId(
|
||||||
pinnedStackInfo.taskIds[pinnedStackInfo.taskIds.length - 1]);
|
pinnedStackInfo.taskIds[pinnedStackInfo.taskIds.length - 1]);
|
||||||
@@ -472,14 +486,14 @@ public class PipMenuActivityController {
|
|||||||
/**
|
/**
|
||||||
* Handles changes in menu visibility.
|
* Handles changes in menu visibility.
|
||||||
*/
|
*/
|
||||||
private void onMenuStateChanged(int menuState, boolean resize) {
|
private void onMenuStateChanged(int menuState, boolean resize, Runnable callback) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "onMenuStateChanged() mMenuState=" + mMenuState
|
Log.d(TAG, "onMenuStateChanged() mMenuState=" + mMenuState
|
||||||
+ " menuState=" + menuState + " resize=" + resize);
|
+ " menuState=" + menuState + " resize=" + resize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menuState != mMenuState) {
|
if (menuState != mMenuState) {
|
||||||
mListeners.forEach(l -> l.onPipMenuStateChanged(menuState, resize));
|
mListeners.forEach(l -> l.onPipMenuStateChanged(menuState, resize, callback));
|
||||||
if (menuState == MENU_STATE_FULL) {
|
if (menuState == MENU_STATE_FULL) {
|
||||||
// Once visible, start listening for media action changes. This call will trigger
|
// Once visible, start listening for media action changes. This call will trigger
|
||||||
// the menu actions to be updated again.
|
// the menu actions to be updated again.
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.IActivityTaskManager;
|
import android.app.IActivityTaskManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Debug;
|
import android.os.Debug;
|
||||||
@@ -123,6 +124,29 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
|||||||
*/
|
*/
|
||||||
private boolean mSpringingToTouch = false;
|
private boolean mSpringingToTouch = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets set in {@link #animateToExpandedState(Rect, Rect, Rect, Runnable)}, this callback is
|
||||||
|
* used to show menu activity when the expand animation is completed.
|
||||||
|
*/
|
||||||
|
private Runnable mPostPipTransitionCallback;
|
||||||
|
|
||||||
|
private final PipTaskOrganizer.PipTransitionCallback mPipTransitionCallback =
|
||||||
|
new PipTaskOrganizer.PipTransitionCallback() {
|
||||||
|
@Override
|
||||||
|
public void onPipTransitionStarted(ComponentName activity, int direction) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPipTransitionFinished(ComponentName activity, int direction) {
|
||||||
|
if (mPostPipTransitionCallback != null) {
|
||||||
|
mPostPipTransitionCallback.run();
|
||||||
|
mPostPipTransitionCallback = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPipTransitionCanceled(ComponentName activity, int direction) {}
|
||||||
|
};
|
||||||
|
|
||||||
public PipMotionHelper(Context context, IActivityTaskManager activityTaskManager,
|
public PipMotionHelper(Context context, IActivityTaskManager activityTaskManager,
|
||||||
PipTaskOrganizer pipTaskOrganizer, PipMenuActivityController menuController,
|
PipTaskOrganizer pipTaskOrganizer, PipMenuActivityController menuController,
|
||||||
PipSnapAlgorithm snapAlgorithm, FlingAnimationUtils flingAnimationUtils,
|
PipSnapAlgorithm snapAlgorithm, FlingAnimationUtils flingAnimationUtils,
|
||||||
@@ -135,6 +159,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
|||||||
mFlingAnimationUtils = flingAnimationUtils;
|
mFlingAnimationUtils = flingAnimationUtils;
|
||||||
mFloatingContentCoordinator = floatingContentCoordinator;
|
mFloatingContentCoordinator = floatingContentCoordinator;
|
||||||
onConfigurationChanged();
|
onConfigurationChanged();
|
||||||
|
mPipTaskOrganizer.registerPipTransitionCallback(mPipTransitionCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -375,9 +400,10 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
|||||||
* Animates the PiP to the expanded state to show the menu.
|
* Animates the PiP to the expanded state to show the menu.
|
||||||
*/
|
*/
|
||||||
float animateToExpandedState(Rect expandedBounds, Rect movementBounds,
|
float animateToExpandedState(Rect expandedBounds, Rect movementBounds,
|
||||||
Rect expandedMovementBounds) {
|
Rect expandedMovementBounds, Runnable callback) {
|
||||||
float savedSnapFraction = mSnapAlgorithm.getSnapFraction(new Rect(mBounds), movementBounds);
|
float savedSnapFraction = mSnapAlgorithm.getSnapFraction(new Rect(mBounds), movementBounds);
|
||||||
mSnapAlgorithm.applySnapFraction(expandedBounds, expandedMovementBounds, savedSnapFraction);
|
mSnapAlgorithm.applySnapFraction(expandedBounds, expandedMovementBounds, savedSnapFraction);
|
||||||
|
mPostPipTransitionCallback = callback;
|
||||||
resizeAndAnimatePipUnchecked(expandedBounds, EXPAND_STACK_TO_MENU_DURATION);
|
resizeAndAnimatePipUnchecked(expandedBounds, EXPAND_STACK_TO_MENU_DURATION);
|
||||||
return savedSnapFraction;
|
return savedSnapFraction;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,8 +182,8 @@ public class PipTouchHandler {
|
|||||||
*/
|
*/
|
||||||
private class PipMenuListener implements PipMenuActivityController.Listener {
|
private class PipMenuListener implements PipMenuActivityController.Listener {
|
||||||
@Override
|
@Override
|
||||||
public void onPipMenuStateChanged(int menuState, boolean resize) {
|
public void onPipMenuStateChanged(int menuState, boolean resize, Runnable callback) {
|
||||||
setMenuState(menuState, resize);
|
setMenuState(menuState, resize, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -204,7 +204,7 @@ public class PipTouchHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void onPipShowMenu() {
|
public void onPipShowMenu() {
|
||||||
mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
||||||
mMovementBounds, true /* allowMenuTimeout */, willResizeMenu());
|
true /* allowMenuTimeout */, willResizeMenu());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,8 +234,8 @@ public class PipTouchHandler {
|
|||||||
new PipResizeGestureHandler(context, pipBoundsHandler, mMotionHelper,
|
new PipResizeGestureHandler(context, pipBoundsHandler, mMotionHelper,
|
||||||
deviceConfig, pipTaskOrganizer);
|
deviceConfig, pipTaskOrganizer);
|
||||||
mTouchState = new PipTouchState(ViewConfiguration.get(context), mHandler,
|
mTouchState = new PipTouchState(ViewConfiguration.get(context), mHandler,
|
||||||
() -> mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
() -> mMenuController.showMenuWithDelay(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
||||||
mMovementBounds, true /* allowMenuTimeout */, willResizeMenu()));
|
true /* allowMenuTimeout */, willResizeMenu()));
|
||||||
|
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
mExpandedShortestEdgeSize = res.getDimensionPixelSize(
|
mExpandedShortestEdgeSize = res.getDimensionPixelSize(
|
||||||
@@ -322,7 +322,7 @@ public class PipTouchHandler {
|
|||||||
// Only show the menu if the user isn't currently interacting with the PiP
|
// Only show the menu if the user isn't currently interacting with the PiP
|
||||||
if (!mTouchState.isUserInteracting()) {
|
if (!mTouchState.isUserInteracting()) {
|
||||||
mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
||||||
mMovementBounds, false /* allowMenuTimeout */, willResizeMenu());
|
false /* allowMenuTimeout */, willResizeMenu());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,7 +358,7 @@ public class PipTouchHandler {
|
|||||||
|
|
||||||
if (mShowPipMenuOnAnimationEnd) {
|
if (mShowPipMenuOnAnimationEnd) {
|
||||||
mMenuController.showMenu(MENU_STATE_CLOSE, mMotionHelper.getBounds(),
|
mMenuController.showMenu(MENU_STATE_CLOSE, mMotionHelper.getBounds(),
|
||||||
mMovementBounds, true /* allowMenuTimeout */, false /* willResizeMenu */);
|
true /* allowMenuTimeout */, false /* willResizeMenu */);
|
||||||
mShowPipMenuOnAnimationEnd = false;
|
mShowPipMenuOnAnimationEnd = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -557,7 +557,7 @@ public class PipTouchHandler {
|
|||||||
|
|
||||||
private void onAccessibilityShowMenu() {
|
private void onAccessibilityShowMenu() {
|
||||||
mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
||||||
mMovementBounds, true /* allowMenuTimeout */, willResizeMenu());
|
true /* allowMenuTimeout */, willResizeMenu());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleTouchEvent(InputEvent inputEvent) {
|
private boolean handleTouchEvent(InputEvent inputEvent) {
|
||||||
@@ -628,8 +628,7 @@ public class PipTouchHandler {
|
|||||||
// Let's not enable menu show/hide for a11y services.
|
// Let's not enable menu show/hide for a11y services.
|
||||||
if (!mAccessibilityManager.isTouchExplorationEnabled()) {
|
if (!mAccessibilityManager.isTouchExplorationEnabled()) {
|
||||||
mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
||||||
mMovementBounds, false /* allowMenuTimeout */,
|
false /* allowMenuTimeout */, false /* willResizeMenu */);
|
||||||
false /* willResizeMenu */);
|
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_HOVER_MOVE: {
|
case MotionEvent.ACTION_HOVER_MOVE: {
|
||||||
if (!shouldDeliverToMenu && !mSendingHoverAccessibilityEvents) {
|
if (!shouldDeliverToMenu && !mSendingHoverAccessibilityEvents) {
|
||||||
@@ -713,7 +712,7 @@ public class PipTouchHandler {
|
|||||||
/**
|
/**
|
||||||
* Sets the menu visibility.
|
* Sets the menu visibility.
|
||||||
*/
|
*/
|
||||||
private void setMenuState(int menuState, boolean resize) {
|
private void setMenuState(int menuState, boolean resize, Runnable callback) {
|
||||||
if (mMenuState == menuState && !resize) {
|
if (mMenuState == menuState && !resize) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -727,7 +726,7 @@ public class PipTouchHandler {
|
|||||||
mResizedBounds.set(mMotionHelper.getBounds());
|
mResizedBounds.set(mMotionHelper.getBounds());
|
||||||
Rect expandedBounds = new Rect(mExpandedBounds);
|
Rect expandedBounds = new Rect(mExpandedBounds);
|
||||||
mSavedSnapFraction = mMotionHelper.animateToExpandedState(expandedBounds,
|
mSavedSnapFraction = mMotionHelper.animateToExpandedState(expandedBounds,
|
||||||
mMovementBounds, mExpandedMovementBounds);
|
mMovementBounds, mExpandedMovementBounds, callback);
|
||||||
}
|
}
|
||||||
} else if (menuState == MENU_STATE_NONE && mMenuState == MENU_STATE_FULL) {
|
} else if (menuState == MENU_STATE_NONE && mMenuState == MENU_STATE_FULL) {
|
||||||
// Try and restore the PiP to the closest edge, using the saved snap fraction
|
// Try and restore the PiP to the closest edge, using the saved snap fraction
|
||||||
@@ -893,7 +892,7 @@ public class PipTouchHandler {
|
|||||||
// If the menu is still visible, then just poke the menu so that
|
// If the menu is still visible, then just poke the menu so that
|
||||||
// it will timeout after the user stops touching it
|
// it will timeout after the user stops touching it
|
||||||
mMenuController.showMenu(mMenuState, mMotionHelper.getBounds(),
|
mMenuController.showMenu(mMenuState, mMotionHelper.getBounds(),
|
||||||
mMovementBounds, true /* allowMenuTimeout */, willResizeMenu());
|
true /* allowMenuTimeout */, willResizeMenu());
|
||||||
} else {
|
} else {
|
||||||
// If the menu is not visible, then we can still be showing the activity for the
|
// If the menu is not visible, then we can still be showing the activity for the
|
||||||
// dismiss overlay, so just finish it after the animation completes
|
// dismiss overlay, so just finish it after the animation completes
|
||||||
@@ -917,7 +916,7 @@ public class PipTouchHandler {
|
|||||||
// User has stalled long enough for this not to be a drag or a double tap, just
|
// User has stalled long enough for this not to be a drag or a double tap, just
|
||||||
// expand the menu
|
// expand the menu
|
||||||
mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(),
|
||||||
mMovementBounds, true /* allowMenuTimeout */, willResizeMenu());
|
true /* allowMenuTimeout */, willResizeMenu());
|
||||||
} else {
|
} else {
|
||||||
// Next touch event _may_ be the second tap for the double-tap, schedule a
|
// Next touch event _may_ be the second tap for the double-tap, schedule a
|
||||||
// fallback runnable to trigger the menu if no touch event occurs before the
|
// fallback runnable to trigger the menu if no touch event occurs before the
|
||||||
|
|||||||
Reference in New Issue
Block a user