Java Code Examples for android.graphics.Paint.getColor()

The following are Jave code examples for showing how to use getColor() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: SpanUtils.java   View Source Code Vote up 6 votes
@Override
public void draw(@NonNull final Canvas canvas, final CharSequence text,
                 @IntRange(from = 0) final int start,
                 @IntRange(from = 0) final int end,
                 final float x, final int top, final int y, final int bottom,
                 @NonNull final Paint paint) {
    Paint.Style style = paint.getStyle();
    int color = paint.getColor();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(this.color);

    canvas.drawRect(x, top, x + width, bottom, paint);

    paint.setStyle(style);
    paint.setColor(color);
}
 
Example 2
Project: GestureLockView   File: LUcomPainter.java   View Source Code Vote up 6 votes
/**
 * 绘制按下状态的点
 *
 * @param point      单位点
 * @param canvas     画布
 * @param pressPaint 按下状态画笔
 */
@Override
public void drawPressPoint(Point point, Canvas canvas, Paint pressPaint) {
    int originColor = pressPaint.getColor();
    // 1.绘制白色底圆
    pressPaint.setStyle(Paint.Style.FILL);
    pressPaint.setColor(Color.WHITE);
    canvas.drawCircle(point.x, point.y, point.radius, pressPaint);
    // 2.绘制实心点
    pressPaint.setColor(originColor);
    canvas.drawCircle(point.x, point.y, point.radius / 3.0F, pressPaint);
    // 3.绘制外部边界圆
    pressPaint.setStyle(Paint.Style.STROKE);
    pressPaint.setStrokeWidth(point.radius / 20.0F);
    canvas.drawCircle(point.x, point.y, point.radius, pressPaint);
}
 
Example 3
Project: SmartMath   File: FlatChart.java   View Source Code Vote up 6 votes
/**
 * Draw a single line text, x, y is in the middle of the line.
 */
public void draw1LineTextAnchorMid(Canvas canvas, String text, double x, double y,
		Paint paint, com.cyzapps.VisualMFP.Color color, double dTextSize, double dRotateDegree) {
	
	float fRotateDegree = (float)dRotateDegree, fX = (float)x, fY = (float)y;
	if (dRotateDegree != 0)	{
		canvas.rotate(fRotateDegree, fX, fY);
	}
	int nPaintOriginalColor = paint.getColor();
	float fPaintOriginalTxtSize = paint.getTextSize();
	if (color != null)	{
		paint.setColor(color.getARGB());
	}	// otherwise, use paint's color.
	paint.setTextSize((float)dTextSize);
	float fWidth = paint.measureText(text);
	canvas.drawText(text, fX - fWidth/2, fY + (float)dTextSize/2 - paint.descent(), paint);
	paint.setTextSize(fPaintOriginalTxtSize);
	paint.setColor(nPaintOriginalColor);
	if (dRotateDegree != 0) {
		canvas.rotate(-fRotateDegree, fX, fY);
	}
}
 
Example 4
Project: Sprog-App   File: FancyQuoteSpan.java   View Source Code Vote up 6 votes
public void drawLeadingMargin(Canvas c,
                              Paint p,
                              int x,
                              int dir,
                              int top,
                              int baseline,
                              int bottom,
                              CharSequence text,
                              int start,
                              int end,
                              boolean first,
                              Layout layout) {
    Paint.Style prevStyle = p.getStyle();
    int prevColor = p.getColor();
    p.setStyle(Paint.Style.FILL);
    p.setColor(lineColor);
    c.drawRect(x, top, x + dir * lineWidth, bottom, p);
    p.setStyle(prevStyle);
    p.setColor(prevColor);
}
 
Example 5
Project: FlexibleRichTextView   File: GeoGebraLogoBox.java   View Source Code Vote up 6 votes
public void draw(Canvas g2, float x, float y) {
	g2.save();
	Paint st = AjLatexMath.getPaint();
	int c = st.getColor();
	Style s = st.getStyle();
	float w = st.getStrokeWidth();

	g2.translate(x + 0.25f * height / 2.15f, y - 1.75f / 2.15f * height);
	st.setColor(gray);
	st.setStrokeWidth(3.79999995f);
	g2.scale(0.05f * height / 2.15f, 0.05f * height / 2.15f);
	g2.rotate((float) Math.toDegrees((-26 * Math.PI / 180)), 20.5f, 17.5f);
	g2.drawArc(new RectF(0f, 0f, 43f, 32f), 0f, 360f, false, st);
	g2.rotate((float) Math.toDegrees((26 * Math.PI / 180)), 20.5f, 17.5f);
	st.setStyle(Style.STROKE);
	drawCircle(st, g2, 16f, -5f);
	drawCircle(st, g2, -1f, 7f);
	drawCircle(st, g2, 5f, 28f);
	drawCircle(st, g2, 27f, 24f);
	drawCircle(st, g2, 36f, 3f);

	st.setColor(c);
	st.setStyle(s);
	st.setStrokeWidth(w);
	g2.restore();
}
 
