From 50db731b546f98d2ba80ced32e4c1218c338f1a3 Mon Sep 17 00:00:00 2001 From: Peeyush Agarwal Date: Wed, 30 Nov 2016 15:54:32 +0000 Subject: Implement requestKeyboardShortcuts for PopupDecorView A call to requestKeyboardShortcuts from popup menu might be dispatched to PopupDecorView or DecorView depending on WindowManagerService's focusedWindow at that moment. In case it gets dispatched to PopupDecorView, we would like to resend it to parent activity's decor view (which can then handle it appropriately). The change adds a notion of mParentRootView which keeps track of popup's parent's decor view. The request is then routed appropriately so as to display the corresponding shortcuts. mAnchor cannot be used as it gets nulled (by dismiss) by the time requestKeyboardShortcuts gets called. Bug: 31850671 Change-Id: I0ee3a1c7801c6d3fce8748bc7513382f250c5c63 Fixes: 31850671 Test: cts-tradefed run cts-dev -m CtsAppTestCases -t android.app.cts.ActivityKeyboardShortcutsTest#testRequestShowKeyboardShortcuts --- core/java/android/widget/PopupWindow.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index fc1520b84259..1de7eafa4b07 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -42,6 +42,7 @@ import android.transition.TransitionSet; import android.util.AttributeSet; import android.view.Gravity; import android.view.KeyEvent; +import android.view.KeyboardShortcutGroup; import android.view.MotionEvent; import android.view.View; import android.view.View.OnAttachStateChangeListener; @@ -57,6 +58,7 @@ import android.view.WindowManager.LayoutParams; import com.android.internal.R; import java.lang.ref.WeakReference; +import java.util.List; /** *

@@ -139,6 +141,12 @@ public class PopupWindow { private Context mContext; private WindowManager mWindowManager; + /** + * Keeps track of popup's parent's decor view. This is needed to dispatch + * requestKeyboardShortcuts to the owning Activity. + */ + private WeakReference mParentRootView; + private boolean mIsShowing; private boolean mIsTransitioningToDismiss; private boolean mIsDropdown; @@ -1119,6 +1127,7 @@ public class PopupWindow { * @param y the popup's y location offset */ public void showAtLocation(View parent, int gravity, int x, int y) { + mParentRootView = new WeakReference<>(parent.getRootView()); showAtLocation(parent.getWindowToken(), gravity, x, y); } @@ -2229,6 +2238,7 @@ public class PopupWindow { mAnchor = new WeakReference<>(anchor); mAnchorRoot = new WeakReference<>(anchorRoot); mIsAnchorRootAttached = anchorRoot.isAttachedToWindow(); + mParentRootView = mAnchorRoot; mAnchorXoff = xoff; mAnchorYoff = yoff; @@ -2414,6 +2424,16 @@ public class PopupWindow { TransitionManager.endTransitions(PopupDecorView.this); } }; + + @Override + public void requestKeyboardShortcuts(List list, int deviceId) { + if (mParentRootView != null) { + View parentRoot = mParentRootView.get(); + if (parentRoot != null) { + parentRoot.requestKeyboardShortcuts(list, deviceId); + } + } + } } private class PopupBackgroundView extends FrameLayout { -- cgit v1.2.3-59-g8ed1b