Loading tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java +31 −0 Original line number Diff line number Diff line Loading @@ -122,4 +122,35 @@ import java.util.Set; /*package*/ static boolean nativeIsSeekable(FileDescriptor fd) { return true; } /** * Set the newly decoded bitmap's density based on the Options. * * Copied from {@link BitmapFactory#setDensityFromOptions(Bitmap, Options)}. */ @LayoutlibDelegate /*package*/ static void setDensityFromOptions(Bitmap outputBitmap, Options opts) { if (outputBitmap == null || opts == null) return; final int density = opts.inDensity; if (density != 0) { outputBitmap.setDensity(density); final int targetDensity = opts.inTargetDensity; if (targetDensity == 0 || density == targetDensity || density == opts.inScreenDensity) { return; } // --- Change from original implementation begins --- // LayoutLib doesn't scale the nine patch when decoding it. Hence, don't change the // density of the source bitmap in case of ninepatch. if (opts.inScaled) { // --- Change from original implementation ends. --- outputBitmap.setDensity(targetDensity); } } else if (opts.inBitmap != null) { // bitmap was reused, ensure density is reset outputBitmap.setDensity(Bitmap.getDefaultDensity()); } } } tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/allwidgets.png +307 B (10.4 KiB) Loading image diff... tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/allwidgets_tab.png 0 → 100644 +7.04 KiB Loading image diff... tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java +16 −1 Original line number Diff line number Diff line Loading @@ -305,6 +305,11 @@ public class Main { renderAndVerify("array_check.xml", "array_check.png"); } @Test public void testAllWidgetsTablet() throws ClassNotFoundException { renderAndVerify("allwidgets.xml", "allwidgets_tab.png", ConfigGenerator.NEXUS_7_2012); } @AfterClass public static void tearDown() { sLayoutLibLog = null; Loading Loading @@ -423,6 +428,16 @@ public class Main { */ private void renderAndVerify(String layoutFileName, String goldenFileName) throws ClassNotFoundException { renderAndVerify(layoutFileName, goldenFileName, ConfigGenerator.NEXUS_5); } /** * Create a new rendering session and test that rendering given layout on given device * doesn't throw any exceptions and matches the provided image. */ private void renderAndVerify(String layoutFileName, String goldenFileName, ConfigGenerator deviceConfig) throws ClassNotFoundException { // Create the layout pull parser. LayoutPullParser parser = new LayoutPullParser(APP_TEST_RES + "/layout/" + layoutFileName); // Create LayoutLibCallback. Loading @@ -430,7 +445,7 @@ public class Main { layoutLibCallback.initResources(); // TODO: Set up action bar handler properly to test menu rendering. // Create session params. SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5, SessionParams params = getSessionParams(parser, deviceConfig, layoutLibCallback, "AppTheme", true, RenderingMode.NORMAL, 22); renderAndVerify(params, goldenFileName); } Loading tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/ConfigGenerator.java +15 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,21 @@ public class ConfigGenerator { .setSoftButtons(true) .setNavigation(Navigation.NONAV); public static final ConfigGenerator NEXUS_7_2012 = new ConfigGenerator() .setScreenHeight(1280) .setScreenWidth(800) .setXdpi(195) .setYdpi(200) .setOrientation(ScreenOrientation.PORTRAIT) .setDensity(Density.TV) .setRatio(ScreenRatio.NOTLONG) .setSize(ScreenSize.LARGE) .setKeyboard(Keyboard.NOKEY) .setTouchScreen(TouchScreen.FINGER) .setKeyboardState(KeyboardState.SOFT) .setSoftButtons(true) .setNavigation(Navigation.NONAV); private static final String TAG_ATTR = "attr"; private static final String TAG_ENUM = "enum"; private static final String TAG_FLAG = "flag"; Loading Loading
tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java +31 −0 Original line number Diff line number Diff line Loading @@ -122,4 +122,35 @@ import java.util.Set; /*package*/ static boolean nativeIsSeekable(FileDescriptor fd) { return true; } /** * Set the newly decoded bitmap's density based on the Options. * * Copied from {@link BitmapFactory#setDensityFromOptions(Bitmap, Options)}. */ @LayoutlibDelegate /*package*/ static void setDensityFromOptions(Bitmap outputBitmap, Options opts) { if (outputBitmap == null || opts == null) return; final int density = opts.inDensity; if (density != 0) { outputBitmap.setDensity(density); final int targetDensity = opts.inTargetDensity; if (targetDensity == 0 || density == targetDensity || density == opts.inScreenDensity) { return; } // --- Change from original implementation begins --- // LayoutLib doesn't scale the nine patch when decoding it. Hence, don't change the // density of the source bitmap in case of ninepatch. if (opts.inScaled) { // --- Change from original implementation ends. --- outputBitmap.setDensity(targetDensity); } } else if (opts.inBitmap != null) { // bitmap was reused, ensure density is reset outputBitmap.setDensity(Bitmap.getDefaultDensity()); } } }
tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/allwidgets.png +307 B (10.4 KiB) Loading image diff...
tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/allwidgets_tab.png 0 → 100644 +7.04 KiB Loading image diff...
tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java +16 −1 Original line number Diff line number Diff line Loading @@ -305,6 +305,11 @@ public class Main { renderAndVerify("array_check.xml", "array_check.png"); } @Test public void testAllWidgetsTablet() throws ClassNotFoundException { renderAndVerify("allwidgets.xml", "allwidgets_tab.png", ConfigGenerator.NEXUS_7_2012); } @AfterClass public static void tearDown() { sLayoutLibLog = null; Loading Loading @@ -423,6 +428,16 @@ public class Main { */ private void renderAndVerify(String layoutFileName, String goldenFileName) throws ClassNotFoundException { renderAndVerify(layoutFileName, goldenFileName, ConfigGenerator.NEXUS_5); } /** * Create a new rendering session and test that rendering given layout on given device * doesn't throw any exceptions and matches the provided image. */ private void renderAndVerify(String layoutFileName, String goldenFileName, ConfigGenerator deviceConfig) throws ClassNotFoundException { // Create the layout pull parser. LayoutPullParser parser = new LayoutPullParser(APP_TEST_RES + "/layout/" + layoutFileName); // Create LayoutLibCallback. Loading @@ -430,7 +445,7 @@ public class Main { layoutLibCallback.initResources(); // TODO: Set up action bar handler properly to test menu rendering. // Create session params. SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5, SessionParams params = getSessionParams(parser, deviceConfig, layoutLibCallback, "AppTheme", true, RenderingMode.NORMAL, 22); renderAndVerify(params, goldenFileName); } Loading
tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/ConfigGenerator.java +15 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,21 @@ public class ConfigGenerator { .setSoftButtons(true) .setNavigation(Navigation.NONAV); public static final ConfigGenerator NEXUS_7_2012 = new ConfigGenerator() .setScreenHeight(1280) .setScreenWidth(800) .setXdpi(195) .setYdpi(200) .setOrientation(ScreenOrientation.PORTRAIT) .setDensity(Density.TV) .setRatio(ScreenRatio.NOTLONG) .setSize(ScreenSize.LARGE) .setKeyboard(Keyboard.NOKEY) .setTouchScreen(TouchScreen.FINGER) .setKeyboardState(KeyboardState.SOFT) .setSoftButtons(true) .setNavigation(Navigation.NONAV); private static final String TAG_ATTR = "attr"; private static final String TAG_ENUM = "enum"; private static final String TAG_FLAG = "flag"; Loading