Loading tools/layoutlib/bridge/src/android/graphics/Canvas.java +37 −38 Original line number Diff line number Diff line Loading @@ -104,22 +104,35 @@ public class Canvas extends _Original_Canvas { * Creates a new {@link Graphics2D} based on the {@link Paint} parameters. * <p/>The object must be disposed ({@link Graphics2D#dispose()}) after being used. */ private Graphics2D getNewGraphics(Paint paint, Graphics2D g) { private Graphics2D getCustomGraphics(Paint paint) { // make new one Graphics2D g = getGraphics2d(); g = (Graphics2D)g.create(); // configure it g.setColor(new Color(paint.getColor())); int alpha = paint.getAlpha(); float falpha = alpha / 255.f; if (paint.getStyle() == Style.STROKE) { Style style = paint.getStyle(); if (style == Style.STROKE || style == Style.FILL_AND_STROKE) { PathEffect e = paint.getPathEffect(); if (e instanceof DashPathEffect) { DashPathEffect dpe = (DashPathEffect)e; g.setStroke(new BasicStroke( paint.getStrokeWidth(), paint.getStrokeCap().getJavaCap(), paint.getStrokeJoin().getJavaJoin(), paint.getStrokeMiter() // FIXME: add dash info. )); paint.getStrokeMiter(), dpe.getIntervals(), dpe.getPhase())); } else { g.setStroke(new BasicStroke( paint.getStrokeWidth(), paint.getStrokeCap().getJavaCap(), paint.getStrokeJoin().getJavaJoin(), paint.getStrokeMiter())); } } Xfermode xfermode = paint.getXfermode(); Loading Loading @@ -795,11 +808,9 @@ public class Canvas extends _Original_Canvas { } private final void doDrawRect(int left, int top, int width, int height, Paint paint) { // get current graphisc if (width > 0 && height > 0) { Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); Style style = paint.getStyle(); Loading @@ -822,11 +833,9 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) { // get current graphisc if (rect.width() > 0 && rect.height() > 0) { Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); Style style = paint.getStyle(); Loading Loading @@ -856,10 +865,8 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { // get current graphisc Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); g.drawLine((int)startX, (int)startY, (int)stopX, (int)stopY); Loading @@ -872,10 +879,8 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawLines(float[] pts, int offset, int count, Paint paint) { // get current graphisc Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); for (int i = 0 ; i < count ; i += 4) { g.drawLine((int)pts[i + offset], (int)pts[i + offset + 1], Loading @@ -899,10 +904,8 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawCircle(float cx, float cy, float radius, Paint paint) { // get current graphisc Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); Style style = paint.getStyle(); Loading @@ -926,10 +929,8 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawOval(RectF oval, Paint paint) { // get current graphics Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); Style style = paint.getStyle(); Loading @@ -951,10 +952,8 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawPath(Path path, Paint paint) { // get current graphics Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); Style style = paint.getStyle(); Loading tools/layoutlib/bridge/src/android/graphics/DashPathEffect.java 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright (C) 2010 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.graphics; public class DashPathEffect extends PathEffect { private final float[] mIntervals; private final float mPhase; /** * The intervals array must contain an even number of entries (>=2), with * the even indices specifying the "on" intervals, and the odd indices * specifying the "off" intervals. phase is an offset into the intervals * array (mod the sum of all of the intervals). The intervals array * controls the length of the dashes. The paint's strokeWidth controls the * thickness of the dashes. * Note: this patheffect only affects drawing with the paint's style is set * to STROKE or STROKE_AND_FILL. It is ignored if the drawing is done with * style == FILL. * @param intervals array of ON and OFF distances * @param phase offset into the intervals array */ public DashPathEffect(float intervals[], float phase) { if (intervals.length < 2) { throw new ArrayIndexOutOfBoundsException(); } mIntervals = intervals; mPhase = phase; } public float[] getIntervals() { return mIntervals; } public float getPhase() { return mPhase; } } tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +1 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ public class CreateInfo { "android.graphics.BitmapShader", "android.graphics._Original_BitmapShader", "android.graphics.Canvas", "android.graphics._Original_Canvas", "android.graphics.ComposeShader", "android.graphics._Original_ComposeShader", "android.graphics.DashPathEffect", "android.graphics._Original_DashPathEffect", "android.graphics.LinearGradient", "android.graphics._Original_LinearGradient", "android.graphics.Matrix", "android.graphics._Original_Matrix", "android.graphics.Paint", "android.graphics._Original_Paint", Loading Loading
tools/layoutlib/bridge/src/android/graphics/Canvas.java +37 −38 Original line number Diff line number Diff line Loading @@ -104,22 +104,35 @@ public class Canvas extends _Original_Canvas { * Creates a new {@link Graphics2D} based on the {@link Paint} parameters. * <p/>The object must be disposed ({@link Graphics2D#dispose()}) after being used. */ private Graphics2D getNewGraphics(Paint paint, Graphics2D g) { private Graphics2D getCustomGraphics(Paint paint) { // make new one Graphics2D g = getGraphics2d(); g = (Graphics2D)g.create(); // configure it g.setColor(new Color(paint.getColor())); int alpha = paint.getAlpha(); float falpha = alpha / 255.f; if (paint.getStyle() == Style.STROKE) { Style style = paint.getStyle(); if (style == Style.STROKE || style == Style.FILL_AND_STROKE) { PathEffect e = paint.getPathEffect(); if (e instanceof DashPathEffect) { DashPathEffect dpe = (DashPathEffect)e; g.setStroke(new BasicStroke( paint.getStrokeWidth(), paint.getStrokeCap().getJavaCap(), paint.getStrokeJoin().getJavaJoin(), paint.getStrokeMiter() // FIXME: add dash info. )); paint.getStrokeMiter(), dpe.getIntervals(), dpe.getPhase())); } else { g.setStroke(new BasicStroke( paint.getStrokeWidth(), paint.getStrokeCap().getJavaCap(), paint.getStrokeJoin().getJavaJoin(), paint.getStrokeMiter())); } } Xfermode xfermode = paint.getXfermode(); Loading Loading @@ -795,11 +808,9 @@ public class Canvas extends _Original_Canvas { } private final void doDrawRect(int left, int top, int width, int height, Paint paint) { // get current graphisc if (width > 0 && height > 0) { Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); Style style = paint.getStyle(); Loading @@ -822,11 +833,9 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) { // get current graphisc if (rect.width() > 0 && rect.height() > 0) { Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); Style style = paint.getStyle(); Loading Loading @@ -856,10 +865,8 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { // get current graphisc Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); g.drawLine((int)startX, (int)startY, (int)stopX, (int)stopY); Loading @@ -872,10 +879,8 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawLines(float[] pts, int offset, int count, Paint paint) { // get current graphisc Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); for (int i = 0 ; i < count ; i += 4) { g.drawLine((int)pts[i + offset], (int)pts[i + offset + 1], Loading @@ -899,10 +904,8 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawCircle(float cx, float cy, float radius, Paint paint) { // get current graphisc Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); Style style = paint.getStyle(); Loading @@ -926,10 +929,8 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawOval(RectF oval, Paint paint) { // get current graphics Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); Style style = paint.getStyle(); Loading @@ -951,10 +952,8 @@ public class Canvas extends _Original_Canvas { */ @Override public void drawPath(Path path, Paint paint) { // get current graphics Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); // get a Graphics2D object configured with the drawing parameters. Graphics2D g = getCustomGraphics(paint); Style style = paint.getStyle(); Loading
tools/layoutlib/bridge/src/android/graphics/DashPathEffect.java 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright (C) 2010 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.graphics; public class DashPathEffect extends PathEffect { private final float[] mIntervals; private final float mPhase; /** * The intervals array must contain an even number of entries (>=2), with * the even indices specifying the "on" intervals, and the odd indices * specifying the "off" intervals. phase is an offset into the intervals * array (mod the sum of all of the intervals). The intervals array * controls the length of the dashes. The paint's strokeWidth controls the * thickness of the dashes. * Note: this patheffect only affects drawing with the paint's style is set * to STROKE or STROKE_AND_FILL. It is ignored if the drawing is done with * style == FILL. * @param intervals array of ON and OFF distances * @param phase offset into the intervals array */ public DashPathEffect(float intervals[], float phase) { if (intervals.length < 2) { throw new ArrayIndexOutOfBoundsException(); } mIntervals = intervals; mPhase = phase; } public float[] getIntervals() { return mIntervals; } public float getPhase() { return mPhase; } }
tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +1 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ public class CreateInfo { "android.graphics.BitmapShader", "android.graphics._Original_BitmapShader", "android.graphics.Canvas", "android.graphics._Original_Canvas", "android.graphics.ComposeShader", "android.graphics._Original_ComposeShader", "android.graphics.DashPathEffect", "android.graphics._Original_DashPathEffect", "android.graphics.LinearGradient", "android.graphics._Original_LinearGradient", "android.graphics.Matrix", "android.graphics._Original_Matrix", "android.graphics.Paint", "android.graphics._Original_Paint", Loading