Example 6
Project: SmartMath   File: FlatChart.java   View Source Code Vote up 6 votes
/**
 * Draws the chart background.
 */
public void drawBackground(Canvas canvas, double x, double y, double width, double height,
							Paint paint, com.cyzapps.VisualMFP.Color newColor) {
	int nPaintOriginalColor = paint.getColor();
	Style stylePaintOriginalStyle = paint.getStyle();
	if (newColor != null) {	// a valid color
		paint.setColor(newColor.getARGB());
	} else if (mcolorBkGrnd != null)	{
		paint.setColor(mcolorBkGrnd.getARGB());
	}
	paint.setStyle(Style.FILL);
	float fLeft = (float)x, fTop = (float)y, fRight = (float)(x + width), fBottom = (float)(y + height);
	canvas.drawRect(fLeft, fTop, fRight, fBottom, paint);
	// restore paint attribute.
	paint.setStyle(stylePaintOriginalStyle);
	paint.setColor(nPaintOriginalColor);
}
 
Example 7
Project: GitHub   File: SpanUtils.java   View Source Code Vote up 5 votes
public void drawLeadingMargin(final Canvas c, final Paint p, final int x, final int dir,
                              final int top, final int baseline, final int bottom,
                              final CharSequence text, final int start, final int end,
                              final boolean first, final Layout layout) {
    Paint.Style style = p.getStyle();
    int color = p.getColor();

    p.setStyle(Paint.Style.FILL);
    p.setColor(this.color);

    c.drawRect(x, top, x + dir * stripeWidth, bottom, p);

    p.setStyle(style);
    p.setColor(color);
}
 
Example 8
Project: markor   File: BackgroundParagraphSpan.java   View Source Code Vote up 5 votes
@Override
public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom, CharSequence text, int start, int end, int lnum) {
    final int paintColorBak = p.getColor();
    boolean isFirstLineOfParagraph = _previousParagraphBeginIndex != start;
    drawBackground(c, p, left, right, top, baseline, bottom, text, start, end, lnum, isFirstLineOfParagraph);
    _previousParagraphBeginIndex = end;
    p.setColor(paintColorBak);
}
 
Example 9
Project: calendarview2   File: DotSpan.java   View Source Code Vote up 5 votes
@Override
public void drawBackground(
        Canvas canvas, Paint paint,
        int left, int right, int top, int baseline, int bottom,
        CharSequence charSequence,
        int start, int end, int lineNum
) {
    int oldColor = paint.getColor();
    if (color != 0) {
        paint.setColor(color);
    }
    canvas.drawCircle((left + right) / 2, bottom + radius, radius, paint);
    paint.setColor(oldColor);
}
 
Example 10
Project: HeadlineNews   File: SpanUtils.java   View Source Code Vote up 5 votes
public void drawLeadingMargin(final Canvas c, final Paint p, final int x, final int dir,
                              final int top, final int baseline, final int bottom,
                              final CharSequence text, final int start, final int end,
                              final boolean first, final Layout layout) {
    Paint.Style style = p.getStyle();
    int color = p.getColor();

    p.setStyle(Paint.Style.FILL);
    p.setColor(this.color);

    c.drawRect(x, top, x + dir * stripeWidth, bottom, p);

    p.setStyle(style);
    p.setColor(color);
}
 
Example 11
Project: Markwon   File: SpannableTheme.java   View Source Code Vote up 5 votes
public void applyListItemStyle(@NonNull Paint paint) {

        final int color;
        if (listItemColor != 0) {
            color = listItemColor;
        } else {
            color = paint.getColor();
        }
        paint.setColor(color);

        if (bulletListItemStrokeWidth != 0) {
            paint.setStrokeWidth(bulletListItemStrokeWidth);
        }
    }
 
Example 12
Project: mvvm-template   File: HrSpan.java   View Source Code Vote up 5 votes
@Override public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top,
                           int y, int bottom, @NonNull Paint paint) {
    final int currentColor = paint.getColor();
    paint.setColor(color);
    paint.setStyle(Paint.Style.FILL);
    int height = 10;
    canvas.drawRect(new Rect(0, bottom - height, (int) x + width, bottom), paint);
    paint.setColor(currentColor);
}
 
