use of android.graphics.LinearGradient in project XCL-Charts by xcltapestry.
the class PlotAreaRender method drawPlotBackground.
/**
* 绘制背景
*/
protected void drawPlotBackground(Canvas canvas) {
if (null == canvas)
return;
if (getBackgroundColorVisible()) {
if (getApplayGradient()) {
LinearGradient linearGradient;
if (getGradientDirection() == XEnum.Direction.VERTICAL) {
linearGradient = new LinearGradient(0, 0, 0, getBottom() - getTop(), getBeginColor(), getEndColor(), getGradientMode());
} else {
linearGradient = new LinearGradient(getLeft(), getBottom(), getRight(), getTop(), getBeginColor(), getEndColor(), getGradientMode());
}
getBackgroundPaint().setShader(linearGradient);
} else {
getBackgroundPaint().setShader(null);
}
canvas.drawRect(mLeft, mTop, mRight, mBottom, getBackgroundPaint());
}
}
use of android.graphics.LinearGradient in project XCL-Charts by xcltapestry.
the class AreaChart method renderBezierArea.
private boolean renderBezierArea(Canvas canvas, Paint paintAreaFill, Path bezierPath, AreaData areaData, List<PointF> lstPathPoints) {
int count = lstPathPoints.size();
if (count < 3)
// 没有或仅一个点就不需要了
return false;
// 设置当前填充色
paintAreaFill.setColor(areaData.getAreaFillColor());
// 仅两点
if (count == 3) {
if (null == bezierPath)
bezierPath = new Path();
bezierPath.moveTo(lstPathPoints.get(0).x, plotArea.getBottom());
bezierPath.lineTo(lstPathPoints.get(0).x, lstPathPoints.get(0).y);
PointF ctl3 = PointHelper.percent(lstPathPoints.get(1), 0.5f, lstPathPoints.get(2), 0.8f);
bezierPath.quadTo(ctl3.x, ctl3.y, lstPathPoints.get(2).x, lstPathPoints.get(2).y);
// canvas.drawCircle(ctl3.x, ctl3.y, 10.f, paintAreaFill); //显示控制点
bezierPath.lineTo(lstPathPoints.get(2).x, plotArea.getBottom());
bezierPath.close();
if (areaData.getApplayGradient()) {
LinearGradient linearGradient;
if (areaData.getGradientDirection() == XEnum.Direction.VERTICAL) {
float lineMaxY = getLineMaxMinY(Y_MAX, lstPathPoints);
linearGradient = new LinearGradient(0, 0, 0, // 2 * h,
plotArea.getBottom() - lineMaxY, // lstPathPoints.get(count -1).x,lineMinY,
areaData.getAreaBeginColor(), areaData.getAreaEndColor(), areaData.getGradientMode());
} else {
float lineMinY = getLineMaxMinY(Y_MIN, lstPathPoints);
linearGradient = new LinearGradient(plotArea.getLeft(), plotArea.getBottom(), lstPathPoints.get(2).x, lineMinY, areaData.getAreaBeginColor(), areaData.getAreaEndColor(), areaData.getGradientMode());
}
paintAreaFill.setShader(linearGradient);
} else {
paintAreaFill.setShader(null);
}
canvas.drawPath(bezierPath, paintAreaFill);
bezierPath.reset();
return true;
}
// 透明度
paintAreaFill.setAlpha(this.mAreaAlpha);
// start point
bezierPath.moveTo(plotArea.getLeft(), plotArea.getBottom());
float axisMinValue = plotArea.getBottom();
for (int i = 0; i < count; i++) {
if (i < 3)
continue;
// 连续两个值都为0,控制点有可能会显示在轴以下,则此种情况下,将其处理为直线
if (lstPathPoints.get(i - 1).y >= axisMinValue && lstPathPoints.get(i).y >= axisMinValue) {
// 如果最后两点为0时此处调用了两次,最后一次跳过不做处理,原因是数组的最后一个点的y值必定为0
if (i == count - 1) {
continue;
}
if (null == bezierPath) {
bezierPath = new Path();
bezierPath.moveTo(lstPathPoints.get(i - 2).x, lstPathPoints.get(i - 2).y);
} else {
bezierPath.lineTo(lstPathPoints.get(i - 2).x, lstPathPoints.get(i - 2).y);
}
// change by chenqiang
if (lstPathPoints.get(i - 2).y >= axisMinValue) {
//连续3个点为0
bezierPath.moveTo(lstPathPoints.get(i - 1).x, lstPathPoints.get(i - 1).y);
} else {
CurveHelper.curve3(lstPathPoints.get(i - 2), lstPathPoints.get(i - 1), lstPathPoints.get(i - 3), lstPathPoints.get(i), mBezierControls);
bezierPath.quadTo(mBezierControls[0].x, mBezierControls[0].y, lstPathPoints.get(i - 1).x, lstPathPoints.get(i - 1).y);
}
bezierPath.close();
if (areaData.getApplayGradient()) {
LinearGradient linearGradient;
if (areaData.getGradientDirection() == XEnum.Direction.VERTICAL) {
float lineMaxY = getLineMaxMinY(Y_MAX, lstPathPoints);
linearGradient = new LinearGradient(0, 0, 0, lineMaxY, areaData.getAreaBeginColor(), areaData.getAreaEndColor(), areaData.getGradientMode());
} else {
float lineMinY = getLineMaxMinY(Y_MIN, lstPathPoints);
linearGradient = new LinearGradient(plotArea.getLeft(), plotArea.getBottom(), lstPathPoints.get(i - 1).x, lineMinY, areaData.getAreaBeginColor(), areaData.getAreaEndColor(), areaData.getGradientMode());
}
paintAreaFill.setShader(linearGradient);
} else {
paintAreaFill.setShader(null);
}
canvas.drawPath(bezierPath, paintAreaFill);
bezierPath.reset();
bezierPath.moveTo(lstPathPoints.get(i).x, lstPathPoints.get(i).y);
continue;
}
CurveHelper.curve3(lstPathPoints.get(i - 2), lstPathPoints.get(i - 1), lstPathPoints.get(i - 3), lstPathPoints.get(i), mBezierControls);
// change by chenqiang
bezierCurvePathAxisMinValue(bezierPath, lstPathPoints.get(i - 2), lstPathPoints.get(i - 1), mBezierControls);
}
// 最后两点间的区域
// 通过calcAllPoints函数,stop的y值一定是0
PointF stop = lstPathPoints.get(count - 1);
if (lstPathPoints.get(count - 2).y >= axisMinValue) {
// 最后一点是0
// change by chenqiang
CurveHelper.curve3(lstPathPoints.get(count - 3), stop, lstPathPoints.get(count - 4), stop, mBezierControls);
bezierCurvePathAxisMinValue(bezierPath, lstPathPoints.get(count - 3), stop, mBezierControls);
} else {
CurveHelper.curve3(lstPathPoints.get(count - 2), stop, lstPathPoints.get(count - 3), stop, mBezierControls);
// change by chenqiang
bezierCurvePathAxisMinValue(bezierPath, lstPathPoints.get(count - 2), lstPathPoints.get(count - 1), mBezierControls);
}
bezierPath.close();
if (areaData.getApplayGradient()) {
LinearGradient linearGradient;
if (areaData.getGradientDirection() == XEnum.Direction.VERTICAL) {
float lineMaxY = getLineMaxMinY(Y_MAX, lstPathPoints);
linearGradient = new LinearGradient(0, 0, 0, lineMaxY, areaData.getAreaBeginColor(), areaData.getAreaEndColor(), areaData.getGradientMode());
} else {
float lineMinY = getLineMaxMinY(Y_MIN, lstPathPoints);
linearGradient = new LinearGradient(plotArea.getLeft(), plotArea.getBottom(), stop.x, lineMinY, areaData.getAreaBeginColor(), areaData.getAreaEndColor(), areaData.getGradientMode());
}
paintAreaFill.setShader(linearGradient);
} else {
paintAreaFill.setShader(null);
}
canvas.drawPath(bezierPath, paintAreaFill);
bezierPath.reset();
return true;
}
use of android.graphics.LinearGradient in project ZI by yixia.
the class ColorPickerView method drawAlphaPanel.
private void drawAlphaPanel(Canvas canvas) {
if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null)
return;
final RectF rect = mAlphaRect;
if (BORDER_WIDTH_PX > 0) {
mBorderPaint.setColor(mBorderColor);
canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint);
}
mAlphaPattern.draw(canvas);
float[] hsv = new float[] { mHue, mSat, mVal };
int color = Color.HSVToColor(hsv);
int acolor = Color.HSVToColor(0, hsv);
mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, color, acolor, TileMode.CLAMP);
mAlphaPaint.setShader(mAlphaShader);
canvas.drawRect(rect, mAlphaPaint);
if (mAlphaSliderText != null && mAlphaSliderText != "") {
canvas.drawText(mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity, mAlphaTextPaint);
}
float rectWidth = 4 * mDensity / 2;
Point p = alphaToPoint(mAlpha);
RectF r = new RectF();
r.left = p.x - rectWidth;
r.right = p.x + rectWidth;
r.top = rect.top - RECTANGLE_TRACKER_OFFSET;
r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET;
canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
}
use of android.graphics.LinearGradient in project ZI by yixia.
the class ColorPickerView method drawSatValPanel.
private void drawSatValPanel(Canvas canvas) {
final RectF rect = mSatValRect;
if (BORDER_WIDTH_PX > 0) {
mBorderPaint.setColor(mBorderColor);
canvas.drawRect(mDrawingRect.left, mDrawingRect.top, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint);
}
if (mValShader == null) {
mValShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, 0xffffffff, 0xff000000, TileMode.CLAMP);
}
int rgb = Color.HSVToColor(new float[] { mHue, 1f, 1f });
mSatShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, 0xffffffff, rgb, TileMode.CLAMP);
ComposeShader mShader = new ComposeShader(mValShader, mSatShader, PorterDuff.Mode.MULTIPLY);
mSatValPaint.setShader(mShader);
canvas.drawRect(rect, mSatValPaint);
Point p = satValToPoint(mSat, mVal);
mSatValTrackerPaint.setColor(0xff000000);
canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS - 1f * mDensity, mSatValTrackerPaint);
mSatValTrackerPaint.setColor(0xffdddddd);
canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS, mSatValTrackerPaint);
}
use of android.graphics.LinearGradient in project ZI by yixia.
the class ColorPickerView method drawHuePanel.
private void drawHuePanel(Canvas canvas) {
final RectF rect = mHueRect;
if (BORDER_WIDTH_PX > 0) {
mBorderPaint.setColor(mBorderColor);
canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint);
}
if (mHueShader == null) {
mHueShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, buildHueColorArray(), null, TileMode.CLAMP);
mHuePaint.setShader(mHueShader);
}
canvas.drawRect(rect, mHuePaint);
float rectHeight = 4 * mDensity / 2;
Point p = hueToPoint(mHue);
RectF r = new RectF();
r.left = rect.left - RECTANGLE_TRACKER_OFFSET;
r.right = rect.right + RECTANGLE_TRACKER_OFFSET;
r.top = p.y - rectHeight;
r.bottom = p.y + rectHeight;
canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
}
Aggregations