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

am: 0c08fc0fc5

* commit '0c08fc0fc58be4f52527d7a0529960752056e83b':
  Fix ninepatch scaling.
This commit is contained in:
Deepanshu Gupta
2016-01-11 18:15:01 +00:00
committed by android-build-merger
6 changed files with 63 additions and 1 deletions

View File

@@ -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());
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@@ -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);
}

View File

@@ -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";

View File

@@ -166,6 +166,7 @@ public final class CreateInfo implements ICreateInfo {
"android.content.res.TypedArray#getValueAt",
"android.content.res.TypedArray#obtain",
"android.graphics.BitmapFactory#finishDecode",
"android.graphics.BitmapFactory#setDensityFromOptions",
"android.graphics.drawable.GradientDrawable#buildRing",
"android.graphics.Typeface#getSystemFontConfigLocation",
"android.os.Handler#sendMessageAtTime",