Merge "Add PiP round corner on/off switch" into rvc-dev am: 8ff649e2da
Change-Id: Ifbb8904de0c99a2b21b91fa07cf0a7fced694eba
This commit is contained in:
@@ -477,6 +477,9 @@
|
|||||||
<!-- Allow PIP to resize to a slightly bigger state upon touch/showing the menu -->
|
<!-- Allow PIP to resize to a slightly bigger state upon touch/showing the menu -->
|
||||||
<bool name="config_pipEnableResizeForMenu">true</bool>
|
<bool name="config_pipEnableResizeForMenu">true</bool>
|
||||||
|
|
||||||
|
<!-- Allow PIP to enable round corner, see also R.dimen.pip_corner_radius -->
|
||||||
|
<bool name="config_pipEnableRoundCorner">false</bool>
|
||||||
|
|
||||||
<!-- SystemUI Plugins that can be loaded on user builds. -->
|
<!-- SystemUI Plugins that can be loaded on user builds. -->
|
||||||
<string-array name="config_pluginWhitelist" translatable="false">
|
<string-array name="config_pluginWhitelist" translatable="false">
|
||||||
<item>com.android.systemui</item>
|
<item>com.android.systemui</item>
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import com.android.internal.annotations.VisibleForTesting;
|
|||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller class of PiP animations (both from and to PiP mode).
|
* Controller class of PiP animations (both from and to PiP mode).
|
||||||
*/
|
*/
|
||||||
@@ -62,12 +64,15 @@ public class PipAnimationController {
|
|||||||
@interface TransitionDirection {}
|
@interface TransitionDirection {}
|
||||||
|
|
||||||
private final Interpolator mFastOutSlowInInterpolator;
|
private final Interpolator mFastOutSlowInInterpolator;
|
||||||
|
private final PipSurfaceTransactionHelper mSurfaceTransactionHelper;
|
||||||
|
|
||||||
private PipTransitionAnimator mCurrentAnimator;
|
private PipTransitionAnimator mCurrentAnimator;
|
||||||
|
|
||||||
PipAnimationController(Context context) {
|
@Inject
|
||||||
|
PipAnimationController(Context context, PipSurfaceTransactionHelper helper) {
|
||||||
mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
|
mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
|
||||||
com.android.internal.R.interpolator.fast_out_slow_in);
|
com.android.internal.R.interpolator.fast_out_slow_in);
|
||||||
|
mSurfaceTransactionHelper = helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -110,6 +115,7 @@ public class PipAnimationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PipTransitionAnimator setupPipTransitionAnimator(PipTransitionAnimator animator) {
|
private PipTransitionAnimator setupPipTransitionAnimator(PipTransitionAnimator animator) {
|
||||||
|
animator.setSurfaceTransactionHelper(mSurfaceTransactionHelper);
|
||||||
animator.setInterpolator(mFastOutSlowInInterpolator);
|
animator.setInterpolator(mFastOutSlowInInterpolator);
|
||||||
animator.setFloatValues(FRACTION_START, FRACTION_END);
|
animator.setFloatValues(FRACTION_START, FRACTION_END);
|
||||||
return animator;
|
return animator;
|
||||||
@@ -151,9 +157,10 @@ public class PipAnimationController {
|
|||||||
private T mEndValue;
|
private T mEndValue;
|
||||||
private T mCurrentValue;
|
private T mCurrentValue;
|
||||||
private PipAnimationCallback mPipAnimationCallback;
|
private PipAnimationCallback mPipAnimationCallback;
|
||||||
private SurfaceControlTransactionFactory mSurfaceControlTransactionFactory;
|
private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
|
||||||
|
mSurfaceControlTransactionFactory;
|
||||||
|
private PipSurfaceTransactionHelper mSurfaceTransactionHelper;
|
||||||
private @TransitionDirection int mTransitionDirection;
|
private @TransitionDirection int mTransitionDirection;
|
||||||
private int mCornerRadius;
|
|
||||||
|
|
||||||
private PipTransitionAnimator(SurfaceControl leash, @AnimationType int animationType,
|
private PipTransitionAnimator(SurfaceControl leash, @AnimationType int animationType,
|
||||||
Rect destinationBounds, T startValue, T endValue) {
|
Rect destinationBounds, T startValue, T endValue) {
|
||||||
@@ -242,15 +249,6 @@ public class PipAnimationController {
|
|||||||
mCurrentValue = value;
|
mCurrentValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getCornerRadius() {
|
|
||||||
return mCornerRadius;
|
|
||||||
}
|
|
||||||
|
|
||||||
PipTransitionAnimator<T> setCornerRadius(int cornerRadius) {
|
|
||||||
mCornerRadius = cornerRadius;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean shouldApplyCornerRadius() {
|
boolean shouldApplyCornerRadius() {
|
||||||
return mTransitionDirection != TRANSITION_DIRECTION_TO_FULLSCREEN;
|
return mTransitionDirection != TRANSITION_DIRECTION_TO_FULLSCREEN;
|
||||||
}
|
}
|
||||||
@@ -273,10 +271,19 @@ public class PipAnimationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setSurfaceControlTransactionFactory(SurfaceControlTransactionFactory factory) {
|
void setSurfaceControlTransactionFactory(
|
||||||
|
PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) {
|
||||||
mSurfaceControlTransactionFactory = factory;
|
mSurfaceControlTransactionFactory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PipSurfaceTransactionHelper getSurfaceTransactionHelper() {
|
||||||
|
return mSurfaceTransactionHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSurfaceTransactionHelper(PipSurfaceTransactionHelper helper) {
|
||||||
|
mSurfaceTransactionHelper = helper;
|
||||||
|
}
|
||||||
|
|
||||||
abstract void applySurfaceControlTransaction(SurfaceControl leash,
|
abstract void applySurfaceControlTransaction(SurfaceControl leash,
|
||||||
SurfaceControl.Transaction tx, float fraction);
|
SurfaceControl.Transaction tx, float fraction);
|
||||||
|
|
||||||
@@ -289,14 +296,11 @@ public class PipAnimationController {
|
|||||||
SurfaceControl.Transaction tx, float fraction) {
|
SurfaceControl.Transaction tx, float fraction) {
|
||||||
final float alpha = getStartValue() * (1 - fraction) + getEndValue() * fraction;
|
final float alpha = getStartValue() * (1 - fraction) + getEndValue() * fraction;
|
||||||
setCurrentValue(alpha);
|
setCurrentValue(alpha);
|
||||||
tx.setAlpha(leash, alpha);
|
getSurfaceTransactionHelper().alpha(tx, leash, alpha);
|
||||||
if (Float.compare(fraction, FRACTION_START) == 0) {
|
if (Float.compare(fraction, FRACTION_START) == 0) {
|
||||||
// Ensure the start condition
|
getSurfaceTransactionHelper()
|
||||||
final Rect bounds = getDestinationBounds();
|
.crop(tx, leash, getDestinationBounds())
|
||||||
tx.setPosition(leash, bounds.left, bounds.top)
|
.round(tx, leash, shouldApplyCornerRadius());
|
||||||
.setWindowCrop(leash, bounds.width(), bounds.height());
|
|
||||||
tx.setCornerRadius(leash,
|
|
||||||
shouldApplyCornerRadius() ? getCornerRadius() : 0);
|
|
||||||
}
|
}
|
||||||
tx.apply();
|
tx.apply();
|
||||||
}
|
}
|
||||||
@@ -325,21 +329,16 @@ public class PipAnimationController {
|
|||||||
getCastedFractionValue(start.right, end.right, fraction),
|
getCastedFractionValue(start.right, end.right, fraction),
|
||||||
getCastedFractionValue(start.bottom, end.bottom, fraction));
|
getCastedFractionValue(start.bottom, end.bottom, fraction));
|
||||||
setCurrentValue(mTmpRect);
|
setCurrentValue(mTmpRect);
|
||||||
tx.setPosition(leash, mTmpRect.left, mTmpRect.top)
|
getSurfaceTransactionHelper().crop(tx, leash, mTmpRect);
|
||||||
.setWindowCrop(leash, mTmpRect.width(), mTmpRect.height());
|
|
||||||
if (Float.compare(fraction, FRACTION_START) == 0) {
|
if (Float.compare(fraction, FRACTION_START) == 0) {
|
||||||
// Ensure the start condition
|
// Ensure the start condition
|
||||||
tx.setAlpha(leash, 1f);
|
getSurfaceTransactionHelper()
|
||||||
tx.setCornerRadius(leash,
|
.alpha(tx, leash, 1f)
|
||||||
shouldApplyCornerRadius() ? getCornerRadius() : 0);
|
.round(tx, leash, shouldApplyCornerRadius());
|
||||||
}
|
}
|
||||||
tx.apply();
|
tx.apply();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SurfaceControlTransactionFactory {
|
|
||||||
SurfaceControl.Transaction getTransaction();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.systemui.pip;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.view.SurfaceControl;
|
||||||
|
|
||||||
|
import com.android.systemui.R;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstracts the common operations on {@link SurfaceControl.Transaction} for PiP transition.
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class PipSurfaceTransactionHelper {
|
||||||
|
|
||||||
|
private final boolean mEnableCornerRadius;
|
||||||
|
private final int mCornerRadius;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public PipSurfaceTransactionHelper(Context context) {
|
||||||
|
final Resources res = context.getResources();
|
||||||
|
mEnableCornerRadius = res.getBoolean(R.bool.config_pipEnableRoundCorner);
|
||||||
|
mCornerRadius = res.getDimensionPixelSize(R.dimen.pip_corner_radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operates the alpha on a given transaction and leash
|
||||||
|
* @return same {@link PipSurfaceTransactionHelper} instance for method chaining
|
||||||
|
*/
|
||||||
|
PipSurfaceTransactionHelper alpha(SurfaceControl.Transaction tx, SurfaceControl leash,
|
||||||
|
float alpha) {
|
||||||
|
tx.setAlpha(leash, alpha);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operates the crop (and position) on a given transaction and leash
|
||||||
|
* @return same {@link PipSurfaceTransactionHelper} instance for method chaining
|
||||||
|
*/
|
||||||
|
PipSurfaceTransactionHelper crop(SurfaceControl.Transaction tx, SurfaceControl leash,
|
||||||
|
Rect destinationBounds) {
|
||||||
|
tx.setWindowCrop(leash, destinationBounds.width(), destinationBounds.height())
|
||||||
|
.setPosition(leash, destinationBounds.left, destinationBounds.top);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operates the round corner radius on a given transaction and leash
|
||||||
|
* @return same {@link PipSurfaceTransactionHelper} instance for method chaining
|
||||||
|
*/
|
||||||
|
PipSurfaceTransactionHelper round(SurfaceControl.Transaction tx, SurfaceControl leash,
|
||||||
|
boolean applyCornerRadius) {
|
||||||
|
if (mEnableCornerRadius) {
|
||||||
|
tx.setCornerRadius(leash, applyCornerRadius ? mCornerRadius : 0);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SurfaceControlTransactionFactory {
|
||||||
|
SurfaceControl.Transaction getTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,7 +32,6 @@ import android.app.PictureInPictureParams;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -46,9 +45,7 @@ import com.android.systemui.R;
|
|||||||
import com.android.systemui.pip.phone.PipUpdateThread;
|
import com.android.systemui.pip.phone.PipUpdateThread;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@@ -78,9 +75,8 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
private final PipAnimationController mPipAnimationController;
|
private final PipAnimationController mPipAnimationController;
|
||||||
private final List<PipTransitionCallback> mPipTransitionCallbacks = new ArrayList<>();
|
private final List<PipTransitionCallback> mPipTransitionCallbacks = new ArrayList<>();
|
||||||
private final Rect mLastReportedBounds = new Rect();
|
private final Rect mLastReportedBounds = new Rect();
|
||||||
private final int mCornerRadius;
|
|
||||||
private final Map<IBinder, Rect> mBoundsToRestore = new HashMap<>();
|
|
||||||
private final int mEnterExitAnimationDuration;
|
private final int mEnterExitAnimationDuration;
|
||||||
|
private final PipSurfaceTransactionHelper mSurfaceTransactionHelper;
|
||||||
|
|
||||||
// These callbacks are called on the update thread
|
// These callbacks are called on the update thread
|
||||||
private final PipAnimationController.PipAnimationCallback mPipAnimationCallback =
|
private final PipAnimationController.PipAnimationCallback mPipAnimationCallback =
|
||||||
@@ -172,16 +168,20 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
private SurfaceControl mLeash;
|
private SurfaceControl mLeash;
|
||||||
private boolean mInPip;
|
private boolean mInPip;
|
||||||
private @PipAnimationController.AnimationType int mOneShotAnimationType = ANIM_TYPE_BOUNDS;
|
private @PipAnimationController.AnimationType int mOneShotAnimationType = ANIM_TYPE_BOUNDS;
|
||||||
|
private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
|
||||||
|
mSurfaceControlTransactionFactory;
|
||||||
|
|
||||||
public PipTaskOrganizer(Context context, @NonNull PipBoundsHandler boundsHandler) {
|
public PipTaskOrganizer(Context context, @NonNull PipBoundsHandler boundsHandler,
|
||||||
|
@NonNull PipSurfaceTransactionHelper surfaceTransactionHelper) {
|
||||||
mMainHandler = new Handler(Looper.getMainLooper());
|
mMainHandler = new Handler(Looper.getMainLooper());
|
||||||
mUpdateHandler = new Handler(PipUpdateThread.get().getLooper(), mUpdateCallbacks);
|
mUpdateHandler = new Handler(PipUpdateThread.get().getLooper(), mUpdateCallbacks);
|
||||||
mTaskOrganizerController = ActivityTaskManager.getTaskOrganizerController();
|
mTaskOrganizerController = ActivityTaskManager.getTaskOrganizerController();
|
||||||
mPipBoundsHandler = boundsHandler;
|
mPipBoundsHandler = boundsHandler;
|
||||||
mPipAnimationController = new PipAnimationController(context);
|
|
||||||
mCornerRadius = context.getResources().getDimensionPixelSize(R.dimen.pip_corner_radius);
|
|
||||||
mEnterExitAnimationDuration = context.getResources()
|
mEnterExitAnimationDuration = context.getResources()
|
||||||
.getInteger(R.integer.config_pipResizeAnimationDuration);
|
.getInteger(R.integer.config_pipResizeAnimationDuration);
|
||||||
|
mSurfaceTransactionHelper = surfaceTransactionHelper;
|
||||||
|
mPipAnimationController = new PipAnimationController(context, surfaceTransactionHelper);
|
||||||
|
mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Handler getUpdateHandler() {
|
public Handler getUpdateHandler() {
|
||||||
@@ -234,7 +234,6 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
throw new RuntimeException("Unable to get leash", e);
|
throw new RuntimeException("Unable to get leash", e);
|
||||||
}
|
}
|
||||||
final Rect currentBounds = mTaskInfo.configuration.windowConfiguration.getBounds();
|
final Rect currentBounds = mTaskInfo.configuration.windowConfiguration.getBounds();
|
||||||
mBoundsToRestore.put(mToken.asBinder(), currentBounds);
|
|
||||||
if (mOneShotAnimationType == ANIM_TYPE_BOUNDS) {
|
if (mOneShotAnimationType == ANIM_TYPE_BOUNDS) {
|
||||||
scheduleAnimateResizePip(currentBounds, destinationBounds,
|
scheduleAnimateResizePip(currentBounds, destinationBounds,
|
||||||
TRANSITION_DIRECTION_TO_PIP, mEnterExitAnimationDuration, null);
|
TRANSITION_DIRECTION_TO_PIP, mEnterExitAnimationDuration, null);
|
||||||
@@ -242,7 +241,6 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
mUpdateHandler.post(() -> mPipAnimationController
|
mUpdateHandler.post(() -> mPipAnimationController
|
||||||
.getAnimator(mLeash, destinationBounds, 0f, 1f)
|
.getAnimator(mLeash, destinationBounds, 0f, 1f)
|
||||||
.setTransitionDirection(TRANSITION_DIRECTION_TO_PIP)
|
.setTransitionDirection(TRANSITION_DIRECTION_TO_PIP)
|
||||||
.setCornerRadius(mCornerRadius)
|
|
||||||
.setPipAnimationCallback(mPipAnimationCallback)
|
.setPipAnimationCallback(mPipAnimationCallback)
|
||||||
.setDuration(mEnterExitAnimationDuration)
|
.setDuration(mEnterExitAnimationDuration)
|
||||||
.start());
|
.start());
|
||||||
@@ -260,8 +258,8 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
Log.wtf(TAG, "Unrecognized token: " + token);
|
Log.wtf(TAG, "Unrecognized token: " + token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Rect boundsToRestore = mBoundsToRestore.remove(mToken.asBinder());
|
scheduleAnimateResizePip(mLastReportedBounds,
|
||||||
scheduleAnimateResizePip(mLastReportedBounds, boundsToRestore,
|
info.configuration.windowConfiguration.getBounds(),
|
||||||
TRANSITION_DIRECTION_TO_FULLSCREEN, mEnterExitAnimationDuration, null);
|
TRANSITION_DIRECTION_TO_FULLSCREEN, mEnterExitAnimationDuration, null);
|
||||||
mInPip = false;
|
mInPip = false;
|
||||||
}
|
}
|
||||||
@@ -307,7 +305,6 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
private void scheduleAnimateResizePip(Rect currentBounds, Rect destinationBounds,
|
private void scheduleAnimateResizePip(Rect currentBounds, Rect destinationBounds,
|
||||||
@PipAnimationController.TransitionDirection int direction, int durationMs,
|
@PipAnimationController.TransitionDirection int direction, int durationMs,
|
||||||
Consumer<Rect> updateBoundsCallback) {
|
Consumer<Rect> updateBoundsCallback) {
|
||||||
Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
|
|
||||||
if (!mInPip) {
|
if (!mInPip) {
|
||||||
// Ignore animation when we are no longer in PIP
|
// Ignore animation when we are no longer in PIP
|
||||||
return;
|
return;
|
||||||
@@ -326,7 +323,6 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
* {@link WindowContainerTransaction} until {@link #scheduleFinishResizePip} is called.
|
* {@link WindowContainerTransaction} until {@link #scheduleFinishResizePip} is called.
|
||||||
*/
|
*/
|
||||||
public void scheduleResizePip(Rect toBounds, Consumer<Rect> updateBoundsCallback) {
|
public void scheduleResizePip(Rect toBounds, Consumer<Rect> updateBoundsCallback) {
|
||||||
Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
|
|
||||||
SomeArgs args = SomeArgs.obtain();
|
SomeArgs args = SomeArgs.obtain();
|
||||||
args.arg1 = updateBoundsCallback;
|
args.arg1 = updateBoundsCallback;
|
||||||
args.arg2 = toBounds;
|
args.arg2 = toBounds;
|
||||||
@@ -334,22 +330,20 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finish a intermediate resize operation. This is expected to be called after
|
* Finish an intermediate resize operation. This is expected to be called after
|
||||||
* {@link #scheduleResizePip}.
|
* {@link #scheduleResizePip}.
|
||||||
*/
|
*/
|
||||||
public void scheduleFinishResizePip(Rect destinationBounds) {
|
public void scheduleFinishResizePip(Rect destinationBounds) {
|
||||||
Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
|
final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
|
||||||
SurfaceControl.Transaction tx = new SurfaceControl.Transaction()
|
mSurfaceTransactionHelper
|
||||||
.setPosition(mLeash, destinationBounds.left, destinationBounds.top)
|
.crop(tx, mLeash, destinationBounds)
|
||||||
.setWindowCrop(mLeash, destinationBounds.width(), destinationBounds.height())
|
.round(tx, mLeash, mInPip);
|
||||||
.setCornerRadius(mLeash, mInPip ? mCornerRadius : 0);
|
|
||||||
scheduleFinishResizePip(tx, destinationBounds, TRANSITION_DIRECTION_NONE, null);
|
scheduleFinishResizePip(tx, destinationBounds, TRANSITION_DIRECTION_NONE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scheduleFinishResizePip(SurfaceControl.Transaction tx,
|
private void scheduleFinishResizePip(SurfaceControl.Transaction tx,
|
||||||
Rect destinationBounds, @PipAnimationController.TransitionDirection int direction,
|
Rect destinationBounds, @PipAnimationController.TransitionDirection int direction,
|
||||||
Consumer<Rect> updateBoundsCallback) {
|
Consumer<Rect> updateBoundsCallback) {
|
||||||
Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
|
|
||||||
SomeArgs args = SomeArgs.obtain();
|
SomeArgs args = SomeArgs.obtain();
|
||||||
args.arg1 = updateBoundsCallback;
|
args.arg1 = updateBoundsCallback;
|
||||||
args.arg2 = tx;
|
args.arg2 = tx;
|
||||||
@@ -367,7 +361,6 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
// Ignore offsets when we are no longer in PIP
|
// Ignore offsets when we are no longer in PIP
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
|
|
||||||
SomeArgs args = SomeArgs.obtain();
|
SomeArgs args = SomeArgs.obtain();
|
||||||
args.arg1 = updateBoundsCallback;
|
args.arg1 = updateBoundsCallback;
|
||||||
args.arg2 = originalBounds;
|
args.arg2 = originalBounds;
|
||||||
@@ -396,17 +389,16 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
throw new RuntimeException("Callers should call scheduleResizePip() instead of this "
|
throw new RuntimeException("Callers should call scheduleResizePip() instead of this "
|
||||||
+ "directly");
|
+ "directly");
|
||||||
}
|
}
|
||||||
Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
|
|
||||||
// Could happen when dismissPip
|
// Could happen when dismissPip
|
||||||
if (mToken == null || mLeash == null) {
|
if (mToken == null || mLeash == null) {
|
||||||
Log.w(TAG, "Abort animation, invalid leash");
|
Log.w(TAG, "Abort animation, invalid leash");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new SurfaceControl.Transaction()
|
final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
|
||||||
.setPosition(mLeash, destinationBounds.left, destinationBounds.top)
|
mSurfaceTransactionHelper
|
||||||
.setWindowCrop(mLeash, destinationBounds.width(), destinationBounds.height())
|
.crop(tx, mLeash, destinationBounds)
|
||||||
.setCornerRadius(mLeash, mInPip ? mCornerRadius : 0)
|
.round(tx, mLeash, mInPip);
|
||||||
.apply();
|
tx.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finishResize(SurfaceControl.Transaction tx, Rect destinationBounds,
|
private void finishResize(SurfaceControl.Transaction tx, Rect destinationBounds,
|
||||||
@@ -449,7 +441,6 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
|
|||||||
mUpdateHandler.post(() -> mPipAnimationController
|
mUpdateHandler.post(() -> mPipAnimationController
|
||||||
.getAnimator(mLeash, currentBounds, destinationBounds)
|
.getAnimator(mLeash, currentBounds, destinationBounds)
|
||||||
.setTransitionDirection(direction)
|
.setTransitionDirection(direction)
|
||||||
.setCornerRadius(mCornerRadius)
|
|
||||||
.setPipAnimationCallback(mPipAnimationCallback)
|
.setPipAnimationCallback(mPipAnimationCallback)
|
||||||
.setDuration(durationMs)
|
.setDuration(durationMs)
|
||||||
.start());
|
.start());
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
|
|||||||
import com.android.systemui.pip.BasePipManager;
|
import com.android.systemui.pip.BasePipManager;
|
||||||
import com.android.systemui.pip.PipBoundsHandler;
|
import com.android.systemui.pip.PipBoundsHandler;
|
||||||
import com.android.systemui.pip.PipSnapAlgorithm;
|
import com.android.systemui.pip.PipSnapAlgorithm;
|
||||||
|
import com.android.systemui.pip.PipSurfaceTransactionHelper;
|
||||||
import com.android.systemui.pip.PipTaskOrganizer;
|
import com.android.systemui.pip.PipTaskOrganizer;
|
||||||
import com.android.systemui.shared.recents.IPinnedStackAnimationListener;
|
import com.android.systemui.shared.recents.IPinnedStackAnimationListener;
|
||||||
import com.android.systemui.shared.system.ActivityManagerWrapper;
|
import com.android.systemui.shared.system.ActivityManagerWrapper;
|
||||||
@@ -210,7 +211,8 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
|
|||||||
FloatingContentCoordinator floatingContentCoordinator,
|
FloatingContentCoordinator floatingContentCoordinator,
|
||||||
DeviceConfigProxy deviceConfig,
|
DeviceConfigProxy deviceConfig,
|
||||||
PipBoundsHandler pipBoundsHandler,
|
PipBoundsHandler pipBoundsHandler,
|
||||||
PipSnapAlgorithm pipSnapAlgorithm) {
|
PipSnapAlgorithm pipSnapAlgorithm,
|
||||||
|
PipSurfaceTransactionHelper surfaceTransactionHelper) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mActivityManager = ActivityManager.getService();
|
mActivityManager = ActivityManager.getService();
|
||||||
|
|
||||||
@@ -224,7 +226,8 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
|
|||||||
|
|
||||||
final IActivityTaskManager activityTaskManager = ActivityTaskManager.getService();
|
final IActivityTaskManager activityTaskManager = ActivityTaskManager.getService();
|
||||||
mPipBoundsHandler = pipBoundsHandler;
|
mPipBoundsHandler = pipBoundsHandler;
|
||||||
mPipTaskOrganizer = new PipTaskOrganizer(mContext, mPipBoundsHandler);
|
mPipTaskOrganizer = new PipTaskOrganizer(context, pipBoundsHandler,
|
||||||
|
surfaceTransactionHelper);
|
||||||
mPipTaskOrganizer.registerPipTransitionCallback(this);
|
mPipTaskOrganizer.registerPipTransitionCallback(this);
|
||||||
mInputConsumerController = InputConsumerController.getPipInputConsumer();
|
mInputConsumerController = InputConsumerController.getPipInputConsumer();
|
||||||
mMediaController = new PipMediaController(context, mActivityManager, broadcastDispatcher);
|
mMediaController = new PipMediaController(context, mActivityManager, broadcastDispatcher);
|
||||||
|
|||||||
@@ -78,10 +78,10 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
|||||||
private final Rect mBounds = new Rect();
|
private final Rect mBounds = new Rect();
|
||||||
|
|
||||||
/** The bounds within which PIP's top-left coordinate is allowed to move. */
|
/** The bounds within which PIP's top-left coordinate is allowed to move. */
|
||||||
private Rect mMovementBounds = new Rect();
|
private final Rect mMovementBounds = new Rect();
|
||||||
|
|
||||||
/** The region that all of PIP must stay within. */
|
/** The region that all of PIP must stay within. */
|
||||||
private Rect mFloatingAllowedArea = new Rect();
|
private final Rect mFloatingAllowedArea = new Rect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bounds that are animated using the physics animator.
|
* Bounds that are animated using the physics animator.
|
||||||
@@ -89,7 +89,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
|||||||
private final Rect mAnimatedBounds = new Rect();
|
private final Rect mAnimatedBounds = new Rect();
|
||||||
|
|
||||||
/** The destination bounds to which PIP is animating. */
|
/** The destination bounds to which PIP is animating. */
|
||||||
private Rect mAnimatingToBounds = new Rect();
|
private final Rect mAnimatingToBounds = new Rect();
|
||||||
|
|
||||||
/** Coordinator instance for resolving conflicts with other floating content. */
|
/** Coordinator instance for resolving conflicts with other floating content. */
|
||||||
private FloatingContentCoordinator mFloatingContentCoordinator;
|
private FloatingContentCoordinator mFloatingContentCoordinator;
|
||||||
@@ -120,7 +120,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
|||||||
new PhysicsAnimator.SpringConfig(
|
new PhysicsAnimator.SpringConfig(
|
||||||
SpringForce.STIFFNESS_LOW, SpringForce.DAMPING_RATIO_LOW_BOUNCY);
|
SpringForce.STIFFNESS_LOW, SpringForce.DAMPING_RATIO_LOW_BOUNCY);
|
||||||
|
|
||||||
private final Consumer<Rect> mUpdateBoundsCallback = (toBounds) -> mBounds.set(toBounds);
|
private final Consumer<Rect> mUpdateBoundsCallback = mBounds::set;
|
||||||
|
|
||||||
public PipMotionHelper(Context context, IActivityTaskManager activityTaskManager,
|
public PipMotionHelper(Context context, IActivityTaskManager activityTaskManager,
|
||||||
PipTaskOrganizer pipTaskOrganizer, PipMenuActivityController menuController,
|
PipTaskOrganizer pipTaskOrganizer, PipMenuActivityController menuController,
|
||||||
@@ -437,7 +437,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
|||||||
* {@link FloatingContentCoordinator.FloatingContent#getFloatingBoundsOnScreen()}.
|
* {@link FloatingContentCoordinator.FloatingContent#getFloatingBoundsOnScreen()}.
|
||||||
*/
|
*/
|
||||||
private void setAnimatingToBounds(Rect bounds) {
|
private void setAnimatingToBounds(Rect bounds) {
|
||||||
mAnimatingToBounds = bounds;
|
mAnimatingToBounds.set(bounds);
|
||||||
mFloatingContentCoordinator.onContentMoved(this);
|
mFloatingContentCoordinator.onContentMoved(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import com.android.systemui.UiOffloadThread;
|
|||||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||||
import com.android.systemui.pip.BasePipManager;
|
import com.android.systemui.pip.BasePipManager;
|
||||||
import com.android.systemui.pip.PipBoundsHandler;
|
import com.android.systemui.pip.PipBoundsHandler;
|
||||||
|
import com.android.systemui.pip.PipSurfaceTransactionHelper;
|
||||||
import com.android.systemui.pip.PipTaskOrganizer;
|
import com.android.systemui.pip.PipTaskOrganizer;
|
||||||
import com.android.systemui.shared.system.ActivityManagerWrapper;
|
import com.android.systemui.shared.system.ActivityManagerWrapper;
|
||||||
import com.android.systemui.shared.system.PinnedStackListenerForwarder.PinnedStackListener;
|
import com.android.systemui.shared.system.PinnedStackListenerForwarder.PinnedStackListener;
|
||||||
@@ -229,7 +230,8 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PipManager(Context context, BroadcastDispatcher broadcastDispatcher,
|
public PipManager(Context context, BroadcastDispatcher broadcastDispatcher,
|
||||||
PipBoundsHandler pipBoundsHandler) {
|
PipBoundsHandler pipBoundsHandler,
|
||||||
|
PipSurfaceTransactionHelper surfaceTransactionHelper) {
|
||||||
if (mInitialized) {
|
if (mInitialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -239,7 +241,8 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
|
|||||||
mPipBoundsHandler = pipBoundsHandler;
|
mPipBoundsHandler = pipBoundsHandler;
|
||||||
mResizeAnimationDuration = context.getResources()
|
mResizeAnimationDuration = context.getResources()
|
||||||
.getInteger(R.integer.config_pipResizeAnimationDuration);
|
.getInteger(R.integer.config_pipResizeAnimationDuration);
|
||||||
mPipTaskOrganizer = new PipTaskOrganizer(mContext, mPipBoundsHandler);
|
mPipTaskOrganizer = new PipTaskOrganizer(mContext, mPipBoundsHandler,
|
||||||
|
surfaceTransactionHelper);
|
||||||
mPipTaskOrganizer.registerPipTransitionCallback(this);
|
mPipTaskOrganizer.registerPipTransitionCallback(this);
|
||||||
mActivityTaskManager = ActivityTaskManager.getService();
|
mActivityTaskManager = ActivityTaskManager.getService();
|
||||||
ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
|
ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ public class PipAnimationControllerTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mPipAnimationController = new PipAnimationController(mContext);
|
mPipAnimationController = new PipAnimationController(
|
||||||
|
mContext, new PipSurfaceTransactionHelper(mContext));
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user