Merge "Fix rect shadow detection" into nyc-dev

This commit is contained in:
Diego Perez
2016-04-07 16:26:58 +00:00
committed by Android (Google) Code Review
6 changed files with 50 additions and 5 deletions

View File

@@ -44,6 +44,11 @@ public class RectShadowPainter {
private static final float PERPENDICULAR_ANGLE = 90f; private static final float PERPENDICULAR_ANGLE = 90f;
public static void paintShadow(Outline viewOutline, float elevation, Canvas canvas) { public static void paintShadow(Outline viewOutline, float elevation, Canvas canvas) {
Rect outline = new Rect();
if (!viewOutline.getRect(outline)) {
throw new IllegalArgumentException("Outline is not a rect shadow");
}
float shadowSize = elevationToShadow(elevation); float shadowSize = elevationToShadow(elevation);
int saved = modifyCanvas(canvas, shadowSize); int saved = modifyCanvas(canvas, shadowSize);
if (saved == -1) { if (saved == -1) {
@@ -54,8 +59,7 @@ public class RectShadowPainter {
cornerPaint.setStyle(Style.FILL); cornerPaint.setStyle(Style.FILL);
Paint edgePaint = new Paint(cornerPaint); Paint edgePaint = new Paint(cornerPaint);
edgePaint.setAntiAlias(false); edgePaint.setAntiAlias(false);
Rect outline = viewOutline.mRect; float radius = viewOutline.getRadius();
float radius = viewOutline.mRadius;
float outerArcRadius = radius + shadowSize; float outerArcRadius = radius + shadowSize;
int[] colors = {START_COLOR, START_COLOR, END_COLOR}; int[] colors = {START_COLOR, START_COLOR, END_COLOR};
cornerPaint.setShader(new RadialGradient(0, 0, outerArcRadius, colors, cornerPaint.setShader(new RadialGradient(0, 0, outerArcRadius, colors,

View File

@@ -64,7 +64,7 @@ public class ViewGroup_Delegate {
private static void drawShadow(ViewGroup parent, Canvas canvas, View child, private static void drawShadow(ViewGroup parent, Canvas canvas, View child,
Outline outline) { Outline outline) {
float elevation = getElevation(child, parent); float elevation = getElevation(child, parent);
if(outline.mRect != null) { if(outline.mMode == Outline.MODE_ROUND_RECT && outline.mRect != null) {
RectShadowPainter.paintShadow(outline, elevation, canvas); RectShadowPainter.paintShadow(outline, elevation, canvas);
return; return;
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@@ -197,6 +197,14 @@
android:inputType="numberPassword" android:inputType="numberPassword"
android:text="numeric password" /> android:text="numeric password" />
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/editText4"
android:layout_toEndOf="@id/editText4"
android:text="New ToggleButton" />
<EditText <EditText
android:id="@id/editText5" android:id="@id/editText5"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -31,8 +31,8 @@ import com.android.io.FolderWrapper;
import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.android.BridgeContext; import com.android.layoutlib.bridge.android.BridgeContext;
import com.android.layoutlib.bridge.android.RenderParamsFlags; import com.android.layoutlib.bridge.android.RenderParamsFlags;
import com.android.layoutlib.bridge.impl.RenderAction;
import com.android.layoutlib.bridge.impl.DelegateManager; import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.layoutlib.bridge.impl.RenderAction;
import com.android.layoutlib.bridge.intensive.setup.ConfigGenerator; import com.android.layoutlib.bridge.intensive.setup.ConfigGenerator;
import com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback; import com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback;
import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser; import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser;
@@ -42,8 +42,12 @@ import com.android.resources.ResourceType;
import com.android.utils.ILogger; import com.android.utils.ILogger;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
@@ -56,9 +60,12 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.google.android.collect.Lists;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@@ -105,6 +112,21 @@ public class Main {
private static ILogger sLogger; private static ILogger sLogger;
private static Bridge sBridge; private static Bridge sBridge;
/** List of log messages generated by a render call. It can be used to find specific errors */
private static ArrayList<String> sRenderMessages = Lists.newArrayList();
@Rule
public static TestWatcher sRenderMessageWatcher = new TestWatcher() {
@Override
protected void succeeded(Description description) {
// We only check error messages if the rest of the test case was successful.
if (!sRenderMessages.isEmpty()) {
fail(description.getMethodName() + " render error message: " + sRenderMessages.get
(0));
}
}
};
static { static {
// Test that System Properties are properly set. // Test that System Properties are properly set.
PLATFORM_DIR = getPlatformDir(); PLATFORM_DIR = getPlatformDir();
@@ -279,6 +301,11 @@ public class Main {
ConfigGenerator.getEnumMap(attrs), getLayoutLog()); ConfigGenerator.getEnumMap(attrs), getLayoutLog());
} }
@Before
public void beforeTestCase() {
sRenderMessages.clear();
}
/** Test activity.xml */ /** Test activity.xml */
@Test @Test
public void testActivity() throws ClassNotFoundException { public void testActivity() throws ClassNotFoundException {
@@ -289,6 +316,9 @@ public class Main {
@Test @Test
public void testAllWidgets() throws ClassNotFoundException { public void testAllWidgets() throws ClassNotFoundException {
renderAndVerify("allwidgets.xml", "allwidgets.png"); renderAndVerify("allwidgets.xml", "allwidgets.png");
// We expect fidelity warnings for Path.isConvex. Fail for anything else.
sRenderMessages.removeIf(message -> message.equals("Path.isConvex is not supported."));
} }
@Test @Test
@@ -299,6 +329,9 @@ public class Main {
@Test @Test
public void testAllWidgetsTablet() throws ClassNotFoundException { public void testAllWidgetsTablet() throws ClassNotFoundException {
renderAndVerify("allwidgets.xml", "allwidgets_tab.png", ConfigGenerator.NEXUS_7_2012); renderAndVerify("allwidgets.xml", "allwidgets_tab.png", ConfigGenerator.NEXUS_7_2012);
// We expect fidelity warnings for Path.isConvex. Fail for anything else.
sRenderMessages.removeIf(message -> message.equals("Path.isConvex is not supported."));
} }
private static void gc() { private static void gc() {
@@ -649,6 +682,6 @@ public class Main {
} }
private static void failWithMsg(@NonNull String msgFormat, Object... args) { private static void failWithMsg(@NonNull String msgFormat, Object... args) {
fail(args == null ? "" : String.format(msgFormat, args)); sRenderMessages.add(args == null ? msgFormat : String.format(msgFormat, args));
} }
} }