aboutsummaryrefslogtreecommitdiff
path: root/bridge/tests/src/com/android/layoutlib/bridge/intensive/RenderTests.java
diff options
context:
space:
mode:
Diffstat (limited to 'bridge/tests/src/com/android/layoutlib/bridge/intensive/RenderTests.java')
-rw-r--r--bridge/tests/src/com/android/layoutlib/bridge/intensive/RenderTests.java161
1 files changed, 103 insertions, 58 deletions
diff --git a/bridge/tests/src/com/android/layoutlib/bridge/intensive/RenderTests.java b/bridge/tests/src/com/android/layoutlib/bridge/intensive/RenderTests.java
index 7b9c163634..c5ef0e0488 100644
--- a/bridge/tests/src/com/android/layoutlib/bridge/intensive/RenderTests.java
+++ b/bridge/tests/src/com/android/layoutlib/bridge/intensive/RenderTests.java
@@ -46,7 +46,6 @@ import org.junit.Test;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
-import android.R.attr;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.res.AssetManager;
@@ -57,7 +56,6 @@ import android.content.res.Resources_Delegate;
import android.graphics.Color;
import android.util.DisplayMetrics;
import android.util.StateSet;
-import android.util.TypedValue;
import android.widget.Button;
import android.widget.LinearLayout;
@@ -72,10 +70,10 @@ import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.util.concurrent.TimeUnit;
+import static android.os._Original_Build.VERSION.SDK_INT;
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;
@@ -974,61 +972,6 @@ public class RenderTests extends RenderTestBase {
}
@Test
- public void testTypedValue() 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 = LayoutPullParser.createFromPath("/empty.xml");
- // Create LayoutLibCallback.
- LayoutLibTestCallback layoutLibCallback =
- new LayoutLibTestCallback(RenderTestBase.getLogger(), mDefaultClassLoader);
- layoutLibCallback.initResources();
- SessionParams params = getSessionParamsBuilder()
- .setConfigGenerator(ConfigGenerator.NEXUS_4)
- .setParser(parser)
- .setCallback(layoutLibCallback)
- .build();
- DisplayMetrics metrics = new DisplayMetrics();
- Configuration configuration = RenderAction.getConfiguration(params);
-
- BridgeContext mContext =
- new BridgeContext(params.getProjectKey(), metrics, params.getResources(),
- params.getAssets(), params.getLayoutlibCallback(), configuration,
- params.getTargetSdkVersion(), params.isRtlSupported());
-
- TypedValue outValue = new TypedValue();
- mContext.resolveThemeAttribute(android.R.attr.colorPrimary, outValue, true);
- assertEquals(TypedValue.TYPE_INT_COLOR_ARGB8, outValue.type);
- assertNotEquals(0, outValue.data);
-
- outValue = new TypedValue();
- mContext.resolveThemeAttribute(android.R.attr.colorError, outValue, true);
- assertEquals(TypedValue.TYPE_INT_COLOR_RGB4, outValue.type);
- assertEquals(-65536, outValue.data);
-
- outValue = new TypedValue();
- mContext.resolveThemeAttribute(attr.colorActivatedHighlight, outValue, true);
- assertEquals(TypedValue.TYPE_INT_COLOR_ARGB4, outValue.type);
- assertEquals(-872349952, outValue.data);
-
- outValue = new TypedValue();
- mContext.resolveThemeAttribute(android.R.attr.isLightTheme, outValue, true);
- assertEquals(TypedValue.TYPE_INT_BOOLEAN, outValue.type);
- assertEquals(1, outValue.data);
-
- outValue = new TypedValue();
- mContext.resolveThemeAttribute(android.R.attr.scrollbarFadeDuration, outValue, true);
- assertEquals(TypedValue.TYPE_INT_DEC, outValue.type);
- assertEquals(250, outValue.data);
-
- outValue = new TypedValue();
- mContext.resolveThemeAttribute(android.R.attr.scrollbarThumbHorizontal, outValue, true);
- assertEquals(TypedValue.TYPE_STRING, outValue.type);
- assertNotNull(outValue.string);
- assertTrue(sRenderMessages.isEmpty());
- }
-
- @Test
public void testColorStateList() throws Exception {
final String STATE_LIST =
"<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
@@ -2130,4 +2073,106 @@ public class RenderTests extends RenderTestBase {
renderAndVerify(params, "html.png", TimeUnit.SECONDS.toNanos(2));
}
+
+ @Test
+ public void testStatusBar() throws ClassNotFoundException {
+ final String layout =
+ "<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
+ " android:layout_width=\"match_parent\"\n" +
+ " android:layout_height=\"match_parent\">\n" + "\n" +
+ " <TextView\n" +
+ " android:layout_width=\"wrap_content\"\n" +
+ " android:layout_height=\"wrap_content\"\n" +
+ " android:text=\"Test status bar colour\"\n" +
+ " android:textSize=\"30sp\"/>\n" +
+ "</FrameLayout>";
+ // Create LayoutLibCallback.
+ LayoutLibTestCallback layoutLibCallback =
+ new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
+ layoutLibCallback.initResources();
+
+ SessionParams params = getSessionParamsBuilder()
+ .setParser(LayoutPullParser.createFromString(layout))
+ .setCallback(layoutLibCallback)
+ .setTheme("DarkStatusBarTheme", true)
+ .setRenderingMode(RenderingMode.V_SCROLL)
+ .build();
+
+ renderAndVerify(params, "dark_status_bar.png", TimeUnit.SECONDS.toNanos(2));
+
+ params = getSessionParamsBuilder()
+ .setParser(LayoutPullParser.createFromString(layout))
+ .setCallback(layoutLibCallback)
+ .setTheme("LightStatusBarTheme", true)
+ .setRenderingMode(RenderingMode.V_SCROLL)
+ .build();
+
+ renderAndVerify(params, "light_status_bar.png", TimeUnit.SECONDS.toNanos(2));
+ }
+
+ @Test
+ public void testSoftwareLayer() throws Exception {
+ String layout =
+ "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
+ " android:padding=\"16dp\"\n" +
+ " android:orientation=\"horizontal\"\n" +
+ " android:layout_width=\"fill_parent\"\n" +
+ " android:layout_height=\"fill_parent\">\n" +
+ " <com.android.layoutlib.test.myapplication.widgets.SoftwareTextView\n" +
+ " android:layout_height=\"200dp\"\n" +
+ " android:layout_width=\"wrap_content\" />\n" +
+ "</LinearLayout>\n";
+ LayoutPullParser parser = LayoutPullParser.createFromString(layout);
+ // Create LayoutLibCallback.
+ LayoutLibTestCallback layoutLibCallback =
+ new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
+ layoutLibCallback.initResources();
+
+ SessionParams params = getSessionParamsBuilder()
+ .setParser(parser)
+ .setCallback(layoutLibCallback)
+ .setTheme("Theme.Material.Light.NoActionBar.Fullscreen", false)
+ .setRenderingMode(RenderingMode.V_SCROLL)
+ .disableDecoration()
+ .build();
+
+ renderAndVerify(params, "software_layer.png",
+ TimeUnit.SECONDS.toNanos(2));
+ }
+
+ @Test
+ public void testHighSimulatedSdk() throws Exception {
+ String layout =
+ "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
+ " android:padding=\"16dp\"\n" +
+ " android:orientation=\"horizontal\"\n" +
+ " android:layout_width=\"fill_parent\"\n" +
+ " android:layout_height=\"fill_parent\">\n" +
+ " <TextView\n" +
+ " android:layout_height=\"wrap_content\"\n" +
+ " android:layout_width=\"wrap_content\"\n" +
+ " android:text=\"This is a TextView\" />\n" +
+ "</LinearLayout>\n";
+ LayoutPullParser parser = LayoutPullParser.createFromString(layout);
+ // Create LayoutLibCallback.
+ LayoutLibTestCallback layoutLibCallback =
+ new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
+ layoutLibCallback.initResources();
+
+ SessionParams params = getSessionParamsBuilder()
+ .setParser(parser)
+ .setCallback(layoutLibCallback)
+ .setTheme("Theme.Material.Light.NoActionBar.Fullscreen", false)
+ .setRenderingMode(RenderingMode.V_SCROLL)
+ .setSimulatedSdk(SDK_INT + 1)
+ .disableDecoration()
+ .build();
+
+ render(sBridge, params, -1);
+ boolean hasApiError = sRenderMessages.removeIf(message -> message.equals(String.format(
+ "The current rendering only supports APIs up to %d. You may encounter crashes if " +
+ "using with higher APIs. To avoid, you can set a lower API for your " +
+ "previews.", SDK_INT)));
+ assertTrue(hasApiError);
+ }
}