summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Peeyush Agarwal <apeeyush@google.com> 2016-11-30 15:54:32 +0000
committer Peeyush Agarwal <apeeyush@google.com> 2016-12-14 18:46:39 +0000
commit50db731b546f98d2ba80ced32e4c1218c338f1a3 (patch)
tree49ed31b679c70325953564a3a540a5cd9922338e
parent929a81b81dc5ebdedf0fb4ba0aaa0ba544829304 (diff)
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
-rw-r--r--core/java/android/widget/PopupWindow.java20
1 files changed, 20 insertions, 0 deletions
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;
/**
* <p>
@@ -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<View> 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<KeyboardShortcutGroup> list, int deviceId) {
+ if (mParentRootView != null) {
+ View parentRoot = mParentRootView.get();
+ if (parentRoot != null) {
+ parentRoot.requestKeyboardShortcuts(list, deviceId);
+ }
+ }
+ }
}
private class PopupBackgroundView extends FrameLayout {