diff options
Diffstat (limited to 'tools/layoutlib')
23 files changed, 274 insertions, 106 deletions
diff --git a/tools/layoutlib/bridge/src/android/view/RectShadowPainter.java b/tools/layoutlib/bridge/src/android/view/RectShadowPainter.java new file mode 100644 index 0000000..ec3a8d6 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/view/RectShadowPainter.java @@ -0,0 +1,156 @@ +/* + * 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. + */ + +package android.view; + +import com.android.layoutlib.bridge.impl.ResourceHelper; + +import android.graphics.Canvas; +import android.graphics.LinearGradient; +import android.graphics.Outline; +import android.graphics.Paint; +import android.graphics.Paint.Style; +import android.graphics.Path; +import android.graphics.Path.FillType; +import android.graphics.RadialGradient; +import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.Region.Op; +import android.graphics.Shader.TileMode; + +/** + * Paints shadow for rounded rectangles. Inspiration from CardView. Couldn't use that directly, + * since it modifies the size of the content, that we can't do. + */ +public class RectShadowPainter { + + + private static final int START_COLOR = ResourceHelper.getColor("#37000000"); + private static final int END_COLOR = ResourceHelper.getColor("#03000000"); + private static final float PERPENDICULAR_ANGLE = 90f; + + public static void paintShadow(Outline viewOutline, float elevation, Canvas canvas) { + float shadowSize = elevationToShadow(elevation); + int saved = modifyCanvas(canvas, shadowSize); + if (saved == -1) { + return; + } + try { + Paint cornerPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); + cornerPaint.setStyle(Style.FILL); + Paint edgePaint = new Paint(cornerPaint); + edgePaint.setAntiAlias(false); + Rect outline = viewOutline.mRect; + float radius = viewOutline.mRadius; + float outerArcRadius = radius + shadowSize; + int[] colors = {START_COLOR, START_COLOR, END_COLOR}; + cornerPaint.setShader(new RadialGradient(0, 0, outerArcRadius, colors, + new float[]{0f, radius / outerArcRadius, 1f}, TileMode.CLAMP)); + edgePaint.setShader(new LinearGradient(0, 0, -shadowSize, 0, START_COLOR, END_COLOR, + TileMode.CLAMP)); + Path path = new Path(); + path.setFillType(FillType.EVEN_ODD); + // A rectangle bounding the complete shadow. + RectF shadowRect = new RectF(outline); + shadowRect.inset(-shadowSize, -shadowSize); + // A rectangle with edges corresponding to the straight edges of the outline. + RectF inset = new RectF(outline); + inset.inset(radius, radius); + // A rectangle used to represent the edge shadow. + RectF edgeShadowRect = new RectF(); + + + // left and right sides. + edgeShadowRect.set(-shadowSize, 0f, 0f, inset.height()); + // Left shadow + sideShadow(canvas, edgePaint, edgeShadowRect, outline.left, inset.top, 0); + // Right shadow + sideShadow(canvas, edgePaint, edgeShadowRect, outline.right, inset.bottom, 2); + // Top shadow + edgeShadowRect.set(-shadowSize, 0, 0, inset.width()); + sideShadow(canvas, edgePaint, edgeShadowRect, inset.right, outline.top, 1); + // bottom shadow. This needs an inset so that blank doesn't appear when the content is + // moved up. + edgeShadowRect.set(-shadowSize, 0, shadowSize / 2f, inset.width()); + edgePaint.setShader(new LinearGradient(edgeShadowRect.right, 0, edgeShadowRect.left, 0, + colors, new float[]{0f, 1 / 3f, 1f}, TileMode.CLAMP)); + sideShadow(canvas, edgePaint, edgeShadowRect, inset.left, outline.bottom, 3); + + // Draw corners. + drawCorner(canvas, cornerPaint, path, inset.right, inset.bottom, outerArcRadius, 0); + drawCorner(canvas, cornerPaint, path, inset.left, inset.bottom, outerArcRadius, 1); + drawCorner(canvas, cornerPaint, path, inset.left, inset.top, outerArcRadius, 2); + drawCorner(canvas, cornerPaint, path, inset.right, inset.top, outerArcRadius, 3); + } finally { + canvas.restoreToCount(saved); + } + } + + private static float elevationToShadow(float elevation) { + // The factor is chosen by eyeballing the shadow size on device and preview. + return elevation * 0.5f; + } + + /** + * Translate canvas by half of shadow size up, so that it appears that light is coming + * slightly from above. Also, remove clipping, so that shadow is not clipped. + */ + private static int modifyCanvas(Canvas canvas, float shadowSize) { + Rect clipBounds = canvas.getClipBounds(); + if (clipBounds.isEmpty()) { + return -1; + } + int saved = canvas.save(); + // Usually canvas has been translated to the top left corner of the view when this is + // called. So, setting a clip rect at 0,0 will clip the top left part of the shadow. + // Thus, we just expand in each direction by width and height of the canvas. + canvas.clipRect(-canvas.getWidth(), -canvas.getHeight(), canvas.getWidth(), + canvas.getHeight(), Op.REPLACE); + canvas.translate(0, shadowSize / 2f); + return saved; + } + + private static void sideShadow(Canvas canvas, Paint edgePaint, + RectF edgeShadowRect, float dx, float dy, int rotations) { + int saved = canvas.save(); + canvas.translate(dx, dy); + canvas.rotate(rotations * PERPENDICULAR_ANGLE); + canvas.drawRect(edgeShadowRect, edgePaint); + canvas.restoreToCount(saved); + } + + /** + * @param canvas Canvas to draw the rectangle on. + * @param paint Paint to use when drawing the corner. + * @param path A path to reuse. Prevents allocating memory for each path. + * @param x Center of circle, which this corner is a part of. + * @param y Center of circle, which this corner is a part of. + * @param radius radius of the arc + * @param rotations number of quarter rotations before starting to paint the arc. + */ + private static void drawCorner(Canvas canvas, Paint paint, Path path, float x, float y, + float radius, int rotations) { + int saved = canvas.save(); + canvas.translate(x, y); + path.reset(); + path.arcTo(-radius, -radius, radius, radius, rotations * PERPENDICULAR_ANGLE, + PERPENDICULAR_ANGLE, false); + path.lineTo(0, 0); + path.close(); + canvas.drawPath(path, paint); + canvas.restoreToCount(saved); + } +} diff --git a/tools/layoutlib/bridge/src/android/view/ViewGroup_Delegate.java b/tools/layoutlib/bridge/src/android/view/ViewGroup_Delegate.java index 82ae1df..e72a0db 100644 --- a/tools/layoutlib/bridge/src/android/view/ViewGroup_Delegate.java +++ b/tools/layoutlib/bridge/src/android/view/ViewGroup_Delegate.java @@ -16,12 +16,9 @@ package android.view; -import com.android.annotations.NonNull; -import com.android.layoutlib.bridge.android.BridgeContext; import com.android.resources.Density; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; -import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap_Delegate; import android.graphics.Canvas; @@ -29,8 +26,6 @@ import android.graphics.Outline; import android.graphics.Path_Delegate; import android.graphics.Rect; import android.graphics.Region.Op; -import android.util.DisplayMetrics; -import android.util.TypedValue; import android.view.animation.Transformation; import java.awt.Graphics2D; @@ -50,33 +45,36 @@ public class ViewGroup_Delegate { @LayoutlibDelegate /*package*/ static boolean drawChild(ViewGroup thisVG, Canvas canvas, View child, long drawingTime) { - boolean retVal = thisVG.drawChild_Original(canvas, child, drawingTime); if (child.getZ() > thisVG.getZ()) { ViewOutlineProvider outlineProvider = child.getOutlineProvider(); Outline outline = new Outline(); outlineProvider.getOutline(child, outline); - + if (outline.mPath == null && outline.mRect == null) { + // Sometimes, the bounds of the background drawable are not set until View.draw() + // is called. So, we set the bounds manually and try to get the outline again. + child.getBackground().setBounds(0, 0, child.mRight - child.mLeft, + child.mBottom - child.mTop); + outlineProvider.getOutline(child, outline); + } if (outline.mPath != null || (outline.mRect != null && !outline.mRect.isEmpty())) { int restoreTo = transformCanvas(thisVG, canvas, child); drawShadow(thisVG, canvas, child, outline); canvas.restoreToCount(restoreTo); } } - return retVal; + return thisVG.drawChild_Original(canvas, child, drawingTime); } private static void drawShadow(ViewGroup parent, Canvas canvas, View child, Outline outline) { + float elevation = getElevation(child, parent); + if(outline.mRect != null) { + RectShadowPainter.paintShadow(outline, elevation, canvas); + return; + } BufferedImage shadow = null; - int x = 0; - if (outline.mRect != null) { - Shadow s = getRectShadow(parent, canvas, child, outline); - if (s != null) { - shadow = s.mShadow; - x = -s.mShadowWidth; - } - } else if (outline.mPath != null) { - shadow = getPathShadow(child, outline, canvas); + if (outline.mPath != null) { + shadow = getPathShadow(outline, canvas, elevation); } if (shadow == null) { return; @@ -85,52 +83,17 @@ public class ViewGroup_Delegate { Density.getEnum(canvas.getDensity())); Rect clipBounds = canvas.getClipBounds(); Rect newBounds = new Rect(clipBounds); - newBounds.left = newBounds.left + x; + newBounds.inset((int)-elevation, (int)-elevation); canvas.clipRect(newBounds, Op.REPLACE); - canvas.drawBitmap(bitmap, x, 0, null); + canvas.drawBitmap(bitmap, 0, 0, null); canvas.clipRect(clipBounds, Op.REPLACE); } - private static Shadow getRectShadow(ViewGroup parent, Canvas canvas, View child, - Outline outline) { - BufferedImage shadow; - Rect clipBounds = canvas.getClipBounds(); - if (clipBounds.isEmpty()) { - return null; - } - float height = child.getZ() - parent.getZ(); - // Draw large shadow if difference in z index is more than 10dp - float largeShadowThreshold = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10f, - getMetrics(child)); - boolean largeShadow = height > largeShadowThreshold; - int shadowSize = largeShadow ? ShadowPainter.SHADOW_SIZE : ShadowPainter.SMALL_SHADOW_SIZE; - shadow = new BufferedImage(clipBounds.width() + shadowSize, clipBounds.height(), - BufferedImage.TYPE_INT_ARGB); - Graphics2D graphics = shadow.createGraphics(); - Rect rect = outline.mRect; - if (largeShadow) { - ShadowPainter.drawRectangleShadow(graphics, - rect.left + shadowSize, rect.top, rect.width(), rect.height()); - } else { - ShadowPainter.drawSmallRectangleShadow(graphics, - rect.left + shadowSize, rect.top, rect.width(), rect.height()); - } - graphics.dispose(); - return new Shadow(shadow, shadowSize); - } - - @NonNull - private static DisplayMetrics getMetrics(View view) { - Context context = view.getContext(); - context = BridgeContext.getBaseContext(context); - if (context instanceof BridgeContext) { - return ((BridgeContext) context).getMetrics(); - } - throw new RuntimeException("View " + view.getClass().getName() + " not created with the " + - "right context"); + private static float getElevation(View child, ViewGroup parent) { + return child.getZ() - parent.getZ(); } - private static BufferedImage getPathShadow(View child, Outline outline, Canvas canvas) { + private static BufferedImage getPathShadow(Outline outline, Canvas canvas, float elevation) { Rect clipBounds = canvas.getClipBounds(); if (clipBounds.isEmpty()) { return null; @@ -140,7 +103,7 @@ public class ViewGroup_Delegate { Graphics2D graphics = image.createGraphics(); graphics.draw(Path_Delegate.getDelegate(outline.mPath.mNativePath).getJavaShape()); graphics.dispose(); - return ShadowPainter.createDropShadow(image, ((int) child.getZ())); + return ShadowPainter.createDropShadow(image, (int) elevation); } // Copied from android.view.View#draw(Canvas, ViewGroup, long) and removed code paths @@ -194,15 +157,4 @@ public class ViewGroup_Delegate { } return restoreTo; } - - private static class Shadow { - public BufferedImage mShadow; - public int mShadowWidth; - - public Shadow(BufferedImage shadow, int shadowWidth) { - mShadow = shadow; - mShadowWidth = shadowWidth; - } - - } } diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build.gradle b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build.gradle index 80be12d..491dee8 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build.gradle +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:0.12.+' + classpath 'com.android.tools.build:gradle:1.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -19,23 +19,21 @@ allprojects { apply plugin: 'com.android.application' android { - compileSdkVersion 20 - buildToolsVersion '20' + compileSdkVersion 21 + buildToolsVersion '21.1.2' defaultConfig { applicationId 'com.android.layoutlib.test.myapplication' minSdkVersion 19 - targetSdkVersion 20 + targetSdkVersion 21 versionCode 1 versionName '1.0' } buildTypes { release { - runProguard false + minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - productFlavors { - } } dependencies { diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/BuildConfig.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/BuildConfig.class Binary files differindex 2b4f7bf..e29e490 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/BuildConfig.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/BuildConfig.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/CustomCalendar.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/CustomCalendar.class Binary files differnew file mode 100644 index 0000000..4ae0da7 --- /dev/null +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/CustomCalendar.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/CustomDate.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/CustomDate.class Binary files differnew file mode 100644 index 0000000..6729eb4 --- /dev/null +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/CustomDate.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/MyActivity.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/MyActivity.class Binary files differindex d252462..985d267 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/MyActivity.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/MyActivity.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$attr.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$attr.class Binary files differindex 9bab801..5142ca6 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$attr.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$attr.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$dimen.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$dimen.class Binary files differindex 7ad8605..cb52ba5 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$dimen.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$dimen.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$drawable.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$drawable.class Binary files differindex e9e0a33..5290cf6 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$drawable.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$drawable.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$id.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$id.class Binary files differindex d109302..49b1df6 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$id.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$id.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$layout.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$layout.class Binary files differindex 816ecc8..85b2029 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$layout.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$layout.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$menu.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$menu.class Binary files differindex b034b75..428fdf4 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$menu.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$menu.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$string.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$string.class Binary files differindex f86b1d3..027d5d3 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$string.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$string.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$style.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$style.class Binary files differindex 8bbae90..c7d64f8 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$style.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$style.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R.class Binary files differindex 8af745d..8831b71 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R.class +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R.class diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/activity.png b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/activity.png Binary files differindex 943cdf1..e38f437 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/activity.png +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/activity.png diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/gradle/wrapper/gradle-wrapper.properties b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/gradle/wrapper/gradle-wrapper.properties index 5de946b..3b51ffe 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/gradle/wrapper/gradle-wrapper.properties +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Apr 10 15:27:10 PDT 2013 +#Tue Mar 17 15:13:06 PDT 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/androidTest/java/com/android/layoulib/test/myapplication/ApplicationTest.java b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/androidTest/java/com/android/layoulib/test/myapplication/ApplicationTest.java deleted file mode 100644 index 7304af1..0000000 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/androidTest/java/com/android/layoulib/test/myapplication/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.android.layoulib.test.myapplication; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> - */ -public class ApplicationTest extends ApplicationTestCase<Application> { - public ApplicationTest() { - super(Application.class); - } -}
\ No newline at end of file diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/java/com/android/layoutlib/test/myapplication/CustomCalendar.java b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/java/com/android/layoutlib/test/myapplication/CustomCalendar.java new file mode 100644 index 0000000..80bbaf1 --- /dev/null +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/java/com/android/layoutlib/test/myapplication/CustomCalendar.java @@ -0,0 +1,31 @@ +package com.android.layoutlib.test.myapplication; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.CalendarView; + +public class CustomCalendar extends CalendarView { + public CustomCalendar(Context context) { + super(context); + init(); + } + + public CustomCalendar(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public CustomCalendar(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + public CustomCalendar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(); + } + + private void init() { + setDate(871703200000L, false, true); + } +} diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/java/com/android/layoutlib/test/myapplication/CustomDate.java b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/java/com/android/layoutlib/test/myapplication/CustomDate.java new file mode 100644 index 0000000..cb750f4 --- /dev/null +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/java/com/android/layoutlib/test/myapplication/CustomDate.java @@ -0,0 +1,31 @@ +package com.android.layoutlib.test.myapplication; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.DatePicker; + +public class CustomDate extends DatePicker { + public CustomDate(Context context) { + super(context); + init(); + } + + public CustomDate(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public CustomDate(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + public CustomDate(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(); + } + + private void init() { + init(2015, 0, 20, null); + } +} diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/layout.xml b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/layout.xml index b8ec5661..c1f663e 100644 --- a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/layout.xml +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/layout.xml @@ -1,17 +1,25 @@ <?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" android:layout_width="match_parent" +<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:columnCount="2" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Some text"/> - <DatePicker - android:layout_width="100dp" - android:layout_height="100dp"/> - <CalendarView + <Switch + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:checked="true" + android:layout_gravity="center" + /> + <com.android.layoutlib.test.myapplication.CustomDate android:layout_width="100dp" - android:layout_height="100dp"/> -</LinearLayout>
\ No newline at end of file + android:layout_height="wrap_content"/> + <com.android.layoutlib.test.myapplication.CustomCalendar + android:layout_width="200dp" + android:layout_gravity="center_horizontal" + android:layout_height="200dp"/> +</GridLayout>
\ No newline at end of file diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java index 96725af..a8c5248 100644 --- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java +++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java @@ -300,7 +300,8 @@ public class Main { FolderConfiguration config = configGenerator.getFolderConfig(); ResourceResolver resourceResolver = ResourceResolver.create(mProjectResources.getConfiguredResources(config), - mFrameworkRepo.getConfiguredResources(config), "Theme.Material", false); + mFrameworkRepo.getConfiguredResources(config), + "Theme.Material.Light.DarkActionBar", false); return new SessionParams( layoutParser, @@ -320,7 +321,7 @@ public class Main { @Override public void warning(String tag, String message, Object data) { System.out.println("Warning " + tag + ": " + message); - fail(message); + failWithMsg(message); } @Override @@ -330,13 +331,13 @@ public class Main { if (throwable != null) { throwable.printStackTrace(); } - fail(message); + failWithMsg(message); } @Override public void error(String tag, String message, Object data) { System.out.println("Error " + tag + ": " + message); - fail(message); + failWithMsg(message); } @Override @@ -345,7 +346,7 @@ public class Main { if (throwable != null) { throwable.printStackTrace(); } - fail(message); + failWithMsg(message); } }; } @@ -360,12 +361,12 @@ public class Main { if (t != null) { t.printStackTrace(); } - fail(String.format(msgFormat, args)); + failWithMsg(msgFormat, args); } @Override public void warning(String msgFormat, Object... args) { - fail(String.format(msgFormat, args)); + failWithMsg(msgFormat, args); } @Override @@ -381,4 +382,8 @@ public class Main { } return mLogger; } + + private static void failWithMsg(String msgFormat, Object... args) { + fail(msgFormat == null || args == null ? "" : String.format(msgFormat, args)); + } } |