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

The following examples show how to use android.graphics.Paint#getColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusbarBattery.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
public StatusbarBattery(View batteryView) {
        mBattery = batteryView;
        createHooks();
        try {
            Object drawable = getDrawable();
            final int[] colors = (int[]) XposedHelpers.getObjectField(drawable, "mColors");
            mDefaultColor = colors[colors.length - 1];
            if (Utils.isLineageOs()) {

                Drawable frameDrawable = (Drawable) XposedHelpers.getObjectField(drawable, "mFrameDrawable");
//                mDefaultFrameColor = frameDrawable.setTint();
                mFrameAlpha = frameDrawable.getAlpha();
            } else {
                final Paint framePaint = (Paint) XposedHelpers.getObjectField(drawable, "mFramePaint");
                mDefaultFrameColor = framePaint.getColor();
                mFrameAlpha = framePaint.getAlpha();
            }

            mDefaultChargeColor = XposedHelpers.getIntField(drawable, "mChargeColor");
        } catch (Throwable t) {
            log("Error backing up original colors: " + t.getMessage());
        }
        if (SysUiManagers.IconManager != null) {
            SysUiManagers.IconManager.registerListener(this);
        }
    }
 
Example 2
Source File: Box.java    From FlexibleRichTextView with Apache License 2.0 6 votes vote down vote up
protected void drawDebug(Canvas g2, float x, float y, boolean showDepth) {
	if (DEBUG) {
		Paint st = AjLatexMath.getPaint();
		int c = st.getColor();
		st.setColor(markForDEBUG);
		st.setStyle(Style.FILL_AND_STROKE);
		if (markForDEBUG != null) {
			g2.drawRect(x, y - height, width, height + depth, st);
		}
		if (width < 0) {
			x += width;
			width = -width;
		}
		g2.drawRect(x, y - height, width, height + depth, st);
		if (showDepth) {
			st.setColor(Color.RED);
			if (depth > 0) {
				g2.drawRect(x, y, width, depth, st);
			} else if (depth < 0) {
				g2.drawRect(x, y + depth, width, -depth, st);
			} else {
			}
		}
		st.setColor(c);
	}
}
 
Example 3
Source File: SpansV1.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
@Override
        public void draw(@NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
//            bitmapCanvas.drawColor(Color.GRAY, PorterDuff.Mode.CLEAR);
            int color = /*paint instanceof TextPaint ? ((TextPaint) paint).bgColor :*/ paint.getColor();
            bitmapCanvas.drawColor(color);
            for (CharacterStyle style : styles) {
                if (style instanceof ReplacementSpan) {
                    ((ReplacementSpan) style).draw(bitmapCanvas, text, start, end, 0, top, y, bottom, paint);
                } else if (paint instanceof TextPaint) {
                    style.updateDrawState((TextPaint) paint);
                }
            }
            paint.setXfermode(xfermode);
            bitmapCanvas.drawText(text, start, end, 0, y, paint);
            canvas.drawBitmap(bitmap, x, 0, null);
        }
 
Example 4
Source File: BulletSpan.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
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 l) {
    if (((Spanned) text).getSpanStart(this) == start) {
        Paint.Style style = p.getStyle();
        int oldcolor = 0;

        if (mWantColor) {
            oldcolor = p.getColor();
            p.setColor(mColor);
        }

        p.setStyle(Paint.Style.FILL);

        c.drawCircle(x + dir * BULLET_RADIUS, (top + bottom) / 2.0f,
                     BULLET_RADIUS, p);

        if (mWantColor) {
            p.setColor(oldcolor);
        }

        p.setStyle(style);
    }
}
 
