Merge change 21408 into donut
* changes: Improved drawing/matrix support in layoutlib
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package android.graphics;
|
||||
|
||||
import com.android.layoutlib.bridge.BridgeCanvas;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
@@ -25,15 +24,15 @@ import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public final class Bitmap extends _Original_Bitmap {
|
||||
|
||||
|
||||
private BufferedImage mImage;
|
||||
|
||||
public Bitmap(File input) throws IOException {
|
||||
super(1, true, null);
|
||||
|
||||
|
||||
mImage = ImageIO.read(input);
|
||||
}
|
||||
|
||||
|
||||
Bitmap(BufferedImage image) {
|
||||
super(1, true, null);
|
||||
mImage = image;
|
||||
@@ -42,9 +41,9 @@ public final class Bitmap extends _Original_Bitmap {
|
||||
public BufferedImage getImage() {
|
||||
return mImage;
|
||||
}
|
||||
|
||||
|
||||
// ----- overriden methods
|
||||
|
||||
|
||||
public enum Config {
|
||||
// these native values must match up with the enum in SkBitmap.h
|
||||
ALPHA_8 (2),
|
||||
@@ -56,27 +55,26 @@ public final class Bitmap extends _Original_Bitmap {
|
||||
this.nativeInt = ni;
|
||||
}
|
||||
final int nativeInt;
|
||||
|
||||
|
||||
/* package */ static Config nativeToConfig(int ni) {
|
||||
return sConfigs[ni];
|
||||
}
|
||||
|
||||
|
||||
private static Config sConfigs[] = {
|
||||
null, null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return mImage.getWidth();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return mImage.getHeight();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an immutable bitmap from the source bitmap. The new bitmap may
|
||||
* be the same object as source, or a copy may have been made.
|
||||
@@ -100,7 +98,7 @@ public final class Bitmap extends _Original_Bitmap {
|
||||
int width, int height) {
|
||||
return new Bitmap(source.mImage.getSubimage(x, y, width, height));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an immutable bitmap from subset of the source bitmap,
|
||||
* transformed by the optional matrix.
|
||||
@@ -158,7 +156,7 @@ public final class Bitmap extends _Original_Bitmap {
|
||||
neww = Math.round(deviceR.width());
|
||||
newh = Math.round(deviceR.height());
|
||||
|
||||
BridgeCanvas canvas = new BridgeCanvas(neww, newh);
|
||||
Canvas canvas = new Canvas(neww, newh);
|
||||
|
||||
canvas.translate(-deviceR.left, -deviceR.top);
|
||||
canvas.concat(m);
|
||||
@@ -169,10 +167,10 @@ public final class Bitmap extends _Original_Bitmap {
|
||||
}
|
||||
|
||||
canvas.drawBitmap(source, srcR, dstR, paint);
|
||||
|
||||
|
||||
return new Bitmap(canvas.getImage());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a mutable bitmap with the specified width and height.
|
||||
*
|
||||
@@ -184,7 +182,7 @@ public final class Bitmap extends _Original_Bitmap {
|
||||
public static Bitmap createBitmap(int width, int height, Config config) {
|
||||
return new Bitmap(new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a immutable bitmap with the specified width and height, with each
|
||||
* pixel value set to the corresponding value in the colors array.
|
||||
@@ -215,7 +213,7 @@ public final class Bitmap extends _Original_Bitmap {
|
||||
|| (lastScanline + width > length)) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
|
||||
// TODO: create an immutable bitmap...
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -14,24 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.layoutlib.bridge;
|
||||
package android.graphics;
|
||||
|
||||
import com.android.layoutlib.api.ILayoutLog;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.DrawFilter;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Picture;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Region;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.Xfermode;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.Paint.Style;
|
||||
@@ -43,6 +35,7 @@ import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Stack;
|
||||
|
||||
@@ -51,36 +44,59 @@ import javax.microedition.khronos.opengles.GL;
|
||||
/**
|
||||
* Re-implementation of the Canvas, 100% in java on top of a BufferedImage.
|
||||
*/
|
||||
public class BridgeCanvas extends Canvas {
|
||||
|
||||
public class Canvas extends _Original_Canvas {
|
||||
|
||||
private BufferedImage mBufferedImage;
|
||||
private final Stack<Graphics2D> mGraphicsStack = new Stack<Graphics2D>();
|
||||
private final ILayoutLog mLogger;
|
||||
|
||||
public BridgeCanvas(int width, int height, ILayoutLog logger) {
|
||||
public Canvas() {
|
||||
mLogger = null;
|
||||
// the mBufferedImage will be taken from a bitmap in #setBitmap()
|
||||
}
|
||||
|
||||
public Canvas(Bitmap bitmap) {
|
||||
mLogger = null;
|
||||
mBufferedImage = bitmap.getImage();
|
||||
mGraphicsStack.push(mBufferedImage.createGraphics());
|
||||
}
|
||||
|
||||
public Canvas(int nativeCanvas) {
|
||||
mLogger = null;
|
||||
throw new UnsupportedOperationException("Can't create Canvas(int)");
|
||||
}
|
||||
|
||||
public Canvas(javax.microedition.khronos.opengles.GL gl) {
|
||||
mLogger = null;
|
||||
throw new UnsupportedOperationException("Can't create Canvas(javax.microedition.khronos.opengles.GL)");
|
||||
}
|
||||
|
||||
// custom constructors for our use.
|
||||
public Canvas(int width, int height, ILayoutLog logger) {
|
||||
mLogger = logger;
|
||||
mBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
mGraphicsStack.push(mBufferedImage.createGraphics());
|
||||
}
|
||||
|
||||
public BridgeCanvas(int width, int height) {
|
||||
|
||||
public Canvas(int width, int height) {
|
||||
this(width, height, null /* logger*/);
|
||||
}
|
||||
|
||||
|
||||
// custom mehtods
|
||||
public BufferedImage getImage() {
|
||||
return mBufferedImage;
|
||||
}
|
||||
|
||||
Graphics2D getGraphics2d() {
|
||||
|
||||
public Graphics2D getGraphics2d() {
|
||||
return mGraphicsStack.peek();
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
|
||||
public void dispose() {
|
||||
while (mGraphicsStack.size() > 0) {
|
||||
mGraphicsStack.pop().dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new {@link Graphics2D} based on the {@link Paint} parameters.
|
||||
* <p/>The object must be disposed ({@link Graphics2D#dispose()}) after being used.
|
||||
@@ -91,11 +107,11 @@ public class BridgeCanvas extends Canvas {
|
||||
g.setColor(new Color(paint.getColor()));
|
||||
int alpha = paint.getAlpha();
|
||||
float falpha = alpha / 255.f;
|
||||
|
||||
|
||||
Xfermode xfermode = paint.getXfermode();
|
||||
if (xfermode instanceof PorterDuffXfermode) {
|
||||
PorterDuff.Mode mode = ((PorterDuffXfermode)xfermode).getMode();
|
||||
|
||||
|
||||
setModeInGraphics(mode, g, falpha);
|
||||
} else {
|
||||
if (mLogger != null && xfermode != null) {
|
||||
@@ -105,7 +121,7 @@ public class BridgeCanvas extends Canvas {
|
||||
}
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha));
|
||||
}
|
||||
|
||||
|
||||
Shader shader = paint.getShader();
|
||||
if (shader instanceof LinearGradient) {
|
||||
g.setPaint(((LinearGradient)shader).getPaint());
|
||||
@@ -116,10 +132,10 @@ public class BridgeCanvas extends Canvas {
|
||||
shader.getClass().getCanonicalName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
|
||||
private void setModeInGraphics(PorterDuff.Mode mode, Graphics2D g, float falpha) {
|
||||
switch (mode) {
|
||||
case CLEAR:
|
||||
@@ -168,14 +184,43 @@ public class BridgeCanvas extends Canvas {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// --------------------
|
||||
|
||||
// OVERRIDEN ENUMS
|
||||
// This is needed since we rename Canvas into _Original_Canvas
|
||||
// --------------------
|
||||
|
||||
public enum EdgeType {
|
||||
BW(0), //!< treat edges by just rounding to nearest pixel boundary
|
||||
AA(1); //!< treat edges by rounding-out, since they may be antialiased
|
||||
|
||||
EdgeType(int nativeInt) {
|
||||
this.nativeInt = nativeInt;
|
||||
}
|
||||
final int nativeInt;
|
||||
}
|
||||
|
||||
|
||||
// --------------------
|
||||
// OVERRIDEN METHODS
|
||||
// --------------------
|
||||
|
||||
@Override
|
||||
public void finalize() throws Throwable {
|
||||
// pass
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#setBitmap(android.graphics.Bitmap)
|
||||
*/
|
||||
@Override
|
||||
public void setBitmap(Bitmap bitmap) {
|
||||
mBufferedImage = bitmap.getImage();
|
||||
mGraphicsStack.push(mBufferedImage.createGraphics());
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#translate(float, float)
|
||||
*/
|
||||
@@ -183,7 +228,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public void translate(float dx, float dy) {
|
||||
getGraphics2d().translate(dx, dy);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#save()
|
||||
*/
|
||||
@@ -191,7 +236,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public int save() {
|
||||
Graphics2D g = (Graphics2D)getGraphics2d().create();
|
||||
mGraphicsStack.push(g);
|
||||
|
||||
|
||||
return mGraphicsStack.size() - 1;
|
||||
}
|
||||
|
||||
@@ -203,7 +248,7 @@ public class BridgeCanvas extends Canvas {
|
||||
// For now we ignore saveFlags
|
||||
return save();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#restore()
|
||||
*/
|
||||
@@ -221,7 +266,7 @@ public class BridgeCanvas extends Canvas {
|
||||
mGraphicsStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#getSaveCount()
|
||||
*/
|
||||
@@ -229,8 +274,8 @@ public class BridgeCanvas extends Canvas {
|
||||
public int getSaveCount() {
|
||||
return mGraphicsStack.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#clipRect(float, float, float, float, android.graphics.Region.Op)
|
||||
*/
|
||||
@@ -288,23 +333,36 @@ public class BridgeCanvas extends Canvas {
|
||||
public boolean clipRect(RectF rect) {
|
||||
return clipRect(rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public boolean quickReject(RectF rect, EdgeType type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean quickReject(RectF rect, _Original_Canvas.EdgeType type) {
|
||||
throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
|
||||
}
|
||||
|
||||
public boolean quickReject(Path path, EdgeType type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean quickReject(Path path, _Original_Canvas.EdgeType type) {
|
||||
throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
|
||||
}
|
||||
|
||||
public boolean quickReject(float left, float top, float right, float bottom,
|
||||
EdgeType type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean quickReject(float left, float top, float right, float bottom,
|
||||
_Original_Canvas.EdgeType type) {
|
||||
throw new UnsupportedOperationException("CALL TO PARENT FORBIDDEN");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the clip bounds, returning true if they are non-empty.
|
||||
*
|
||||
@@ -324,31 +382,31 @@ public class BridgeCanvas extends Canvas {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#drawColor(int, android.graphics.PorterDuff.Mode)
|
||||
*/
|
||||
@Override
|
||||
public void drawColor(int color, PorterDuff.Mode mode) {
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
// save old color
|
||||
Color c = g.getColor();
|
||||
|
||||
|
||||
Composite composite = g.getComposite();
|
||||
|
||||
|
||||
// get the alpha from the color
|
||||
int alpha = color >>> 24;
|
||||
float falpha = alpha / 255.f;
|
||||
|
||||
|
||||
setModeInGraphics(mode, g, falpha);
|
||||
|
||||
|
||||
g.setColor(new Color(color));
|
||||
|
||||
|
||||
getGraphics2d().fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
|
||||
g.setComposite(composite);
|
||||
|
||||
|
||||
// restore color
|
||||
g.setColor(c);
|
||||
}
|
||||
@@ -360,7 +418,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawColor(int color) {
|
||||
drawColor(color, PorterDuff.Mode.SRC_OVER);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#drawARGB(int, int, int, int)
|
||||
*/
|
||||
@@ -368,7 +426,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawARGB(int a, int r, int g, int b) {
|
||||
drawColor(a << 24 | r << 16 | g << 8 | b, PorterDuff.Mode.SRC_OVER);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#drawRGB(int, int, int)
|
||||
*/
|
||||
@@ -377,7 +435,7 @@ public class BridgeCanvas extends Canvas {
|
||||
drawColor(0xFF << 24 | r << 16 | g << 8 | b, PorterDuff.Mode.SRC_OVER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#getWidth()
|
||||
*/
|
||||
@@ -385,7 +443,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public int getWidth() {
|
||||
return mBufferedImage.getWidth();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#getHeight()
|
||||
*/
|
||||
@@ -401,7 +459,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawPaint(Paint paint) {
|
||||
drawColor(paint.getColor());
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#drawBitmap(android.graphics.Bitmap, float, float, android.graphics.Paint)
|
||||
*/
|
||||
@@ -417,7 +475,32 @@ public class BridgeCanvas extends Canvas {
|
||||
*/
|
||||
@Override
|
||||
public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) {
|
||||
throw new UnsupportedOperationException();
|
||||
boolean needsRestore = false;
|
||||
if (matrix.isIdentity() == false) {
|
||||
// create a new graphics and apply the matrix to it
|
||||
save(); // this creates a new Graphics2D, and stores it for children call to use
|
||||
needsRestore = true;
|
||||
Graphics2D g = getGraphics2d(); // get the newly create Graphics2D
|
||||
|
||||
// get the Graphics2D current matrix
|
||||
AffineTransform currentTx = g.getTransform();
|
||||
// get the AffineTransform from the matrix
|
||||
AffineTransform matrixTx = matrix.getTransform();
|
||||
|
||||
// combine them so that the matrix is applied after.
|
||||
currentTx.preConcatenate(matrixTx);
|
||||
|
||||
// give it to the graphics as a new matrix replacing all previous transform
|
||||
g.setTransform(currentTx);
|
||||
}
|
||||
|
||||
// draw the bitmap
|
||||
drawBitmap(bitmap, 0, 0, paint);
|
||||
|
||||
if (needsRestore) {
|
||||
// remove the new graphics
|
||||
restore();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -456,39 +539,42 @@ public class BridgeCanvas extends Canvas {
|
||||
int height, boolean hasAlpha, Paint paint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
private void drawBitmap(Bitmap bitmap, int sleft, int stop, int sright, int sbottom, int dleft,
|
||||
int dtop, int dright, int dbottom, Paint paint) {
|
||||
BufferedImage image = bitmap.getImage();
|
||||
|
||||
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
Composite c = null;
|
||||
|
||||
if (paint.isFilterBitmap()) {
|
||||
g = (Graphics2D)g.create();
|
||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
|
||||
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
|
||||
if (paint != null) {
|
||||
if (paint.isFilterBitmap()) {
|
||||
g = (Graphics2D)g.create();
|
||||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
|
||||
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
}
|
||||
|
||||
if (paint.getAlpha() != 0xFF) {
|
||||
c = g.getComposite();
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
||||
paint.getAlpha()/255.f));
|
||||
}
|
||||
}
|
||||
|
||||
if (paint.getAlpha() != 0xFF) {
|
||||
c = g.getComposite();
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
||||
paint.getAlpha()/255.f));
|
||||
}
|
||||
|
||||
|
||||
g.drawImage(image, dleft, dtop, dright, dbottom,
|
||||
sleft, stop, sright, sbottom, null);
|
||||
|
||||
if (paint.isFilterBitmap()) {
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
if (c != null) {
|
||||
g.setComposite(c);
|
||||
if (paint != null) {
|
||||
if (paint.isFilterBitmap()) {
|
||||
g.dispose();
|
||||
}
|
||||
if (c != null) {
|
||||
g.setComposite(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#rotate(float, float, float)
|
||||
*/
|
||||
@@ -509,7 +595,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public void rotate(float degrees) {
|
||||
getGraphics2d().rotate(Math.toRadians(degrees));
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#scale(float, float, float, float)
|
||||
*/
|
||||
@@ -528,19 +614,19 @@ public class BridgeCanvas extends Canvas {
|
||||
public void scale(float sx, float sy) {
|
||||
getGraphics2d().scale(sx, sy);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#drawText(char[], int, int, float, float, android.graphics.Paint)
|
||||
*/
|
||||
@Override
|
||||
public void drawText(char[] text, int index, int count, float x, float y, Paint paint) {
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
g = (Graphics2D)g.create();
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
|
||||
g.setFont(paint.getFont());
|
||||
|
||||
|
||||
// set the color. because this only handles RGB we have to handle the alpha separately
|
||||
g.setColor(new Color(paint.getColor()));
|
||||
int alpha = paint.getAlpha();
|
||||
@@ -557,9 +643,9 @@ public class BridgeCanvas extends Canvas {
|
||||
x -= m;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
g.drawChars(text, index, count, (int)x, (int)y);
|
||||
|
||||
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
@@ -586,7 +672,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawText(String text, int start, int end, float x, float y, Paint paint) {
|
||||
drawText(text.toCharArray(), start, end - start, x, y, paint);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#drawRect(android.graphics.RectF, android.graphics.Paint)
|
||||
*/
|
||||
@@ -594,7 +680,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawRect(RectF rect, Paint paint) {
|
||||
doDrawRect((int)rect.left, (int)rect.top, (int)rect.width(), (int)rect.height(), paint);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#drawRect(float, float, float, float, android.graphics.Paint)
|
||||
*/
|
||||
@@ -614,11 +700,11 @@ public class BridgeCanvas extends Canvas {
|
||||
private final void doDrawRect(int left, int top, int width, int height, Paint paint) {
|
||||
// get current graphisc
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
g = getNewGraphics(paint, g);
|
||||
|
||||
Style style = paint.getStyle();
|
||||
|
||||
|
||||
// draw
|
||||
if (style == Style.FILL || style == Style.FILL_AND_STROKE) {
|
||||
g.fillRect(left, top, width, height);
|
||||
@@ -639,16 +725,16 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) {
|
||||
// get current graphisc
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
g = getNewGraphics(paint, g);
|
||||
|
||||
Style style = paint.getStyle();
|
||||
|
||||
|
||||
// draw
|
||||
|
||||
|
||||
int arcWidth = (int)(rx * 2);
|
||||
int arcHeight = (int)(ry * 2);
|
||||
|
||||
|
||||
if (style == Style.FILL || style == Style.FILL_AND_STROKE) {
|
||||
g.fillRoundRect((int)rect.left, (int)rect.top, (int)rect.width(), (int)rect.height(),
|
||||
arcWidth, arcHeight);
|
||||
@@ -671,7 +757,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) {
|
||||
// get current graphisc
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
g = getNewGraphics(paint, g);
|
||||
|
||||
g.drawLine((int)startX, (int)startY, (int)stopX, (int)stopY);
|
||||
@@ -679,7 +765,7 @@ public class BridgeCanvas extends Canvas {
|
||||
// dispose Graphics2D object
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#drawLines(float[], int, int, android.graphics.Paint)
|
||||
*/
|
||||
@@ -687,7 +773,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawLines(float[] pts, int offset, int count, Paint paint) {
|
||||
// get current graphisc
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
g = getNewGraphics(paint, g);
|
||||
|
||||
for (int i = 0 ; i < count ; i += 4) {
|
||||
@@ -706,7 +792,7 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawLines(float[] pts, Paint paint) {
|
||||
drawLines(pts, 0, pts.length, paint);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#drawCircle(float, float, float, android.graphics.Paint)
|
||||
*/
|
||||
@@ -714,11 +800,11 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawCircle(float cx, float cy, float radius, Paint paint) {
|
||||
// get current graphisc
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
g = getNewGraphics(paint, g);
|
||||
|
||||
Style style = paint.getStyle();
|
||||
|
||||
|
||||
int size = (int)(radius * 2);
|
||||
|
||||
// draw
|
||||
@@ -741,11 +827,11 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawOval(RectF oval, Paint paint) {
|
||||
// get current graphics
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
g = getNewGraphics(paint, g);
|
||||
|
||||
Style style = paint.getStyle();
|
||||
|
||||
|
||||
// draw
|
||||
if (style == Style.FILL || style == Style.FILL_AND_STROKE) {
|
||||
g.fillOval((int)oval.left, (int)oval.top, (int)oval.width(), (int)oval.height());
|
||||
@@ -758,7 +844,7 @@ public class BridgeCanvas extends Canvas {
|
||||
// dispose Graphics2D object
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#drawPath(android.graphics.Path, android.graphics.Paint)
|
||||
*/
|
||||
@@ -766,11 +852,11 @@ public class BridgeCanvas extends Canvas {
|
||||
public void drawPath(Path path, Paint paint) {
|
||||
// get current graphics
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
g = getNewGraphics(paint, g);
|
||||
|
||||
Style style = paint.getStyle();
|
||||
|
||||
|
||||
// draw
|
||||
if (style == Style.FILL || style == Style.FILL_AND_STROKE) {
|
||||
g.fill(path.getAwtShape());
|
||||
@@ -783,7 +869,7 @@ public class BridgeCanvas extends Canvas {
|
||||
// dispose Graphics2D object
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#setMatrix(android.graphics.Matrix)
|
||||
*/
|
||||
@@ -795,10 +881,10 @@ public class BridgeCanvas extends Canvas {
|
||||
|
||||
// get the new current graphics
|
||||
Graphics2D g = getGraphics2d();
|
||||
|
||||
|
||||
// and apply the matrix
|
||||
g.setTransform(matrix.getTransform());
|
||||
|
||||
|
||||
if (mLogger != null && matrix.hasPerspective()) {
|
||||
mLogger.warning("android.graphics.Canvas#setMatrix(android.graphics.Matrix) only supports affine transformations in the Layout Editor.");
|
||||
}
|
||||
@@ -1058,15 +1144,6 @@ public class BridgeCanvas extends Canvas {
|
||||
return super.saveLayerAlpha(bounds, alpha, saveFlags);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#setBitmap(android.graphics.Bitmap)
|
||||
*/
|
||||
@Override
|
||||
public void setBitmap(Bitmap bitmap) {
|
||||
// TODO Auto-generated method stub
|
||||
super.setBitmap(bitmap);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.graphics.Canvas#setDrawFilter(android.graphics.DrawFilter)
|
||||
*/
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.graphics;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.NoninvertibleTransformException;
|
||||
|
||||
|
||||
/**
|
||||
@@ -747,7 +748,24 @@ public class Matrix extends _Original_Matrix {
|
||||
* inverted, ignore inverse and return false.
|
||||
*/
|
||||
public boolean invert(Matrix inverse) {
|
||||
throw new UnsupportedOperationException("STUB NEEDED");
|
||||
if (inverse == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
AffineTransform affineTransform = getTransform();
|
||||
AffineTransform inverseTransform = affineTransform.createInverse();
|
||||
inverse.mValues[0] = (float)inverseTransform.getScaleX();
|
||||
inverse.mValues[1] = (float)inverseTransform.getShearX();
|
||||
inverse.mValues[2] = (float)inverseTransform.getTranslateX();
|
||||
inverse.mValues[3] = (float)inverseTransform.getScaleX();
|
||||
inverse.mValues[4] = (float)inverseTransform.getShearY();
|
||||
inverse.mValues[5] = (float)inverseTransform.getTranslateY();
|
||||
|
||||
return true;
|
||||
} catch (NoninvertibleTransformException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -770,7 +788,19 @@ public class Matrix extends _Original_Matrix {
|
||||
public void mapPoints(float[] dst, int dstIndex, float[] src, int srcIndex,
|
||||
int pointCount) {
|
||||
checkPointArrays(src, srcIndex, dst, dstIndex, pointCount);
|
||||
throw new UnsupportedOperationException("STUB NEEDED");
|
||||
|
||||
for (int i = 0 ; i < pointCount ; i++) {
|
||||
// just in case we are doing in place, we better put this in temp vars
|
||||
float x = mValues[0] * src[i + srcIndex] +
|
||||
mValues[1] * src[i + srcIndex + 1] +
|
||||
mValues[2];
|
||||
float y = mValues[3] * src[i + srcIndex] +
|
||||
mValues[4] * src[i + srcIndex + 1] +
|
||||
mValues[5];
|
||||
|
||||
dst[i + dstIndex] = x;
|
||||
dst[i + dstIndex + 1] = y;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -858,7 +888,26 @@ public class Matrix extends _Original_Matrix {
|
||||
if (dst == null || src == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
throw new UnsupportedOperationException("STUB NEEDED");
|
||||
|
||||
// array with 4 corners
|
||||
float[] corners = new float[] {
|
||||
src.left, src.top,
|
||||
src.right, src.top,
|
||||
src.right, src.bottom,
|
||||
src.left, src.bottom,
|
||||
};
|
||||
|
||||
// apply the transform to them.
|
||||
mapPoints(corners);
|
||||
|
||||
// now put the result in the rect. We take the min/max of Xs and min/max of Ys
|
||||
dst.left = Math.min(Math.min(corners[0], corners[2]), Math.min(corners[4], corners[6]));
|
||||
dst.right = Math.max(Math.max(corners[0], corners[2]), Math.max(corners[4], corners[6]));
|
||||
|
||||
dst.top = Math.min(Math.min(corners[1], corners[3]), Math.min(corners[5], corners[7]));
|
||||
dst.bottom = Math.max(Math.max(corners[1], corners[3]), Math.max(corners[5], corners[7]));
|
||||
|
||||
return rectStaysRect();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.android.tools.layoutlib.create.MethodAdapter;
|
||||
import com.android.tools.layoutlib.create.OverrideMethod;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region;
|
||||
import android.graphics.Typeface;
|
||||
@@ -401,8 +402,7 @@ public final class Bridge implements ILayoutBridge {
|
||||
view.layout(0, screenOffset, screenWidth, screenHeight);
|
||||
|
||||
// draw them
|
||||
BridgeCanvas canvas = new BridgeCanvas(screenWidth, screenHeight - screenOffset,
|
||||
logger);
|
||||
Canvas canvas = new Canvas(screenWidth, screenHeight - screenOffset, logger);
|
||||
|
||||
root.draw(canvas);
|
||||
canvas.dispose();
|
||||
|
||||
@@ -30,17 +30,17 @@ public class NinePatchDrawable extends Drawable {
|
||||
NinePatchDrawable(NinePatch ninePatch) {
|
||||
m9Patch = ninePatch;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMinimumWidth() {
|
||||
return m9Patch.getWidth();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMinimumHeight() {
|
||||
return m9Patch.getHeight();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the intrinsic width of the underlying drawable object. Returns
|
||||
* -1 if it has no intrinsic width, such as with a solid color.
|
||||
@@ -58,7 +58,7 @@ public class NinePatchDrawable extends Drawable {
|
||||
public int getIntrinsicHeight() {
|
||||
return m9Patch.getHeight();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return in padding the insets suggested by this Drawable for placing
|
||||
* content inside the drawable's bounds. Positive values move toward the
|
||||
@@ -76,24 +76,18 @@ public class NinePatchDrawable extends Drawable {
|
||||
padding.bottom = padd[3];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
if (canvas instanceof BridgeCanvas) {
|
||||
BridgeCanvas bridgeCanvas = (BridgeCanvas)canvas;
|
||||
|
||||
Rect r = getBounds();
|
||||
m9Patch.draw(bridgeCanvas.getGraphics2d(), r.left, r.top, r.width(), r.height());
|
||||
|
||||
return;
|
||||
}
|
||||
Rect r = getBounds();
|
||||
m9Patch.draw(canvas.getGraphics2d(), r.left, r.top, r.width(), r.height());
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------- Not implemented methods ---------------
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
|
||||
@@ -54,18 +54,19 @@ public class Main {
|
||||
},
|
||||
new String[] { // classes to rename (so that we can replace them in layoutlib)
|
||||
// original-platform-class-name ======> renamed-class-name
|
||||
"android.graphics.Bitmap", "android.graphics._Original_Bitmap",
|
||||
"android.graphics.BitmapShader", "android.graphics._Original_BitmapShader",
|
||||
"android.graphics.Canvas", "android.graphics._Original_Canvas",
|
||||
"android.graphics.ComposeShader", "android.graphics._Original_ComposeShader",
|
||||
"android.graphics.LinearGradient", "android.graphics._Original_LinearGradient",
|
||||
"android.graphics.Matrix", "android.graphics._Original_Matrix",
|
||||
"android.graphics.Paint", "android.graphics._Original_Paint",
|
||||
"android.graphics.Typeface", "android.graphics._Original_Typeface",
|
||||
"android.graphics.Bitmap", "android.graphics._Original_Bitmap",
|
||||
"android.graphics.Path", "android.graphics._Original_Path",
|
||||
"android.graphics.PorterDuffXfermode", "android.graphics._Original_PorterDuffXfermode",
|
||||
"android.graphics.Shader", "android.graphics._Original_Shader",
|
||||
"android.graphics.LinearGradient", "android.graphics._Original_LinearGradient",
|
||||
"android.graphics.BitmapShader", "android.graphics._Original_BitmapShader",
|
||||
"android.graphics.ComposeShader", "android.graphics._Original_ComposeShader",
|
||||
"android.graphics.RadialGradient", "android.graphics._Original_RadialGradient",
|
||||
"android.graphics.Shader", "android.graphics._Original_Shader",
|
||||
"android.graphics.SweepGradient", "android.graphics._Original_SweepGradient",
|
||||
"android.graphics.Typeface", "android.graphics._Original_Typeface",
|
||||
"android.os.ServiceManager", "android.os._Original_ServiceManager",
|
||||
"android.util.FloatMath", "android.util._Original_FloatMath",
|
||||
"android.view.SurfaceView", "android.view._Original_SurfaceView",
|
||||
|
||||
Reference in New Issue
Block a user