Example 13
Project: mvvm-template   File: CodeBackgroundRoundedSpan.java   View Source Code Vote up 5 votes
@Override public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom,
                                     CharSequence text, int start, int end, int lnum) {
    Paint.Style style = p.getStyle();
    int color = p.getColor();
    p.setStyle(Paint.Style.FILL);
    p.setColor(this.color);
    rect.set(left, top, right, bottom);
    c.drawRect(rect, p);
    p.setColor(color);
    p.setStyle(style);
}
 
Example 14
Project: SmartMath   File: XYChart.java   View Source Code Vote up 4 votes
@Override
public void draw(Canvas canvas, double x, double y, double width, double height, Paint paint) {
	Log.e(LOG_TAG, "in XYChart.draw");
	
	//calcCoordArea(x, y, width, height);
	//update();

	int nPaintOriginalColor = paint.getColor();
	// draw background
	paint.setColor(mcolorBkGrnd.getARGB());
	drawBackground(canvas, x, y, width, height, paint, null);
	
	paint.setColor(mcolorForeGrnd.getARGB());
	// draw title
	draw1LineTextAnchorMid(canvas, mstrChartTitle, width / 2, y + mdSmallSize/2, paint, null, mdSmallSize, 0);
	
	
	// draw x-axis
	drawAxis(canvas, mcaXAxis, mp3CoordLeftBottomInTO.getX(), mp3CoordLeftBottomInTO.getY(),
			mp3CoordLeftBottomInTO.getX() + mdCoordWidth, mp3CoordLeftBottomInTO.getY(),
			paint, mcolorForeGrnd, false);
	// draw y-axis
	drawAxis(canvas, mcaYAxis, mp3CoordLeftBottomInTO.getX(), mp3CoordLeftBottomInTO.getY(),
			mp3CoordLeftBottomInTO.getX(), mp3CoordLeftBottomInTO.getY() - mdCoordHeight,
			paint, mcolorForeGrnd, true);
	
	paint.setColor(mcolorHint.getARGB());
	// draw a rectangle for drawing area
	float fCoordLeft = (float)mp3CoordLeftBottomInTO.getX(),
			fCoordTop = (float)(mp3CoordLeftBottomInTO.getY() - mdCoordHeight),
			fCoordRight = (float)(mp3CoordLeftBottomInTO.getX() + mdCoordWidth),
			fCoordBottom = (float)mp3CoordLeftBottomInTO.getY();
	canvas.drawLine(fCoordLeft, fCoordTop, fCoordRight, fCoordTop, paint);
	canvas.drawLine(fCoordRight, fCoordTop, fCoordRight, fCoordBottom, paint);
	
	if (mbShowGrid)	{
		drawGrid(canvas, paint);
	}
	
	Rect rectClip = canvas.getClipBounds();
	canvas.clipRect(fCoordLeft, fCoordTop, fCoordRight, fCoordBottom, Op.REPLACE);
	drawDataCurves(canvas, mmapperP2P, mDataSet, mp3CoordLeftBottomInTO.getX(), mp3CoordLeftBottomInTO.getY() - mdCoordHeight,
			mdCoordWidth, mdCoordHeight, paint);
	canvas.clipRect(rectClip, Op.REPLACE);
	
	drawLegends(canvas, mdCoordWidth <= mdCoordHeight, paint);
	
       drawButtons(canvas, x, y, width, height, paint);

	paint.setColor(nPaintOriginalColor);
	
	Log.e(LOG_TAG, "out of XYChart.draw");
}
 
