List of usage examples for android.graphics Paint getColor
@ColorInt public int getColor()
From source file:Main.java
public static String toRGB(Paint paint) { if (paint == null) return "null"; return toRGB(paint.getColor()); }
From source file:com.ridgelineapps.wallpaper.Utils.java
public static Paint copy(Paint paint) { int c = paint.getColor(); return Utils.createPaint(Color.alpha(c), Color.red(c), Color.green(c), Color.blue(c)); }
From source file:com.ridgelineapps.wallpaper.Utils.java
public static Paint createPaint(Paint p, int colorChange, int alphaChange) { int a = Color.alpha(p.getColor()) + alphaChange; int r = Color.red(p.getColor()) + colorChange; int g = Color.green(p.getColor()) + colorChange; int b = Color.blue(p.getColor()) + colorChange; if (a < 0) a = 0;/*from www. ja v a 2 s. co m*/ if (a > 255) a = 255; if (r < 0) r = 0; if (r > 255) r = 255; if (g < 0) g = 0; if (g > 255) g = 255; if (b < 0) b = 0; if (b > 255) b = 255; return createPaint(a, r, g, b); }
From source file:com.viewpagerindicator.RichTitlePageIndicator.java
private void drawLeftItem(Canvas canvas, int pos, Rect bound, Paint paint, boolean drawIcon) { int c1 = paint.getColor(); int c2 = 0;//from ww w.j a va 2 s . c om Paint blur = new Paint(paint); Shader shader = new LinearGradient(bound.left, 0, bound.right, 0, new int[] { c2, c1 }, new float[] { 0, 1 }, TileMode.CLAMP); blur.setShader(shader); drawItem(canvas, pos, bound, blur, drawIcon); //paint.setShader(null); }
From source file:com.viewpagerindicator.RichTitlePageIndicator.java
private void drawRightItem(Canvas canvas, int pos, Rect bound, Paint paint, boolean drawIcon) { int c1 = paint.getColor(); int c2 = 0;/*from w w w. j a va 2 s . c o m*/ Paint blur = new Paint(paint); Shader shader = new LinearGradient(bound.left, 0, bound.right, 0, new int[] { c1, c2 }, new float[] { 0, 1 }, TileMode.CLAMP); blur.setShader(shader); drawItem(canvas, pos, bound, blur, drawIcon); //paint.setShader(null); }
From source file:org.navitproject.navit.NavitGraphics.java
protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy, int bgcolor) { int oldcolor = paint.getColor(); Path path = null;//from w w w . j a v a 2 s .c o m paint.setTextSize(size / 15); paint.setStyle(Paint.Style.FILL); if (dx != 0x10000 || dy != 0) { path = new Path(); path.moveTo(x, y); path.rLineTo(dx, dy); paint.setTextAlign(android.graphics.Paint.Align.LEFT); } if (bgcolor != 0) { paint.setStrokeWidth(3); paint.setColor(bgcolor); paint.setStyle(Paint.Style.STROKE); if (path == null) { draw_canvas.drawText(text, x, y, paint); } else { draw_canvas.drawTextOnPath(text, path, 0, 0, paint); } paint.setStyle(Paint.Style.FILL); paint.setColor(oldcolor); } if (path == null) { draw_canvas.drawText(text, x, y, paint); } else { draw_canvas.drawTextOnPath(text, path, 0, 0, paint); } paint.clearShadowLayer(); }
From source file:net.droidsolutions.droidcharts.core.renderer.AbstractCategoryItemRenderer.java
/** * Returns a legend item for a series. This default implementation will * return <code>null</code> if {@link #isSeriesVisible(int)} or * {@link #isSeriesVisibleInLegend(int)} returns <code>false</code>. * /*from w w w. j a va 2 s. com*/ * @param datasetIndex * the dataset index (zero-based). * @param series * the series index (zero-based). * * @return The legend item (possibly <code>null</code>). * * @see #getLegendItems() */ public LegendItem getLegendItem(int datasetIndex, int series) { CategoryPlot p = getPlot(); if (p == null) { return null; } // check that a legend item needs to be displayed... if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) { return null; } CategoryDataset dataset = p.getDataset(datasetIndex); String label = this.legendItemLabelGenerator.generateLabel(dataset, series); String description = label; String toolTipText = null; if (this.legendItemToolTipGenerator != null) { toolTipText = this.legendItemToolTipGenerator.generateLabel(dataset, series); } String urlText = null; if (this.legendItemURLGenerator != null) { urlText = this.legendItemURLGenerator.generateLabel(dataset, series); } Shape shape = lookupLegendShape(series); Paint paint = lookupSeriesPaint(series); Paint outlinePaint = lookupSeriesOutlinePaint(series); float outlineStroke = lookupSeriesOutlineStroke(series); LegendItem item = new LegendItem(label, description, toolTipText, urlText, shape, paint.getColor(), outlineStroke, outlinePaint.getColor()); item.setLabelFont(lookupLegendTextFont(series)); Paint labelPaint = lookupLegendTextPaint(series); if (labelPaint != null) { item.setLabelPaint(labelPaint); } item.setSeriesKey(dataset.getRowKey(series)); item.setSeriesIndex(series); item.setDataset(dataset); item.setDatasetIndex(datasetIndex); return item; }
From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java
/** * Returns a default legend item for the specified series. Subclasses * should override this method to generate customised items. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return A legend item for the series. *///w w w . j ava2 s .c om public LegendItem getLegendItem(int datasetIndex, int series) { LegendItem result = null; XYPlot xyplot = getPlot(); if (xyplot != null) { XYDataset dataset = xyplot.getDataset(datasetIndex); if (dataset != null) { String label = this.legendItemLabelGenerator.generateLabel(dataset, series); String description = label; Shape shape = lookupLegendShape(series); Paint paint = lookupSeriesPaint(series); Paint outlinePaint = lookupSeriesOutlinePaint(series); Float outlineStroke = lookupSeriesOutlineStroke(series); result = new LegendItem(label, description, "", "", shape, paint.getColor(), outlineStroke, outlinePaint.getColor()); Paint labelPaint = lookupLegendTextPaint(series); result.setLabelFont(lookupLegendTextFont(series)); if (labelPaint != null) { result.setLabelPaint(labelPaint); } result.setSeriesKey(dataset.getSeriesKey(series)); result.setSeriesIndex(series); result.setDataset(dataset); result.setDatasetIndex(datasetIndex); } } return result; }
From source file:net.droidsolutions.droidcharts.core.renderer.category.LineAndShapeRenderer.java
/** * Returns a legend item for a series.//from ww w . j av a 2 s . c om * * @param datasetIndex * the dataset index (zero-based). * @param series * the series index (zero-based). * * @return The legend item. */ public LegendItem getLegendItem(int datasetIndex, int series) { CategoryPlot cp = getPlot(); if (cp == null) { return null; } if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) { CategoryDataset dataset = cp.getDataset(datasetIndex); String label = getLegendItemLabelGenerator().generateLabel(dataset, series); String description = label; Shape shape = lookupLegendShape(series); Paint paint = lookupSeriesPaint(series); Paint fillPaint = (this.useFillPaint ? getItemFillPaint(series, 0) : paint); boolean shapeOutlineVisible = this.drawOutlines; Paint outlinePaint = (this.useOutlinePaint ? getItemOutlinePaint(series, 0) : paint); Float outlineStroke = lookupSeriesOutlineStroke(series); boolean lineVisible = getItemLineVisible(series, 0); boolean shapeVisible = getItemShapeVisible(series, 0); LegendItem result = new LegendItem(label, description, "", "", shapeVisible, shape, getItemShapeFilled(series, 0), fillPaint.getColor(), shapeOutlineVisible, outlinePaint.getColor(), outlineStroke, lineVisible, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), getItemStroke(series, 0), getItemPaint(series, 0).getColor()); result.setLabelFont(lookupLegendTextFont(series)); Paint labelPaint = lookupLegendTextPaint(series); if (labelPaint != null) { result.setLabelPaint(labelPaint); } result.setDataset(dataset); result.setDatasetIndex(datasetIndex); result.setSeriesKey(dataset.getRowKey(series)); result.setSeriesIndex(series); return result; } return null; }
From source file:com.google.appinventor.components.runtime.util.NativeOpenStreetMapController.java
private Drawable rasterizeSVG(MapMarker aiMarker, SVG markerSvg) { SVG.Svg svg = markerSvg.getRootElement(); final float density = view.getContext().getResources().getDisplayMetrics().density; float height = aiMarker.Height() <= 0 ? getBestGuessHeight(svg) : aiMarker.Height(); float width = aiMarker.Width() <= 0 ? getBestGuessWidth(svg) : aiMarker.Width(); float scaleH = height / getBestGuessHeight(svg); float scaleW = width / getBestGuessWidth(svg); float scale = (float) Math.sqrt(scaleH * scaleH + scaleW * scaleW); // update fill color of SVG <path> Paint fillPaint = new Paint(); Paint strokePaint = new Paint(); PaintUtil.changePaint(fillPaint, aiMarker.FillColor()); PaintUtil.changePaint(strokePaint, aiMarker.StrokeColor()); SVG.Length strokeWidth = new SVG.Length(aiMarker.StrokeWidth() / scale); for (SVG.SvgObject element : svg.getChildren()) { if (element instanceof SVG.SvgConditionalElement) { SVG.SvgConditionalElement path = (SVG.SvgConditionalElement) element; path.baseStyle.fill = new SVG.Colour(fillPaint.getColor()); path.baseStyle.fillOpacity = fillPaint.getAlpha() / 255.0f; path.baseStyle.stroke = new SVG.Colour(strokePaint.getColor()); path.baseStyle.strokeOpacity = strokePaint.getAlpha() / 255.0f; path.baseStyle.strokeWidth = strokeWidth; if (path.style != null) { if ((path.style.specifiedFlags & SPECIFIED_FILL) == 0) { path.style.fill = new SVG.Colour(fillPaint.getColor()); path.style.specifiedFlags |= SPECIFIED_FILL; }// ww w.j a v a2s . c om if ((path.style.specifiedFlags & SPECIFIED_FILL_OPACITY) == 0) { path.style.fillOpacity = fillPaint.getAlpha() / 255.0f; path.style.specifiedFlags |= SPECIFIED_FILL_OPACITY; } if ((path.style.specifiedFlags & SPECIFIED_STROKE) == 0) { path.style.stroke = new SVG.Colour(strokePaint.getColor()); path.style.specifiedFlags |= SPECIFIED_STROKE; } if ((path.style.specifiedFlags & SPECIFIED_STROKE_OPACITY) == 0) { path.style.strokeOpacity = strokePaint.getAlpha() / 255.0f; path.style.specifiedFlags |= SPECIFIED_STROKE_OPACITY; } if ((path.style.specifiedFlags & SPECIFIED_STROKE_WIDTH) == 0) { path.style.strokeWidth = strokeWidth; path.style.specifiedFlags |= SPECIFIED_STROKE_WIDTH; } } } } // draw SVG to Picture and create a BitmapDrawable for rendering Picture picture = markerSvg.renderToPicture(); Picture scaledPicture = new Picture(); Canvas canvas = scaledPicture.beginRecording((int) ((width + 2.0f * aiMarker.StrokeWidth()) * density), (int) ((height + 2.0f * aiMarker.StrokeWidth()) * density)); canvas.scale(density * scaleW, density * scaleH); canvas.translate(strokeWidth.floatValue(), strokeWidth.floatValue()); picture.draw(canvas); scaledPicture.endRecording(); return new PictureDrawable(scaledPicture); }