Java Code Examples for android.text.TextPaint#ascent()

The following examples show how to use android.text.TextPaint#ascent() . 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: SplashView.java    From KA27 with Apache License 2.0 6 votes vote down vote up
private void draw(Canvas canvas, int x, int y, int radius) {
    if (radius > 0) canvas.drawCircle(x / 2, y / 2, radius, mPaintCircle);
    matrix.postRotate(rotate);
    Bitmap iconRotate = Bitmap.createBitmap(icon, 0, 0, icon.getWidth(), icon.getHeight(), matrix, false);
    canvas.drawBitmap(iconRotate, x / 2 - iconRotate.getWidth() / 2, y / 2 - iconRotate.getHeight() / 2, mPaintCircle);

    TextPaint textPaint = new TextPaint();
    textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
    textPaint.setColor(textColor);
    textPaint.setAntiAlias(true);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setTextSize(textSize);
    float textHeight = textPaint.descent() - textPaint.ascent();
    float textOffset = (textHeight / 2) - textPaint.descent();

    canvas.drawText(getResources().getString(R.string.root_waiting), x / 2, y - textOffset - y / 4, textPaint);
}
 
Example 2
Source File: SimpleMonthView.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
private void drawDaysOfWeek(Canvas canvas) {
    final TextPaint p = mDayOfWeekPaint;
    final int headerHeight = mMonthHeight;
    final int rowHeight = mDayOfWeekHeight;
    final int colWidth = mCellWidth;

    // Text is vertically centered within the day of week height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    final int rowCenter = headerHeight + rowHeight / 2;

    for (int col = 0; col < DAYS_IN_WEEK; col++) {
        final int colCenter = colWidth * col + colWidth / 2;
        final int colCenterRtl;
        if (isLayoutRtl()) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {
            colCenterRtl = colCenter;
        }

        final String label = mDayOfWeekLabels[col];
        canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p);
    }
}
 
Example 3
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the row (0 indexed) closest to previouslyFocusedRect or center if null.
 */
private int findClosestRow(@Nullable Rect previouslyFocusedRect) {
    if (previouslyFocusedRect == null) {
        return 3;
    } else if (mDayHeight == 0) {
        return 0; // There hasn't been a layout, so just choose the first row
    } else {
        int centerY = previouslyFocusedRect.centerY();

        final TextPaint p = mDayPaint;
        final int headerHeight = mMonthHeight + mDayOfWeekHeight;
        final int rowHeight = mDayHeight;

        // Text is vertically centered within the row height.
        final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
        final int rowCenter = headerHeight + rowHeight / 2;

        centerY -= rowCenter - halfLineHeight;
        int row = Math.round(centerY / (float) rowHeight);
        final int maxDay = findDayOffset() + mDaysInMonth;
        final int maxRows = (maxDay / DAYS_IN_WEEK) - ((maxDay % DAYS_IN_WEEK == 0) ? 1 : 0);

        row = MathUtils.constrain(row, 0, maxRows);
        return row;
    }
}
 
Example 4
Source File: JumpingBeansSpan.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private void initIfNecessary(TextPaint tp) {
    if (jumpAnimator != null) {
        return;
    }

    shift = (int) tp.ascent() / 2;
    jumpAnimator = ValueAnimator.ofInt(0, shift, 0);
    jumpAnimator
            .setDuration(loopDuration)
            .setStartDelay(delay);
    jumpAnimator.setInterpolator(new JumpInterpolator(animatedRange));
    jumpAnimator.setRepeatCount(ValueAnimator.INFINITE);
    jumpAnimator.setRepeatMode(ValueAnimator.RESTART);
    jumpAnimator.addUpdateListener(this);
    jumpAnimator.start();
}
 
