summaryrefslogtreecommitdiff
path: root/core/java/android/view/InsetsSourceConsumer.java
diff options
context:
space:
mode:
authorJorim Jaggi <jjaggi@google.com>2020-04-06 14:15:46 +0200
committerJorim Jaggi <jjaggi@google.com>2020-04-06 14:28:59 +0200
commit33a2183d4b26e4ad72a2cbe5b01bfe6da5807a26 (patch)
treeca35336f98521243ea8f691082c125f7722fec9b /core/java/android/view/InsetsSourceConsumer.java
parent25e19732fc31f809b39019439c124518bbdf72df (diff)
Revert "Revert "Defer updating InsetsSource.mFrame while animating""
This reverts commit 8c56ac6b945e4050d56968e2adac673e052b772d. Underlying issue has been fixed: Test: InsetsControllerTest Bug: 152071027 Change-Id: I2b80de7067bf688a6b36233b9a1e92e2cf31c148
Diffstat (limited to 'core/java/android/view/InsetsSourceConsumer.java')
-rw-r--r--core/java/android/view/InsetsSourceConsumer.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java
index f74221dc3e3a..69bab4df2cae 100644
--- a/core/java/android/view/InsetsSourceConsumer.java
+++ b/core/java/android/view/InsetsSourceConsumer.java
@@ -16,11 +16,13 @@
package android.view;
+import static android.view.InsetsController.ANIMATION_TYPE_NONE;
import static android.view.InsetsController.AnimationType;
import static android.view.InsetsState.toPublicType;
import android.annotation.IntDef;
import android.annotation.Nullable;
+import android.graphics.Rect;
import android.view.InsetsState.InternalInsetsType;
import android.view.SurfaceControl.Transaction;
import android.view.WindowInsets.Type.InsetsType;
@@ -64,6 +66,8 @@ public class InsetsSourceConsumer {
private final Supplier<Transaction> mTransactionSupplier;
private @Nullable InsetsSourceControl mSourceControl;
private boolean mHasWindowFocus;
+ private Rect mPendingFrame;
+ private Rect mPendingVisibleFrame;
public InsetsSourceConsumer(@InternalInsetsType int type, InsetsState state,
Supplier<Transaction> transactionSupplier, InsetsController controller) {
@@ -215,6 +219,38 @@ public class InsetsSourceConsumer {
// no-op for types that always return ShowResult#SHOW_IMMEDIATELY.
}
+ void updateSource(InsetsSource newSource) {
+ InsetsSource source = mState.peekSource(mType);
+ if (source == null || mController.getAnimationType(mType) == ANIMATION_TYPE_NONE
+ || source.getFrame().equals(newSource.getFrame())) {
+ mState.addSource(newSource);
+ return;
+ }
+
+ // Frame is changing while animating. Keep note of the new frame but keep existing frame
+ // until animaition is finished.
+ newSource = new InsetsSource(newSource);
+ mPendingFrame = new Rect(newSource.getFrame());
+ mPendingVisibleFrame = newSource.getVisibleFrame() != null
+ ? new Rect(newSource.getVisibleFrame())
+ : null;
+ newSource.setFrame(source.getFrame());
+ newSource.setVisibleFrame(source.getVisibleFrame());
+ mState.addSource(newSource);
+ }
+
+ boolean notifyAnimationFinished() {
+ if (mPendingFrame != null) {
+ InsetsSource source = mState.getSource(mType);
+ source.setFrame(mPendingFrame);
+ source.setVisibleFrame(mPendingVisibleFrame);
+ mPendingFrame = null;
+ mPendingVisibleFrame = null;
+ return true;
+ }
+ return false;
+ }
+
/**
* Sets requested visibility from the client, regardless of whether we are able to control it at
* the moment.