Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +5 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/AppCompatActionBar.java +5 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading @@ -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 { Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/BridgeActionBar.java +13 −7 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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(); Loading @@ -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); } /** Loading Loading @@ -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; } Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java +10 −5 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FrameworkActionBar.java +7 −5 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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 Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +5 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/AppCompatActionBar.java +5 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading @@ -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 { Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/BridgeActionBar.java +13 −7 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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(); Loading @@ -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); } /** Loading Loading @@ -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; } Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java +10 −5 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FrameworkActionBar.java +7 −5 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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