Merge "Make canBeImeTarget be compatible with legacy behavior" into rvc-dev

This commit is contained in:
Tiger Huang
2020-03-25 17:36:56 +00:00
committed by Android (Google) Code Review
4 changed files with 19 additions and 16 deletions

View File

@@ -1249,6 +1249,7 @@ public class InputMethodService extends AbstractInputMethodService {
WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.BOTTOM, false); WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.BOTTOM, false);
mWindow.getWindow().getAttributes().setFitInsetsTypes(statusBars() | navigationBars()); mWindow.getWindow().getAttributes().setFitInsetsTypes(statusBars() | navigationBars());
mWindow.getWindow().getAttributes().setFitInsetsSides(Side.all() & ~Side.BOTTOM); mWindow.getWindow().getAttributes().setFitInsetsSides(Side.all() & ~Side.BOTTOM);
mWindow.getWindow().getAttributes().setFitInsetsIgnoringVisibility(true);
// IME layout should always be inset by navigation bar, no matter its current visibility, // IME layout should always be inset by navigation bar, no matter its current visibility,
// unless automotive requests it, since automotive may hide the navigation bar. // unless automotive requests it, since automotive may hide the navigation bar.

View File

@@ -20,6 +20,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Handler; import android.os.Handler;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Slog; import android.util.Slog;
@@ -97,7 +98,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
} }
if (mSystemWindows.mDisplayController.getDisplayLayout(displayId).rotation() if (mSystemWindows.mDisplayController.getDisplayLayout(displayId).rotation()
!= pd.mRotation && isImeShowing(displayId)) { != pd.mRotation && isImeShowing(displayId)) {
pd.startAnimation(true); pd.startAnimation(true, false /* forceRestart */);
} }
} }
@@ -200,7 +201,15 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
continue; continue;
} }
if (activeControl.getType() == InsetsState.ITYPE_IME) { if (activeControl.getType() == InsetsState.ITYPE_IME) {
mHandler.post(() -> {
final Point lastSurfacePosition = mImeSourceControl != null
? mImeSourceControl.getSurfacePosition() : null;
mImeSourceControl = activeControl; mImeSourceControl = activeControl;
if (!activeControl.getSurfacePosition().equals(lastSurfacePosition)
&& mAnimation != null) {
startAnimation(mImeShowing, true /* forceRestart */);
}
});
} }
} }
} }
@@ -212,7 +221,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 */); startAnimation(true /* show */, false /* forceRestart */);
} }
@Override @Override
@@ -221,7 +230,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 */); startAnimation(false /* show */, false /* forceRestart */);
} }
/** /**
@@ -239,7 +248,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
return imeSource.getFrame().top + (int) surfaceOffset; return imeSource.getFrame().top + (int) surfaceOffset;
} }
private void startAnimation(final boolean show) { private void startAnimation(final boolean show, final boolean forceRestart) {
final InsetsSource imeSource = mInsetsState.getSource(InsetsState.ITYPE_IME); final InsetsSource imeSource = mInsetsState.getSource(InsetsState.ITYPE_IME);
if (imeSource == null || mImeSourceControl == null) { if (imeSource == null || mImeSourceControl == null) {
return; return;
@@ -250,7 +259,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
+ (mAnimationDirection == DIRECTION_SHOW ? "SHOW" + (mAnimationDirection == DIRECTION_SHOW ? "SHOW"
: (mAnimationDirection == DIRECTION_HIDE ? "HIDE" : "NONE"))); : (mAnimationDirection == DIRECTION_HIDE ? "HIDE" : "NONE")));
} }
if ((mAnimationDirection == DIRECTION_SHOW && show) if (!forceRestart && (mAnimationDirection == DIRECTION_SHOW && show)
|| (mAnimationDirection == DIRECTION_HIDE && !show)) { || (mAnimationDirection == DIRECTION_HIDE && !show)) {
return; return;
} }
@@ -270,11 +279,6 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
final float shownY = defaultY; final float shownY = defaultY;
final float startY = show ? hiddenY : shownY; final float startY = show ? hiddenY : shownY;
final float endY = show ? shownY : hiddenY; final float endY = show ? shownY : hiddenY;
if (mImeShowing && show) {
// IME is already showing, so set seek to end
seekValue = shownY;
seek = true;
}
mImeShowing = show; mImeShowing = show;
mAnimation = ValueAnimator.ofFloat(startY, endY); mAnimation = ValueAnimator.ofFloat(startY, endY);
mAnimation.setDuration( mAnimation.setDuration(

View File

@@ -2275,9 +2275,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
return false; return false;
} }
if (PixelFormat.formatHasAlpha(mAttrs.format) && mAttrs.alpha == 0) { if (PixelFormat.formatHasAlpha(mAttrs.format)) {
// Support legacy use cases where completely transparent windows can still be ime target // Support legacy use cases where transparent windows can still be ime target with
// with FLAG_NOT_FOCUSABLE and ALT_FOCUSABLE_IM set. // FLAG_NOT_FOCUSABLE and ALT_FOCUSABLE_IM set.
// Certain apps listen for IME insets using transparent windows and ADJUST_NOTHING to // Certain apps listen for IME insets using transparent windows and ADJUST_NOTHING to
// manually synchronize app content to IME animation b/144619551. // manually synchronize app content to IME animation b/144619551.
// TODO(b/145812508): remove this once new focus management is complete b/141738570 // TODO(b/145812508): remove this once new focus management is complete b/141738570

View File

@@ -251,11 +251,9 @@ public class WindowStateTests extends WindowTestsBase {
// b/145812508: special legacy use-case for transparent/translucent windows. // b/145812508: special legacy use-case for transparent/translucent windows.
appWindow.mAttrs.format = PixelFormat.TRANSPARENT; appWindow.mAttrs.format = PixelFormat.TRANSPARENT;
appWindow.mAttrs.alpha = 0;
assertTrue(appWindow.canBeImeTarget()); assertTrue(appWindow.canBeImeTarget());
appWindow.mAttrs.format = PixelFormat.OPAQUE; appWindow.mAttrs.format = PixelFormat.OPAQUE;
appWindow.mAttrs.alpha = 1;
appWindow.mAttrs.flags &= ~FLAG_ALT_FOCUSABLE_IM; appWindow.mAttrs.flags &= ~FLAG_ALT_FOCUSABLE_IM;
assertFalse(appWindow.canBeImeTarget()); assertFalse(appWindow.canBeImeTarget());
appWindow.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE; appWindow.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE;