summaryrefslogtreecommitdiffstats
path: root/core/java/android/view
diff options
context:
space:
mode:
authorYigit Boyar <yboyar@google.com>2014-09-20 04:46:21 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-09-20 04:46:21 +0000
commit565dc77229361b56727526f0e3b83e55690c1f4f (patch)
tree2b5775a125aa6c1e429b1b7d8c328c6909807fa2 /core/java/android/view
parent2a46170cd62430e01f129b983edc79c6f8566bba (diff)
parent6e6e3fbdb27c679ff146af3fc0fe520a88f4de20 (diff)
downloadframeworks_base-565dc77229361b56727526f0e3b83e55690c1f4f.zip
frameworks_base-565dc77229361b56727526f0e3b83e55690c1f4f.tar.gz
frameworks_base-565dc77229361b56727526f0e3b83e55690c1f4f.tar.bz2
am 3439d367: am 646e0428: Merge "Find activity from context in menu inflator for click events" into lmp-dev
* commit '3439d367f662f84cc26c3e7a0eefb6d5d57be5c0': Find activity from context in menu inflator for click events
Diffstat (limited to 'core/java/android/view')
-rw-r--r--core/java/android/view/MenuInflater.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/core/java/android/view/MenuInflater.java b/core/java/android/view/MenuInflater.java
index 71296fa..5811c17 100644
--- a/core/java/android/view/MenuInflater.java
+++ b/core/java/android/view/MenuInflater.java
@@ -23,6 +23,7 @@ import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.content.Context;
+import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
@@ -74,7 +75,6 @@ public class MenuInflater {
*/
public MenuInflater(Context context) {
mContext = context;
- mRealOwner = context;
mActionViewConstructorArguments = new Object[] {context};
mActionProviderConstructorArguments = mActionViewConstructorArguments;
}
@@ -259,6 +259,23 @@ public class MenuInflater {
}
}
}
+
+ private Object getRealOwner() {
+ if (mRealOwner == null) {
+ mRealOwner = findRealOwner(mContext);
+ }
+ return mRealOwner;
+ }
+
+ private Object findRealOwner(Object owner) {
+ if (owner instanceof Activity) {
+ return owner;
+ }
+ if (owner instanceof ContextWrapper) {
+ return findRealOwner(((ContextWrapper) owner).getBaseContext());
+ }
+ return owner;
+ }
/**
* State for the current menu.
@@ -439,7 +456,7 @@ public class MenuInflater {
+ "be used within a restricted context");
}
item.setOnMenuItemClickListener(
- new InflatedOnMenuItemClickListener(mRealOwner, itemListenerMethodName));
+ new InflatedOnMenuItemClickListener(getRealOwner(), itemListenerMethodName));
}
if (item instanceof MenuItemImpl) {