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

Commit d1dde055 authored by Deepanshu Gupta's avatar Deepanshu Gupta Committed by Android Git Automerger
Browse files

am e5afc311: Move the layout code out of RenderSessionImpl. [DO NOT MERGE]

* commit 'e5afc311':
  Move the layout code out of RenderSessionImpl. [DO NOT MERGE]
parents 87f5fd6b e5afc311
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -593,9 +593,13 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {

    /**
     * Returns the integer id of a framework resource, from a given resource type and resource name.
     * <p/>
     * If no resource is found, it creates a dynamic id for the resource.
     *
     * @param type the type of the resource
     * @param name the name of the resource.
     * @return an {@link Integer} containing the resource id, or null if no resource were found.
     *
     * @return an {@link Integer} containing the resource id.
     */
    @NonNull
    public static Integer getResourceId(ResourceType type, String name) {
+5 −5
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.graphics.drawable.Drawable;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import java.lang.reflect.InvocationTargetException;
@@ -51,9 +50,8 @@ public class AppCompatActionBar extends BridgeActionBar {
    /**
     * Inflate the action bar and attach it to {@code parentView}
     */
    public AppCompatActionBar(@NonNull BridgeContext context, @NonNull SessionParams params,
            @NonNull ViewGroup parentView) {
        super(context, params, parentView);
    public AppCompatActionBar(@NonNull BridgeContext context, @NonNull SessionParams params) {
        super(context, params);
        int contentRootId = context.getProjectResourceValue(ResourceType.ID,
                "action_bar_activity_content", 0);
        View contentView = getDecorContent().findViewById(contentRootId);
@@ -64,7 +62,9 @@ public class AppCompatActionBar extends BridgeActionBar {
            // Something went wrong. Create a new FrameLayout in the enclosing layout.
            FrameLayout contentRoot = new FrameLayout(context);
            setMatchParent(contentRoot);
            if (mEnclosingLayout != null) {
                mEnclosingLayout.addView(contentRoot);
            }
            setContentRoot(contentRoot);
        }
        try {
+13 −7
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.ide.common.rendering.api.SessionParams;
import com.android.layoutlib.bridge.android.BridgeContext;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -39,7 +40,7 @@ public abstract class BridgeActionBar {
    @NonNull protected final BridgeContext mBridgeContext;
    @NonNull protected final SessionParams mParams;
    // A Layout that contains the inflated action bar. The menu popup is added to this layout.
    @NonNull protected final ViewGroup mEnclosingLayout;
    @Nullable protected final ViewGroup mEnclosingLayout;

    private final View mDecorContent;
    private final ActionBarCallback mCallback;
@@ -47,8 +48,7 @@ public abstract class BridgeActionBar {
    @SuppressWarnings("NullableProblems")  // Should be initialized by subclasses.
    @NonNull private FrameLayout mContentRoot;

    public BridgeActionBar(@NonNull BridgeContext context, @NonNull SessionParams params,
            @NonNull ViewGroup parentView) {
    public BridgeActionBar(@NonNull BridgeContext context, @NonNull SessionParams params) {
        mBridgeContext = context;
        mParams = params;
        mCallback = params.getLayoutlibCallback().getActionBarCallback();
@@ -75,14 +75,13 @@ public abstract class BridgeActionBar {
            // added.
            mEnclosingLayout = new RelativeLayout(mBridgeContext);
            setMatchParent(mEnclosingLayout);
            parentView.addView(mEnclosingLayout);
        } else {
            mEnclosingLayout = parentView;
            mEnclosingLayout = null;
        }

        // Inflate action bar layout.
        mDecorContent = getInflater(context).inflate(layoutId, mEnclosingLayout, true);

        mDecorContent =
                getInflater(context).inflate(layoutId, mEnclosingLayout, mEnclosingLayout != null);
    }

    /**
@@ -153,6 +152,13 @@ public abstract class BridgeActionBar {

    public abstract void createMenuPopup();

    /**
     * The root view that represents the action bar and possibly the content included in it.
     */
    public View getRootView() {
        return mEnclosingLayout == null ? mDecorContent : mEnclosingLayout;
    }

    public ActionBarCallback getCallBack() {
        return mCallback;
    }
+10 −5
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ abstract class CustomBar extends LinearLayout {
    protected abstract TextView getStyleableTextView();

    protected CustomBar(BridgeContext context, int orientation, String layoutPath,
            String name, int simulatedPlatformVersion) throws XmlPullParserException {
            String name, int simulatedPlatformVersion) {
        super(context);
        mSimulatedPlatformVersion = simulatedPlatformVersion;
        setOrientation(orientation);
@@ -81,11 +81,16 @@ abstract class CustomBar extends LinearLayout {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);

        XmlPullParser parser = ParserFactory.create(getClass().getResourceAsStream(layoutPath),
                name);
        XmlPullParser parser;
        try {
            parser = ParserFactory.create(getClass().getResourceAsStream(layoutPath), name);
        } catch (XmlPullParserException e) {
            // Should not happen as the resource is bundled with the jar, and  ParserFactory should
            // have been initialized.
            throw new AssertionError(e);
        }

        BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(
                parser, (BridgeContext) context, false /*platformFile*/);
        BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(parser, context, false);

        try {
            inflater.inflate(bridgeParser, this, true);
+7 −5
Original line number Diff line number Diff line
@@ -60,23 +60,24 @@ public class FrameworkActionBar extends BridgeActionBar {
    /**
     * Inflate the action bar and attach it to {@code parentView}
     */
    public FrameworkActionBar(@NonNull BridgeContext context, @NonNull SessionParams params,
            @NonNull ViewGroup parentView) {
        super(context, params, parentView);
    public FrameworkActionBar(@NonNull BridgeContext context, @NonNull SessionParams params) {
        super(context, params);

        View decorContent = getDecorContent();

        mActionBar = FrameworkActionBarWrapper.getActionBarWrapper(context, getCallBack(),
                decorContent);

        FrameLayout contentRoot = (FrameLayout) mEnclosingLayout.findViewById(android.R.id.content);
        FrameLayout contentRoot = (FrameLayout) decorContent.findViewById(android.R.id.content);

        // If something went wrong and we were not able to initialize the content root,
        // just add a frame layout inside this and return.
        if (contentRoot == null) {
            contentRoot = new FrameLayout(context);
            setMatchParent(contentRoot);
            if (mEnclosingLayout != null) {
                mEnclosingLayout.addView(contentRoot);
            }
            setContentRoot(contentRoot);
        } else {
            setContentRoot(contentRoot);
@@ -162,6 +163,7 @@ public class FrameworkActionBar extends BridgeActionBar {
        listView.setDivider(a.getDrawable(R.attr.actionBarDivider));
        a.recycle();
        listView.setElevation(mActionBar.getMenuPopupElevation());
        assert mEnclosingLayout != null : "Unable to find view to attach ActionMenuPopup.";
        mEnclosingLayout.addView(listView);
    }

Loading