Merge "Fix controlWindowInsets for IME" into rvc-dev

This commit is contained in:
Taran Singh
2020-02-28 19:34:01 +00:00
committed by Android (Google) Code Review
6 changed files with 40 additions and 17 deletions

View File

@@ -16,6 +16,8 @@
package android.view; package android.view;
import static android.view.InsetsController.ANIMATION_TYPE_USER;
import static android.view.InsetsController.AnimationType;
import static android.view.InsetsState.ITYPE_IME; import static android.view.InsetsState.ITYPE_IME;
import android.annotation.Nullable; import android.annotation.Nullable;
@@ -99,9 +101,15 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
} }
@Override @Override
void hide(boolean animationFinished) { void hide(boolean animationFinished, @AnimationType int animationType) {
super.hide(); super.hide();
if (animationFinished) {
if (!animationFinished) {
if (animationType == ANIMATION_TYPE_USER) {
// if controlWindowInsetsAnimation is hiding keyboard.
notifyHidden();
}
} else {
// remove IME surface as IME has finished hide animation. // remove IME surface as IME has finished hide animation.
removeSurface(); removeSurface();
} }
@@ -118,7 +126,8 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
// If we had a request before to show from IME (tracked with mImeRequestedShow), reaching // If we had a request before to show from IME (tracked with mImeRequestedShow), reaching
// this code here means that we now got control, so we can start the animation immediately. // this code here means that we now got control, so we can start the animation immediately.
if (fromIme || mImeRequestedShow) { // If client window is trying to control IME and IME is already visible, it is immediate.
if (fromIme || mImeRequestedShow || mState.getSource(getType()).isVisible()) {
mImeRequestedShow = false; mImeRequestedShow = false;
return ShowResult.SHOW_IMMEDIATELY; return ShowResult.SHOW_IMMEDIATELY;
} }

View File

@@ -16,6 +16,7 @@
package android.view; package android.view;
import static android.view.InsetsController.AnimationType;
import static android.view.InsetsState.ISIDE_BOTTOM; import static android.view.InsetsState.ISIDE_BOTTOM;
import static android.view.InsetsState.ISIDE_FLOATING; import static android.view.InsetsState.ISIDE_FLOATING;
import static android.view.InsetsState.ISIDE_LEFT; import static android.view.InsetsState.ISIDE_LEFT;
@@ -64,10 +65,10 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
private final Insets mShownInsets; private final Insets mShownInsets;
private final Matrix mTmpMatrix = new Matrix(); private final Matrix mTmpMatrix = new Matrix();
private final InsetsState mInitialInsetsState; private final InsetsState mInitialInsetsState;
private final @AnimationType int mAnimationType;
private final @InsetsType int mTypes; private final @InsetsType int mTypes;
private final InsetsAnimationControlCallbacks mController; private final InsetsAnimationControlCallbacks mController;
private final WindowInsetsAnimation mAnimation; private final WindowInsetsAnimation mAnimation;
private final Rect mFrame;
private final boolean mFade; private final boolean mFade;
private Insets mCurrentInsets; private Insets mCurrentInsets;
private Insets mPendingInsets; private Insets mPendingInsets;
@@ -83,7 +84,8 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
InsetsState state, WindowInsetsAnimationControlListener listener, InsetsState state, WindowInsetsAnimationControlListener listener,
@InsetsType int types, @InsetsType int types,
InsetsAnimationControlCallbacks controller, long durationMs, Interpolator interpolator, InsetsAnimationControlCallbacks controller, long durationMs, Interpolator interpolator,
boolean fade, @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation) { boolean fade, @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation,
@AnimationType int animationType) {
mControls = controls; mControls = controls;
mListener = listener; mListener = listener;
mTypes = types; mTypes = types;
@@ -96,12 +98,12 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
null /* typeSideMap */); null /* typeSideMap */);
mShownInsets = calculateInsets(mInitialInsetsState, frame, controls, true /* shown */, mShownInsets = calculateInsets(mInitialInsetsState, frame, controls, true /* shown */,
mTypeSideMap); mTypeSideMap);
mFrame = new Rect(frame);
buildTypeSourcesMap(mTypeSideMap, mSideSourceMap, mControls); buildTypeSourcesMap(mTypeSideMap, mSideSourceMap, mControls);
mAnimation = new WindowInsetsAnimation(mTypes, interpolator, mAnimation = new WindowInsetsAnimation(mTypes, interpolator,
durationMs); durationMs);
mAnimation.setAlpha(getCurrentAlpha()); mAnimation.setAlpha(getCurrentAlpha());
mAnimationType = animationType;
mController.startAnimation(this, listener, types, mAnimation, mController.startAnimation(this, listener, types, mAnimation,
new Bounds(mHiddenInsets, mShownInsets), layoutInsetsDuringAnimation); new Bounds(mHiddenInsets, mShownInsets), layoutInsetsDuringAnimation);
} }
@@ -135,6 +137,10 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
return InsetsState.toInternalType(mTypes).contains(type); return InsetsState.toInternalType(mTypes).contains(type);
} }
@AnimationType int getAnimationType() {
return mAnimationType;
}
@Override @Override
public void setInsetsAndAlpha(Insets insets, float alpha, float fraction) { public void setInsetsAndAlpha(Insets insets, float alpha, float fraction) {
if (mFinished) { if (mFinished) {

View File

@@ -582,7 +582,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
final InsetsAnimationControlImpl controller = new InsetsAnimationControlImpl(controls, final InsetsAnimationControlImpl controller = new InsetsAnimationControlImpl(controls,
frame, mState, listener, typesReady, this, durationMs, interpolator, fade, frame, mState, listener, typesReady, this, durationMs, interpolator, fade,
layoutInsetsDuringAnimation); layoutInsetsDuringAnimation, animationType);
mRunningAnimations.add(new RunningAnimation(controller, animationType)); mRunningAnimations.add(new RunningAnimation(controller, animationType));
mRunningInsetsAnimations.add(controller.getAnimation()); mRunningInsetsAnimations.add(controller.getAnimation());
cancellationSignal.setOnCancelListener(controller::onCancelled); cancellationSignal.setOnCancelListener(controller::onCancelled);
@@ -598,7 +598,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
int typesReady = 0; int typesReady = 0;
boolean imeReady = true; boolean imeReady = true;
for (int i = internalTypes.size() - 1; i >= 0; i--) { for (int i = internalTypes.size() - 1; i >= 0; i--) {
InsetsSourceConsumer consumer = getSourceConsumer(internalTypes.valueAt(i)); final InsetsSourceConsumer consumer = getSourceConsumer(internalTypes.valueAt(i));
boolean show = animationType == ANIMATION_TYPE_SHOW boolean show = animationType == ANIMATION_TYPE_SHOW
|| animationType == ANIMATION_TYPE_USER; || animationType == ANIMATION_TYPE_USER;
boolean canRun = false; boolean canRun = false;
@@ -694,7 +694,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
if (shown) { if (shown) {
showDirectly(controller.getTypes()); showDirectly(controller.getTypes());
} else { } else {
hideDirectly(controller.getTypes(), true /* animationFinished */); hideDirectly(controller.getTypes(), true /* animationFinished */,
controller.getAnimationType());
} }
} }
@@ -852,10 +853,11 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
: LAYOUT_INSETS_DURING_ANIMATION_HIDDEN); : LAYOUT_INSETS_DURING_ANIMATION_HIDDEN);
} }
private void hideDirectly(@InsetsType int types, boolean animationFinished) { private void hideDirectly(
@InsetsType int types, boolean animationFinished, @AnimationType int animationType) {
final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types); final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types);
for (int i = internalTypes.size() - 1; i >= 0; i--) { for (int i = internalTypes.size() - 1; i >= 0; i--) {
getSourceConsumer(internalTypes.valueAt(i)).hide(animationFinished); getSourceConsumer(internalTypes.valueAt(i)).hide(animationFinished, animationType);
} }
} }
@@ -887,8 +889,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
if (layoutDuringAnimation == LAYOUT_INSETS_DURING_ANIMATION_SHOWN) { if (layoutDuringAnimation == LAYOUT_INSETS_DURING_ANIMATION_SHOWN) {
showDirectly(types); showDirectly(types);
} else { } else {
hideDirectly(types, false /* animationFinished */); hideDirectly(types, false /* animationFinished */, controller.getAnimationType());
} }
if (mViewRoot.mView == null) { if (mViewRoot.mView == null) {
return; return;
} }

