use of android.graphics.SweepGradient in project android_frameworks_base by ResurrectionRemix.
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.SweepGradient in project android_frameworks_base by DirtyUnicorns.
the class GradientDrawable method ensureValidRect.
/**
* This checks mGradientIsDirty, and if it is true, recomputes both our drawing
* rectangle (mRect) and the gradient itself, since it depends on our
* rectangle too.
* @return true if the resulting rectangle is not empty, false otherwise
*/
private boolean ensureValidRect() {
if (mGradientIsDirty) {
mGradientIsDirty = false;
Rect bounds = getBounds();
float inset = 0;
if (mStrokePaint != null) {
inset = mStrokePaint.getStrokeWidth() * 0.5f;
}
final GradientState st = mGradientState;
mRect.set(bounds.left + inset, bounds.top + inset, bounds.right - inset, bounds.bottom - inset);
final int[] gradientColors = st.mGradientColors;
if (gradientColors != null) {
final RectF r = mRect;
final float x0, x1, y0, y1;
if (st.mGradient == LINEAR_GRADIENT) {
final float level = st.mUseLevel ? getLevel() / 10000.0f : 1.0f;
switch(st.mOrientation) {
case TOP_BOTTOM:
x0 = r.left;
y0 = r.top;
x1 = x0;
y1 = level * r.bottom;
break;
case TR_BL:
x0 = r.right;
y0 = r.top;
x1 = level * r.left;
y1 = level * r.bottom;
break;
case RIGHT_LEFT:
x0 = r.right;
y0 = r.top;
x1 = level * r.left;
y1 = y0;
break;
case BR_TL:
x0 = r.right;
y0 = r.bottom;
x1 = level * r.left;
y1 = level * r.top;
break;
case BOTTOM_TOP:
x0 = r.left;
y0 = r.bottom;
x1 = x0;
y1 = level * r.top;
break;
case BL_TR:
x0 = r.left;
y0 = r.bottom;
x1 = level * r.right;
y1 = level * r.top;
break;
case LEFT_RIGHT:
x0 = r.left;
y0 = r.top;
x1 = level * r.right;
y1 = y0;
break;
default:
/* TL_BR */
x0 = r.left;
y0 = r.top;
x1 = level * r.right;
y1 = level * r.bottom;
break;
}
mFillPaint.setShader(new LinearGradient(x0, y0, x1, y1, gradientColors, st.mPositions, Shader.TileMode.CLAMP));
} else if (st.mGradient == RADIAL_GRADIENT) {
x0 = r.left + (r.right - r.left) * st.mCenterX;
y0 = r.top + (r.bottom - r.top) * st.mCenterY;
float radius = st.mGradientRadius;
if (st.mGradientRadiusType == RADIUS_TYPE_FRACTION) {
// Fall back to parent width or height if intrinsic
// size is not specified.
final float width = st.mWidth >= 0 ? st.mWidth : r.width();
final float height = st.mHeight >= 0 ? st.mHeight : r.height();
radius *= Math.min(width, height);
} else if (st.mGradientRadiusType == RADIUS_TYPE_FRACTION_PARENT) {
radius *= Math.min(r.width(), r.height());
}
if (st.mUseLevel) {
radius *= getLevel() / 10000.0f;
}
mGradientRadius = radius;
if (radius <= 0) {
// We can't have a shader with non-positive radius, so
// let's have a very, very small radius.
radius = 0.001f;
}
mFillPaint.setShader(new RadialGradient(x0, y0, radius, gradientColors, null, Shader.TileMode.CLAMP));
} else if (st.mGradient == SWEEP_GRADIENT) {
x0 = r.left + (r.right - r.left) * st.mCenterX;
y0 = r.top + (r.bottom - r.top) * st.mCenterY;
int[] tempColors = gradientColors;
float[] tempPositions = null;
if (st.mUseLevel) {
tempColors = st.mTempColors;
final int length = gradientColors.length;
if (tempColors == null || tempColors.length != length + 1) {
tempColors = st.mTempColors = new int[length + 1];
}
System.arraycopy(gradientColors, 0, tempColors, 0, length);
tempColors[length] = gradientColors[length - 1];
tempPositions = st.mTempPositions;
final float fraction = 1.0f / (length - 1);
if (tempPositions == null || tempPositions.length != length + 1) {
tempPositions = st.mTempPositions = new float[length + 1];
}
final float level = getLevel() / 10000.0f;
for (int i = 0; i < length; i++) {
tempPositions[i] = i * fraction * level;
}
tempPositions[length] = 1.0f;
}
mFillPaint.setShader(new SweepGradient(x0, y0, tempColors, tempPositions));
}
// maxed out so that alpha modulation works correctly.
if (st.mSolidColors == null) {
mFillPaint.setColor(Color.BLACK);
}
}
}
return !mRect.isEmpty();
}
use of android.graphics.SweepGradient 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.SweepGradient in project android_packages_apps_Gallery2 by LineageOS.
the class ColorRectView method setUpColorPanel.
private void setUpColorPanel() {
float val = mHSVO[2];
int v = 0xFF000000 | 0x10101 * (int) (val * 0xFF);
int[] colors = new int[] { 0x0000000, v };
int[] colors2 = new int[] { 0x0000000, 0xFF000000 };
int[] wheelColor = new int[mColors.length];
float[] hsv = new float[3];
for (int i = 0; i < wheelColor.length; i++) {
Color.colorToHSV(mColors[i], hsv);
hsv[2] = mHSVO[2];
wheelColor[i] = Color.HSVToColor(hsv);
}
updateDot();
updateDotPaint();
SweepGradient sg = new SweepGradient(mCtrX, mCtrY, wheelColor, null);
LinearGradient lg = new LinearGradient(mBorder, 0, mWidth - mBorder, 0, wheelColor, null, Shader.TileMode.CLAMP);
mWheelPaint1.setShader(lg);
LinearGradient rg = new LinearGradient(0, mBorder, 0, mHeight - mBorder, colors, null, Shader.TileMode.CLAMP);
mWheelPaint2.setShader(rg);
LinearGradient rg2 = new LinearGradient(0, mBorder, 0, mHeight - mBorder, colors2, null, Shader.TileMode.CLAMP);
mWheelPaint3.setShader(rg2);
}
use of android.graphics.SweepGradient in project AndoridLib by twp520.
the class YbbView method getGradient.
/**
* 得到一个渐变的圆弧叠加层
*
* @param d 圆的直径
* @param colors 渐变数组
* @param startArc 从什么角度开始渐变
* @return
*/
private SweepGradient getGradient(int d, int[] colors, int startArc) {
SweepGradient sweepGradient = new SweepGradient(d / 2.0f, d / 2.0f, colors, null);
// 旋转 不然是从0度开始渐变
Matrix matrix = new Matrix();
matrix.setRotate(startArc, d / 2.0f, d / 2.0f);
sweepGradient.setLocalMatrix(matrix);
return sweepGradient;
}
Aggregations