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:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

@Override
protected void onSizeChanged(int width, int height, int oldw, int oldh) {
    mViewWidth = width;/*from  ww w.  j  a va 2  s  .c  o  m*/
    mViewHeight = height;
    mEdgeEffectTop.setSize(mViewWidth, mViewHeight);
    mEdgeEffectBottom.setSize(mViewWidth, mViewHeight);
    int gridAreaWidth = width - mHoursWidth;
    mCellWidth = (gridAreaWidth - (mNumDays * DAY_GAP)) / mNumDays;

    // This would be about 1 day worth in a 7 day view
    mHorizontalSnapBackThreshold = width / 7;

    Paint p = new Paint();
    p.setTextSize(HOURS_TEXT_SIZE);
    mHoursTextHeight = (int) Math.abs(p.ascent());
    remeasure(width, height);
}

From source file:com.android.mail.ui.FolderDisplayer.java

public static void drawFolder(Canvas canvas, float x, float y, int width, int height, String name, int fgColor,
        int bgColor, FolderDisplayer.FolderDrawableResources res, BidiFormatter formatter, Paint paint) {
    canvas.save();/*from  w  ww. j  a  v a  2 s .  co m*/
    canvas.translate(x, y + res.folderVerticalOffset);

    // Draw the box.
    paint.setColor(bgColor);
    paint.setStyle(Paint.Style.FILL);
    final RectF rect = new RectF(0, 0, width, height);
    canvas.drawRoundRect(rect, res.folderRoundedCornerRadius, res.folderRoundedCornerRadius, paint);

    // Draw the text based on the language locale and layout direction.
    paint.setColor(fgColor);
    paint.setStyle(Paint.Style.FILL);

    // Compute the text/gradient indices
    final int textLength = (int) paint.measureText(name);
    final int gradientX0;
    final int gradientX1;
    final int textX;

    /***************************************************************************************************
     * width               - the actual folder chip rectangle.                                         *
     * textLength          - the length of the folder's full name (can be longer than                  *
     *                         the actual chip, which is what overflow gradient is for).               *
     * innerPadding        - the padding between the text and the chip edge.                           *
     * overflowPadding     - the padding between start of overflow and the chip edge.                  *
     *                                                                                                 *
     *                                                                                                 *
     * text is in a RTL language                                                                       *
     *                                                                                                 *
     *                   index-0                                                                       *
     *                      |<---------------------------- width ---------------------------->|        *
     *        |<-------------------------textLength------------------>|                       |        *
     *        |             |<----- overflowPadding ----->|                                   |        *
     *        |             |<- innerPadding ->|<-------->|<--------->|<- horizontalPadding ->|        *
     *       textX                            gX1        gX0                                           *
     *                                                                                                 *
     *                                                                                                 *
     * text is in a LTR language.                                                                      *
     *                                                                                                 *
     *     index-0                                                                                     *
     *        |<------------------------------ width ------------------------------->|                 *
     *        |                       |<-------------------------textLength-------------------->|      *
     *        |                                   |<-------- overflowPadding ------->|                 *
     *        |<- horizontalPadding ->|<--------->|<-------->|<- horizontalPadding ->|                 *
     *                              textX        gX0        gX1                                        *
     *                                                                                                 *
     **************************************************************************************************/
    if (formatter.isRtl(name)) {
        gradientX0 = res.overflowGradientPadding;
        gradientX1 = res.folderHorizontalPadding;
        textX = width - res.folderHorizontalPadding - textLength;
    } else {
        gradientX0 = width - res.overflowGradientPadding;
        gradientX1 = width - res.folderHorizontalPadding;
        textX = res.folderHorizontalPadding;
    }

    // Draw the text and the possible overflow gradient
    // Overflow happens when the text is longer than the chip width minus side paddings.
    if (textLength > width - 2 * res.folderHorizontalPadding) {
        final Shader shader = new LinearGradient(gradientX0, 0, gradientX1, 0, fgColor,
                Utils.getTransparentColor(fgColor), Shader.TileMode.CLAMP);
        paint.setShader(shader);
    }
    final int textY = height / 2 - (int) (paint.descent() + paint.ascent()) / 2;
    canvas.drawText(name, textX, textY, paint);
    paint.setShader(null);

    canvas.restore();
}