Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +14 −1 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ import android.database.DatabaseErrorHandler; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.hardware.display.DisplayManager; import android.net.Uri; Loading Loading @@ -381,6 +382,18 @@ public class BridgeContext extends Context { return true; } String stringValue = value.getValue(); if (!stringValue.isEmpty()) { if (stringValue.charAt(0) == '#') { outValue.type = TypedValue.TYPE_INT_COLOR_ARGB8; outValue.data = Color.parseColor(value.getValue()); } else if (stringValue.charAt(0) == '@') { outValue.type = TypedValue.TYPE_REFERENCE; } } int a; // if this is a framework value. if (value.isFramework()) { Loading @@ -399,7 +412,7 @@ public class BridgeContext extends Context { } // If the value is not a valid reference, fallback to pass the value as a string. outValue.string = value.getValue(); outValue.string = stringValue; return true; } Loading tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/RenderTests.java +34 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.content.res.AssetManager; import android.content.res.Configuration; import android.content.res.Resources; import android.util.DisplayMetrics; import android.util.TypedValue; import java.lang.reflect.Field; import java.util.concurrent.TimeUnit; Loading @@ -43,6 +44,7 @@ import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; Loading Loading @@ -334,6 +336,7 @@ public class RenderTests extends RenderTestBase { AssetManager assetManager = AssetManager.getSystem(); DisplayMetrics metrics = new DisplayMetrics(); Configuration configuration = RenderAction.getConfiguration(params); //noinspection deprecation Resources resources = new Resources(assetManager, metrics, configuration); resources.mLayoutlibCallback = params.getLayoutlibCallback(); resources.mContext = Loading Loading @@ -370,6 +373,7 @@ public class RenderTests extends RenderTestBase { AssetManager assetManager = AssetManager.getSystem(); DisplayMetrics metrics = new DisplayMetrics(); Configuration configuration = RenderAction.getConfiguration(params); //noinspection deprecation Resources resources = new Resources(assetManager, metrics, configuration); resources.mLayoutlibCallback = params.getLayoutlibCallback(); resources.mContext = Loading @@ -390,4 +394,34 @@ public class RenderTests extends RenderTestBase { // TODO: styles seem to be broken in TextView renderAndVerify("fonts_test.xml", "font_test.png"); } @Test public void testColorTypedValue() throws Exception { // Setup // Create the layout pull parser for our resources (empty.xml can not be part of the test // app as it won't compile). LayoutPullParser parser = new LayoutPullParser("/empty.xml"); // Create LayoutLibCallback. LayoutLibTestCallback layoutLibCallback = new LayoutLibTestCallback(RenderTestBase.getLogger(), mDefaultClassLoader); layoutLibCallback.initResources(); SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_4, layoutLibCallback, "AppTheme", true, RenderingMode.NORMAL, 22); AssetManager assetManager = AssetManager.getSystem(); DisplayMetrics metrics = new DisplayMetrics(); Configuration configuration = RenderAction.getConfiguration(params); //noinspection deprecation Resources resources = new Resources(assetManager, metrics, configuration); resources.mLayoutlibCallback = params.getLayoutlibCallback(); resources.mContext = new BridgeContext(params.getProjectKey(), metrics, params.getResources(), params.getAssets(), params.getLayoutlibCallback(), configuration, params.getTargetSdkVersion(), params.isRtlSupported()); TypedValue outValue = new TypedValue(); resources.mContext.resolveThemeAttribute(android.R.attr.colorPrimary, outValue, true); assertEquals(TypedValue.TYPE_INT_COLOR_ARGB8, outValue.type); assertNotEquals(0, outValue.data); assertTrue(sRenderMessages.isEmpty()); } } Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +14 −1 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ import android.database.DatabaseErrorHandler; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.hardware.display.DisplayManager; import android.net.Uri; Loading Loading @@ -381,6 +382,18 @@ public class BridgeContext extends Context { return true; } String stringValue = value.getValue(); if (!stringValue.isEmpty()) { if (stringValue.charAt(0) == '#') { outValue.type = TypedValue.TYPE_INT_COLOR_ARGB8; outValue.data = Color.parseColor(value.getValue()); } else if (stringValue.charAt(0) == '@') { outValue.type = TypedValue.TYPE_REFERENCE; } } int a; // if this is a framework value. if (value.isFramework()) { Loading @@ -399,7 +412,7 @@ public class BridgeContext extends Context { } // If the value is not a valid reference, fallback to pass the value as a string. outValue.string = value.getValue(); outValue.string = stringValue; return true; } Loading
tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/RenderTests.java +34 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.content.res.AssetManager; import android.content.res.Configuration; import android.content.res.Resources; import android.util.DisplayMetrics; import android.util.TypedValue; import java.lang.reflect.Field; import java.util.concurrent.TimeUnit; Loading @@ -43,6 +44,7 @@ import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; Loading Loading @@ -334,6 +336,7 @@ public class RenderTests extends RenderTestBase { AssetManager assetManager = AssetManager.getSystem(); DisplayMetrics metrics = new DisplayMetrics(); Configuration configuration = RenderAction.getConfiguration(params); //noinspection deprecation Resources resources = new Resources(assetManager, metrics, configuration); resources.mLayoutlibCallback = params.getLayoutlibCallback(); resources.mContext = Loading Loading @@ -370,6 +373,7 @@ public class RenderTests extends RenderTestBase { AssetManager assetManager = AssetManager.getSystem(); DisplayMetrics metrics = new DisplayMetrics(); Configuration configuration = RenderAction.getConfiguration(params); //noinspection deprecation Resources resources = new Resources(assetManager, metrics, configuration); resources.mLayoutlibCallback = params.getLayoutlibCallback(); resources.mContext = Loading @@ -390,4 +394,34 @@ public class RenderTests extends RenderTestBase { // TODO: styles seem to be broken in TextView renderAndVerify("fonts_test.xml", "font_test.png"); } @Test public void testColorTypedValue() throws Exception { // Setup // Create the layout pull parser for our resources (empty.xml can not be part of the test // app as it won't compile). LayoutPullParser parser = new LayoutPullParser("/empty.xml"); // Create LayoutLibCallback. LayoutLibTestCallback layoutLibCallback = new LayoutLibTestCallback(RenderTestBase.getLogger(), mDefaultClassLoader); layoutLibCallback.initResources(); SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_4, layoutLibCallback, "AppTheme", true, RenderingMode.NORMAL, 22); AssetManager assetManager = AssetManager.getSystem(); DisplayMetrics metrics = new DisplayMetrics(); Configuration configuration = RenderAction.getConfiguration(params); //noinspection deprecation Resources resources = new Resources(assetManager, metrics, configuration); resources.mLayoutlibCallback = params.getLayoutlibCallback(); resources.mContext = new BridgeContext(params.getProjectKey(), metrics, params.getResources(), params.getAssets(), params.getLayoutlibCallback(), configuration, params.getTargetSdkVersion(), params.isRtlSupported()); TypedValue outValue = new TypedValue(); resources.mContext.resolveThemeAttribute(android.R.attr.colorPrimary, outValue, true); assertEquals(TypedValue.TYPE_INT_COLOR_ARGB8, outValue.type); assertNotEquals(0, outValue.data); assertTrue(sRenderMessages.isEmpty()); } }