use of android.graphics.RadialGradient in project material by rey5137.
the class RevealDrawable method fillCanvasWithHole.
private void fillCanvasWithHole(Canvas canvas, ColorChangeTask task, float radius, boolean transparent) {
if (transparent)
return;
float scale = radius / GRADIENT_RADIUS;
mMatrix.reset();
mMatrix.postScale(scale, scale, task.x, task.y);
RadialGradient shader = getShader(task);
shader.setLocalMatrix(mMatrix);
mShaderPaint.setShader(shader);
canvas.drawRect(getBounds(), mShaderPaint);
}
use of android.graphics.RadialGradient in project material by rey5137.
the class Switch method buildShadow.
private void buildShadow() {
if (mShadowSize <= 0)
return;
if (mShadowPaint == null) {
mShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mShadowPaint.setStyle(Paint.Style.FILL);
mShadowPaint.setDither(true);
}
float startRatio = (float) mThumbRadius / (mThumbRadius + mShadowSize + mShadowOffset);
mShadowPaint.setShader(new RadialGradient(0, 0, mThumbRadius + mShadowSize, new int[] { COLOR_SHADOW_START, COLOR_SHADOW_START, COLOR_SHADOW_END }, new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP));
if (mShadowPath == null) {
mShadowPath = new Path();
mShadowPath.setFillType(Path.FillType.EVEN_ODD);
} else
mShadowPath.reset();
float radius = mThumbRadius + mShadowSize;
mTempRect.set(-radius, -radius, radius, radius);
mShadowPath.addOval(mTempRect, Path.Direction.CW);
radius = mThumbRadius - 1;
mTempRect.set(-radius, -radius - mShadowOffset, radius, radius - mShadowOffset);
mShadowPath.addOval(mTempRect, Path.Direction.CW);
}
use of android.graphics.RadialGradient in project platform_frameworks_base by android.
the class FakeShadowDrawable method buildShadowCorners.
private void buildShadowCorners() {
RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
RectF outerBounds = new RectF(innerBounds);
outerBounds.inset(-mShadowSize, -mShadowSize);
if (mCornerShadowPath == null) {
mCornerShadowPath = new Path();
} else {
mCornerShadowPath.reset();
}
mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
mCornerShadowPath.moveTo(-mCornerRadius, 0);
mCornerShadowPath.rLineTo(-mShadowSize, 0);
// outer arc
mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
// inner arc
mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
mCornerShadowPath.close();
float startRatio = mCornerRadius / (mCornerRadius + mShadowSize);
mCornerShadowPaint.setShader(new RadialGradient(0, 0, mCornerRadius + mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP));
// we offset the content shadowSize/2 pixels up to make it more realistic.
// this is why edge shadow shader has some extra space
// When drawing bottom edge shadow, we use that extra space.
mEdgeShadowPaint.setShader(new LinearGradient(0, -mCornerRadius + mShadowSize, 0, -mCornerRadius - mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, .5f, 1f }, Shader.TileMode.CLAMP));
}
use of android.graphics.RadialGradient in project platform_frameworks_base by android.
the class GradientColor method onColorsChange.
private void onColorsChange() {
int[] tempColors = null;
float[] tempOffsets = null;
if (mItemColors != null) {
int length = mItemColors.length;
tempColors = new int[length];
tempOffsets = new float[length];
for (int i = 0; i < length; i++) {
tempColors[i] = mItemColors[i];
tempOffsets[i] = mItemOffsets[i];
}
} else {
if (mHasCenterColor) {
tempColors = new int[3];
tempColors[0] = mStartColor;
tempColors[1] = mCenterColor;
tempColors[2] = mEndColor;
tempOffsets = new float[3];
tempOffsets[0] = 0.0f;
// Since 0.5f is default value, try to take the one that isn't 0.5f
tempOffsets[1] = 0.5f;
tempOffsets[2] = 1f;
} else {
tempColors = new int[2];
tempColors[0] = mStartColor;
tempColors[1] = mEndColor;
}
}
if (tempColors.length < 2) {
Log.w(TAG, "<gradient> tag requires 2 color values specified!" + tempColors.length + " " + tempColors);
}
if (mGradientType == GradientDrawable.LINEAR_GRADIENT) {
mShader = new LinearGradient(mStartX, mStartY, mEndX, mEndY, tempColors, tempOffsets, parseTileMode(mTileMode));
} else {
if (mGradientType == GradientDrawable.RADIAL_GRADIENT) {
mShader = new RadialGradient(mCenterX, mCenterY, mGradientRadius, tempColors, tempOffsets, parseTileMode(mTileMode));
} else {
mShader = new SweepGradient(mCenterX, mCenterY, tempColors, tempOffsets);
}
}
mDefaultColor = tempColors[0];
}
use of android.graphics.RadialGradient in project material-components-android by material-components.
the class ShadowDrawableWrapper method buildShadowCorners.
private void buildShadowCorners() {
RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
RectF outerBounds = new RectF(innerBounds);
outerBounds.inset(-mShadowSize, -mShadowSize);
if (mCornerShadowPath == null) {
mCornerShadowPath = new Path();
} else {
mCornerShadowPath.reset();
}
mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
mCornerShadowPath.moveTo(-mCornerRadius, 0);
mCornerShadowPath.rLineTo(-mShadowSize, 0);
// outer arc
mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
// inner arc
mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
mCornerShadowPath.close();
float shadowRadius = -outerBounds.top;
if (shadowRadius > 0f) {
float startRatio = mCornerRadius / shadowRadius;
float midRatio = startRatio + ((1f - startRatio) / 2f);
mCornerShadowPaint.setShader(new RadialGradient(0, 0, shadowRadius, new int[] { 0, mShadowStartColor, mShadowMiddleColor, mShadowEndColor }, new float[] { 0f, startRatio, midRatio, 1f }, Shader.TileMode.CLAMP));
}
// we offset the content shadowSize/2 pixels up to make it more realistic.
// this is why edge shadow shader has some extra space
// When drawing bottom edge shadow, we use that extra space.
mEdgeShadowPaint.setShader(new LinearGradient(0, innerBounds.top, 0, outerBounds.top, new int[] { mShadowStartColor, mShadowMiddleColor, mShadowEndColor }, new float[] { 0f, .5f, 1f }, Shader.TileMode.CLAMP));
mEdgeShadowPaint.setAntiAlias(false);
}
Aggregations