Example 15
Project: SmartMath   File: PolarChart.java   View Source Code Vote up 4 votes
@Override
public void draw(Canvas canvas, double x, double y, double width, double height, Paint paint) {
	Log.e(LOG_TAG, "in PolarChart.draw");
	
	//calcCoordArea(x, y, width, height);
	//update();

	int nPaintOriginalColor = paint.getColor();
	// draw background
	paint.setColor(mcolorBkGrnd.getARGB());
	drawBackground(canvas, x, y, width, height, paint, null);
	
	paint.setColor(mcolorForeGrnd.getARGB());
	// draw title
	draw1LineTextAnchorMid(canvas, mstrChartTitle, width / 2, y + mdSmallSize/2, paint, null, mdSmallSize, 0);
	
	// draw r-axis only if it is visible.
	if (mp3CoordOriginInTO.getX() <= mp3CoordLeftBottomInTO.getX() + mdCoordWidth)	{
		drawAxis(canvas, mcaXAxis, mp3CoordOriginInTO.getX(), mp3CoordOriginInTO.getY(),
				mp3CoordLeftBottomInTO.getX() + mdCoordWidth, mp3CoordOriginInTO.getY(),
				paint, mcolorForeGrnd, false);
	}
	
	// draw a rectangle for drawing area
	float fCoordLeft = (float)mp3CoordLeftBottomInTO.getX(),
			fCoordTop = (float)(mp3CoordLeftBottomInTO.getY() - mdCoordHeight),
			fCoordRight = (float)(mp3CoordLeftBottomInTO.getX() + mdCoordWidth),
			fCoordBottom = (float)mp3CoordLeftBottomInTO.getY();
	
	Rect rectClip = canvas.getClipBounds();
	canvas.clipRect(fCoordLeft, fCoordTop, fCoordRight, fCoordBottom, Op.REPLACE);
	if (mbShowGrid)	{
		drawGrid(canvas, paint);
	}
	
	drawDataCurves(canvas, mmapperPolarXY, mDataSet, fCoordLeft, fCoordTop, mdCoordWidth, mdCoordHeight, paint);
	canvas.clipRect(rectClip, Op.REPLACE);
	
	drawLegends(canvas, mdCoordWidth <= mdCoordHeight, paint);
	
       drawButtons(canvas, x, y, width, height, paint);

	paint.setColor(nPaintOriginalColor);
	
	Log.e(LOG_TAG, "out of PolarChart.draw");
}
 
Example 16
Project: simple-keyboard   File: KeyboardView.java   View Source Code Vote up 4 votes
private static void blendAlpha(@NonNull final Paint paint, final int alpha) {
    final int color = paint.getColor();
    paint.setARGB((paint.getAlpha() * alpha) / Constants.Color.ALPHA_OPAQUE,
            Color.red(color), Color.green(color), Color.blue(color));
}
 
Example 17
Project: SDHtmlTextView   File: HorizontalLineSpan.java   View Source Code Vote up 4 votes
@Override
public void drawBackground(Canvas c, Paint p,
                           int left, int right,
                           int top, int baseline, int bottom,
                           CharSequence text, int start, int end,
                           int lnum) {

    int baseMargin = 0;

    if ( style.getMarginLeft() != null ) {
        StyleValue styleValue = style.getMarginLeft();

        if ( styleValue.getUnit() == StyleValue.Unit.PX ) {
            if ( styleValue.getIntValue() > 0 ) {
                baseMargin = styleValue.getIntValue();
            }
        } else if ( styleValue.getFloatValue() > 0f ) {
            baseMargin = (int) (styleValue.getFloatValue() * HtmlSpanner.HORIZONTAL_EM_WIDTH);
        }

        //Leave a little bit of room
        baseMargin--;
    }

    if ( baseMargin > 0 ) {
        left = left + baseMargin;
    }

    int originalColor = p.getColor();
    float originalStrokeWidth = p.getStrokeWidth();

    p.setColor(Color.parseColor("#000000"));
    if (style.getBorderColor() != null ) {
        p.setColor( style.getBorderColor() );
    }

    int strokeWidth;

    if ( style.getBorderWidth() != null && style.getBorderWidth().getUnit() == StyleValue.Unit.PX ) {
        strokeWidth = style.getBorderWidth().getIntValue();
    } else {
        strokeWidth = 1;
    }

    p.setStrokeWidth( strokeWidth );
    right -= strokeWidth;

    p.setStyle(Paint.Style.STROKE);

    Log.d("HorizontalSpan", "Drawing line");

    int center=(bottom+top)/2;
    c.drawLine(left, center, right, center, p);

    p.setColor(originalColor);
    p.setStrokeWidth(originalStrokeWidth);
}
 
