use of android.graphics.DashPathEffect in project WilliamChart by diogobernardino.
the class LineChartView method onDrawChart.
/**
* Method responsible to draw a line with the parsed screen points.
*
* @param canvas The canvas to draw on.
*/
@Override
public void onDrawChart(Canvas canvas, ArrayList<ChartSet> data) {
LineSet lineSet;
Path linePath;
for (ChartSet set : data) {
lineSet = (LineSet) set;
if (lineSet.isVisible()) {
mStyle.mLinePaint.setColor(lineSet.getColor());
mStyle.mLinePaint.setStrokeWidth(lineSet.getThickness());
applyShadow(mStyle.mLinePaint, lineSet.getAlpha(), lineSet.getShadowDx(), lineSet.getShadowDy(), lineSet.getShadowRadius(), lineSet.getShadowColor());
if (lineSet.isDashed())
mStyle.mLinePaint.setPathEffect(new DashPathEffect(lineSet.getDashedIntervals(), lineSet.getDashedPhase()));
else
mStyle.mLinePaint.setPathEffect(null);
if (!lineSet.isSmooth())
linePath = createLinePath(lineSet);
else
linePath = createSmoothLinePath(lineSet);
//Draw background
if (lineSet.hasFill() || lineSet.hasGradientFill())
canvas.drawPath(createBackgroundPath(new Path(linePath), lineSet), mStyle.mFillPaint);
//Draw line
canvas.drawPath(linePath, mStyle.mLinePaint);
//Draw points
drawPoints(canvas, lineSet);
}
}
}
use of android.graphics.DashPathEffect in project WilliamChart by diogobernardino.
the class StackedCardOne method show.
@Override
public void show(Runnable action) {
super.show(action);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
mChart.setOnEntryClickListener(new OnEntryClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(int setIndex, int entryIndex, Rect rect) {
if (setIndex == 2)
mLegendOneRed.animate().scaleY(1.3f).scaleX(1.3f).setDuration(100).withEndAction(new Runnable() {
@Override
public void run() {
mLegendOneRed.animate().scaleY(1.0f).scaleX(1.0f).setDuration(100);
}
});
else if (setIndex == 1) {
mLegendOneYellow.animate().scaleY(1.3f).scaleX(1.3f).setDuration(100).withEndAction(new Runnable() {
@Override
public void run() {
mLegendOneYellow.animate().scaleY(1.0f).scaleX(1.0f).setDuration(100);
}
});
} else {
mLegendOneGreen.animate().scaleY(1.3f).scaleX(1.3f).setDuration(100).withEndAction(new Runnable() {
@Override
public void run() {
mLegendOneGreen.animate().scaleY(1.0f).scaleX(1.0f).setDuration(100);
}
});
}
}
});
Paint thresPaint = new Paint();
thresPaint.setColor(Color.parseColor("#dad8d6"));
thresPaint.setPathEffect(new DashPathEffect(new float[] { 10, 20 }, 0));
thresPaint.setStyle(Paint.Style.STROKE);
thresPaint.setAntiAlias(true);
thresPaint.setStrokeWidth(Tools.fromDpToPx(.75f));
BarSet stackBarSet = new BarSet(mLabels, mValuesOne[0]);
stackBarSet.setColor(Color.parseColor("#a1d949"));
mChart.addData(stackBarSet);
stackBarSet = new BarSet(mLabels, mValuesOne[1]);
stackBarSet.setColor(Color.parseColor("#ffcc6a"));
mChart.addData(stackBarSet);
stackBarSet = new BarSet(mLabels, mValuesOne[2]);
stackBarSet.setColor(Color.parseColor("#ff7a57"));
mChart.addData(stackBarSet);
mChart.setBarSpacing(Tools.fromDpToPx(15));
mChart.setRoundCorners(Tools.fromDpToPx(1));
mChart.setXAxis(false).setXLabels(XRenderer.LabelPosition.OUTSIDE).setYAxis(false).setYLabels(YRenderer.LabelPosition.NONE).setValueThreshold(89.f, 89.f, thresPaint);
int[] order = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
mChart.show(new Animation().setOverlap(.5f, order).setEndAction(action));
}
use of android.graphics.DashPathEffect in project UltimateAndroid by cymcsg.
the class HomeDiagram method drawBrokenLine.
/**
* 绘制折线
*
* @param c
*/
public void drawBrokenLine(Canvas c) {
int index = 0;
float temp_x = 0;
float temp_y = 0;
float base = (getHeight() - tb * 3.0f) / (Collections.max(milliliter) - Collections.min(milliliter));
Shader mShader = new LinearGradient(0, 0, 0, getHeight(), new int[] { Color.argb(100, 0, 255, 255), Color.argb(45, 0, 255, 255), Color.argb(10, 0, 255, 255) }, null, Shader.TileMode.CLAMP);
framPanint.setShader(mShader);
for (int i = 0; i < milliliter.size() - 1; i++) {
float x1 = interval_left_right * i;
float y1 = getHeight() - tb * 1.5f - (base * milliliter.get(i));
float x2 = interval_left_right * (i + 1);
float y2 = getHeight() - tb * 1.5f - (base * milliliter.get(i + 1));
if ((int) (base * milliliter.get(i + 1)) == 0 && index == 0) {
index++;
temp_x = x1;
temp_y = y1;
}
if ((int) (base * milliliter.get(i + 1)) != 0 && index != 0) {
index = 0;
x1 = temp_x;
y1 = temp_y;
}
if (index == 0) {
c.drawLine(x1, y1, x2, y2, paint_brokenLine);
path.lineTo(x1, y1);
if (i != 0)
c.drawBitmap(bitmap_point, x1 - bitmap_point.getWidth() / 2, y1 - bitmap_point.getHeight() / 2, null);
if (i == milliliter.size() - 2) {
path.lineTo(x2, y2);
path.lineTo(x2, getHeight());
path.lineTo(0, getHeight());
path.close();
c.drawPath(path, framPanint);
c.drawBitmap(bitmap_point, x2 - bitmap_point.getWidth() / 2, y2 - bitmap_point.getHeight() / 2, null);
}
}
}
paint_dottedline.setColor(orangeLineColor);
Path path = new Path();
path.moveTo(0, getHeight() - tb * 6.5f);
path.lineTo(getWidth(), getHeight() - tb * 6.5f);
PathEffect effects = new DashPathEffect(new float[] { tb * 0.3f, tb * 0.3f, tb * 0.3f, tb * 0.3f }, tb * 0.1f);
paint_dottedline.setPathEffect(effects);
c.drawPath(path, paint_dottedline);
}
use of android.graphics.DashPathEffect in project android_frameworks_base by ParanoidAndroid.
the class GradientDrawable method initializeWithState.
private void initializeWithState(GradientState state) {
if (state.mHasSolidColor) {
mFillPaint.setColor(state.mSolidColor);
} else if (state.mColors == null) {
// If we don't have a solid color and we don't have a gradient,
// the app is stroking the shape, set the color to the default
// value of state.mSolidColor
mFillPaint.setColor(0);
}
mPadding = state.mPadding;
if (state.mStrokeWidth >= 0) {
mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mStrokePaint.setStyle(Paint.Style.STROKE);
mStrokePaint.setStrokeWidth(state.mStrokeWidth);
mStrokePaint.setColor(state.mStrokeColor);
if (state.mStrokeDashWidth != 0.0f) {
DashPathEffect e = new DashPathEffect(new float[] { state.mStrokeDashWidth, state.mStrokeDashGap }, 0);
mStrokePaint.setPathEffect(e);
}
}
}
use of android.graphics.DashPathEffect in project MPAndroidChart by PhilJay.
the class LegendRenderer method drawForm.
/**
* Draws the Legend-form at the given position with the color at the given
* index.
*
* @param c canvas to draw with
* @param x position
* @param y position
* @param entry the entry to render
* @param legend the legend context
*/
protected void drawForm(Canvas c, float x, float y, LegendEntry entry, Legend legend) {
if (entry.formColor == ColorTemplate.COLOR_SKIP || entry.formColor == ColorTemplate.COLOR_NONE || entry.formColor == 0)
return;
int restoreCount = c.save();
Legend.LegendForm form = entry.form;
if (form == Legend.LegendForm.DEFAULT)
form = legend.getForm();
mLegendFormPaint.setColor(entry.formColor);
final float formSize = Utils.convertDpToPixel(Float.isNaN(entry.formSize) ? legend.getFormSize() : entry.formSize);
final float half = formSize / 2f;
switch(form) {
case NONE:
// Do nothing
break;
case EMPTY:
// Do not draw, but keep space for the form
break;
case DEFAULT:
case CIRCLE:
mLegendFormPaint.setStyle(Paint.Style.FILL);
c.drawCircle(x + half, y, half, mLegendFormPaint);
break;
case SQUARE:
mLegendFormPaint.setStyle(Paint.Style.FILL);
c.drawRect(x, y - half, x + formSize, y + half, mLegendFormPaint);
break;
case LINE:
{
final float formLineWidth = Utils.convertDpToPixel(Float.isNaN(entry.formLineWidth) ? legend.getFormLineWidth() : entry.formLineWidth);
final DashPathEffect formLineDashEffect = entry.formLineDashEffect == null ? legend.getFormLineDashEffect() : entry.formLineDashEffect;
mLegendFormPaint.setStyle(Paint.Style.STROKE);
mLegendFormPaint.setStrokeWidth(formLineWidth);
mLegendFormPaint.setPathEffect(formLineDashEffect);
mLineFormPath.reset();
mLineFormPath.moveTo(x, y);
mLineFormPath.lineTo(x + formSize, y);
c.drawPath(mLineFormPath, mLegendFormPaint);
}
break;
}
c.restoreToCount(restoreCount);
}
Aggregations