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

Commit dbbe63a9 authored by Josh Guilfoyle's avatar Josh Guilfoyle Committed by Josh Guilfoyle
Browse files

Reverted dynamic menu theme hack.

This hack is no longer necessary with the new theme engine design.

Change-Id: I2b74cfa8233fe761725a0621981fea606103c7ac
parent 90c4a873
Loading
Loading
Loading
Loading
+0 −89
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010, T-Mobile USA, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.util;

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

/**
 * This class was modified from com.tmobile.themehelper.ThemeUtilities.
 * Modifications made to improve performance by assuming that the theme-specific
 * APIs are present (and therefore reflection is not necessary).
 */
public class ThemeUtilities {
    /**
     * 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;
    }
}
+2 −42
Original line number Diff line number Diff line
/*
 * Copyright (C) 2006 The Android Open Source Project
 * This code has been modified.  Portions copyright (C) 2010, T-Mobile USA, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -18,8 +17,6 @@
package com.android.internal.view.menu;


import com.android.internal.util.ThemeUtilities;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -27,7 +24,6 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
@@ -79,16 +75,6 @@ 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,
@@ -190,9 +176,8 @@ 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 = new ContextThemeWrapper(getContext(),
                        resolveDefaultTheme(getContext(), THEME_ATTR_FOR_TYPE[mMenuType],
                                THEME_RES_FOR_TYPE[mMenuType]));
                Context wrappedContext = new ContextThemeWrapper(mContext,
                        THEME_RES_FOR_TYPE[mMenuType]); 
                mInflater = (LayoutInflater) wrappedContext
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            }
@@ -232,31 +217,6 @@ public class MenuBuilder implements Menu {
        boolean hasMenuView() {
            return mMenuView != null && mMenuView.get() != null;
        }

        /**
         * 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 = ThemeUtilities.resolveDefaultStyleAttr(context, themeAttrName, 0);
                if (attrId != 0) {
                    TypedArray a = context.obtainStyledAttributes(new int[] { attrId });
                    try {
                        return a.getResourceId(0, fallbackStyleId);
                    } finally {
                        a.recycle();
                    }
                }
            }
            return fallbackStyleId;
        }
    }
    
    /**