Merge "Inline some of the files into the tests"
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:padding="16dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<ImageView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:src="@drawable/adaptive" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:padding="16dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<ProgressBar
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:padding="16dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.android.layoutlib.test.myapplication.widgets.InsetsWidget
|
||||
android:text="Hello world"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/text1"/>
|
||||
</LinearLayout>
|
||||
@@ -1,32 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (C) 2016 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin">
|
||||
|
||||
<TextView
|
||||
android:text="@string/hello_world"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="200dp"
|
||||
android:background="#FF0000"
|
||||
android:id="@+id/text1"/>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (C) 2015 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:padding="16dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<ImageView
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:src="@drawable/multi_path" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (C) 2016 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:padding="16dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<ImageView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:src="@drawable/android"/>
|
||||
<ImageView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:src="@drawable/headset"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -26,6 +26,8 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
/**
|
||||
* Set of render tests
|
||||
*/
|
||||
@@ -38,18 +40,19 @@ public class PerformanceTests extends RenderTestBase {
|
||||
}
|
||||
|
||||
|
||||
private void render(@NonNull String layoutFileName) throws ClassNotFoundException {
|
||||
private void render(@NonNull String layoutFileName)
|
||||
throws ClassNotFoundException, FileNotFoundException {
|
||||
SessionParams params = createSessionParams(layoutFileName, ConfigGenerator.NEXUS_5);
|
||||
render(params, 250);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActivity() throws ClassNotFoundException {
|
||||
public void testActivity() throws ClassNotFoundException, FileNotFoundException {
|
||||
render("activity.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllWidgets() throws ClassNotFoundException {
|
||||
public void testAllWidgets() throws ClassNotFoundException, FileNotFoundException {
|
||||
render("allwidgets.xml");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@@ -483,8 +484,9 @@ public class RenderTestBase {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected LayoutPullParser createLayoutPullParser(String layoutPath) {
|
||||
return new LayoutPullParser(APP_TEST_RES + "/layout/" + layoutPath);
|
||||
protected LayoutPullParser createParserFromPath(String layoutPath)
|
||||
throws FileNotFoundException {
|
||||
return LayoutPullParser.createFromPath(APP_TEST_RES + "/layout/" + layoutPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,7 +495,7 @@ public class RenderTestBase {
|
||||
*/
|
||||
@Nullable
|
||||
protected RenderResult renderAndVerify(String layoutFileName, String goldenFileName)
|
||||
throws ClassNotFoundException {
|
||||
throws ClassNotFoundException, FileNotFoundException {
|
||||
return renderAndVerify(layoutFileName, goldenFileName, ConfigGenerator.NEXUS_5);
|
||||
}
|
||||
|
||||
@@ -503,15 +505,15 @@ public class RenderTestBase {
|
||||
*/
|
||||
@Nullable
|
||||
protected RenderResult renderAndVerify(String layoutFileName, String goldenFileName,
|
||||
ConfigGenerator deviceConfig) throws ClassNotFoundException {
|
||||
ConfigGenerator deviceConfig) throws ClassNotFoundException, FileNotFoundException {
|
||||
SessionParams params = createSessionParams(layoutFileName, deviceConfig);
|
||||
return renderAndVerify(params, goldenFileName);
|
||||
}
|
||||
|
||||
protected SessionParams createSessionParams(String layoutFileName, ConfigGenerator deviceConfig)
|
||||
throws ClassNotFoundException {
|
||||
throws ClassNotFoundException, FileNotFoundException {
|
||||
// Create the layout pull parser.
|
||||
LayoutPullParser parser = createLayoutPullParser(layoutFileName);
|
||||
LayoutPullParser parser = createParserFromPath(layoutFileName);
|
||||
// Create LayoutLibCallback.
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
|
||||
@@ -38,6 +38,7 @@ import android.content.res.Resources;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -54,17 +55,32 @@ import static org.junit.Assert.assertTrue;
|
||||
public class RenderTests extends RenderTestBase {
|
||||
|
||||
@Test
|
||||
public void testActivity() throws ClassNotFoundException {
|
||||
public void testActivity() throws ClassNotFoundException, FileNotFoundException {
|
||||
renderAndVerify("activity.xml", "activity.png");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActivityOnOldTheme() throws ClassNotFoundException {
|
||||
public void testActivityOnOldTheme() throws ClassNotFoundException, FileNotFoundException {
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
layoutLibCallback.initResources();
|
||||
|
||||
LayoutPullParser parser = createLayoutPullParser("simple_activity.xml");
|
||||
LayoutPullParser parser = LayoutPullParser.createFromString(
|
||||
"<RelativeLayout xmlns:android=\"http://schemas" +
|
||||
".android.com/apk/res/android\"\n" +
|
||||
" android:layout_width=\"match_parent\"\n" +
|
||||
" android:layout_height=\"match_parent\"\n" +
|
||||
" android:paddingLeft=\"@dimen/activity_horizontal_margin\"\n" +
|
||||
" android:paddingRight=\"@dimen/activity_horizontal_margin\"\n" +
|
||||
" android:paddingTop=\"@dimen/activity_vertical_margin\"\n" +
|
||||
" android:paddingBottom=\"@dimen/activity_vertical_margin\">\n" +
|
||||
" <TextView\n" +
|
||||
" android:text=\"@string/hello_world\"\n" +
|
||||
" android:layout_width=\"wrap_content\"\n" +
|
||||
" android:layout_height=\"200dp\"\n" +
|
||||
" android:background=\"#FF0000\"\n" +
|
||||
" android:id=\"@+id/text1\"/>\n" +
|
||||
"</RelativeLayout>");
|
||||
SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5,
|
||||
layoutLibCallback, "Theme.NoTitleBar", false,
|
||||
RenderingMode.NORMAL, 22);
|
||||
@@ -73,24 +89,24 @@ public class RenderTests extends RenderTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTranslucentBars() throws ClassNotFoundException {
|
||||
public void testTranslucentBars() throws ClassNotFoundException, FileNotFoundException {
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
layoutLibCallback.initResources();
|
||||
|
||||
LayoutPullParser parser = createLayoutPullParser("four_corners.xml");
|
||||
LayoutPullParser parser = createParserFromPath("four_corners.xml");
|
||||
SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5,
|
||||
layoutLibCallback, "Theme.Material.Light.NoActionBar.TranslucentDecor", false,
|
||||
RenderingMode.NORMAL, 22);
|
||||
renderAndVerify(params, "four_corners_translucent.png");
|
||||
|
||||
parser = createLayoutPullParser("four_corners.xml");
|
||||
parser = createParserFromPath("four_corners.xml");
|
||||
params = getSessionParams(parser, ConfigGenerator.NEXUS_5_LAND,
|
||||
layoutLibCallback, "Theme.Material.Light.NoActionBar.TranslucentDecor", false,
|
||||
RenderingMode.NORMAL, 22);
|
||||
renderAndVerify(params, "four_corners_translucent_land.png");
|
||||
|
||||
parser = createLayoutPullParser("four_corners.xml");
|
||||
parser = createParserFromPath("four_corners.xml");
|
||||
params = getSessionParams(parser, ConfigGenerator.NEXUS_5,
|
||||
layoutLibCallback, "Theme.Material.Light.NoActionBar", false,
|
||||
RenderingMode.NORMAL, 22);
|
||||
@@ -98,7 +114,7 @@ public class RenderTests extends RenderTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllWidgets() throws ClassNotFoundException {
|
||||
public void testAllWidgets() throws ClassNotFoundException, FileNotFoundException {
|
||||
renderAndVerify("allwidgets.xml", "allwidgets.png");
|
||||
|
||||
// We expect fidelity warnings for Path.isConvex. Fail for anything else.
|
||||
@@ -106,12 +122,12 @@ public class RenderTests extends RenderTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayCheck() throws ClassNotFoundException {
|
||||
public void testArrayCheck() throws ClassNotFoundException, FileNotFoundException {
|
||||
renderAndVerify("array_check.xml", "array_check.png");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllWidgetsTablet() throws ClassNotFoundException {
|
||||
public void testAllWidgetsTablet() throws ClassNotFoundException, FileNotFoundException {
|
||||
renderAndVerify("allwidgets.xml", "allwidgets_tab.png", ConfigGenerator.NEXUS_7_2012);
|
||||
|
||||
// We expect fidelity warnings for Path.isConvex. Fail for anything else.
|
||||
@@ -120,7 +136,23 @@ public class RenderTests extends RenderTestBase {
|
||||
|
||||
@Test
|
||||
public void testActivityActionBar() throws ClassNotFoundException {
|
||||
LayoutPullParser parser = createLayoutPullParser("simple_activity.xml");
|
||||
String simpleActivity =
|
||||
"<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
|
||||
" android:layout_width=\"match_parent\"\n" +
|
||||
" android:layout_height=\"match_parent\"\n" +
|
||||
" android:paddingLeft=\"@dimen/activity_horizontal_margin\"\n" +
|
||||
" android:paddingRight=\"@dimen/activity_horizontal_margin\"\n" +
|
||||
" android:paddingTop=\"@dimen/activity_vertical_margin\"\n" +
|
||||
" android:paddingBottom=\"@dimen/activity_vertical_margin\">\n" +
|
||||
" <TextView\n" +
|
||||
" android:text=\"@string/hello_world\"\n" +
|
||||
" android:layout_width=\"wrap_content\"\n" +
|
||||
" android:layout_height=\"200dp\"\n" +
|
||||
" android:background=\"#FF0000\"\n" +
|
||||
" android:id=\"@+id/text1\"/>\n" +
|
||||
"</RelativeLayout>";
|
||||
|
||||
LayoutPullParser parser = LayoutPullParser.createFromString(simpleActivity);
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
layoutLibCallback.initResources();
|
||||
@@ -131,7 +163,7 @@ public class RenderTests extends RenderTestBase {
|
||||
|
||||
renderAndVerify(params, "simple_activity_noactionbar.png");
|
||||
|
||||
parser = createLayoutPullParser("simple_activity.xml");
|
||||
parser = LayoutPullParser.createFromString(simpleActivity);
|
||||
params = getSessionParams(parser, ConfigGenerator.NEXUS_5,
|
||||
layoutLibCallback, "Theme.Material.Light", false,
|
||||
RenderingMode.V_SCROLL, 22);
|
||||
@@ -140,7 +172,7 @@ public class RenderTests extends RenderTestBase {
|
||||
|
||||
// This also tests that a theme with "NoActionBar" DOES HAVE an action bar when we are
|
||||
// displaying menus.
|
||||
parser = createLayoutPullParser("simple_activity.xml");
|
||||
parser = LayoutPullParser.createFromString(simpleActivity);
|
||||
params = getSessionParams(parser, ConfigGenerator.NEXUS_5,
|
||||
layoutLibCallback, "Theme.Material.Light.NoActionBar", false,
|
||||
RenderingMode.V_SCROLL, 22);
|
||||
@@ -158,7 +190,17 @@ public class RenderTests extends RenderTestBase {
|
||||
Field field = insetsWidgetClass.getDeclaredField("sApplyInsetsCalled");
|
||||
assertFalse((Boolean)field.get(null));
|
||||
|
||||
LayoutPullParser parser = createLayoutPullParser("insets.xml");
|
||||
LayoutPullParser parser = LayoutPullParser.createFromString(
|
||||
"<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
|
||||
" android:padding=\"16dp\"\n" +
|
||||
" android:orientation=\"horizontal\"\n" +
|
||||
" android:layout_width=\"wrap_content\"\n" +
|
||||
" android:layout_height=\"wrap_content\">\n" + "\n" +
|
||||
" <com.android.layoutlib.test.myapplication.widgets.InsetsWidget\n" +
|
||||
" android:text=\"Hello world\"\n" +
|
||||
" android:layout_width=\"wrap_content\"\n" +
|
||||
" android:layout_height=\"wrap_content\"\n" +
|
||||
" android:id=\"@+id/text1\"/>\n" + "</LinearLayout>\n");
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
layoutLibCallback.initResources();
|
||||
@@ -174,9 +216,9 @@ public class RenderTests extends RenderTestBase {
|
||||
|
||||
/** Test expand_layout.xml */
|
||||
@Test
|
||||
public void testExpand() throws ClassNotFoundException {
|
||||
public void testExpand() throws ClassNotFoundException, FileNotFoundException {
|
||||
// Create the layout pull parser.
|
||||
LayoutPullParser parser = createLayoutPullParser("expand_vert_layout.xml");
|
||||
LayoutPullParser parser = createParserFromPath("expand_vert_layout.xml");
|
||||
// Create LayoutLibCallback.
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
@@ -199,7 +241,7 @@ public class RenderTests extends RenderTestBase {
|
||||
.setScreenHeight(300)
|
||||
.setDensity(Density.XHIGH)
|
||||
.setNavigation(Navigation.NONAV);
|
||||
parser = createLayoutPullParser("expand_horz_layout.xml");
|
||||
parser = createParserFromPath("expand_horz_layout.xml");
|
||||
params = getSessionParams(parser, customConfigGenerator,
|
||||
layoutLibCallback, "Theme.Material.Light.NoActionBar.Fullscreen", false,
|
||||
RenderingMode.H_SCROLL, 22);
|
||||
@@ -210,8 +252,18 @@ public class RenderTests extends RenderTestBase {
|
||||
/** Test indeterminate_progressbar.xml */
|
||||
@Test
|
||||
public void testVectorAnimation() throws ClassNotFoundException {
|
||||
String layout = "\n" +
|
||||
"<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" + "\n" +
|
||||
" <ProgressBar\n" + " android:layout_height=\"fill_parent\"\n" +
|
||||
" android:layout_width=\"fill_parent\" />\n" + "\n" +
|
||||
"</LinearLayout>\n";
|
||||
|
||||
// Create the layout pull parser.
|
||||
LayoutPullParser parser = createLayoutPullParser("indeterminate_progressbar.xml");
|
||||
LayoutPullParser parser = LayoutPullParser.createFromString(layout);
|
||||
// Create LayoutLibCallback.
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
@@ -223,7 +275,7 @@ public class RenderTests extends RenderTestBase {
|
||||
|
||||
renderAndVerify(params, "animated_vector.png", TimeUnit.SECONDS.toNanos(2));
|
||||
|
||||
parser = createLayoutPullParser("indeterminate_progressbar.xml");
|
||||
parser = LayoutPullParser.createFromString(layout);
|
||||
params = getSessionParams(parser, ConfigGenerator.NEXUS_5,
|
||||
layoutLibCallback, "Theme.Material.NoActionBar.Fullscreen", false,
|
||||
RenderingMode.V_SCROLL, 22);
|
||||
@@ -237,7 +289,17 @@ public class RenderTests extends RenderTestBase {
|
||||
@Test
|
||||
public void testVectorDrawable() throws ClassNotFoundException {
|
||||
// Create the layout pull parser.
|
||||
LayoutPullParser parser = createLayoutPullParser("vector_drawable.xml");
|
||||
LayoutPullParser parser = LayoutPullParser.createFromString(
|
||||
"<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" +
|
||||
" <ImageView\n" +
|
||||
" android:layout_height=\"fill_parent\"\n" +
|
||||
" android:layout_width=\"fill_parent\"\n" +
|
||||
" android:src=\"@drawable/multi_path\" />\n" + "\n" +
|
||||
"</LinearLayout>");
|
||||
// Create LayoutLibCallback.
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
@@ -256,7 +318,21 @@ public class RenderTests extends RenderTestBase {
|
||||
@Test
|
||||
public void testVectorDrawable91383() throws ClassNotFoundException {
|
||||
// Create the layout pull parser.
|
||||
LayoutPullParser parser = createLayoutPullParser("vector_drawable_android.xml");
|
||||
LayoutPullParser parser = LayoutPullParser.createFromString(
|
||||
"<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
|
||||
" android:padding=\"16dp\"\n" +
|
||||
" android:orientation=\"vertical\"\n" +
|
||||
" android:layout_width=\"fill_parent\"\n" +
|
||||
" android:layout_height=\"fill_parent\">\n" +
|
||||
" <ImageView\n" +
|
||||
" android:layout_height=\"wrap_content\"\n" +
|
||||
" android:layout_width=\"wrap_content\"\n" +
|
||||
" android:src=\"@drawable/android\"/>\n" +
|
||||
" <ImageView\n" +
|
||||
" android:layout_height=\"wrap_content\"\n" +
|
||||
" android:layout_width=\"wrap_content\"\n" +
|
||||
" android:src=\"@drawable/headset\"/>\n" +
|
||||
"</LinearLayout>");
|
||||
// Create LayoutLibCallback.
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
@@ -271,9 +347,9 @@ public class RenderTests extends RenderTestBase {
|
||||
|
||||
/** Test activity.xml */
|
||||
@Test
|
||||
public void testScrollingAndMeasure() throws ClassNotFoundException {
|
||||
public void testScrollingAndMeasure() throws ClassNotFoundException, FileNotFoundException {
|
||||
// Create the layout pull parser.
|
||||
LayoutPullParser parser = createLayoutPullParser("scrolled.xml");
|
||||
LayoutPullParser parser = createParserFromPath("scrolled.xml");
|
||||
// Create LayoutLibCallback.
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
@@ -307,7 +383,7 @@ public class RenderTests extends RenderTestBase {
|
||||
assertEquals(690, rootLayout.getChildren().get(5).getChildren().get(0).getRight());
|
||||
|
||||
// Do a full render pass
|
||||
parser = createLayoutPullParser("scrolled.xml");
|
||||
parser = createParserFromPath("scrolled.xml");
|
||||
|
||||
params = getSessionParams(parser, ConfigGenerator.NEXUS_5,
|
||||
layoutLibCallback, "Theme.Material.NoActionBar.Fullscreen", false,
|
||||
@@ -326,7 +402,7 @@ public class RenderTests extends RenderTestBase {
|
||||
// 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");
|
||||
LayoutPullParser parser = LayoutPullParser.createFromPath("/empty.xml");
|
||||
// Create LayoutLibCallback.
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
@@ -363,7 +439,7 @@ public class RenderTests extends RenderTestBase {
|
||||
// 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");
|
||||
LayoutPullParser parser = LayoutPullParser.createFromPath("/empty.xml");
|
||||
// Create LayoutLibCallback.
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(RenderTestBase.getLogger(), mDefaultClassLoader);
|
||||
@@ -390,15 +466,25 @@ public class RenderTests extends RenderTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFonts() throws ClassNotFoundException {
|
||||
public void testFonts() throws ClassNotFoundException, FileNotFoundException {
|
||||
// TODO: styles seem to be broken in TextView
|
||||
renderAndVerify("fonts_test.xml", "font_test.png");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdaptiveIcon() throws ClassNotFoundException {
|
||||
public void testAdaptiveIcon() throws ClassNotFoundException, FileNotFoundException {
|
||||
// Create the layout pull parser.
|
||||
LayoutPullParser parser = createLayoutPullParser("adaptive_icon.xml");
|
||||
LayoutPullParser parser = LayoutPullParser.createFromString(
|
||||
"<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" +
|
||||
" <ImageView\n" +
|
||||
" android:layout_height=\"wrap_content\"\n" +
|
||||
" android:layout_width=\"wrap_content\"\n" +
|
||||
" android:src=\"@drawable/adaptive\" />\n" +
|
||||
"</LinearLayout>\n");
|
||||
// Create LayoutLibCallback.
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(getLogger(), mDefaultClassLoader);
|
||||
@@ -416,7 +502,7 @@ public class RenderTests extends RenderTestBase {
|
||||
// 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");
|
||||
LayoutPullParser parser = LayoutPullParser.createFromPath("/empty.xml");
|
||||
// Create LayoutLibCallback.
|
||||
LayoutLibTestCallback layoutLibCallback =
|
||||
new LayoutLibTestCallback(RenderTestBase.getLogger(), mDefaultClassLoader);
|
||||
|
||||
@@ -39,6 +39,7 @@ import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -147,7 +148,11 @@ public class LayoutLibTestCallback extends LayoutlibCallback {
|
||||
|
||||
@Override
|
||||
public ILayoutPullParser getParser(ResourceValue layoutResource) {
|
||||
return new LayoutPullParser(new File(layoutResource.getValue()));
|
||||
try {
|
||||
return LayoutPullParser.createFromFile(new File(layoutResource.getValue()));
|
||||
} catch (FileNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,11 +21,15 @@ import com.android.ide.common.rendering.api.ILayoutPullParser;
|
||||
import org.kxml2.io.KXmlParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOError;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -37,37 +41,40 @@ import static com.android.SdkConstants.SPINNER;
|
||||
import static com.android.SdkConstants.TOOLS_URI;
|
||||
|
||||
public class LayoutPullParser extends KXmlParser implements ILayoutPullParser{
|
||||
@NonNull
|
||||
public static LayoutPullParser createFromFile(@NonNull File layoutFile)
|
||||
throws FileNotFoundException {
|
||||
return new LayoutPullParser(new FileInputStream(layoutFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param layoutPath Must start with '/' and be relative to test resources.
|
||||
*/
|
||||
public LayoutPullParser(String layoutPath) {
|
||||
@NonNull
|
||||
public static LayoutPullParser createFromPath(@NonNull String layoutPath) {
|
||||
if (layoutPath.startsWith("/")) {
|
||||
layoutPath = layoutPath.substring(1);
|
||||
}
|
||||
|
||||
return new LayoutPullParser(LayoutPullParser.class.getClassLoader().getResourceAsStream
|
||||
(layoutPath));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static LayoutPullParser createFromString(@NonNull String contents) {
|
||||
return new LayoutPullParser(new ByteArrayInputStream(
|
||||
contents.getBytes(Charset.forName("UTF-8"))));
|
||||
}
|
||||
|
||||
private LayoutPullParser(@NonNull InputStream inputStream) {
|
||||
try {
|
||||
init(getClass().getClassLoader().getResourceAsStream(layoutPath));
|
||||
setFeature(FEATURE_PROCESS_NAMESPACES, true);
|
||||
setInput(inputStream, null);
|
||||
} catch (XmlPullParserException e) {
|
||||
throw new IOError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param layoutFile Path of the layout xml file on disk.
|
||||
*/
|
||||
public LayoutPullParser(File layoutFile) {
|
||||
try {
|
||||
init(new FileInputStream(layoutFile));
|
||||
} catch (XmlPullParserException | FileNotFoundException e) {
|
||||
throw new IOError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void init(InputStream stream) throws XmlPullParserException {
|
||||
setFeature(FEATURE_PROCESS_NAMESPACES, true);
|
||||
setInput(stream, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getViewCookie() {
|
||||
// TODO: Implement this properly.
|
||||
|
||||
Reference in New Issue
Block a user