Example 5
Source File: CircleChart.java    From kernel_adiutor with Apache License 2.0 6 votes vote down vote up
private void draw(Canvas canvas, int x, int y) {
    mRectF.set(mPadding, mPadding, x - mPadding, y - mPadding);
    canvas.drawArc(mRectF, 0, 360, false, mPaintBackground);
    float offset = 360 / (float) mMax;
    canvas.drawArc(mRectF, 270, offset * mProgress, false, mPaintCircle);

    TextPaint textPaint = new TextPaint();
    textPaint.setColor(mCircleColor);
    textPaint.setAntiAlias(true);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setTextSize(mTextsize);
    float textHeight = textPaint.descent() - textPaint.ascent();
    float textOffset = (textHeight / 2) - textPaint.descent();

    RectF bounds = new RectF(mPadding, mPadding, x - mPadding, y - mPadding);
    String text = String.valueOf(mProgress);
    canvas.drawText(text, bounds.centerX(), bounds.centerY() + textOffset, textPaint);
}
 
Example 6
Source File: SplashView.java    From kernel_adiutor with Apache License 2.0 6 votes vote down vote up
private void draw(Canvas canvas, int x, int y, int radius) {
    if (radius > 0) canvas.drawCircle(x / 2, y / 2, radius, mPaintCircle);
    matrix.postRotate(rotate);
    Bitmap iconRotate = Bitmap.createBitmap(icon, 0, 0, icon.getWidth(), icon.getHeight(), matrix, false);
    canvas.drawBitmap(iconRotate, x / 2 - iconRotate.getWidth() / 2, y / 2 - iconRotate.getHeight() / 2, mPaintCircle);

    TextPaint textPaint = new TextPaint();
    textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
    textPaint.setColor(textColor);
    textPaint.setAntiAlias(true);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setTextSize(textSize);
    float textHeight = textPaint.descent() - textPaint.ascent();
    float textOffset = (textHeight / 2) - textPaint.descent();

    canvas.drawText(getResources().getString(R.string.root_waiting), x / 2, y - textOffset - y / 4, textPaint);
}
 
Example 7
Source File: SuperscriptSpan.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint tp) {
    tp.baselineShift += (int) (tp.ascent() / 2);
}
 
Example 8
Source File: SimpleMonthView.java    From DateTimePicker with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the month days.
 */
private void drawDays(Canvas canvas) {
    final TextPaint p = mDayPaint;
    final int headerHeight = mMonthHeight + mDayOfWeekHeight;
    final int rowHeight = mDayHeight;
    final int colWidth = mCellWidth;

    // Text is vertically centered within the row height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    int rowCenter = headerHeight + rowHeight / 2;

    for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
        final int colCenter = colWidth * col + colWidth / 2;
        final int colCenterRtl;
        if (isLayoutRtl()) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {
            colCenterRtl = colCenter;
        }

        int stateMask = 0;

        final boolean isDayEnabled = isDayEnabled(day);
        if (isDayEnabled) {
            stateMask |= StateSet.VIEW_STATE_ENABLED;
        }

        final boolean isDayActivated = mActivatedDay == day;
        final boolean isDayHighlighted = mHighlightedDay == day;
        if (isDayActivated) {
            stateMask |= StateSet.VIEW_STATE_ACTIVATED;

            // Adjust the circle to be centered on the row.
            final Paint paint = isDayHighlighted ? mDayHighlightSelectorPaint :
                    mDaySelectorPaint;
            canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, paint);
        } else if (isDayHighlighted) {
            stateMask |= StateSet.VIEW_STATE_PRESSED;

            if (isDayEnabled) {
                // Adjust the circle to be centered on the row.
                canvas.drawCircle(colCenterRtl, rowCenter,
                        mDaySelectorRadius, mDayHighlightPaint);
            }
        }

        final boolean isDayToday = mToday == day;
        final int dayTextColor;
        if (isDayToday && !isDayActivated) {
            dayTextColor = mDaySelectorPaint.getColor();
        } else {
            final int[] stateSet = StateSet.get(stateMask);
            dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
        }
        p.setColor(dayTextColor);

        canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p);

        col++;

        if (col == DAYS_IN_WEEK) {
            col = 0;
            rowCenter += rowHeight;
        }
    }
}
 
Example 9
Source File: Super.java    From Ruisi with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint tp) {
    tp.baselineShift += (int) (tp.ascent() / 2);
}
 
Example 10
Source File: SubscriptSpan.java    From JotaTextEditor with Apache License 2.0 4 votes vote down vote up
@Override
public void updateMeasureState(TextPaint tp) {
    tp.baselineShift -= (int) (tp.ascent() / 2);
}
 
