summaryrefslogtreecommitdiff
path: root/core/java/android/view/InsetsAnimationControlImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/view/InsetsAnimationControlImpl.java')
-rw-r--r--core/java/android/view/InsetsAnimationControlImpl.java36
1 files changed, 28 insertions, 8 deletions
diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java
index 7ea4f3062e21..cdfd397a732a 100644
--- a/core/java/android/view/InsetsAnimationControlImpl.java
+++ b/core/java/android/view/InsetsAnimationControlImpl.java
@@ -68,22 +68,26 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
private final InsetsController mController;
private final WindowInsetsAnimationCallback.InsetsAnimation mAnimation;
private final Rect mFrame;
+ private final boolean mFade;
private Insets mCurrentInsets;
private Insets mPendingInsets;
private float mPendingFraction;
private boolean mFinished;
private boolean mCancelled;
private boolean mShownOnFinish;
+ private float mCurrentAlpha;
+ private float mPendingAlpha;
@VisibleForTesting
public InsetsAnimationControlImpl(SparseArray<InsetsSourceConsumer> consumers, Rect frame,
InsetsState state, WindowInsetsAnimationControlListener listener,
@InsetsType int types,
Supplier<SyncRtSurfaceTransactionApplier> transactionApplierSupplier,
- InsetsController controller, long durationMs) {
+ InsetsController controller, long durationMs, boolean fade) {
mConsumers = consumers;
mListener = listener;
mTypes = types;
+ mFade = fade;
mTransactionApplierSupplier = transactionApplierSupplier;
mController = controller;
mInitialInsetsState = new InsetsState(state, true /* copySources */);
@@ -100,6 +104,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
mAnimation = new WindowInsetsAnimationCallback.InsetsAnimation(mTypes,
InsetsController.INTERPOLATOR, durationMs);
+ mAnimation.setAlpha(getCurrentAlpha());
mController.dispatchAnimationStarted(mAnimation,
new AnimationBounds(mHiddenInsets, mShownInsets));
}
@@ -120,6 +125,11 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
}
@Override
+ public float getCurrentAlpha() {
+ return mCurrentAlpha;
+ }
+
+ @Override
@InsetsType public int getTypes() {
return mTypes;
}
@@ -136,6 +146,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
}
mPendingFraction = sanitize(fraction);
mPendingInsets = sanitize(insets);
+ mPendingAlpha = 1 - sanitize(alpha);
mController.scheduleApplyChangeInsets();
}
@@ -148,17 +159,24 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
return false;
}
final Insets offset = Insets.subtract(mShownInsets, mPendingInsets);
+ final Float alphaOffset = 1 - mPendingAlpha;
ArrayList<SurfaceParams> params = new ArrayList<>();
- updateLeashesForSide(ISIDE_LEFT, offset.left, mPendingInsets.left, params, state);
- updateLeashesForSide(ISIDE_TOP, offset.top, mPendingInsets.top, params, state);
- updateLeashesForSide(ISIDE_RIGHT, offset.right, mPendingInsets.right, params, state);
- updateLeashesForSide(ISIDE_BOTTOM, offset.bottom, mPendingInsets.bottom, params, state);
- updateLeashesForSide(ISIDE_FLOATING, 0 /* offset */, 0 /* inset */, params, state);
+ updateLeashesForSide(ISIDE_LEFT, offset.left, mShownInsets.left, mPendingInsets.left,
+ params, state, alphaOffset);
+ updateLeashesForSide(ISIDE_TOP, offset.top, mShownInsets.top, mPendingInsets.top, params,
+ state, alphaOffset);
+ updateLeashesForSide(ISIDE_RIGHT, offset.right, mShownInsets.right, mPendingInsets.right,
+ params, state, alphaOffset);
+ updateLeashesForSide(ISIDE_BOTTOM, offset.bottom, mShownInsets.bottom,
+ mPendingInsets.bottom, params, state, alphaOffset);
+ updateLeashesForSide(ISIDE_FLOATING, 0 /* offset */, 0 /* inset */, 0 /* maxInset */,
+ params, state, alphaOffset);
SyncRtSurfaceTransactionApplier applier = mTransactionApplierSupplier.get();
applier.scheduleApply(params.toArray(new SurfaceParams[params.size()]));
mCurrentInsets = mPendingInsets;
mAnimation.setFraction(mPendingFraction);
+ mCurrentAlpha = 1 - alphaOffset;
if (mFinished) {
mController.notifyFinished(this, mShownOnFinish);
}
@@ -233,7 +251,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
}
private void updateLeashesForSide(@InternalInsetsSide int side, int offset, int inset,
- ArrayList<SurfaceParams> surfaceParams, InsetsState state) {
+ int maxInset, ArrayList<SurfaceParams> surfaceParams, InsetsState state, Float alpha) {
ArraySet<InsetsSourceConsumer> items = mSideSourceMap.get(side);
if (items == null) {
return;
@@ -257,7 +275,9 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
// If the system is controlling the insets source, the leash can be null.
if (leash != null) {
- surfaceParams.add(new SurfaceParams(leash, 1f /* alpha */, mTmpMatrix,
+ // TODO: use a better interpolation for fade.
+ alpha = mFade ? ((float) maxInset / inset * 0.3f + 0.7f) : alpha;
+ surfaceParams.add(new SurfaceParams(leash, alpha, mTmpMatrix,
null /* windowCrop */, 0 /* layer */, 0f /* cornerRadius*/,
side == ISIDE_FLOATING ? consumer.isVisible() : inset != 0 /* visible */));
}