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

Commit 88ab6978 authored by Adam Powell's avatar Adam Powell
Browse files

Fix bug 5087752 - Maintain correct contrast against action bars in

inverse-bar themes

Add the actionBarWidgetTheme theme attribute. This lets a theme
specify a wrapper theme that can be used to create views that will
end up in the action bar so that the rest of the code can ignore
differences in contrast. (e.g. the inverse action bar themes.)

Apps can use ActionBar#getThemedContext() to obtain a Context with a
proper theme for views that will end up in the action
bar. MenuInflaters generated by Activities will automatically use this
to properly theme inflated action views.

Change-Id: Ib28c82bf47c25d446cca2a63f617b8a4a0afa6b2
parent b03c4af0
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -198,6 +198,7 @@ package android {
    field public static final int actionBarTabBarStyle = 16843508; // 0x10102f4
    field public static final int actionBarTabStyle = 16843507; // 0x10102f3
    field public static final int actionBarTabTextStyle = 16843509; // 0x10102f5
    field public static final int actionBarWidgetTheme = 16843683; // 0x10103a3
    field public static final int actionButtonStyle = 16843480; // 0x10102d8
    field public static final int actionDropDownStyle = 16843479; // 0x10102d7
    field public static final int actionLayout = 16843515; // 0x10102fb
@@ -2243,6 +2244,7 @@ package android.app {
    method public abstract java.lang.CharSequence getSubtitle();
    method public abstract android.app.ActionBar.Tab getTabAt(int);
    method public abstract int getTabCount();
    method public android.content.Context getThemedContext();
    method public abstract java.lang.CharSequence getTitle();
    method public abstract void hide();
    method public abstract boolean isShowing();
@@ -2263,7 +2265,7 @@ package android.app {
    method public abstract void setDisplayShowHomeEnabled(boolean);
    method public abstract void setDisplayShowTitleEnabled(boolean);
    method public abstract void setDisplayUseLogoEnabled(boolean);
    method public abstract void setHomeButtonEnabled(boolean);
    method public void setHomeButtonEnabled(boolean);
    method public abstract void setIcon(int);
    method public abstract void setIcon(android.graphics.drawable.Drawable);
    method public abstract void setListNavigationCallbacks(android.widget.SpinnerAdapter, android.app.ActionBar.OnNavigationListener);
+12 −1
Original line number Diff line number Diff line
@@ -627,7 +627,18 @@ public abstract class ActionBar {
     *
     * @param enabled true to enable the home button, false to disable the home button.
     */
    public abstract void setHomeButtonEnabled(boolean enabled);
    public void setHomeButtonEnabled(boolean enabled) { }

    /**
     * Returns a {@link Context} with an appropriate theme for creating views that
     * will appear in the action bar. If you are inflating or instantiating custom views
     * that will appear in an action bar, you should use the Context returned by this method.
     * (This includes adapters used for list navigation mode.)
     * This will ensure that views contrast properly against the action bar.
     *
     * @return A themed Context for creating views
     */
    public Context getThemedContext() { return null; }

    /**
     * Listener interface for ActionBar navigation events.
+13 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.Resources.Theme;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -54,6 +55,7 @@ import android.util.AttributeSet;
import android.util.EventLog;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.ActionMode;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@@ -672,6 +674,7 @@ public class Activity extends ContextThemeWrapper
    /*package*/ int mConfigChangeFlags;
    /*package*/ Configuration mCurrentConfig;
    private SearchManager mSearchManager;
    private MenuInflater mMenuInflater;

    static final class NonConfigurationInstances {
        Object activity;
@@ -3083,7 +3086,16 @@ public class Activity extends ContextThemeWrapper
     * Returns a {@link MenuInflater} with this context.
     */
    public MenuInflater getMenuInflater() {
        return new MenuInflater(this);
        // Make sure that action views can get an appropriate theme.
        if (mMenuInflater == null) {
            initActionBar();
            if (mActionBar != null) {
                mMenuInflater = new MenuInflater(mActionBar.getThemedContext());
            } else {
                mMenuInflater = new MenuInflater(this);
            }
        }
        return mMenuInflater;
    }

    @Override
+21 −0
Original line number Diff line number Diff line
@@ -35,10 +35,13 @@ import android.app.Dialog;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.util.TypedValue;
import android.view.ActionMode;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -61,6 +64,7 @@ public class ActionBarImpl extends ActionBar {
    private static final String TAG = "ActionBarImpl";

    private Context mContext;
    private Context mThemedContext;
    private Activity mActivity;
    private Dialog mDialog;

@@ -605,6 +609,23 @@ public class ActionBarImpl extends ActionBar {
        }
    }

    public Context getThemedContext() {
        if (mThemedContext == null) {
            TypedValue outValue = new TypedValue();
            Resources.Theme currentTheme = mContext.getTheme();
            currentTheme.resolveAttribute(com.android.internal.R.attr.actionBarWidgetTheme,
                    outValue, true);
            final int targetThemeRes = outValue.resourceId;
            
            if (targetThemeRes != 0 && mContext.getThemeResId() != targetThemeRes) {
                mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
            } else {
                mThemedContext = mContext;
            }
        }
        return mThemedContext;
    }
    
    /**
     * @hide 
     */
+8 −0
Original line number Diff line number Diff line
@@ -616,6 +616,14 @@
             buttons. actionBarStyle is still used for the primary
             bar. -->
        <attr name="actionBarSplitStyle" format="reference" />
        <!-- Reference to a theme that should be used to inflate widgets
             and layouts destined for the action bar. Most of the time
             this will be a reference to the current theme, but when
             the action bar has a significantly different contrast
             profile than the rest of the activity the difference
             can become important. If this is set to @null the current
             theme will be used.-->
        <attr name="actionBarWidgetTheme" format="reference" />
        <!-- Size of the Action Bar, including the contextual
             bar used to present Action Modes. -->
        <attr name="actionBarSize" format="dimension" >
Loading