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

Commit e18b1865 authored by Josh Guilfoyle's avatar Josh Guilfoyle
Browse files

ESPRESSO-823: Removing menu theme attrs.

This functionality is being preserved by using dynamic lookup of a new
category of attributes named as com_tmobile_framework_*.

CR: Dirk Sigurdson
parent c252429e
Loading
Loading
Loading
Loading
+36 −26
Original line number Diff line number Diff line
@@ -76,6 +76,16 @@ public class MenuBuilder implements Menu {
        0,
    };

    /**
     * Added by T-Mobile to allow dynamic lookup of the menu style based on the
     * currently applied global theme.  Must be ordered to match {@link #THEME_RES_FOR_TYPE}.
     */
    static final String THEME_ATTR_FOR_TYPE[] = new String[] {
        "com_tmobile_framework_iconMenuTheme",
        "com_tmobile_framework_expandedMenuTheme",
        null,
    };
    
    // Order must be the same order as the TYPE_*
    static final int LAYOUT_RES_FOR_TYPE[] = new int[] {
        com.android.internal.R.layout.icon_menu_layout,
@@ -177,22 +187,9 @@ public class MenuBuilder implements Menu {
        LayoutInflater getInflater() {
            // Create an inflater that uses the given theme for the Views it inflates
            if (mInflater == null) {
                Context wrappedContext = null;
                // We theme expanded menu view only for now.
                if (mMenuType == TYPE_EXPANDED) {
                    wrappedContext = new ContextThemeWrapper(getContext(), 
                            resolveDefaultTheme(getContext(), 0, 
                                    com.android.internal.R.styleable.Theme_expandedMenuTheme, 
                                    com.android.internal.R.style.Theme_ExpandedMenu));
                } else if (mMenuType == TYPE_ICON) {
                    wrappedContext = new ContextThemeWrapper(getContext(),
                            resolveDefaultTheme(getContext(), 0, 
                                    com.android.internal.R.styleable.Theme_iconMenuTheme, 
                                    com.android.internal.R.style.Theme_IconMenu));    
                } else {
                    wrappedContext = new ContextThemeWrapper(getContext(),
                            THEME_RES_FOR_TYPE[mMenuType]);
                }
                Context wrappedContext = new ContextThemeWrapper(getContext(),
                        resolveDefaultTheme(getContext(), THEME_ATTR_FOR_TYPE[mMenuType],
                                THEME_RES_FOR_TYPE[mMenuType]));
                mInflater = (LayoutInflater) wrappedContext
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            }
@@ -233,18 +230,31 @@ public class MenuBuilder implements Menu {
            return mMenuView != null && mMenuView.get() != null;
        }

        int resolveDefaultTheme(Context context, int theme, int themeAttrIndex,
                int defStyle) {
            if (theme != 0) {
                return theme;
            } else {
                TypedArray a = context.obtainStyledAttributes(android.R.styleable.Theme);
                int newTheme = a.getResourceId(themeAttrIndex, defStyle);
        /**
         * Dynamically search for a suitable menu theme based on the menu type
         * and the currently applied global theme.
         * 
         * @param themeAttrName Attribute name to search for dynamically in the
         *            current theme. Should be a reference to a style.
         * @param fallbackStyleId Hardcoded Android style to fallback to if the
         *            theme provides no value.
         * @return Style id pointing to the theme chosen.
         */
        int resolveDefaultTheme(Context context, String themeAttrName, int fallbackStyleId) {
            if (themeAttrName != null) {
                int attrId = Utils.resolveDefaultStyleAttr(context, themeAttrName, 0);
                if (attrId != 0) {
                    TypedArray a = context.obtainStyledAttributes(new int[] { attrId });
                    try {
                        return a.getResourceId(0, fallbackStyleId);
                    } finally {
                        a.recycle();
                return newTheme;
                    }
                }
            }
            return fallbackStyleId;
        }
    }
    
    /**
     * Called by menu to notify of close and selection changes
+73 −0
Original line number Diff line number Diff line
package com.android.internal.view.menu;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

/**
 * This class was partially copied from com.tmobile.widget.Utils.  Copied here
 * to avoid a bizarre framework dependency on a platform library provided by
 * T-Mobile.
 */
public class Utils {
    /**
     * Alternative to {@link #resolveDefaultStyleAttr(Context, String)} which
     * allows you to specify a resource id for fallback. This is merely an
     * optimization which avoids by name lookup in the current application
     * package scope.
     *
     * @param context
     * @param attrName Attribute name in the currently applied theme.
     * @param fallbackAttrId Attribute id to return if the currently applied
     *            theme does not specify the supplied <code>attrName</code>.
     * @see #resolveDefaultStyleAttr(Context, String)
     */
    public static int resolveDefaultStyleAttr(Context context, String attrName,
            int fallbackAttrId) {
        /* First try to resolve in the currently applied global theme. */
        int attrId = getThemeStyleAttr(context, attrName);
        if (attrId != 0) {
            return attrId;
        }
        /* Fallback to the provided value. */
        return fallbackAttrId;
    }

    /**
     * Dynamically resolve the supplied attribute name within the theme or
     * application scope. First looks at the currently applied global theme,
     * then fallbacks to the current application package.
     *
     * @param context
     * @param attrName Attribute name in the currently applied theme.
     * @return the attribute id suitable for passing to a View's constructor or
     *         0 if neither are provided.
     * @see View#View(Context, android.util.AttributeSet, int)
     */
    public static int resolveDefaultStyleAttr(Context context, String attrName) {
        /* First try to resolve in the currently applied global theme. */
        int attrId = resolveDefaultStyleAttr(context, attrName, 0);
        if (attrId != 0) {
            return attrId;
        }
        /* Then try to lookup in the application's package. */
        return context.getResources().getIdentifier(attrName, "attr",
                context.getPackageName());
    }

    private static int getThemeStyleAttr(Context context, String attrName) {
        String themePackage = getCurrentThemePackage(context);
        if (themePackage == null) {
            return 0;
        }
        return context.getResources().getIdentifier(attrName, "attr", themePackage);
    }

    private static String getCurrentThemePackage(Context context) {
        String themePackage = context.getResources().getAssets().getThemePackageName();
        if (TextUtils.isEmpty(themePackage)) {
            return null;
        }
        return themePackage;
    }
}
+0 −7
Original line number Diff line number Diff line
@@ -301,13 +301,6 @@
             because there will be no such interaction coming. -->
        <attr name="windowNoDisplay" format="boolean" />

        <!-- ============ -->
        <!-- Menu theme -->
        <!-- ============ -->
        <eat-comment />
        <attr name="iconMenuTheme" format="reference" />
        <attr name="expandedMenuTheme" format="reference" />
        
        <!-- ============ -->
        <!-- Alert Dialog styles -->
        <!-- ============ -->
+0 −3
Original line number Diff line number Diff line
@@ -1225,9 +1225,6 @@
     =============================================================== -->
  <eat-comment />

  <public type="attr" name="expandedMenuTheme" id="0x010102c1" />
  <public type="attr" name="iconMenuTheme" />

  <!-- The following have been temporarily added here to avoid any accidental
       modifications to R.attr and R.id.  Will be removed shortly. -->
  <eat-comment />
+0 −4
Original line number Diff line number Diff line
@@ -119,10 +119,6 @@
        <!-- Dialog attributes -->
        <item name="alertDialogStyle">@android:style/AlertDialog</item>
        
        <!-- Menu attributes -->
        <item name="iconMenuTheme">@android:style/Theme.IconMenu</item>
        <item name="expandedMenuTheme">@android:style/Theme.ExpandedMenu</item>
        
        <!-- Panel attributes -->
        <item name="panelBackground">@android:drawable/menu_background</item>
        <item name="panelFullBackground">@android:drawable/menu_background_fill_parent_width</item>