am d3026e16: Merge "ADT/Layoutlib: 2 color, linear gradient support." into eclair

Merge commit 'd3026e1618d893db55c2131d66b08bc4a6e7aaf4' into eclair-plus-aosp

* commit 'd3026e1618d893db55c2131d66b08bc4a6e7aaf4':
  ADT/Layoutlib: 2 color, linear gradient support.
This commit is contained in:
Xavier Ducrohet
2010-01-14 10:08:37 -08:00
committed by Android Git Automerger
8 changed files with 92 additions and 56 deletions

View File

@@ -16,6 +16,8 @@
package android.graphics;
import java.awt.Paint;
public class BitmapShader extends Shader {
// we hold on just for the GC, since our native counterpart is using it
@@ -31,11 +33,16 @@ public class BitmapShader extends Shader {
public BitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY) {
mBitmap = bitmap;
}
//---------- Custom methods
public Bitmap getBitmap() {
return mBitmap;
}
@Override
Paint getPaint() {
return null;
}
}

View File

@@ -125,13 +125,16 @@ public class Canvas extends _Original_Canvas {
}
Shader shader = paint.getShader();
if (shader instanceof LinearGradient) {
g.setPaint(((LinearGradient)shader).getPaint());
} else {
if (mLogger != null && shader != null) {
mLogger.warning(String.format(
"Shader '%1$s' is not supported in the Layout Editor.",
shader.getClass().getCanonicalName()));
if (shader != null) {
java.awt.Paint shaderPaint = shader.getPaint();
if (shaderPaint != null) {
g.setPaint(shaderPaint);
} else {
if (mLogger != null) {
mLogger.warning(String.format(
"Shader '%1$s' is not supported in the Layout Editor.",
shader.getClass().getCanonicalName()));
}
}
}
@@ -409,7 +412,7 @@ public class Canvas extends _Original_Canvas {
g.setColor(new Color(color));
getGraphics2d().fillRect(0, 0, getWidth(), getHeight());
g.fillRect(0, 0, getWidth(), getHeight());
g.setComposite(composite);

View File

@@ -16,6 +16,8 @@
package android.graphics;
import java.awt.Paint;
/** A subclass of shader that returns the composition of two other shaders, combined by
an {@link android.graphics.Xfermode} subclass.
*/
@@ -42,5 +44,10 @@ public class ComposeShader extends Shader {
public ComposeShader(Shader shaderA, Shader shaderB, PorterDuff.Mode mode) {
// FIXME Implement shader
}
@Override
Paint getPaint() {
return null;
}
}

View File

@@ -21,51 +21,59 @@ import java.awt.Color;
import java.awt.Paint;
public class LinearGradient extends Shader {
private GradientPaint mGradientPaint;
/** Create a shader that draws a linear gradient along a line.
@param x0 The x-coordinate for the start of the gradient line
@param y0 The y-coordinate for the start of the gradient line
@param x1 The x-coordinate for the end of the gradient line
@param y1 The y-coordinate for the end of the gradient line
@param colors The colors to be distributed along the gradient line
@param positions May be null. The relative positions [0..1] of
each corresponding color in the colors array. If this is null,
the the colors are distributed evenly along the gradient line.
@param tile The Shader tiling mode
*/
public LinearGradient(float x0, float y0, float x1, float y1,
int colors[], float positions[], TileMode tile) {
/**
* Create a shader that draws a linear gradient along a line.
*
* @param x0 The x-coordinate for the start of the gradient line
* @param y0 The y-coordinate for the start of the gradient line
* @param x1 The x-coordinate for the end of the gradient line
* @param y1 The y-coordinate for the end of the gradient line
* @param colors The colors to be distributed along the gradient line
* @param positions May be null. The relative positions [0..1] of each
* corresponding color in the colors array. If this is null, the
* the colors are distributed evenly along the gradient line.
* @param tile The Shader tiling mode
*/
public LinearGradient(float x0, float y0, float x1, float y1, int colors[], float positions[],
TileMode tile) {
if (colors.length < 2) {
throw new IllegalArgumentException("needs >= 2 number of colors");
}
if (positions != null && colors.length != positions.length) {
throw new IllegalArgumentException("color and position arrays must be of equal length");
}
// FIXME implement multi color linear gradient
if (colors.length == 2) {
mGradientPaint = new GradientPaint(x0, y0, new Color(colors[0], true /* hasalpha */),
x1, y1, new Color(colors[1], true /* hasalpha */), tile != TileMode.CLAMP);
}
}
/** Create a shader that draws a linear gradient along a line.
@param x0 The x-coordinate for the start of the gradient line
@param y0 The y-coordinate for the start of the gradient line
@param x1 The x-coordinate for the end of the gradient line
@param y1 The y-coordinate for the end of the gradient line
@param color0 The color at the start of the gradient line.
@param color1 The color at the end of the gradient line.
@param tile The Shader tiling mode
*/
public LinearGradient(float x0, float y0, float x1, float y1,
int color0, int color1, TileMode tile) {
mGradientPaint = new GradientPaint(x0, y0, new Color(color0, true /* hasalpha */),
x1,y1, new Color(color1, true /* hasalpha */), tile != TileMode.CLAMP);
/**
* Create a shader that draws a linear gradient along a line.
*
* @param x0 The x-coordinate for the start of the gradient line
* @param y0 The y-coordinate for the start of the gradient line
* @param x1 The x-coordinate for the end of the gradient line
* @param y1 The y-coordinate for the end of the gradient line
* @param color0 The color at the start of the gradient line.
* @param color1 The color at the end of the gradient line.
* @param tile The Shader tiling mode
*/
public LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1,
TileMode tile) {
mGradientPaint = new GradientPaint(x0, y0, new Color(color0, true /* hasalpha */), x1, y1,
new Color(color1, true /* hasalpha */), tile != TileMode.CLAMP);
}
//---------- Custom Methods
// ---------- Custom Methods
@Override
public Paint getPaint() {
return mGradientPaint;
}
}

View File

@@ -59,23 +59,14 @@ public class Paint extends _Original_Paint {
private final FontRenderContext mFontContext = new FontRenderContext(
new AffineTransform(), true, true);
@SuppressWarnings("hiding")
public static final int ANTI_ALIAS_FLAG = _Original_Paint.ANTI_ALIAS_FLAG;
@SuppressWarnings("hiding")
public static final int FILTER_BITMAP_FLAG = _Original_Paint.FILTER_BITMAP_FLAG;
@SuppressWarnings("hiding")
public static final int DITHER_FLAG = _Original_Paint.DITHER_FLAG;
@SuppressWarnings("hiding")
public static final int UNDERLINE_TEXT_FLAG = _Original_Paint.UNDERLINE_TEXT_FLAG;
@SuppressWarnings("hiding")
public static final int STRIKE_THRU_TEXT_FLAG = _Original_Paint.STRIKE_THRU_TEXT_FLAG;
@SuppressWarnings("hiding")
public static final int FAKE_BOLD_TEXT_FLAG = _Original_Paint.FAKE_BOLD_TEXT_FLAG;
@SuppressWarnings("hiding")
public static final int LINEAR_TEXT_FLAG = _Original_Paint.LINEAR_TEXT_FLAG;
@SuppressWarnings("hiding")
public static final int SUBPIXEL_TEXT_FLAG = _Original_Paint.SUBPIXEL_TEXT_FLAG;
@SuppressWarnings("hiding")
public static final int DEV_KERN_TEXT_FLAG = _Original_Paint.DEV_KERN_TEXT_FLAG;
public static class FontMetrics extends _Original_Paint.FontMetrics {

View File

@@ -16,6 +16,8 @@
package android.graphics;
import java.awt.Paint;
public class RadialGradient extends Shader {
/** Create a shader that draws a radial gradient given the center and radius.
@@ -58,5 +60,11 @@ public class RadialGradient extends Shader {
}
// FIXME Implement shader
}
@Override
Paint getPaint() {
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -16,14 +16,16 @@
package android.graphics;
/**
* Shader is the based class for objects that return horizontal spans of colors
* during drawing. A subclass of Shader is installed in a Paint calling
* paint.setShader(shader). After that any object (other than a bitmap) that is
* drawn with that paint will get its color(s) from the shader.
*/
public class Shader {
public abstract class Shader {
private final Matrix mMatrix = new Matrix();
public enum TileMode {
@@ -41,7 +43,7 @@ public class Shader {
* mirror images so that adjacent images always seam
*/
MIRROR (2);
TileMode(int nativeInt) {
this.nativeInt = nativeInt;
}
@@ -57,7 +59,7 @@ public class Shader {
if (localM != null) {
localM.set(mMatrix);
}
return !mMatrix.isIdentity();
}
@@ -73,4 +75,6 @@ public class Shader {
mMatrix.reset();
}
}
abstract java.awt.Paint getPaint();
}

View File

@@ -16,6 +16,8 @@
package android.graphics;
import java.awt.Paint;
public class SweepGradient extends Shader {
/**
@@ -41,7 +43,7 @@ public class SweepGradient extends Shader {
throw new IllegalArgumentException(
"color and position arrays must be of equal length");
}
// FIXME Implement shader
}
@@ -56,5 +58,11 @@ public class SweepGradient extends Shader {
public SweepGradient(float cx, float cy, int color0, int color1) {
// FIXME Implement shader
}
@Override
Paint getPaint() {
// TODO Auto-generated method stub
return null;
}
}