From 5702d4dfb5b81491f873a3617f8d8fc8dc5279e6 Mon Sep 17 00:00:00 2001 From: Craig Mautner Date: Sat, 30 Jun 2012 14:10:16 -0700 Subject: Notify client side of window movement. Add a one way method to notify Views that the window has moved on the screen. Fixes issues arising from the IME popping up and translating the window that uses it. Accessibility was left unaware of these movements and was drawing the box around the wrong widgets. Similarly PopupWindow used getLocationOnScreen to determine how much screen real estate was above and below the anchor point to determine where to put an anchored window. Fixes bug 6623031. Change-Id: I4731a94d5424c1ec77bf1729fba8fc9ea34cae46 --- core/java/android/view/ViewRootImpl.java | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'core/java/android/view/ViewRootImpl.java') diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 17783a49c9ea..97488bc930d8 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -2724,6 +2724,7 @@ public final class ViewRootImpl implements ViewParent, private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 22; private final static int MSG_DISPATCH_DONE_ANIMATING = 23; private final static int MSG_INVALIDATE_WORLD = 24; + private final static int MSG_WINDOW_MOVED = 25; final class ViewRootHandler extends Handler { @Override @@ -2775,6 +2776,8 @@ public final class ViewRootImpl implements ViewParent, return "MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST"; case MSG_DISPATCH_DONE_ANIMATING: return "MSG_DISPATCH_DONE_ANIMATING"; + case MSG_WINDOW_MOVED: + return "MSG_WINDOW_MOVED"; } return super.getMessageName(message); } @@ -2819,6 +2822,7 @@ public final class ViewRootImpl implements ViewParent, if (config != null) { updateConfiguration(config, false); } + // TODO: Should left/top stay unchanged and only change the right/bottom? mWinFrame.left = 0; mWinFrame.right = msg.arg1; mWinFrame.top = 0; @@ -2835,6 +2839,23 @@ public final class ViewRootImpl implements ViewParent, requestLayout(); } break; + case MSG_WINDOW_MOVED: + if (mAdded) { + final int w = mWinFrame.width(); + final int h = mWinFrame.height(); + final int l = msg.arg1; + final int t = msg.arg2; + mWinFrame.left = l; + mWinFrame.right = l + w; + mWinFrame.top = t; + mWinFrame.bottom = t + h; + + if (mView != null) { + forceLayout(mView); + } + requestLayout(); + } + break; case MSG_WINDOW_FOCUS_CHANGED: { if (mAdded) { boolean hasWindowFocus = msg.arg1 != 0; @@ -4054,6 +4075,18 @@ public final class ViewRootImpl implements ViewParent, mHandler.sendMessage(msg); } + public void dispatchMoved(int newX, int newY) { + if (DEBUG_LAYOUT) Log.v(TAG, "Window moved " + this + ": newX=" + newX + " newY=" + newY); + if (mTranslator != null) { + PointF point = new PointF(newX, newY); + mTranslator.translatePointInScreenToAppWindow(point); + newX = (int) (point.x + 0.5); + newY = (int) (point.y + 0.5); + } + Message msg = mHandler.obtainMessage(MSG_WINDOW_MOVED, newX, newY); + mHandler.sendMessage(msg); + } + /** * Represents a pending input event that is waiting in a queue. * @@ -4693,6 +4726,14 @@ public final class ViewRootImpl implements ViewParent, } } + @Override + public void moved(int newX, int newY) { + final ViewRootImpl viewAncestor = mViewAncestor.get(); + if (viewAncestor != null) { + viewAncestor.dispatchMoved(newX, newY); + } + } + public void dispatchAppVisibility(boolean visible) { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { -- cgit v1.2.3