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

Commit 0c08fc0f authored by Deepanshu Gupta's avatar Deepanshu Gupta Committed by Android (Google) Code Review
Browse files

Merge "Fix ninepatch scaling." into mnc-ub-dev

parents 171a2a93 95e58dea
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -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());
        }
    }
}
+307 B (10.4 KiB)
Loading image diff...
+7.04 KiB
Loading image diff...
+16 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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.
@@ -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);
    }
+15 −0
Original line number Diff line number Diff line
@@ -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