Example 11
Source File: SuperScriptSpan.java    From Markwon with Apache License 2.0 4 votes vote down vote up
private void apply(TextPaint paint) {
    paint.setTextSize(paint.getTextSize() * HtmlPlugin.SCRIPT_DEF_TEXT_SIZE_RATIO);
    paint.baselineShift += (int) (paint.ascent() / 2);
}
 
Example 12
Source File: SpanAdjuster.java    From px-android with MIT License 4 votes vote down vote up
@Override
public void updateDrawState(@NonNull final TextPaint paint) {
    paint.baselineShift += (int) (paint.ascent() * RATE);
}
 
Example 13
Source File: SubscriptSpan.java    From JotaTextEditor with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint tp) {
    tp.baselineShift -= (int) (tp.ascent() / 2);
}
 
Example 14
Source File: CenterAlignedRelativeSizeSpan.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint tp) {
  tp.setTextSize(tp.getTextSize() * relativeSize);
  tp.baselineShift += (int) (tp.ascent() * relativeSize) / 4;
}
 
Example 15
Source File: SuperscriptSpanAdjuster.java    From px-android with MIT License 4 votes vote down vote up
@Override
public void updateMeasureState(final TextPaint paint) {
    paint.baselineShift += (int) (paint.ascent() * rate);
}
 
Example 16
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the month days.
 */
private void drawDays(Canvas canvas) {
    final TextPaint p = mDayPaint;
    final int headerHeight = mMonthHeight + mDayOfWeekHeight;
    final int rowHeight = mDayHeight;
    final int colWidth = mCellWidth;

    // Text is vertically centered within the row height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    int rowCenter = headerHeight + rowHeight / 2;

    for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
        final int colCenter = colWidth * col + colWidth / 2;
        final int colCenterRtl;
        if (isLayoutRtl()) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {
            colCenterRtl = colCenter;
        }

        int stateMask = 0;

        final boolean isDayEnabled = isDayEnabled(day);
        if (isDayEnabled) {
            stateMask |= StateSet.VIEW_STATE_ENABLED;
        }

        final boolean isDayActivated = mActivatedDay == day;
        final boolean isDayHighlighted = mHighlightedDay == day;
        if (isDayActivated) {
            stateMask |= StateSet.VIEW_STATE_ACTIVATED;

            // Adjust the circle to be centered on the row.
            final Paint paint = isDayHighlighted ? mDayHighlightSelectorPaint :
                    mDaySelectorPaint;
            canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, paint);
        } else if (isDayHighlighted) {
            stateMask |= StateSet.VIEW_STATE_PRESSED;

            if (isDayEnabled) {
                // Adjust the circle to be centered on the row.
                canvas.drawCircle(colCenterRtl, rowCenter,
                        mDaySelectorRadius, mDayHighlightPaint);
            }
        }

        final boolean isDayToday = mToday == day;
        final int dayTextColor;
        if (isDayToday && !isDayActivated) {
            dayTextColor = mDaySelectorPaint.getColor();
        } else {
            final int[] stateSet = StateSet.get(stateMask);
            dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
        }
        p.setColor(dayTextColor);

        canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p);

        col++;

        if (col == DAYS_IN_WEEK) {
            col = 0;
            rowCenter += rowHeight;
        }
    }
}
 
Example 17
Source File: Sub.java    From Ruisi with Apache License 2.0 4 votes vote down vote up
@Override
public void updateMeasureState(TextPaint tp) {
    tp.baselineShift -= (int) (tp.ascent() / 2);
}
 
Example 18
Source File: SuperscriptSpan.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void updateMeasureState(@NonNull TextPaint textPaint) {
    textPaint.baselineShift += (int) (textPaint.ascent() / 2);
}
 
Example 19
Source File: SuperscriptSpan.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(@NonNull TextPaint textPaint) {
    textPaint.baselineShift += (int) (textPaint.ascent() / 2);
}
 
Example 20
Source File: Sub.java    From Ruisi with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint tp) {
    tp.baselineShift -= (int) (tp.ascent() / 2);
}