Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a74dc45 authored by Yigit Boyar's avatar Yigit Boyar Committed by Android (Google) Code Review
Browse files

Merge "Find activity from context in menu inflator for click events" into lmp-dev

parents 6e53b747 b8c19b1b
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -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;
    }
@@ -260,6 +260,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.
     * <p>
@@ -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) {