Example 5
Source File: SpannableStringUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
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 6
Source File: SpansV1.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
protected void drawDebugLines(@NonNull Canvas canvas, float x, int top, int y, int bottom, @NonNull Paint paint) {
    int width = frame.width();
    int oldColor = paint.getColor();

    // x, y
    canvas.drawLine(x, y, x + width, y, paint);

    // x, top
    paint.setColor(Color.RED);
    canvas.drawLine(x, top, x + width, top, paint);
    canvas.drawLine(x, y + fontMetricsInt.top, x + width, bottom, paint);

    // x, ascent
    paint.setColor(Color.GREEN);
    canvas.drawLine(x, y + paint.ascent(), x + width, bottom, paint);
    canvas.drawLine(x, y + fontMetricsInt.ascent, x + width, y + fontMetricsInt.ascent, paint);

    // x, descent
    paint.setColor(Color.BLUE);
    canvas.drawLine(x, y + paint.descent(), x + width, top, paint);
    canvas.drawLine(x, y + fontMetricsInt.descent, x + width, y + fontMetricsInt.descent, paint);

    // x, bottom
    paint.setColor(Color.YELLOW);
    canvas.drawLine(x, bottom, x + width, bottom, paint);
    canvas.drawLine(x, y + fontMetricsInt.bottom, x + width, top, paint);

    paint.setColor(oldColor);
}
 
Example 7
Source File: SpannableStringUtils.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
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 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
Source File: QuoteSpan.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Override
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 style = p.getStyle();
	int color = p.getColor();
	p.setStyle(Paint.Style.FILL);
	p.setColor(this.color);
	c.drawRect(x + dir * paddingLeft, top, x + dir * (paddingLeft + width), bottom, p);
	p.setStyle(style);
	p.setColor(color);
}
 
Example 9
Source File: MaterialContainerTransform.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void maybeDrawContainerColor(Canvas canvas, Paint containerPaint) {
  // Fill the container at the current layer with a color. Useful when the start or end view
  // does not have a background or when the container size exceeds the image size which it can
  // in large start/end size changes.
  if (containerPaint.getColor() != Color.TRANSPARENT && containerPaint.getAlpha() > 0) {
    canvas.drawRect(getBounds(), containerPaint);
  }
}
 
Example 10
Source File: RadiusCornerBackgroundColorSpan.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
    int color = paint.getColor();//保存文字颜色
    paint.setColor(mColor);//设置背景颜色
    paint.setAntiAlias(true);// 设置画笔的锯齿效果
    RectF oval = new RectF(x, y + paint.ascent(), x + mSize, y + paint.descent());
    //设置文字背景矩形,x为span其实左上角相对整个TextView的x值,y为span左上角相对整个View的y值。paint.ascent()获得文字上边缘,paint.descent()获得文字下边缘
    canvas.drawRoundRect(oval, mRadius, mRadius, paint);//绘制圆角矩形,第二个参数是x半径,第三个参数是y半径
    paint.setColor(color);//恢复画笔的文字颜色
    canvas.drawText(text, start, end, x + mRadius, y, paint);//绘制文字
}
 
Example 11
Source File: CustomHtmlToSpannedConverter.java    From zulip-android with Apache License 2.0 5 votes vote down vote up
@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 paddingInPx = ConvertDpPx.convertDpToPixel(12);
    Rect rect = new Rect(left - paddingInPx, top - paddingInPx,
            right + paddingInPx, bottom + paddingInPx);
    final int paintColor = p.getColor();
    p.setColor(this.fillColor);
    c.drawRect(rect, p);
    p.setColor(paintColor);
}
 