Example 18
Project: SmartMath   File: XYChart.java   View Source Code Vote up 4 votes
public void drawAxis(Canvas canvas, CoordAxis caAxis, double x0, double y0, double x1, double y1,
		Paint paint, com.cyzapps.VisualMFP.Color newColor, boolean bTxtPlacedClockWise) {
	float fX0 = (float)x0, fY0 = (float)y0, fX1 = (float)x1, fY1 = (float)y1;
	int nPaintOriginalColor = paint.getColor();
	if (newColor != null)	{
		paint.setColor(newColor.getARGB());
	} else if (caAxis.mclr != null)	 {
		paint.setColor(caAxis.mclr.getARGB());
	} else if (mcolorForeGrnd != null)	{
		paint.setColor(mcolorForeGrnd.getARGB());
	}	// otherwise, use paint's color
	canvas.drawLine(fX0, fY0, fX1, fY1, paint);
	double dAngle0To1 = Math.atan2(y1 - y0, x1 - x0);
	// arrow angle, 
	double dAngleArrowLn1 = -Math.PI - mdArrowAngle / 2 + dAngle0To1;
	double dAngleArrowLn2 = -Math.PI + mdArrowAngle / 2 + dAngle0To1;
	float fArrowLn1PntX = (float) (Math.cos(dAngleArrowLn1) * mdSmallSize + x1);
	float fArrowLn1PntY = (float) (Math.sin(dAngleArrowLn1) * mdSmallSize + y1);
	float fArrowLn2PntX = (float) (Math.cos(dAngleArrowLn2) * mdSmallSize + x1);
	float fArrowLn2PntY = (float) (Math.sin(dAngleArrowLn2) * mdSmallSize + y1);
	canvas.drawLine(fX1, fY1, fArrowLn1PntX, fArrowLn1PntY, paint);
	canvas.drawLine(fX1, fY1, fArrowLn2PntX, fArrowLn2PntY, paint);
	
	double dAngleLn2Txt = Math.PI/2 + dAngle0To1;
	if (bTxtPlacedClockWise)	{
		dAngleLn2Txt = -Math.PI/2 + dAngle0To1;
	}
	for (int idx = 0; idx < caAxis.marraydScaleMarks.length; idx++)	{
		double dX = 0, dY = 0;
		if (caAxis.mdValueTo != caAxis.mdValueFrom)	{
			dX = (x1 - x0)/(caAxis.mdValueTo - caAxis.mdValueFrom) * (caAxis.marraydScaleMarks[idx] - caAxis.mdValueFrom) + x0;
			dY = (y1 - y0)/(caAxis.mdValueTo - caAxis.mdValueFrom) * (caAxis.marraydScaleMarks[idx] - caAxis.mdValueFrom) + y0;
			float fX = (float)dX, fY = (float)dY, fTinySize = (float)mdTinySize;
			canvas.drawCircle(fX, fY, fTinySize, paint);
			double dMarkTxtX = dX, dMarkTxtY = dY;
			dMarkTxtX = Math.cos(dAngleLn2Txt) * mdSmallSize + dX;
			dMarkTxtY = Math.sin(dAngleLn2Txt) * mdSmallSize + dY;
			draw1LineTextAnchorMid(canvas, caAxis.marraystrMarkTxts[idx],
					dMarkTxtX, dMarkTxtY, paint, null, 
					mdSmallSize, dAngle0To1 * 180 / Math.PI);
		}
	}
	
	double dNameTxtX = (x0 + x1)/2, dNameTxtY = (y0 + y1)/2;
	dNameTxtX = Math.cos(dAngleLn2Txt) * mdSmallSize * 2 + dNameTxtX;
	dNameTxtY = Math.sin(dAngleLn2Txt) * mdSmallSize * 2 + dNameTxtY;
	// write title of the axis
	draw1LineTextAnchorMid(canvas, caAxis.mstrAxisName, dNameTxtX, dNameTxtY, paint, null,
			mdSmallSize, dAngle0To1 * 180 / Math.PI);
	paint.setColor(nPaintOriginalColor);
}
 
Example 19
Project: AOSP-Kayboard-7.1.2   File: KeyboardView.java   View Source Code Vote up 4 votes
private static void blendAlpha(@Nonnull final Paint paint, final int alpha) {
    final int color = paint.getColor();
    paint.setARGB((paint.getAlpha() * alpha) / Constants.Color.ALPHA_OPAQUE,
            Color.red(color), Color.green(color), Color.blue(color));
}
 
Example 20
Project: android_ui   File: TextAppearance.java   View Source Code Vote up 3 votes
/**
 * Updates color setting for the given <var>paint</var> the the specified one.
 *
 * @param paint The paint to be updated.
 * @param color The desired color.
 * @return {@code True} if paint's color setting has changed, {@code false} otherwise.
 * @see Paint#setColor(int)
 */
public static boolean updatePaintColor(@NonNull Paint paint, @ColorInt int color) {
	if (paint.getColor() != color) {
		paint.setColor(color);
		return true;
	}
	return false;
}