Java Code Examples for android.graphics.Paint.Align

The following are Jave code examples for showing how to use Align 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: phonk   File: PCanvas.java   View Source Code Vote up 6 votes
public PCanvas textAlign(String alignTo) {
    Paint.Align alignment = Paint.Align.LEFT;

    switch (alignTo) {
        case "left":
            alignment = Paint.Align.LEFT;
            break;

        case "center":
            alignment = Paint.Align.CENTER;
            break;

        case "right":
            alignment = Paint.Align.RIGHT;
            break;
    }

    mPaintFill.setTextAlign(alignment);
    mPaintStroke.setTextAlign(alignment);

    return this;
}
 
Example 2
Project: planetcon   File: GalaxyView.java   View Source Code Vote up 5 votes
private void drawText(Canvas canvas, float textSize, Paint.Align align, int color, int alpha,
        String value, float x, float y, float dx, float dy) {
    // Draw text with shadow
    mTextPaint.setTextSize(textSize);
    mTextPaint.setTextAlign(align);
    mTextPaint.setColor(Color.BLACK);
    if (alpha < 255) mTextPaint.setAlpha(alpha);
    canvas.drawText(value, x + dx, y + dy, mTextPaint);
    mTextPaint.setColor(color);
    if (alpha < 255) mTextPaint.setAlpha(alpha);
    canvas.drawText(value, x, y, mTextPaint);
}
 
Example 3
Project: GitHub   File: Utils.java   View Source Code Vote up 4 votes
public static void drawXAxisValue(Canvas c, String text, float x, float y,
                                  Paint paint,
                                  MPPointF anchor, float angleDegrees) {

    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);

    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);
            FSize.recycleInstance(rotatedSize);
        }

        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);
}
 
Example 4
Project: GitHub   File: Utils.java   View Source Code Vote up 4 votes
public static void drawMultilineText(Canvas c, StaticLayout textLayout,
                                     float x, float y,
                                     TextPaint paint,
                                     MPPointF anchor, float angleDegrees) {

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

    final float lineHeight = paint.getFontMetrics(mFontMetricsBuffer);

    drawWidth = textLayout.getWidth();
    drawHeight = textLayout.getLineCount() * lineHeight;

    // 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 += drawHeight;

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

    if (angleDegrees != 0.f) {

        // Move the text drawing rect in a way that it always rotates around its center
        drawOffsetX -= drawWidth * 0.5f;
        drawOffsetY -= drawHeight * 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(
                    drawWidth,
                    drawHeight,
                    angleDegrees);

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

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

        c.translate(drawOffsetX, drawOffsetY);
        textLayout.draw(c);

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

            drawOffsetX -= drawWidth * anchor.x;
            drawOffsetY -= drawHeight * anchor.y;
        }

        drawOffsetX += x;
        drawOffsetY += y;

        c.save();

        c.translate(drawOffsetX, drawOffsetY);
        textLayout.draw(c);

        c.restore();
    }

    paint.setTextAlign(originalTextAlign);
}
 
Example 5
Project: GitHub   File: PercentStyle.java   View Source Code Vote up 4 votes
public Paint.Align getAlign() {
	return align;
}
 
Example 6
Project: GitHub   File: PercentStyle.java   View Source Code Vote up 4 votes
public void setAlign(Paint.Align align) {
	this.align = align;
}
 
Example 7
Project: empty-state-recyclerview   File: ImageTextStateDisplay.java   View Source Code Vote up 4 votes
/**
 * Sets the paint alignment that draws the title.
 * @param align {@link android.graphics.Paint.Align}
 */
public void setTitleTextAlign(Paint.Align align) {
    this.titlePaint.setTextAlign(align);
    invalidateConfig();
}
 
Example 8
Project: empty-state-recyclerview   File: ImageTextStateDisplay.java   View Source Code Vote up 4 votes
/**
 * Sets the paint alignment that draws the subtitle.
 * @param align {@link android.graphics.Paint.Align}
 */
public void setSubtitleTextAlign(Paint.Align align) {
    this.subtitlePaint.setTextAlign(align);
    invalidateConfig();
}
 
Example 9
Project: empty-state-recyclerview   File: TextStateDisplay.java   View Source Code Vote up 4 votes
/**
 * Sets the paint alignment that draws the title.
 * @param align {@link android.graphics.Paint.Align}
 */
public void setTitleTextAlign(Paint.Align align) {
    this.titlePaint.setTextAlign(align);
    invalidateText();
}
 
Example 10
Project: empty-state-recyclerview   File: TextStateDisplay.java   View Source Code Vote up 4 votes
/**
 * Sets the paint alignment that draws the subtitle.
 * @param align {@link android.graphics.Paint.Align}
 */
public void setSubtitleTextAlign(Paint.Align align) {
    this.subtitlePaint.setTextAlign(align);
    invalidateText();
}
 
Example 11
Project: TrackIt-Android   File: PercentStyle.java   View Source Code Vote up 4 votes
public Paint.Align getAlign() {
    return align;
}
 
Example 12
Project: TrackIt-Android   File: PercentStyle.java   View Source Code Vote up 4 votes
public void setAlign(Paint.Align align) {
    this.align = align;
}
 
Example 13
Project: SmingZZick_App   File: AlignControl.java   View Source Code Vote up 4 votes
@Override
public void onClick(View v) {
    Paint.Align align = (Paint.Align) v.getTag();
    textPreviewView.setAlign(align);
    update();
}
 
Example 14
Project: SmingZZick_App   File: TextPreviewView.java   View Source Code Vote up 4 votes
public Paint.Align getAlign() {
    return textMakingInfo.getAlign();
}
 
Example 15
Project: SmingZZick_App   File: TextPreviewView.java   View Source Code Vote up 4 votes
public void setAlign(Paint.Align align) {
    textMakingInfo.setAlign(align);
}
 
Example 16
Project: SmingZZick_App   File: TextMakingInfo.java   View Source Code Vote up 4 votes
public Paint.Align getAlign() {
    return align;
}
 
Example 17
Project: SmingZZick_App   File: TextMakingInfo.java   View Source Code Vote up 4 votes
public void setAlign(Paint.Align align) {
    this.align = align;
}
 
Example 18
Project: CanvasScript   File: PaintScript.java   View Source Code Vote up 4 votes
public PaintScript textAlign(Paint.Align align) {
    paint.setTextAlign(align);
    return this;
}
 
Example 19
Project: GitHub   File: Description.java   View Source Code Vote up 2 votes
/**
 * Sets the text alignment of the description text. Default RIGHT.
 *
 * @param align
 */
public void setTextAlign(Paint.Align align) {
    this.mTextAlign = align;
}
 
Example 20
Project: GitHub   File: Description.java   View Source Code Vote up 2 votes
/**
 * Returns the text alignment of the description.
 *
 * @return
 */
public Paint.Align getTextAlign() {
    return mTextAlign;
}