Example 12
Source File: SpansV1.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(@NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
    drawDebugLines(canvas, x, top, y, bottom, paint);

    float oldStrokeWidth = paint.getStrokeWidth();
    Paint.Style oldStyle = paint.getStyle();
    int oldColor = paint.getColor();
    paint.setStrokeWidth(strokeWidth);
    paint.setStyle(style);
    paint.setColor(color);
    canvas.save();
    canvas.translate(x + strokeWidth / 2, fontMetricsInt.ascent - fontMetricsInt.top + strokeWidth / 2);
    shape.draw(canvas, paint);
    canvas.restore();
    paint.setColor(oldColor);
    paint.setStyle(oldStyle);
    paint.setStrokeWidth(oldStrokeWidth);

    int width = frame.width();

    paint.setTextSize(paint.getTextSize() * 0.8f);
    if (drawText) {
        if (false) {
            paint.setTextAlign(Paint.Align.CENTER);
            canvas.drawText(text, start, end, frame.centerX(), y, paint);
        } else {
            canvas.drawText(text, start, end, x + (width * 0.2f) / 2, y, paint);
        }
    }
}
 
Example 13
Source File: SpanFormatter.java    From NFCard with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top,
		int y, int bottom, Paint paint) {

	canvas.save();
	canvas.translate(x, (bottom + top) / 2 - height);

	final int c = paint.getColor();
	final float w = paint.getStrokeWidth();
	final Style s = paint.getStyle();
	final PathEffect e = paint.getPathEffect();

	paint.setColor(color);
	paint.setStyle(Paint.Style.STROKE);
	paint.setStrokeWidth(height);
	paint.setPathEffect(effe);

	path.moveTo(x, 0);
	path.lineTo(x + width, 0);

	canvas.drawPath(path, paint);

	paint.setColor(c);
	paint.setStyle(s);
	paint.setStrokeWidth(w);
	paint.setPathEffect(e);

	canvas.restore();
}
 
Example 14
Source File: SpansV1.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
protected void drawDebugLines(@NonNull Canvas canvas, float x, int top, int y, int bottom, @NonNull Paint paint) {
    int width = frame.width();
    int oldColor = paint.getColor();

    // x, y
    canvas.drawLine(x, y, x + width, y, paint);

    // x, top
    paint.setColor(Color.RED);
    canvas.drawLine(x, top, x + width, top, paint);
    canvas.drawLine(x, y + fontMetricsInt.top, x + width, bottom, paint);

    // x, ascent
    paint.setColor(Color.GREEN);
    canvas.drawLine(x, y + paint.ascent(), x + width, bottom, paint);
    canvas.drawLine(x, y + fontMetricsInt.ascent, x + width, y + fontMetricsInt.ascent, paint);

    // x, descent
    paint.setColor(Color.BLUE);
    canvas.drawLine(x, y + paint.descent(), x + width, top, paint);
    canvas.drawLine(x, y + fontMetricsInt.descent, x + width, y + fontMetricsInt.descent, paint);

    // x, bottom
    paint.setColor(Color.YELLOW);
    canvas.drawLine(x, bottom, x + width, bottom, paint);
    canvas.drawLine(x, y + fontMetricsInt.bottom, x + width, top, paint);

    paint.setColor(oldColor);
}
 
Example 15
Source File: Spans.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
protected void drawDebugLines(Rect outRect, @NonNull Canvas canvas, float x, int top, int y, int bottom, @NonNull Paint paint) {
    int width = frame.width();
    int oldColor = paint.getColor();

    // x, y
    canvas.drawLine(x, y, x + width, y, paint);

    // x, top
    paint.setColor(Color.RED);
    canvas.drawLine(x, top, x + width, top, paint);
    canvas.drawLine(x, y + fontMetricsInt.top, x + width, bottom, paint);

    // x, ascent
    paint.setColor(Color.GREEN);
    canvas.drawLine(x, y + paint.ascent(), x + width, bottom, paint);
    canvas.drawLine(x, y + fontMetricsInt.ascent, x + width, y + fontMetricsInt.ascent, paint);

    // x, descent
    paint.setColor(Color.BLUE);
    canvas.drawLine(x, y + paint.descent(), x + width, top, paint);
    canvas.drawLine(x, y + fontMetricsInt.descent, x + width, y + fontMetricsInt.descent, paint);

    // x, bottom
    paint.setColor(Color.YELLOW);
    canvas.drawLine(x, bottom, x + width, bottom, paint);
    canvas.drawLine(x, y + fontMetricsInt.bottom, x + width, top, paint);

    paint.setColor(oldColor);
}
 
