本文整理汇总了Java中lecho.lib.hellocharts.util.ChartUtils.dp2px方法的典型用法代码示例。如果您正苦于以下问题:Java ChartUtils.dp2px方法的具体用法?Java ChartUtils.dp2px怎么用?Java ChartUtils.dp2px使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lecho.lib.hellocharts.util.ChartUtils
的用法示例。
在下文中一共展示了ChartUtils.dp2px方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AbstractChartRenderer
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
public AbstractChartRenderer(Context context, Chart chart) {
this.density = context.getResources().getDisplayMetrics().density;
this.scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
this.chart = chart;
this.computator = chart.getChartComputator();
labelMargin = ChartUtils.dp2px(density, DEFAULT_LABEL_MARGIN_DP);
labelOffset = labelMargin;
labelPaint.setAntiAlias(true);
labelPaint.setStyle(Paint.Style.FILL);
labelPaint.setTextAlign(Align.LEFT);
labelPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
labelPaint.setColor(Color.WHITE);
labelBackgroundPaint.setAntiAlias(true);
labelBackgroundPaint.setStyle(Paint.Style.FILL);
}
示例2: LineChartRenderer
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
public LineChartRenderer(Context context, Chart chart, LineChartDataProvider dataProvider) {
super(context, chart);
this.dataProvider = dataProvider;
touchToleranceMargin = ChartUtils.dp2px(density, DEFAULT_TOUCH_TOLERANCE_MARGIN_DP);
linePaint.setAntiAlias(true);
linePaint.setStyle(Paint.Style.STROKE);
linePaint.setStrokeCap(Cap.ROUND);
linePaint.setStrokeWidth(ChartUtils.dp2px(density, DEFAULT_LINE_STROKE_WIDTH_DP));
pointPaint.setAntiAlias(true);
pointPaint.setStyle(Paint.Style.FILL);
checkPrecision = ChartUtils.dp2px(density, 2);
}
示例3: checkTouch
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
@Override
public boolean checkTouch(float touchX, float touchY) {
selectedValue.clear();
final LineChartData data = dataProvider.getLineChartData();
int lineIndex = 0;
for (Line line : data.getLines()) {
if (checkIfShouldDrawPoints(line)) {
int pointRadius = ChartUtils.dp2px(density, line.getPointRadius());
int valueIndex = 0;
for (PointValue pointValue : line.getValues()) {
final float rawValueX = computator.computeRawX(pointValue.getX());
final float rawValueY = computator.computeRawY(pointValue.getY());
if (isInArea(rawValueX, rawValueY, touchX, touchY, pointRadius + touchToleranceMargin)) {
selectedValue.set(lineIndex, valueIndex, SelectedValueType.LINE);
}
++valueIndex;
}
}
++lineIndex;
}
return isTouched();
}
示例4: drawPoints
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
private void drawPoints(Canvas canvas, Line line, int lineIndex, int mode) {
pointPaint.setColor(line.getPointColor());
int valueIndex = 0;
for (PointValue pointValue : line.getValues()) {
int pointRadius = ChartUtils.dp2px(density, line.getPointRadius());
final float rawX = computator.computeRawX(pointValue.getX());
final float rawY = computator.computeRawY(pointValue.getY());
if (computator.isWithinContentRect(rawX, rawY, checkPrecision)) {
// Draw points only if they are within contentRectMinusAllMargins, using contentRectMinusAllMargins
// instead of viewport to avoid some
// float rounding problems.
if (MODE_DRAW == mode) {
drawPoint(canvas, line, pointValue, rawX, rawY, pointRadius);
if (line.hasLabels()) {
drawLabel(canvas, line, pointValue, rawX, rawY, pointRadius + labelOffset);
}
} else if (MODE_HIGHLIGHT == mode) {
highlightPoint(canvas, line, pointValue, rawX, rawY, lineIndex, valueIndex);
} else {
throw new IllegalStateException("Cannot process points in mode: " + mode);
}
}
++valueIndex;
}
}
示例5: PieChartRenderer
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
public PieChartRenderer(Context context, Chart chart, PieChartDataProvider dataProvider) {
super(context, chart);
this.dataProvider = dataProvider;
this.touchAdditional = ChartUtils.dp2px(this.density, 8);
this.slicePaint.setAntiAlias(true);
this.slicePaint.setStyle(Style.FILL);
this.centerCirclePaint.setAntiAlias(true);
this.centerCirclePaint.setStyle(Style.FILL);
this.centerCirclePaint.setXfermode(new PorterDuffXfermode(Mode.SRC));
this.centerCircleText1Paint.setAntiAlias(true);
this.centerCircleText1Paint.setTextAlign(Align.CENTER);
this.centerCircleText2Paint.setAntiAlias(true);
this.centerCircleText2Paint.setTextAlign(Align.CENTER);
this.separationLinesPaint.setAntiAlias(true);
this.separationLinesPaint.setStyle(Style.STROKE);
this.separationLinesPaint.setStrokeCap(Cap.ROUND);
this.separationLinesPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
this.separationLinesPaint.setColor(0);
}
示例6: drawSeparationLines
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
private void drawSeparationLines(Canvas canvas) {
PieChartData data = this.dataProvider.getPieChartData();
if (data.getValues().size() >= 2) {
int sliceSpacing = ChartUtils.dp2px(this.density, data.getSlicesSpacing());
if (sliceSpacing >= 1) {
float sliceScale = 360.0f / this.maxSum;
float lastAngle = (float) this.rotation;
float circleRadius = this.originCircleOval.width() / 2.0f;
this.separationLinesPaint.setStrokeWidth((float) sliceSpacing);
for (SliceValue sliceValue : data.getValues()) {
float angle = Math.abs(sliceValue.getValue()) * sliceScale;
this.sliceVector.set((float) Math.cos(Math.toRadians((double) lastAngle)), (float) Math.sin(Math.toRadians((double) lastAngle)));
normalizeVector(this.sliceVector);
Canvas canvas2 = canvas;
canvas2.drawLine(this.originCircleOval.centerX(), this.originCircleOval.centerY(), (this.sliceVector.x * (((float) this.touchAdditional) + circleRadius)) + this.originCircleOval.centerX(), (this.sliceVector.y * (((float) this.touchAdditional) + circleRadius)) + this.originCircleOval.centerY(), this.separationLinesPaint);
lastAngle += angle;
}
}
}
}
示例7: AbstractChartRenderer
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
public AbstractChartRenderer(Context context, Chart chart) {
this.context = context;
this.density = context.getResources().getDisplayMetrics().density;
this.scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
this.chart = chart;
this.computator = chart.getChartComputator();
this.resources = context.getResources();
this.labelMargin = ChartUtils.dp2px(this.density, this.DEFAULT_LABEL_MARGIN_DP);
this.labelOffset = this.labelMargin;
this.labelPaint.setAntiAlias(true);
this.labelPaint.setStyle(Style.FILL);
this.labelPaint.setTextAlign(Align.LEFT);
this.labelPaint.setTypeface(Typeface.defaultFromStyle(1));
this.labelPaint.setColor(-1);
this.labelBackgroundPaint.setAntiAlias(true);
this.labelBackgroundPaint.setStyle(Style.FILL);
}
示例8: LineChartRenderer
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
public LineChartRenderer(Context context, Chart chart, LineChartDataProvider dataProvider) {
super(context, chart);
this.dataProvider = dataProvider;
this.touchToleranceMargin = ChartUtils.dp2px(this.density, 4);
this.linePaint.setAntiAlias(true);
this.linePaint.setStyle(Style.STROKE);
this.linePaint.setStrokeCap(Cap.ROUND);
this.linePaint.setStrokeWidth((float) ChartUtils.dp2px(this.density, 3));
this.pointPaint.setAntiAlias(true);
this.pointPaint.setStyle(Style.FILL);
this.weightStrPaint.setAntiAlias(true);
this.weightStrPaint.setColor(-1);
this.weightStrPaint.setTextSize((float) ChartUtils.dp2px(this.density, 12));
this.weightLinePaint.setAntiAlias(true);
this.weightLinePaint.setStyle(Style.STROKE);
this.weightLinePaint.setStrokeWidth((float) ChartUtils.dp2px(this.density, 1));
this.weightLinePaint.setColor(ChartUtils.DEFAULT_TARGET_COLOR);
this.checkPrecision = ChartUtils.dp2px(this.density, 2);
}
示例9: AxesRenderer
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
public AxesRenderer(Context context, Chart chart) {
this.chart = chart;
this.resources = context.getResources();
this.mContext = context;
this.computator = chart.getChartComputator();
this.density = context.getResources().getDisplayMetrics().density;
this.scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
this.axisMargin = ChartUtils.dp2px(this.density, 2);
for (int position = 0; position < 4; position++) {
this.labelPaintTab[position].setStyle(Style.FILL);
this.labelPaintTab[position].setAntiAlias(true);
this.namePaintTab[position].setStyle(Style.FILL);
this.namePaintTab[position].setAntiAlias(true);
this.linePaintTab[position].setStyle(Style.STROKE);
this.linePaintTab[position].setAntiAlias(true);
}
}
示例10: drawTargetCaloryText
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
public void drawTargetCaloryText(Canvas drawCanvas) {
if (this.targetCalory > 0) {
float currentLeft = 0.0f;
Viewport currentViewport = this.computator.getCurrentViewport();
if (currentViewport != null) {
currentLeft = currentViewport.left;
}
float rawX1 = this.computator.computeRawX(currentLeft);
float y = this.computator.computeRawY((float) this.targetCalory);
String targetStr = String.valueOf(this.targetCalory);
float textWidth = this.caloryTextPaint.measureText(targetStr);
float textX = (rawX1 - textWidth) - ((float) ChartUtils.dp2px(this.density, 2));
float textY = y + (getTextHeight() / aj.hA);
RectF rect = new RectF(textX, y - (getTextHeight() / 2.0f), textX + textWidth, (getTextHeight() / 2.0f) + y);
this.caloryTextPaint.setColor(ChartUtils.COLOR_BACKGROUND);
drawCanvas.drawRoundRect(rect, 5.0f, 5.0f, this.caloryTextPaint);
if (this.targetCaloryTextColor != 0) {
this.caloryTextPaint.setColor(this.targetCaloryTextColor);
} else {
this.caloryTextPaint.setColor(ChartUtils.DEFAULT_TARGET_COLOR);
}
drawCanvas.drawText(targetStr, textX, textY, this.caloryTextPaint);
}
}
示例11: PieChartRenderer
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
public PieChartRenderer(Context context, Chart chart, PieChartDataProvider dataProvider) {
super(context, chart);
this.dataProvider = dataProvider;
touchAdditional = ChartUtils.dp2px(density, DEFAULT_TOUCH_ADDITIONAL_DP);
slicePaint.setAntiAlias(true);
slicePaint.setStyle(Paint.Style.FILL);
centerCirclePaint.setAntiAlias(true);
centerCirclePaint.setStyle(Paint.Style.FILL);
centerCirclePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
centerCircleText1Paint.setAntiAlias(true);
centerCircleText1Paint.setTextAlign(Align.CENTER);
centerCircleText2Paint.setAntiAlias(true);
centerCircleText2Paint.setTextAlign(Align.CENTER);
separationLinesPaint.setAntiAlias(true);
separationLinesPaint.setStyle(Paint.Style.STROKE);
separationLinesPaint.setStrokeCap(Paint.Cap.ROUND);
separationLinesPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
separationLinesPaint.setColor(Color.TRANSPARENT);
}
示例12: onChartDataOrSizeChanged
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
private void onChartDataOrSizeChanged() {
if (this.chart instanceof LineChartData) {
this.imgRadius = ChartUtils.dp2px(this.density, ((LineChartData) this.chart.getChartData()).getImgRadius());
}
initAxis(this.chart.getChartData().getAxisXTop(), 0);
initAxis(this.chart.getChartData().getAxisXBottom(), 3);
initAxis(this.chart.getChartData().getAxisYLeft(), 1);
initAxis(this.chart.getChartData().getAxisYRight(), 2);
}
示例13: calculateContentRectInternalMargin
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
private int calculateContentRectInternalMargin() {
int contentAreaMargin = 0;
final LineChartData data = dataProvider.getLineChartData();
for (Line line : data.getLines()) {
if (checkIfShouldDrawPoints(line)) {
int margin = line.getPointRadius() + DEFAULT_TOUCH_TOLERANCE_MARGIN_DP;
if (margin > contentAreaMargin) {
contentAreaMargin = margin;
}
}
}
return ChartUtils.dp2px(density, contentAreaMargin);
}
示例14: highlightPoint
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
private void highlightPoint(Canvas canvas, Line line, PointValue pointValue, float rawX, float rawY, int lineIndex,
int valueIndex) {
if (selectedValue.getFirstIndex() == lineIndex && selectedValue.getSecondIndex() == valueIndex) {
int pointRadius = ChartUtils.dp2px(density, line.getPointRadius());
pointPaint.setColor(line.getDarkenColor());
drawPoint(canvas, line, pointValue, rawX, rawY, pointRadius + touchToleranceMargin);
if (line.hasLabels() || line.hasLabelsOnlyForSelected()) {
drawLabel(canvas, line, pointValue, rawX, rawY, pointRadius + labelOffset);
}
}
}
示例15: drawSeparationLines
import lecho.lib.hellocharts.util.ChartUtils; //导入方法依赖的package包/类
private void drawSeparationLines(Canvas canvas) {
final PieChartData data = dataProvider.getPieChartData();
if (data.getValues().size() < 2) {
//No need for separation lines for 0 or 1 slices.
return;
}
final int sliceSpacing = ChartUtils.dp2px(density, data.getSlicesSpacing());
if (sliceSpacing < 1) {
//No need for separation lines
return;
}
final float sliceScale = 360f / maxSum;
float lastAngle = rotation;
final float circleRadius = originCircleOval.width() / 2f;
separationLinesPaint.setStrokeWidth(sliceSpacing);
for (SliceValue sliceValue : data.getValues()) {
final float angle = Math.abs(sliceValue.getValue()) * sliceScale;
sliceVector.set((float) (Math.cos(Math.toRadians(lastAngle))),
(float) (Math.sin(Math.toRadians(lastAngle))));
normalizeVector(sliceVector);
float x1 = sliceVector.x * (circleRadius + touchAdditional) + originCircleOval.centerX();
float y1 = sliceVector.y * (circleRadius + touchAdditional) + originCircleOval.centerY();
canvas.drawLine(originCircleOval.centerX(), originCircleOval.centerY(), x1, y1, separationLinesPaint);
lastAngle += angle;
}
}