Example usage for android.graphics Paint ascent

List of usage examples for android.graphics Paint ascent

Introduction

In this page you can find the example usage for android.graphics Paint ascent.

Prototype

public float ascent() 

Source Link

Document

Return the distance above (negative) the baseline (ascent) based on the current typeface and text size.

Usage

From source file:ggikko.me.steppertest.stepper.RoundedView.java

private void drawText(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size));

    Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());

    RectF bounds = new RectF(areaRect);

    bounds.right = paint.measureText(text, 0, text.length());

    bounds.bottom = paint.descent() - paint.ascent();

    bounds.left += (areaRect.width() - bounds.right) / 2.0f;
    bounds.top += (areaRect.height() - bounds.bottom) / 2.0f;

    paint.setColor(Color.WHITE);/*w  w w .ja va  2 s . c  om*/
    canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint);
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

/**
 * Using the trigonometric Unit Circle, calculate the positions that the text will need to be
 * drawn at based on the specified circle radius. Place the values in the textGridHeights and
 * textGridWidths parameters.// w ww .jav a 2  s .co  m
 */
private static void calculatePositions(Paint paint, float radius, float xCenter, float yCenter, float textSize,
        float[] x, float[] y) {
    // Adjust yCenter to account for the text's baseline.
    paint.setTextSize(textSize);
    yCenter -= (paint.descent() + paint.ascent()) / 2;

    for (int i = 0; i < NUM_POSITIONS; i++) {
        x[i] = xCenter - radius * COS_30[i];
        y[i] = yCenter - radius * SIN_30[i];
    }
}

From source file:com.zzq.viewpagerindicator.TitlePageIndicator.java

private Rect calcBounds(int index, Paint paint) {
    // Calculate the text bounds
    Rect bounds = new Rect();
    CharSequence title = getTitle(index);
    bounds.right = (int) paint.measureText(title, 0, title.length());
    bounds.bottom = (int) (paint.descent() - paint.ascent());
    return bounds;
}

From source file:com.fanfou.app.opensource.ui.viewpager.TitlePageIndicator.java

/**
 * Calculate the bounds for a view's title
 * /*from w ww  .  ja va 2  s  . com*/
 * @param index
 * @param paint
 * @return
 */
private RectF calcBounds(final int index, final Paint paint) {
    // Calculate the text bounds
    final RectF bounds = new RectF();
    bounds.right = paint.measureText(this.mTitleProvider.getTitle(index));
    bounds.bottom = paint.descent() - paint.ascent();
    return bounds;
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * Return text As bitmap/*w ww  . ja v a  2  s.c  o  m*/
 *
 * @param text
 * @param textSize
 * @param textColor
 * @return
 */
public static Bitmap textAsBitmap(String text, float textSize, int textColor) {
    Paint paint = new Paint(ANTI_ALIAS_FLAG);
    paint.setTextSize(textSize); //text size
    paint.setColor(textColor); //text color
    paint.setTextAlign(Paint.Align.LEFT); //align center
    float baseline = -paint.ascent(); // ascent() is negative
    int width = (int) (paint.measureText(text) + 0.0f); // round
    int height = (int) (baseline + paint.descent() + 0.0f);
    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    canvas.drawText(text, 0, baseline, paint); //draw text
    return image;
}

From source file:at.ac.uniklu.mobile.sportal.ui.viewpagerindicator.TitlePageIndicator.java

/**
 * Calculate the bounds for a view's title
 *
 * @param index// w  w w .  j av  a  2s . c  o m
 * @param paint
 * @return
 */
private RectF calcBounds(int index, Paint paint) {
    //Calculate the text bounds
    RectF bounds = new RectF();
    bounds.right = paint.measureText(mTitleProvider.getTitle(index));
    bounds.bottom = paint.descent() - paint.ascent();
    return bounds;
}

From source file:com.android.common.TitlePageIndicator.java

/**
 * Calculate the bounds for a view's title
 *
 * @param index/*from  w  w  w .  j  a  v  a 2 s  .  c o  m*/
 * @param paint
 * @return
 */
private RectF calcBounds(int index, Paint paint) {
    //Calculate the text bounds
    RectF bounds = new RectF();
    bounds.right = paint.measureText(mTitleProvider.GetTitle(index));
    bounds.bottom = paint.descent() - paint.ascent();
    return bounds;
}

From source file:org.cicadasong.samples.tubestatus.TubeStatus.java

protected void onDraw(Canvas canvas) {
    Paint paint = new Paint();
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setTypeface(Typeface.DEFAULT_BOLD);

    // We've centered the output vertically, so it works with the reduced canvas height in
    // widget mode.
    int y = canvas.getHeight() / 2;
    int x = canvas.getWidth() / 2;

    paint.setTypeface(Typeface.DEFAULT);
    paint.setTextSize(11);/* w w  w.  j  a va2s . c o m*/
    canvas.drawText(TubeLine.allLines.get(selectionIndex).name, x, y - paint.descent() - 1, paint);

    paint.setTextSize(11); // TODO dynamically adjust font size depending on length of status string?
    canvas.drawText(status, x, y + (int) -paint.ascent() + 1, paint);
}

From source file:com.icloud.listenbook.base.view.viewpagerindicator.FixedTitlePageIndicator.java

/**
 * //  ww w  .j a va  2s. c om
 * 
 * @param index
 * @param paint
 * @return
 */
private RectF calcBounds(int index, Paint paint) {
    // Calculate the text bounds
    RectF bounds = new RectF();
    bounds.right = paint.measureText(mTitleProvider.getPageTitle(index).toString());
    bounds.bottom = paint.descent() - paint.ascent();
    return bounds;
}

From source file:com.pc.pager.indicator.TitlePageIndicator.java

/**
 * Calculate the bounds for a view's title
 * @param index/*  ww  w .  j a v a2 s  .c  o m*/
 * @param paint
 * @return
 */
private Rect calcBounds(int index, Paint paint) {
    // Calculate the text bounds
    Rect bounds = new Rect();
    CharSequence title = getTitle(index);
    bounds.right = (int) paint.measureText(title, 0, title.length()) + TextMaginLeftAndRight;
    bounds.bottom = (int) (paint.descent() - paint.ascent());
    return bounds;
}