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

Commit 4b002d32 authored by Alan Viverette's avatar Alan Viverette
Browse files

Fix action bar menu inflation context

Change-Id: I9da159d7721f41974b711e74edbaba6d6740f183
parent a48e7b55
Loading
Loading
Loading
Loading
+136 −135

File changed.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Diff line number Diff line
@@ -2274,9 +2274,10 @@

  <public type="style" name="ThemeOverlay" />
  <public type="style" name="ThemeOverlay.Quantum" />
  <public type="style" name="ThemeOverlay.Quantum.ActionBar" />
  <public type="style" name="ThemeOverlay.Quantum.Light" />
  <public type="style" name="ThemeOverlay.Quantum.Dark" />
  <public type="style" name="ThemeOverlay.Quantum.ActionBarWidget" />
  <public type="style" name="ThemeOverlay.Quantum.Dark.ActionBar" />

  <public type="style" name="Widget.Quantum" />
  <public type="style" name="Widget.Quantum.ActionBar" />
+14 −7
Original line number Diff line number Diff line
@@ -306,8 +306,8 @@ please see themes_device_defaults.xml.
        <item name="actionBarStyle">@style/Widget.Quantum.ActionBar.Solid</item>
        <item name="actionBarSize">@dimen/action_bar_default_height_quantum</item>
        <item name="actionModePopupWindowStyle">@style/Widget.Quantum.PopupWindow.ActionMode</item>
        <item name="actionBarWidgetTheme">@style/ThemeOverlay.Quantum.ActionBarWidget</item>
        <item name="actionBarTheme">@null</item>
        <item name="actionBarWidgetTheme">@null</item>
        <item name="actionBarTheme">@style/ThemeOverlay.Quantum.ActionBar</item>
        <item name="actionBarItemBackground">?attr/selectableItemBackgroundBorderless</item>

        <item name="actionModeCutDrawable">@drawable/ic_menu_cut_quantum</item>
@@ -652,8 +652,8 @@ please see themes_device_defaults.xml.
        <item name="actionBarStyle">@style/Widget.Quantum.Light.ActionBar.Solid</item>
        <item name="actionBarSize">@dimen/action_bar_default_height_quantum</item>
        <item name="actionModePopupWindowStyle">@style/Widget.Quantum.Light.PopupWindow.ActionMode</item>
        <item name="actionBarWidgetTheme">@style/ThemeOverlay.Quantum.ActionBarWidget</item>
        <item name="actionBarTheme">@null</item>
        <item name="actionBarWidgetTheme">@null</item>
        <item name="actionBarTheme">@style/ThemeOverlay.Quantum.ActionBar</item>
        <item name="actionBarItemBackground">?attr/selectableItemBackgroundBorderless</item>

        <item name="actionModeCutDrawable">@drawable/ic_menu_cut_quantum</item>
@@ -728,8 +728,8 @@ please see themes_device_defaults.xml.
         with an inverse color profile. The dark action bar sharply stands out against
         the light content. -->
    <style name="Theme.Quantum.Light.DarkActionBar">
        <item name="actionBarWidgetTheme">@style/ThemeOverlay.Quantum.ActionBarWidget</item>
        <item name="actionBarTheme">@style/ThemeOverlay.Quantum.Dark</item>
        <item name="actionBarWidgetTheme">@null</item>
        <item name="actionBarTheme">@style/ThemeOverlay.Quantum.Dark.ActionBar</item>
    </style>

    <style name="ThemeOverlay" />
@@ -810,7 +810,14 @@ please see themes_device_defaults.xml.

    <!-- Theme overlay that replaces the normal control color, which by default is the same as the
         secondary text color, with the primary text color. -->
    <style name="ThemeOverlay.Quantum.ActionBarWidget">
    <style name="ThemeOverlay.Quantum.ActionBar">
        <item name="colorControlNormal">?attr/textColorPrimary</item>
    </style>

    <!-- Theme overlay that replaces colors with their dark versions and replaces the normal
         control color, which by default is the same as the secondary text color, with the primary
         text color. -->
    <style name="ThemeOverlay.Quantum.Dark.ActionBar">
        <item name="colorControlNormal">?attr/textColorPrimary</item>
    </style>

+29 −9
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -1159,22 +1160,41 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
    protected boolean initializePanelMenu(final PanelFeatureState st) {
        Context context = getContext();

        // If we have an action bar, initialize the menu with a context themed for it.
        // If we have an action bar, initialize the menu with the right theme. 
        if ((st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_ACTION_BAR) &&
                mDecorContentParent != null) {
            TypedValue outValue = new TypedValue();
            Resources.Theme currentTheme = context.getTheme();
            currentTheme.resolveAttribute(com.android.internal.R.attr.actionBarWidgetTheme,
                    outValue, true);
            final int targetThemeRes = outValue.resourceId;
            // TODO: We should pull the theme directly from the ActionBar.
            final TypedValue outValue = new TypedValue();
            final Theme baseTheme = context.getTheme();
            baseTheme.resolveAttribute(com.android.internal.R.attr.actionBarTheme, outValue, true);

            Theme widgetTheme = null;
            if (outValue.resourceId != 0) {
                widgetTheme = context.getResources().newTheme();
                widgetTheme.setTo(baseTheme);
                widgetTheme.applyStyle(outValue.resourceId, true);
                widgetTheme.resolveAttribute(
                        com.android.internal.R.attr.actionBarWidgetTheme, outValue, true);
            } else {
                baseTheme.resolveAttribute(
                        com.android.internal.R.attr.actionBarWidgetTheme, outValue, true);
            }

            if (targetThemeRes != 0 && context.getThemeResId() != targetThemeRes) {
                context = new ContextThemeWrapper(context, targetThemeRes);
            if (outValue.resourceId != 0) {
                if (widgetTheme == null) {
                    widgetTheme = context.getResources().newTheme();
                    widgetTheme.setTo(baseTheme);
                }
                widgetTheme.applyStyle(outValue.resourceId, true);
            }

        final MenuBuilder menu = new MenuBuilder(context);
            if (widgetTheme != null) {
                context = new ContextThemeWrapper(context, 0);
                context.getTheme().setTo(widgetTheme);
            }
        }

        final MenuBuilder menu = new MenuBuilder(context);
        menu.setCallback(this);
        st.setMenu(menu);