Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +5 −1 Original line number Original line Diff line number Diff line Loading @@ -594,9 +594,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. * 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 type the type of the resource * @param name the name 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 @NonNull public static Integer getResourceId(ResourceType type, String name) { 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 Original line Diff line number Diff line Loading @@ -31,7 +31,6 @@ import android.graphics.drawable.Drawable; import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.LayoutInflater; import android.view.View; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.FrameLayout; import java.lang.reflect.InvocationTargetException; 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} * Inflate the action bar and attach it to {@code parentView} */ */ public AppCompatActionBar(@NonNull BridgeContext context, @NonNull SessionParams params, public AppCompatActionBar(@NonNull BridgeContext context, @NonNull SessionParams params) { @NonNull ViewGroup parentView) { super(context, params); super(context, params, parentView); int contentRootId = context.getProjectResourceValue(ResourceType.ID, int contentRootId = context.getProjectResourceValue(ResourceType.ID, "action_bar_activity_content", 0); "action_bar_activity_content", 0); View contentView = getDecorContent().findViewById(contentRootId); 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. // Something went wrong. Create a new FrameLayout in the enclosing layout. FrameLayout contentRoot = new FrameLayout(context); FrameLayout contentRoot = new FrameLayout(context); setMatchParent(contentRoot); setMatchParent(contentRoot); if (mEnclosingLayout != null) { mEnclosingLayout.addView(contentRoot); mEnclosingLayout.addView(contentRoot); } setContentRoot(contentRoot); setContentRoot(contentRoot); } } try { try { Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/BridgeActionBar.java +13 −7 Original line number Original line 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 com.android.layoutlib.bridge.android.BridgeContext; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.view.LayoutInflater; import android.view.LayoutInflater; import android.view.View; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup; Loading @@ -39,7 +40,7 @@ public abstract class BridgeActionBar { @NonNull protected final BridgeContext mBridgeContext; @NonNull protected final BridgeContext mBridgeContext; @NonNull protected final SessionParams mParams; @NonNull protected final SessionParams mParams; // A Layout that contains the inflated action bar. The menu popup is added to this layout. // 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 View mDecorContent; private final ActionBarCallback mCallback; private final ActionBarCallback mCallback; Loading @@ -47,8 +48,7 @@ public abstract class BridgeActionBar { @SuppressWarnings("NullableProblems") // Should be initialized by subclasses. @SuppressWarnings("NullableProblems") // Should be initialized by subclasses. @NonNull private FrameLayout mContentRoot; @NonNull private FrameLayout mContentRoot; public BridgeActionBar(@NonNull BridgeContext context, @NonNull SessionParams params, public BridgeActionBar(@NonNull BridgeContext context, @NonNull SessionParams params) { @NonNull ViewGroup parentView) { mBridgeContext = context; mBridgeContext = context; mParams = params; mParams = params; mCallback = params.getLayoutlibCallback().getActionBarCallback(); mCallback = params.getLayoutlibCallback().getActionBarCallback(); Loading @@ -75,14 +75,13 @@ public abstract class BridgeActionBar { // added. // added. mEnclosingLayout = new RelativeLayout(mBridgeContext); mEnclosingLayout = new RelativeLayout(mBridgeContext); setMatchParent(mEnclosingLayout); setMatchParent(mEnclosingLayout); parentView.addView(mEnclosingLayout); } else { } else { mEnclosingLayout = parentView; mEnclosingLayout = null; } } // Inflate action bar layout. // 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(); 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() { public ActionBarCallback getCallBack() { return mCallback; return mCallback; } } Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java +44 −22 Original line number Original line Diff line number Diff line Loading @@ -32,7 +32,6 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException; import android.annotation.NonNull; import android.annotation.NonNull; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.Bitmap; import android.graphics.Bitmap_Delegate; import android.graphics.Bitmap_Delegate; Loading Loading @@ -68,7 +67,7 @@ abstract class CustomBar extends LinearLayout { protected abstract TextView getStyleableTextView(); protected abstract TextView getStyleableTextView(); protected CustomBar(BridgeContext context, int orientation, String layoutPath, protected CustomBar(BridgeContext context, int orientation, String layoutPath, String name, int simulatedPlatformVersion) throws XmlPullParserException { String name, int simulatedPlatformVersion) { super(context); super(context); mSimulatedPlatformVersion = simulatedPlatformVersion; mSimulatedPlatformVersion = simulatedPlatformVersion; setOrientation(orientation); setOrientation(orientation); Loading @@ -78,14 +77,18 @@ abstract class CustomBar extends LinearLayout { setGravity(Gravity.CENTER_HORIZONTAL); setGravity(Gravity.CENTER_HORIZONTAL); } } LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( LayoutInflater inflater = LayoutInflater.from(mContext); Context.LAYOUT_INFLATER_SERVICE); XmlPullParser parser = ParserFactory.create(getClass().getResourceAsStream(layoutPath), XmlPullParser parser; name); 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( BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(parser, context, false); parser, (BridgeContext) context, false /*platformFile*/); try { try { inflater.inflate(bridgeParser, this, true); inflater.inflate(bridgeParser, this, true); Loading Loading @@ -154,7 +157,7 @@ abstract class CustomBar extends LinearLayout { protected void setStyle(String themeEntryName) { protected void setStyle(String themeEntryName) { BridgeContext bridgeContext = (BridgeContext) mContext; BridgeContext bridgeContext = getContext(); RenderResources res = bridgeContext.getRenderResources(); RenderResources res = bridgeContext.getRenderResources(); ResourceValue value = res.findItemInTheme(themeEntryName, true /*isFrameworkAttr*/); ResourceValue value = res.findItemInTheme(themeEntryName, true /*isFrameworkAttr*/); Loading Loading @@ -214,27 +217,47 @@ abstract class CustomBar extends LinearLayout { } } } } @Override public BridgeContext getContext() { return (BridgeContext) mContext; } /** /** * Given a theme attribute name, get the color referenced by it. The theme attribute may be * Find the background color for this bar from the theme attributes. Only relevant to StatusBar * used in a layout like "?attr/foo". * and NavigationBar. * <p/> * <p/> * Returns 0 if not found. * Returns 0 if not found. * * * @param colorAttrName the attribute name for the background color * @param translucentAttrName the attribute name for the translucency property of the bar. * * @throws NumberFormatException if color resolved to an invalid string. * @throws NumberFormatException if color resolved to an invalid string. */ */ protected int getThemeAttrColor(@NonNull String attrName, boolean isFramework) { protected int getBarColor(@NonNull String colorAttrName, @NonNull String translucentAttrName) { if (!Config.isGreaterOrEqual(mSimulatedPlatformVersion, LOLLIPOP)) { if (!Config.isGreaterOrEqual(mSimulatedPlatformVersion, LOLLIPOP)) { return 0; return 0; } } assert mContext instanceof BridgeContext; RenderResources renderResources = getContext().getRenderResources(); BridgeContext context = ((BridgeContext) mContext); // First check if the bar is translucent. RenderResources renderResources = context.getRenderResources(); boolean translucent = ResourceHelper.getBooleanThemeValue(renderResources, translucentAttrName, true, false); if (translucent) { // Keep in sync with R.color.system_bar_background_semi_transparent from system ui. return 0x66000000; // 40% black. } boolean transparent = ResourceHelper.getBooleanThemeValue(renderResources, "windowDrawsSystemBarBackgrounds", true, false); if (transparent) { return getColor(renderResources, colorAttrName); } return 0; } private static int getColor(RenderResources renderResources, String attr) { // From ?attr/foo to @color/bar. This is most likely an ItemResourceValue. // From ?attr/foo to @color/bar. This is most likely an ItemResourceValue. ResourceValue resource = renderResources.findItemInTheme(attrName, isFramework); ResourceValue resource = renderResources.findItemInTheme(attr, true); if (resource != null) { // Form @color/bar to the #AARRGGBB // Form @color/bar to the #AARRGGBB resource = renderResources.resolveResValue(resource); resource = renderResources.resolveResValue(resource); } if (resource != null && ResourceType.COLOR.equals(resource.getResourceType())) { if (resource != null && ResourceType.COLOR.equals(resource.getResourceType())) { return ResourceHelper.getColor(resource.getValue()); return ResourceHelper.getColor(resource.getValue()); } } Loading @@ -242,8 +265,7 @@ abstract class CustomBar extends LinearLayout { } } private ResourceValue getResourceValue(String reference) { private ResourceValue getResourceValue(String reference) { BridgeContext bridgeContext = (BridgeContext) mContext; RenderResources res = getContext().getRenderResources(); RenderResources res = bridgeContext.getRenderResources(); // find the resource // find the resource ResourceValue value = res.findResValue(reference, false); ResourceValue value = res.findResValue(reference, false); Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FrameworkActionBar.java +7 −5 Original line number Original line 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} * Inflate the action bar and attach it to {@code parentView} */ */ public FrameworkActionBar(@NonNull BridgeContext context, @NonNull SessionParams params, public FrameworkActionBar(@NonNull BridgeContext context, @NonNull SessionParams params) { @NonNull ViewGroup parentView) { super(context, params); super(context, params, parentView); View decorContent = getDecorContent(); View decorContent = getDecorContent(); mActionBar = FrameworkActionBarWrapper.getActionBarWrapper(context, getCallBack(), mActionBar = FrameworkActionBarWrapper.getActionBarWrapper(context, getCallBack(), decorContent); 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, // If something went wrong and we were not able to initialize the content root, // just add a frame layout inside this and return. // just add a frame layout inside this and return. if (contentRoot == null) { if (contentRoot == null) { contentRoot = new FrameLayout(context); contentRoot = new FrameLayout(context); setMatchParent(contentRoot); setMatchParent(contentRoot); if (mEnclosingLayout != null) { mEnclosingLayout.addView(contentRoot); mEnclosingLayout.addView(contentRoot); } setContentRoot(contentRoot); setContentRoot(contentRoot); } else { } else { setContentRoot(contentRoot); setContentRoot(contentRoot); Loading Loading @@ -162,6 +163,7 @@ public class FrameworkActionBar extends BridgeActionBar { listView.setDivider(a.getDrawable(R.attr.actionBarDivider)); listView.setDivider(a.getDrawable(R.attr.actionBarDivider)); a.recycle(); a.recycle(); listView.setElevation(mActionBar.getMenuPopupElevation()); listView.setElevation(mActionBar.getMenuPopupElevation()); assert mEnclosingLayout != null : "Unable to find view to attach ActionMenuPopup."; mEnclosingLayout.addView(listView); mEnclosingLayout.addView(listView); } } Loading Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +5 −1 Original line number Original line Diff line number Diff line Loading @@ -594,9 +594,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. * 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 type the type of the resource * @param name the name 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 @NonNull public static Integer getResourceId(ResourceType type, String name) { 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 Original line Diff line number Diff line Loading @@ -31,7 +31,6 @@ import android.graphics.drawable.Drawable; import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.LayoutInflater; import android.view.View; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.FrameLayout; import java.lang.reflect.InvocationTargetException; 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} * Inflate the action bar and attach it to {@code parentView} */ */ public AppCompatActionBar(@NonNull BridgeContext context, @NonNull SessionParams params, public AppCompatActionBar(@NonNull BridgeContext context, @NonNull SessionParams params) { @NonNull ViewGroup parentView) { super(context, params); super(context, params, parentView); int contentRootId = context.getProjectResourceValue(ResourceType.ID, int contentRootId = context.getProjectResourceValue(ResourceType.ID, "action_bar_activity_content", 0); "action_bar_activity_content", 0); View contentView = getDecorContent().findViewById(contentRootId); 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. // Something went wrong. Create a new FrameLayout in the enclosing layout. FrameLayout contentRoot = new FrameLayout(context); FrameLayout contentRoot = new FrameLayout(context); setMatchParent(contentRoot); setMatchParent(contentRoot); if (mEnclosingLayout != null) { mEnclosingLayout.addView(contentRoot); mEnclosingLayout.addView(contentRoot); } setContentRoot(contentRoot); setContentRoot(contentRoot); } } try { try { Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/BridgeActionBar.java +13 −7 Original line number Original line 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 com.android.layoutlib.bridge.android.BridgeContext; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.view.LayoutInflater; import android.view.LayoutInflater; import android.view.View; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup; Loading @@ -39,7 +40,7 @@ public abstract class BridgeActionBar { @NonNull protected final BridgeContext mBridgeContext; @NonNull protected final BridgeContext mBridgeContext; @NonNull protected final SessionParams mParams; @NonNull protected final SessionParams mParams; // A Layout that contains the inflated action bar. The menu popup is added to this layout. // 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 View mDecorContent; private final ActionBarCallback mCallback; private final ActionBarCallback mCallback; Loading @@ -47,8 +48,7 @@ public abstract class BridgeActionBar { @SuppressWarnings("NullableProblems") // Should be initialized by subclasses. @SuppressWarnings("NullableProblems") // Should be initialized by subclasses. @NonNull private FrameLayout mContentRoot; @NonNull private FrameLayout mContentRoot; public BridgeActionBar(@NonNull BridgeContext context, @NonNull SessionParams params, public BridgeActionBar(@NonNull BridgeContext context, @NonNull SessionParams params) { @NonNull ViewGroup parentView) { mBridgeContext = context; mBridgeContext = context; mParams = params; mParams = params; mCallback = params.getLayoutlibCallback().getActionBarCallback(); mCallback = params.getLayoutlibCallback().getActionBarCallback(); Loading @@ -75,14 +75,13 @@ public abstract class BridgeActionBar { // added. // added. mEnclosingLayout = new RelativeLayout(mBridgeContext); mEnclosingLayout = new RelativeLayout(mBridgeContext); setMatchParent(mEnclosingLayout); setMatchParent(mEnclosingLayout); parentView.addView(mEnclosingLayout); } else { } else { mEnclosingLayout = parentView; mEnclosingLayout = null; } } // Inflate action bar layout. // 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(); 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() { public ActionBarCallback getCallBack() { return mCallback; return mCallback; } } Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java +44 −22 Original line number Original line Diff line number Diff line Loading @@ -32,7 +32,6 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException; import android.annotation.NonNull; import android.annotation.NonNull; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.Bitmap; import android.graphics.Bitmap_Delegate; import android.graphics.Bitmap_Delegate; Loading Loading @@ -68,7 +67,7 @@ abstract class CustomBar extends LinearLayout { protected abstract TextView getStyleableTextView(); protected abstract TextView getStyleableTextView(); protected CustomBar(BridgeContext context, int orientation, String layoutPath, protected CustomBar(BridgeContext context, int orientation, String layoutPath, String name, int simulatedPlatformVersion) throws XmlPullParserException { String name, int simulatedPlatformVersion) { super(context); super(context); mSimulatedPlatformVersion = simulatedPlatformVersion; mSimulatedPlatformVersion = simulatedPlatformVersion; setOrientation(orientation); setOrientation(orientation); Loading @@ -78,14 +77,18 @@ abstract class CustomBar extends LinearLayout { setGravity(Gravity.CENTER_HORIZONTAL); setGravity(Gravity.CENTER_HORIZONTAL); } } LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( LayoutInflater inflater = LayoutInflater.from(mContext); Context.LAYOUT_INFLATER_SERVICE); XmlPullParser parser = ParserFactory.create(getClass().getResourceAsStream(layoutPath), XmlPullParser parser; name); 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( BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(parser, context, false); parser, (BridgeContext) context, false /*platformFile*/); try { try { inflater.inflate(bridgeParser, this, true); inflater.inflate(bridgeParser, this, true); Loading Loading @@ -154,7 +157,7 @@ abstract class CustomBar extends LinearLayout { protected void setStyle(String themeEntryName) { protected void setStyle(String themeEntryName) { BridgeContext bridgeContext = (BridgeContext) mContext; BridgeContext bridgeContext = getContext(); RenderResources res = bridgeContext.getRenderResources(); RenderResources res = bridgeContext.getRenderResources(); ResourceValue value = res.findItemInTheme(themeEntryName, true /*isFrameworkAttr*/); ResourceValue value = res.findItemInTheme(themeEntryName, true /*isFrameworkAttr*/); Loading Loading @@ -214,27 +217,47 @@ abstract class CustomBar extends LinearLayout { } } } } @Override public BridgeContext getContext() { return (BridgeContext) mContext; } /** /** * Given a theme attribute name, get the color referenced by it. The theme attribute may be * Find the background color for this bar from the theme attributes. Only relevant to StatusBar * used in a layout like "?attr/foo". * and NavigationBar. * <p/> * <p/> * Returns 0 if not found. * Returns 0 if not found. * * * @param colorAttrName the attribute name for the background color * @param translucentAttrName the attribute name for the translucency property of the bar. * * @throws NumberFormatException if color resolved to an invalid string. * @throws NumberFormatException if color resolved to an invalid string. */ */ protected int getThemeAttrColor(@NonNull String attrName, boolean isFramework) { protected int getBarColor(@NonNull String colorAttrName, @NonNull String translucentAttrName) { if (!Config.isGreaterOrEqual(mSimulatedPlatformVersion, LOLLIPOP)) { if (!Config.isGreaterOrEqual(mSimulatedPlatformVersion, LOLLIPOP)) { return 0; return 0; } } assert mContext instanceof BridgeContext; RenderResources renderResources = getContext().getRenderResources(); BridgeContext context = ((BridgeContext) mContext); // First check if the bar is translucent. RenderResources renderResources = context.getRenderResources(); boolean translucent = ResourceHelper.getBooleanThemeValue(renderResources, translucentAttrName, true, false); if (translucent) { // Keep in sync with R.color.system_bar_background_semi_transparent from system ui. return 0x66000000; // 40% black. } boolean transparent = ResourceHelper.getBooleanThemeValue(renderResources, "windowDrawsSystemBarBackgrounds", true, false); if (transparent) { return getColor(renderResources, colorAttrName); } return 0; } private static int getColor(RenderResources renderResources, String attr) { // From ?attr/foo to @color/bar. This is most likely an ItemResourceValue. // From ?attr/foo to @color/bar. This is most likely an ItemResourceValue. ResourceValue resource = renderResources.findItemInTheme(attrName, isFramework); ResourceValue resource = renderResources.findItemInTheme(attr, true); if (resource != null) { // Form @color/bar to the #AARRGGBB // Form @color/bar to the #AARRGGBB resource = renderResources.resolveResValue(resource); resource = renderResources.resolveResValue(resource); } if (resource != null && ResourceType.COLOR.equals(resource.getResourceType())) { if (resource != null && ResourceType.COLOR.equals(resource.getResourceType())) { return ResourceHelper.getColor(resource.getValue()); return ResourceHelper.getColor(resource.getValue()); } } Loading @@ -242,8 +265,7 @@ abstract class CustomBar extends LinearLayout { } } private ResourceValue getResourceValue(String reference) { private ResourceValue getResourceValue(String reference) { BridgeContext bridgeContext = (BridgeContext) mContext; RenderResources res = getContext().getRenderResources(); RenderResources res = bridgeContext.getRenderResources(); // find the resource // find the resource ResourceValue value = res.findResValue(reference, false); ResourceValue value = res.findResValue(reference, false); Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FrameworkActionBar.java +7 −5 Original line number Original line 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} * Inflate the action bar and attach it to {@code parentView} */ */ public FrameworkActionBar(@NonNull BridgeContext context, @NonNull SessionParams params, public FrameworkActionBar(@NonNull BridgeContext context, @NonNull SessionParams params) { @NonNull ViewGroup parentView) { super(context, params); super(context, params, parentView); View decorContent = getDecorContent(); View decorContent = getDecorContent(); mActionBar = FrameworkActionBarWrapper.getActionBarWrapper(context, getCallBack(), mActionBar = FrameworkActionBarWrapper.getActionBarWrapper(context, getCallBack(), decorContent); 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, // If something went wrong and we were not able to initialize the content root, // just add a frame layout inside this and return. // just add a frame layout inside this and return. if (contentRoot == null) { if (contentRoot == null) { contentRoot = new FrameLayout(context); contentRoot = new FrameLayout(context); setMatchParent(contentRoot); setMatchParent(contentRoot); if (mEnclosingLayout != null) { mEnclosingLayout.addView(contentRoot); mEnclosingLayout.addView(contentRoot); } setContentRoot(contentRoot); setContentRoot(contentRoot); } else { } else { setContentRoot(contentRoot); setContentRoot(contentRoot); Loading Loading @@ -162,6 +163,7 @@ public class FrameworkActionBar extends BridgeActionBar { listView.setDivider(a.getDrawable(R.attr.actionBarDivider)); listView.setDivider(a.getDrawable(R.attr.actionBarDivider)); a.recycle(); a.recycle(); listView.setElevation(mActionBar.getMenuPopupElevation()); listView.setElevation(mActionBar.getMenuPopupElevation()); assert mEnclosingLayout != null : "Unable to find view to attach ActionMenuPopup."; mEnclosingLayout.addView(listView); mEnclosingLayout.addView(listView); } } Loading