DO NOT MERGE : Backport I5723f627ce323b0d12b Reduce window resizing during IME transition
Bug: 5137498
Change-Id: Ieb8fd700d193eddaa31b0c5ebd8c7f7885586372
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java
index 94762b9..6df0bcc 100644
--- a/core/java/android/view/WindowManagerPolicy.java
+++ b/core/java/android/view/WindowManagerPolicy.java
@@ -1090,6 +1090,13 @@
public void stopScreenSaver();
/**
+ * Set the last used input method window state. This state is used to make IME transition
+ * smooth.
+ * @hide
+ */
+ public void setLastInputMethodWindowLw(WindowState ime, WindowState target);
+
+ /**
* Print the WindowManagerPolicy's state into the given stream.
*
* @param prefix Text to print at the front of each line.
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index d9a5e5f..82783f9 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -323,6 +323,8 @@
volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
boolean mPendingPowerKeyUpCanceled;
Handler mHandler;
+ WindowState mLastInputMethodWindow = null;
+ WindowState mLastInputMethodTargetWindow = null;
static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
@@ -2397,6 +2399,14 @@
if (win == mStatusBar || win == mNavigationBar) {
return;
}
+ final boolean needsToOffsetInputMethodTarget =
+ (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
+ if (needsToOffsetInputMethodTarget) {
+ if (DEBUG_LAYOUT) {
+ Slog.i(TAG, "Offset ime target window by the last ime window state");
+ }
+ offsetInputMethodWindowLw(mLastInputMethodWindow);
+ }
final int fl = attrs.flags;
final int sim = attrs.softInputMode;
@@ -2674,22 +2684,27 @@
// Dock windows carve out the bottom of the screen, so normal windows
// can't appear underneath them.
if (attrs.type == TYPE_INPUT_METHOD && !win.getGivenInsetsPendingLw()) {
- int top = win.getContentFrameLw().top;
- top += win.getGivenContentInsetsLw().top;
- if (mContentBottom > top) {
- mContentBottom = top;
- }
- top = win.getVisibleFrameLw().top;
- top += win.getGivenVisibleInsetsLw().top;
- if (mCurBottom > top) {
- mCurBottom = top;
- }
- if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom="
- + mDockBottom + " mContentBottom="
- + mContentBottom + " mCurBottom=" + mCurBottom);
+ setLastInputMethodWindowLw(null, null);
+ offsetInputMethodWindowLw(win);
}
}
+ private void offsetInputMethodWindowLw(WindowState win) {
+ int top = win.getContentFrameLw().top;
+ top += win.getGivenContentInsetsLw().top;
+ if (mContentBottom > top) {
+ mContentBottom = top;
+ }
+ top = win.getVisibleFrameLw().top;
+ top += win.getGivenVisibleInsetsLw().top;
+ if (mCurBottom > top) {
+ mCurBottom = top;
+ }
+ if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom="
+ + mDockBottom + " mContentBottom="
+ + mContentBottom + " mCurBottom=" + mCurBottom);
+ }
+
/** {@inheritDoc} */
@Override
public void finishLayoutLw() {
@@ -4186,6 +4201,12 @@
return mHasNavigationBar;
}
+ @Override
+ public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
+ mLastInputMethodWindow = ime;
+ mLastInputMethodTargetWindow = target;
+ }
+
public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
pw.print(" mSystemReady="); pw.print(mSystemReady);
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 28fca69..4021d3d 100755
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -2262,6 +2262,7 @@
boolean imMayMove = true;
if (attrs.type == TYPE_INPUT_METHOD) {
+ win.mGivenInsetsPending = true;
mInputMethodWindow = win;
addInputMethodWindowToListLocked(win);
imMayMove = false;
@@ -3422,6 +3423,9 @@
synchronized(mWindowMap) {
WindowToken wtoken = mTokenMap.remove(token);
if (wtoken != null) {
+ if (wtoken.windowType == TYPE_INPUT_METHOD && mInputMethodWindow != null) {
+ mPolicy.setLastInputMethodWindowLw(mInputMethodWindow, mInputMethodTarget);
+ }
boolean delayed = false;
if (!wtoken.hidden) {
wtoken.hidden = true;