Example 16
Source File: TintedDrawableSpan.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas, CharSequence text,
        int start, int end, float x, int top, int y, int bottom, Paint paint) {
    int color = paint.getColor();
    if (mOldTint != color) {
        mOldTint = color;
        mDrawable.setTint(mOldTint);
    }
    super.draw(canvas, text, start, end, x, top, y, bottom, paint);
}
 
Example 17
Source File: QuoteSpan.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
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 style = p.getStyle();
    int color = p.getColor();

    p.setStyle(Paint.Style.FILL);
    p.setColor(mColor);

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

    p.setStyle(style);
    p.setColor(color);
}
 
Example 18
Source File: KeyboardView.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
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 19
Source File: ChartUtils.java    From fingen with Apache License 2.0 4 votes vote down vote up
public static void drawXAxisValue(Canvas c, String text, float x, float y,
                                  Paint paint,
                                  PointF anchor, float angleDegrees,
                                  int color) {

    float drawOffsetX = 0.f;
    float drawOffsetY = 0.f;

    final float lineHeight = paint.getFontMetrics(mFontMetricsBuffer);
    paint.getTextBounds(text, 0, text.length(), mDrawTextRectBuffer);

    // Android sometimes has pre-padding
    drawOffsetX -= mDrawTextRectBuffer.left;

    // Android does not snap the bounds to line boundaries,
    //  and draws from bottom to top.
    // And we want to normalize it.
    drawOffsetY += -mFontMetricsBuffer.ascent;

    // To have a consistent point of reference, we always draw left-aligned
    Paint.Align originalTextAlign = paint.getTextAlign();
    paint.setTextAlign(Paint.Align.LEFT);

    Paint.Style oldStyle = paint.getStyle();
    paint.setStyle(Paint.Style.STROKE);
    float oldStroleWidth = paint.getStrokeWidth();
    paint.setStrokeWidth(ScreenUtils.dpToPx(3f, FGApplication.getContext()));
    int oldColor = paint.getColor();
    paint.setColor(color);

    if (angleDegrees != 0.f) {

        // Move the text drawing rect in a way that it always rotates around its center
        drawOffsetX -= mDrawTextRectBuffer.width() * 0.5f;
        drawOffsetY -= lineHeight * 0.5f;

        float translateX = x;
        float translateY = y;

        // Move the "outer" rect relative to the anchor, assuming its centered
        if (anchor.x != 0.5f || anchor.y != 0.5f) {
            final FSize rotatedSize = getSizeOfRotatedRectangleByDegrees(
                    mDrawTextRectBuffer.width(),
                    lineHeight,
                    angleDegrees);

            translateX -= rotatedSize.width * (anchor.x - 0.5f);
            translateY -= rotatedSize.height * (anchor.y - 0.5f);
        }

        c.save();
        c.translate(translateX, translateY);
        c.rotate(angleDegrees);

        c.drawText(text, drawOffsetX, drawOffsetY, paint);

        c.restore();
    } else {
        if (anchor.x != 0.f || anchor.y != 0.f) {

            drawOffsetX -= mDrawTextRectBuffer.width() * anchor.x;
            drawOffsetY -= lineHeight * anchor.y;
        }

        drawOffsetX += x;
        drawOffsetY += y;

        c.drawText(text, drawOffsetX, drawOffsetY, paint);
    }

    paint.setTextAlign(originalTextAlign);

    paint.setStyle(oldStyle);
    paint.setStrokeWidth(oldStroleWidth);
    paint.setColor(oldColor);
}
 
Example 20
Source File: KeyboardView.java    From openboard with GNU General Public License v3.0 4 votes vote down vote up
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));
}