Example usage for android.graphics Paint descent

List of usage examples for android.graphics Paint descent

Introduction

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

Prototype

public float descent() 

Source Link

Document

Return the distance below (positive) the baseline (descent) based on the current typeface and text size.

Usage

From source file:org.cicadasong.samples.nextbuses.NextBuses.java

protected void onDraw(Canvas canvas) {
    // Set font for heading
    Paint paint = isWidget() ? metawatch5px : metawatch7px;

    int x = 2;/*from w ww . j a  v  a 2 s.  c o  m*/
    int y = 2 + (int) -paint.ascent();

    canvas.drawText("Next buses at...", x, y, paint);

    y += (int) paint.descent() + 2;

    // Set font for stop name
    paint = isWidget() ? metawatch7px : metawatch11px;
    y += (int) -paint.ascent();

    canvas.drawText(stopName, x, y, paint);

    y += (int) paint.descent() + 2;

    // Set font for "body"
    paint = isWidget() ? metawatch5px : default10pt;
    y += (int) -paint.ascent();

    if (inInitialFetch) {
        canvas.drawText("Fetching...", x, y, paint);
    } else if (predictions == null) {
        canvas.drawText("Network Error", x, y, paint);
    } else if (isWidget()) {
        String singleLineResult = "";
        List<Prediction> allPredictions = predictions.getAllPredictions();
        StringBuilder resultBuilder = new StringBuilder();
        for (Prediction prediction : allPredictions) {
            if (resultBuilder.length() > 0) {
                resultBuilder.append(" ");
            }
            resultBuilder.append(prediction.route);
            resultBuilder.append("~");
            resultBuilder.append(prediction.minutes);
            resultBuilder.append("m");
        }
        singleLineResult = resultBuilder.toString();
        canvas.drawText(singleLineResult, x, y, paint);
    } else {
        // We're in app mode, so we have more screen space to work with
        for (String route : predictions.getRoutes()) {
            StringBuilder resultBuilder = new StringBuilder();
            resultBuilder.append(route);
            resultBuilder.append(":");
            for (Prediction prediction : predictions.getPredictionsForRoute(route)) {
                resultBuilder.append(" ");
                resultBuilder.append(prediction.minutes);
                resultBuilder.append("m");
            }
            canvas.drawText(resultBuilder.toString(), x, y, paint);
            y += paint.getFontSpacing();
        }
    }
}

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./*  www  . jav a  2  s . c  om*/
 */
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: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);/*from w  w w.  j  a  v  a  2  s. com*/
    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.fanfou.app.opensource.ui.viewpager.TitlePageIndicator.java

/**
 * Calculate the bounds for a view's title
 * /*from www  . j  av a2s . 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:at.ac.uniklu.mobile.sportal.ui.viewpagerindicator.TitlePageIndicator.java

/**
 * Calculate the bounds for a view's title
 *
 * @param index/*  w  w  w  .j  a va  2 s . c om*/
 * @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/*  w w w .j  a v  a2s. co  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.appunite.list.FastScroller.java

public void draw(Canvas canvas) {

    if (mState == STATE_NONE) {
        // No need to draw anything
        return;// ww  w  .jav  a  2 s  .com
    }

    final int y = mThumbY;
    final int viewWidth = mList.getWidth();
    final FastScroller.ScrollFade scrollFade = mScrollFade;

    int alpha = -1;
    if (mState == STATE_EXIT) {
        alpha = scrollFade.getAlpha();
        if (alpha < ScrollFade.ALPHA_MAX / 2) {
            mThumbDrawable.setAlpha(alpha * 2);
        }
        int left = 0;
        switch (mPosition) {
        case View.SCROLLBAR_POSITION_RIGHT:
            left = viewWidth - (mThumbW * alpha) / ScrollFade.ALPHA_MAX;
            break;
        case View.SCROLLBAR_POSITION_LEFT:
            left = -mThumbW + (mThumbW * alpha) / ScrollFade.ALPHA_MAX;
            break;
        }
        mThumbDrawable.setBounds(left, 0, left + mThumbW, mThumbH);
        mChangedBounds = true;
    }

    if (mTrackDrawable != null) {
        final Rect thumbBounds = mThumbDrawable.getBounds();
        final int left = thumbBounds.left;
        final int halfThumbHeight = (thumbBounds.bottom - thumbBounds.top) / 2;
        final int trackWidth = mTrackDrawable.getIntrinsicWidth();
        final int trackLeft = (left + mThumbW / 2) - trackWidth / 2;
        mTrackDrawable.setBounds(trackLeft, halfThumbHeight, trackLeft + trackWidth,
                mList.getHeight() - halfThumbHeight);
        mTrackDrawable.draw(canvas);
    }

    canvas.translate(0, y);
    mThumbDrawable.draw(canvas);
    canvas.translate(0, -y);

    // If user is dragging the scroll bar, draw the alphabet overlay
    if (mState == STATE_DRAGGING && mDrawOverlay) {
        if (mOverlayPosition == OVERLAY_AT_THUMB) {
            int left = 0;
            switch (mPosition) {
            default:
            case View.SCROLLBAR_POSITION_RIGHT:
                left = Math.max(0, mThumbDrawable.getBounds().left - mThumbW - mOverlaySize);
                break;
            case View.SCROLLBAR_POSITION_LEFT:
                left = Math.min(mThumbDrawable.getBounds().right + mThumbW, mList.getWidth() - mOverlaySize);
                break;
            }

            int top = Math.max(0, Math.min(y + (mThumbH - mOverlaySize) / 2, mList.getHeight() - mOverlaySize));

            final RectF pos = mOverlayPos;
            pos.left = left;
            pos.right = pos.left + mOverlaySize;
            pos.top = top;
            pos.bottom = pos.top + mOverlaySize;
            if (mOverlayDrawable != null) {
                mOverlayDrawable.setBounds((int) pos.left, (int) pos.top, (int) pos.right, (int) pos.bottom);
            }
        }
        mOverlayDrawable.draw(canvas);
        final Paint paint = mPaint;
        float descent = paint.descent();
        final RectF rectF = mOverlayPos;
        final Rect tmpRect = mTmpRect;
        mOverlayDrawable.getPadding(tmpRect);
        final int hOff = (tmpRect.right - tmpRect.left) / 2;
        final int vOff = (tmpRect.bottom - tmpRect.top) / 2;
        canvas.drawText(mSectionText, (int) (rectF.left + rectF.right) / 2 - hOff,
                (int) (rectF.bottom + rectF.top) / 2 + mOverlaySize / 4 - descent - vOff, paint);
    } else if (mState == STATE_EXIT) {
        if (alpha == 0) { // Done with exit
            setState(STATE_NONE);
        } else if (mTrackDrawable != null) {
            mList.invalidate(viewWidth - mThumbW, 0, viewWidth, mList.getHeight());
        } else {
            mList.invalidate(viewWidth - mThumbW, y, viewWidth, y + mThumbH);
        }
    }
}

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

/**
 * Return text As bitmap// www . j av  a2  s. com
 *
 * @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:com.icloud.listenbook.base.view.viewpagerindicator.FixedTitlePageIndicator.java

/**
 * /*from  w w w .j  a v a 2  s  .  co m*/
 * 
 * @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;
}