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

Commit ada85905 authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

Fix AppCompat action bar theming.

Use themed context to inflate the action bar when AppCompat is used.
Also fix minor issues exposed as a result.

 - Set project callback when LayoutInflater is created by
   LayoutInflater.from(context).
 - Remove duplication of code to get base context from context wrapper.

Bug: http://b.android.com/159711
Change-Id: I379ba2ba71c0ef547460987c3aa5db521c7de967
parent 2e4d9324
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ import android.util.AttributeSet;

import java.io.File;

import static com.android.layoutlib.bridge.android.BridgeContext.getBaseContext;

/**
 * Custom implementation of {@link LayoutInflater} to handle custom views.
 */
@@ -56,8 +58,13 @@ public final class BridgeInflater extends LayoutInflater {

    protected BridgeInflater(LayoutInflater original, Context newContext) {
        super(original, newContext);
        newContext = getBaseContext(newContext);
        if (newContext instanceof BridgeContext) {
            mProjectCallback = ((BridgeContext) newContext).getProjectCallback();
        } else {
            mProjectCallback = null;
        }
    }

    /**
     * Instantiate a new BridgeInflater with an {@link IProjectCallback} object.
@@ -151,9 +158,7 @@ public final class BridgeInflater extends LayoutInflater {
    @Override
    public View inflate(int resource, ViewGroup root) {
        Context context = getContext();
        while (context instanceof ContextThemeWrapper) {
            context = ((ContextThemeWrapper) context).getBaseContext();
        }
        context = getBaseContext(context);
        if (context instanceof BridgeContext) {
            BridgeContext bridgeContext = (BridgeContext)context;

@@ -217,9 +222,7 @@ public final class BridgeInflater extends LayoutInflater {

    private void setupViewInContext(View view, AttributeSet attrs) {
        Context context = getContext();
        while (context instanceof ContextThemeWrapper) {
            context = ((ContextThemeWrapper) context).getBaseContext();
        }
        context = getBaseContext(context);
        if (context instanceof BridgeContext) {
            BridgeContext bc = (BridgeContext) context;
            // get the view key
+1 −3
Original line number Diff line number Diff line
@@ -48,9 +48,7 @@ public class MenuInflater_Delegate {
            AttributeSet attrs) {
        if (menuItem instanceof BridgeMenuItemImpl) {
            Context context = thisInflater.getContext();
            while (context instanceof ContextThemeWrapper) {
                context = ((ContextThemeWrapper) context).getBaseContext();
            }
            context = BridgeContext.getBaseContext(context);
            if (context instanceof BridgeContext) {
                Object viewKey = BridgeInflater.getViewKeyFromParser(
                        attrs, ((BridgeContext) context), null, false);
+1 −3
Original line number Diff line number Diff line
@@ -122,9 +122,7 @@ public class ViewGroup_Delegate {
    @NonNull
    private static DisplayMetrics getMetrics(View view) {
        Context context = view.getContext();
        while (context instanceof ContextThemeWrapper) {
            context = ((ContextThemeWrapper) context).getBaseContext();
        }
        context = BridgeContext.getBaseContext(context);
        if (context instanceof BridgeContext) {
            return ((BridgeContext) context).getMetrics();
        }
+1 −4
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.internal.view.menu;
import com.android.layoutlib.bridge.android.BridgeContext;

import android.content.Context;
import android.view.ContextThemeWrapper;
import android.view.View;

/**
@@ -42,9 +41,7 @@ public class BridgeMenuItemImpl extends MenuItemImpl {
            CharSequence title, int showAsAction) {
        super(menu, group, id, categoryOrder, ordering, title, showAsAction);
        Context context = menu.getContext();
        while (context instanceof ContextThemeWrapper) {
            context = ((ContextThemeWrapper) context).getBaseContext();
        }
        context = BridgeContext.getBaseContext(context);
        if (context instanceof BridgeContext) {
            mContext = ((BridgeContext) context);
        }
+8 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
@@ -924,6 +925,13 @@ public final class BridgeContext extends Context {
        return defValue;
    }

    public static Context getBaseContext(Context context) {
        while (context instanceof ContextWrapper) {
            context = ((ContextWrapper) context).getBaseContext();
        }
        return context;
    }

    //------------ NOT OVERRIDEN --------------------

    @Override
Loading