Merge "Post insets update to handler" into rvc-dev am: dcb47baf63
Change-Id: I263a18fa4a7d461310d6be55f68ab2248022e8f7
This commit is contained in:
@@ -187,19 +187,21 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insetsChanged(InsetsState insetsState) {
|
public void insetsChanged(InsetsState insetsState) {
|
||||||
if (mInsetsState.equals(insetsState)) {
|
mHandler.post(() -> {
|
||||||
return;
|
if (mInsetsState.equals(insetsState)) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final InsetsSource newSource = insetsState.getSource(InsetsState.ITYPE_IME);
|
final InsetsSource newSource = insetsState.getSource(InsetsState.ITYPE_IME);
|
||||||
final Rect newFrame = newSource.getFrame();
|
final Rect newFrame = newSource.getFrame();
|
||||||
final Rect oldFrame = mInsetsState.getSource(InsetsState.ITYPE_IME).getFrame();
|
final Rect oldFrame = mInsetsState.getSource(InsetsState.ITYPE_IME).getFrame();
|
||||||
|
|
||||||
mInsetsState.set(insetsState, true /* copySources */);
|
mInsetsState.set(insetsState, true /* copySources */);
|
||||||
if (mImeShowing && !newFrame.equals(oldFrame) && newSource.isVisible()) {
|
if (mImeShowing && !newFrame.equals(oldFrame) && newSource.isVisible()) {
|
||||||
if (DEBUG) Slog.d(TAG, "insetsChanged when IME showing, restart animation");
|
if (DEBUG) Slog.d(TAG, "insetsChanged when IME showing, restart animation");
|
||||||
startAnimation(mImeShowing, true /* forceRestart */);
|
startAnimation(mImeShowing, true /* forceRestart */);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -232,7 +234,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DEBUG) Slog.d(TAG, "Got showInsets for ime");
|
if (DEBUG) Slog.d(TAG, "Got showInsets for ime");
|
||||||
startAnimation(true /* show */, false /* forceRestart */);
|
mHandler.post(() -> startAnimation(true /* show */, false /* forceRestart */));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -241,7 +243,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DEBUG) Slog.d(TAG, "Got hideInsets for ime");
|
if (DEBUG) Slog.d(TAG, "Got hideInsets for ime");
|
||||||
startAnimation(false /* show */, false /* forceRestart */);
|
mHandler.post(() -> startAnimation(false /* show */, false /* forceRestart */));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,108 +271,106 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
|
|||||||
if (newFrame.height() != 0) {
|
if (newFrame.height() != 0) {
|
||||||
mImeFrame.set(newFrame);
|
mImeFrame.set(newFrame);
|
||||||
}
|
}
|
||||||
mHandler.post(() -> {
|
if (DEBUG) {
|
||||||
if (DEBUG) {
|
Slog.d(TAG, "Run startAnim show:" + show + " was:"
|
||||||
Slog.d(TAG, "Run startAnim show:" + show + " was:"
|
+ (mAnimationDirection == DIRECTION_SHOW ? "SHOW"
|
||||||
+ (mAnimationDirection == DIRECTION_SHOW ? "SHOW"
|
: (mAnimationDirection == DIRECTION_HIDE ? "HIDE" : "NONE")));
|
||||||
: (mAnimationDirection == DIRECTION_HIDE ? "HIDE" : "NONE")));
|
}
|
||||||
}
|
if (!forceRestart && (mAnimationDirection == DIRECTION_SHOW && show)
|
||||||
if (!forceRestart && (mAnimationDirection == DIRECTION_SHOW && show)
|
|| (mAnimationDirection == DIRECTION_HIDE && !show)) {
|
||||||
|| (mAnimationDirection == DIRECTION_HIDE && !show)) {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
boolean seek = false;
|
||||||
boolean seek = false;
|
float seekValue = 0;
|
||||||
float seekValue = 0;
|
if (mAnimation != null) {
|
||||||
if (mAnimation != null) {
|
if (mAnimation.isRunning()) {
|
||||||
if (mAnimation.isRunning()) {
|
seekValue = (float) mAnimation.getAnimatedValue();
|
||||||
seekValue = (float) mAnimation.getAnimatedValue();
|
|
||||||
seek = true;
|
|
||||||
}
|
|
||||||
mAnimation.cancel();
|
|
||||||
}
|
|
||||||
final float defaultY = mImeSourceControl.getSurfacePosition().y;
|
|
||||||
final float x = mImeSourceControl.getSurfacePosition().x;
|
|
||||||
final float hiddenY = defaultY + mImeFrame.height();
|
|
||||||
final float shownY = defaultY;
|
|
||||||
final float startY = show ? hiddenY : shownY;
|
|
||||||
final float endY = show ? shownY : hiddenY;
|
|
||||||
if (mAnimationDirection == DIRECTION_NONE && mImeShowing && show) {
|
|
||||||
// IME is already showing, so set seek to end
|
|
||||||
seekValue = shownY;
|
|
||||||
seek = true;
|
seek = true;
|
||||||
}
|
}
|
||||||
mAnimationDirection = show ? DIRECTION_SHOW : DIRECTION_HIDE;
|
mAnimation.cancel();
|
||||||
mImeShowing = show;
|
}
|
||||||
mAnimation = ValueAnimator.ofFloat(startY, endY);
|
final float defaultY = mImeSourceControl.getSurfacePosition().y;
|
||||||
mAnimation.setDuration(
|
final float x = mImeSourceControl.getSurfacePosition().x;
|
||||||
show ? ANIMATION_DURATION_SHOW_MS : ANIMATION_DURATION_HIDE_MS);
|
final float hiddenY = defaultY + mImeFrame.height();
|
||||||
if (seek) {
|
final float shownY = defaultY;
|
||||||
mAnimation.setCurrentFraction((seekValue - startY) / (endY - startY));
|
final float startY = show ? hiddenY : shownY;
|
||||||
}
|
final float endY = show ? shownY : hiddenY;
|
||||||
|
if (mAnimationDirection == DIRECTION_NONE && mImeShowing && show) {
|
||||||
|
// IME is already showing, so set seek to end
|
||||||
|
seekValue = shownY;
|
||||||
|
seek = true;
|
||||||
|
}
|
||||||
|
mAnimationDirection = show ? DIRECTION_SHOW : DIRECTION_HIDE;
|
||||||
|
mImeShowing = show;
|
||||||
|
mAnimation = ValueAnimator.ofFloat(startY, endY);
|
||||||
|
mAnimation.setDuration(
|
||||||
|
show ? ANIMATION_DURATION_SHOW_MS : ANIMATION_DURATION_HIDE_MS);
|
||||||
|
if (seek) {
|
||||||
|
mAnimation.setCurrentFraction((seekValue - startY) / (endY - startY));
|
||||||
|
}
|
||||||
|
|
||||||
mAnimation.addUpdateListener(animation -> {
|
mAnimation.addUpdateListener(animation -> {
|
||||||
|
SurfaceControl.Transaction t = mTransactionPool.acquire();
|
||||||
|
float value = (float) animation.getAnimatedValue();
|
||||||
|
t.setPosition(mImeSourceControl.getLeash(), x, value);
|
||||||
|
dispatchPositionChanged(mDisplayId, imeTop(value), t);
|
||||||
|
t.apply();
|
||||||
|
mTransactionPool.release(t);
|
||||||
|
});
|
||||||
|
mAnimation.setInterpolator(INTERPOLATOR);
|
||||||
|
mAnimation.addListener(new AnimatorListenerAdapter() {
|
||||||
|
private boolean mCancelled = false;
|
||||||
|
@Override
|
||||||
|
public void onAnimationStart(Animator animation) {
|
||||||
SurfaceControl.Transaction t = mTransactionPool.acquire();
|
SurfaceControl.Transaction t = mTransactionPool.acquire();
|
||||||
float value = (float) animation.getAnimatedValue();
|
t.setPosition(mImeSourceControl.getLeash(), x, startY);
|
||||||
t.setPosition(mImeSourceControl.getLeash(), x, value);
|
if (DEBUG) {
|
||||||
dispatchPositionChanged(mDisplayId, imeTop(value), t);
|
Slog.d(TAG, "onAnimationStart d:" + mDisplayId + " top:"
|
||||||
|
+ imeTop(hiddenY) + "->" + imeTop(shownY)
|
||||||
|
+ " showing:" + (mAnimationDirection == DIRECTION_SHOW));
|
||||||
|
}
|
||||||
|
dispatchStartPositioning(mDisplayId, imeTop(hiddenY),
|
||||||
|
imeTop(shownY), mAnimationDirection == DIRECTION_SHOW,
|
||||||
|
t);
|
||||||
|
if (mAnimationDirection == DIRECTION_SHOW) {
|
||||||
|
t.show(mImeSourceControl.getLeash());
|
||||||
|
}
|
||||||
t.apply();
|
t.apply();
|
||||||
mTransactionPool.release(t);
|
mTransactionPool.release(t);
|
||||||
});
|
|
||||||
mAnimation.setInterpolator(INTERPOLATOR);
|
|
||||||
mAnimation.addListener(new AnimatorListenerAdapter() {
|
|
||||||
private boolean mCancelled = false;
|
|
||||||
@Override
|
|
||||||
public void onAnimationStart(Animator animation) {
|
|
||||||
SurfaceControl.Transaction t = mTransactionPool.acquire();
|
|
||||||
t.setPosition(mImeSourceControl.getLeash(), x, startY);
|
|
||||||
if (DEBUG) {
|
|
||||||
Slog.d(TAG, "onAnimationStart d:" + mDisplayId + " top:"
|
|
||||||
+ imeTop(hiddenY) + "->" + imeTop(shownY)
|
|
||||||
+ " showing:" + (mAnimationDirection == DIRECTION_SHOW));
|
|
||||||
}
|
|
||||||
dispatchStartPositioning(mDisplayId, imeTop(hiddenY),
|
|
||||||
imeTop(shownY), mAnimationDirection == DIRECTION_SHOW,
|
|
||||||
t);
|
|
||||||
if (mAnimationDirection == DIRECTION_SHOW) {
|
|
||||||
t.show(mImeSourceControl.getLeash());
|
|
||||||
}
|
|
||||||
t.apply();
|
|
||||||
mTransactionPool.release(t);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onAnimationCancel(Animator animation) {
|
|
||||||
mCancelled = true;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animator animation) {
|
|
||||||
if (DEBUG) Slog.d(TAG, "onAnimationEnd " + mCancelled);
|
|
||||||
SurfaceControl.Transaction t = mTransactionPool.acquire();
|
|
||||||
if (!mCancelled) {
|
|
||||||
t.setPosition(mImeSourceControl.getLeash(), x, endY);
|
|
||||||
}
|
|
||||||
dispatchEndPositioning(mDisplayId, mCancelled, t);
|
|
||||||
if (mAnimationDirection == DIRECTION_HIDE && !mCancelled) {
|
|
||||||
t.hide(mImeSourceControl.getLeash());
|
|
||||||
}
|
|
||||||
t.apply();
|
|
||||||
mTransactionPool.release(t);
|
|
||||||
|
|
||||||
mAnimationDirection = DIRECTION_NONE;
|
|
||||||
mAnimation = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!show) {
|
|
||||||
// When going away, queue up insets change first, otherwise any bounds changes
|
|
||||||
// can have a "flicker" of ime-provided insets.
|
|
||||||
setVisibleDirectly(false /* visible */);
|
|
||||||
}
|
}
|
||||||
mAnimation.start();
|
@Override
|
||||||
if (show) {
|
public void onAnimationCancel(Animator animation) {
|
||||||
// When showing away, queue up insets change last, otherwise any bounds changes
|
mCancelled = true;
|
||||||
// can have a "flicker" of ime-provided insets.
|
}
|
||||||
setVisibleDirectly(true /* visible */);
|
@Override
|
||||||
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
if (DEBUG) Slog.d(TAG, "onAnimationEnd " + mCancelled);
|
||||||
|
SurfaceControl.Transaction t = mTransactionPool.acquire();
|
||||||
|
if (!mCancelled) {
|
||||||
|
t.setPosition(mImeSourceControl.getLeash(), x, endY);
|
||||||
|
}
|
||||||
|
dispatchEndPositioning(mDisplayId, mCancelled, t);
|
||||||
|
if (mAnimationDirection == DIRECTION_HIDE && !mCancelled) {
|
||||||
|
t.hide(mImeSourceControl.getLeash());
|
||||||
|
}
|
||||||
|
t.apply();
|
||||||
|
mTransactionPool.release(t);
|
||||||
|
|
||||||
|
mAnimationDirection = DIRECTION_NONE;
|
||||||
|
mAnimation = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!show) {
|
||||||
|
// When going away, queue up insets change first, otherwise any bounds changes
|
||||||
|
// can have a "flicker" of ime-provided insets.
|
||||||
|
setVisibleDirectly(false /* visible */);
|
||||||
|
}
|
||||||
|
mAnimation.start();
|
||||||
|
if (show) {
|
||||||
|
// When showing away, queue up insets change last, otherwise any bounds changes
|
||||||
|
// can have a "flicker" of ime-provided insets.
|
||||||
|
setVisibleDirectly(true /* visible */);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user