View File

@@ -16,6 +16,7 @@
package android.view; package android.view;
import static android.view.InsetsController.AnimationType;
import static android.view.InsetsState.toPublicType; import static android.view.InsetsState.toPublicType;
import android.annotation.IntDef; import android.annotation.IntDef;
@@ -57,9 +58,10 @@ public class InsetsSourceConsumer {
protected final InsetsController mController; protected final InsetsController mController;
protected boolean mRequestedVisible; protected boolean mRequestedVisible;
protected final InsetsState mState;
protected final @InternalInsetsType int mType;
private final Supplier<Transaction> mTransactionSupplier; private final Supplier<Transaction> mTransactionSupplier;
private final @InternalInsetsType int mType;
private final InsetsState mState;
private @Nullable InsetsSourceControl mSourceControl; private @Nullable InsetsSourceControl mSourceControl;
private boolean mHasWindowFocus; private boolean mHasWindowFocus;
@@ -135,7 +137,7 @@ public class InsetsSourceConsumer {
setRequestedVisible(false); setRequestedVisible(false);
} }
void hide(boolean animationFinished) { void hide(boolean animationFinished, @AnimationType int animationType) {
hide(); hide();
} }

View File

@@ -123,7 +123,7 @@ public class InsetsAnimationControlImplTest {
mController = new InsetsAnimationControlImpl(controls, mController = new InsetsAnimationControlImpl(controls,
new Rect(0, 0, 500, 500), mInsetsState, mMockListener, systemBars(), new Rect(0, 0, 500, 500), mInsetsState, mMockListener, systemBars(),
mMockController, 10 /* durationMs */, new LinearInterpolator(), mMockController, 10 /* durationMs */, new LinearInterpolator(),
false /* fade */, LAYOUT_INSETS_DURING_ANIMATION_SHOWN); false /* fade */, LAYOUT_INSETS_DURING_ANIMATION_SHOWN, 0 /* animationType */);
} }
@Test @Test

View File

@@ -20,6 +20,8 @@ import static android.app.StatusBarManager.WINDOW_STATE_HIDDEN;
import static android.app.StatusBarManager.WINDOW_STATE_SHOWING; import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
import static android.view.InsetsController.ANIMATION_TYPE_HIDE;
import static android.view.InsetsController.ANIMATION_TYPE_SHOW;
import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_HIDDEN; import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_HIDDEN;
import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_SHOWN; import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_SHOWN;
import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
@@ -354,7 +356,8 @@ class InsetsPolicy {
mListener, typesReady, this, mListener.getDurationMs(), mListener, typesReady, this, mListener.getDurationMs(),
InsetsController.INTERPOLATOR, true, InsetsController.INTERPOLATOR, true,
show ? LAYOUT_INSETS_DURING_ANIMATION_SHOWN show ? LAYOUT_INSETS_DURING_ANIMATION_SHOWN
: LAYOUT_INSETS_DURING_ANIMATION_HIDDEN); : LAYOUT_INSETS_DURING_ANIMATION_HIDDEN,
show ? ANIMATION_TYPE_SHOW : ANIMATION_TYPE_HIDE);
SurfaceAnimationThread.getHandler().post( SurfaceAnimationThread.getHandler().post(
() -> mListener.onReady(mAnimationControl, typesReady)); () -> mListener.onReady(mAnimationControl, typesReady));
} }