android.text.TextPaint#ascent ( )源码实例Demo

下面列出了android.text.TextPaint#ascent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: KA27   文件: SplashView.java
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);
}
 
源代码2 项目: android_9.0.0_r45   文件: SimpleMonthView.java
/**
 * 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;
    }
}
 
源代码3 项目: UltimateAndroid   文件: JumpingBeansSpan.java
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();
}
 
源代码4 项目: kernel_adiutor   文件: SplashView.java
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);
}
 
源代码5 项目: kernel_adiutor   文件: CircleChart.java
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);
}
 
源代码6 项目: DateTimePicker   文件: SimpleMonthView.java
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);
    }
}
 
@Override
public void updateDrawState(TextPaint tp) {
  tp.setTextSize(tp.getTextSize() * relativeSize);
  tp.baselineShift += (int) (tp.ascent() * relativeSize) / 4;
}
 
源代码8 项目: Ruisi   文件: Sub.java
@Override
public void updateDrawState(TextPaint tp) {
    tp.baselineShift -= (int) (tp.ascent() / 2);
}
 
源代码9 项目: android_9.0.0_r45   文件: SuperscriptSpan.java
@Override
public void updateDrawState(@NonNull TextPaint textPaint) {
    textPaint.baselineShift += (int) (textPaint.ascent() / 2);
}
 
源代码10 项目: android_9.0.0_r45   文件: SuperscriptSpan.java
@Override
public void updateMeasureState(@NonNull TextPaint textPaint) {
    textPaint.baselineShift += (int) (textPaint.ascent() / 2);
}
 
源代码11 项目: Ruisi   文件: Sub.java
@Override
public void updateMeasureState(TextPaint tp) {
    tp.baselineShift -= (int) (tp.ascent() / 2);
}
 
源代码12 项目: android_9.0.0_r45   文件: SimpleMonthView.java
/**
 * 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;
        }
    }
}
 
源代码13 项目: px-android   文件: SuperscriptSpanAdjuster.java
@Override
public void updateMeasureState(final TextPaint paint) {
    paint.baselineShift += (int) (paint.ascent() * rate);
}
 
源代码14 项目: PowerFileExplorer   文件: SuperscriptSpan.java
@Override
public void updateDrawState(TextPaint tp) {
    tp.baselineShift += (int) (tp.ascent() / 2);
}
 
源代码15 项目: JotaTextEditor   文件: SubscriptSpan.java
@Override
public void updateDrawState(TextPaint tp) {
    tp.baselineShift -= (int) (tp.ascent() / 2);
}
 
源代码16 项目: px-android   文件: SpanAdjuster.java
@Override
public void updateDrawState(@NonNull final TextPaint paint) {
    paint.baselineShift += (int) (paint.ascent() * RATE);
}
 
源代码17 项目: Markwon   文件: SuperScriptSpan.java
private void apply(TextPaint paint) {
    paint.setTextSize(paint.getTextSize() * HtmlPlugin.SCRIPT_DEF_TEXT_SIZE_RATIO);
    paint.baselineShift += (int) (paint.ascent() / 2);
}
 
源代码18 项目: JotaTextEditor   文件: SubscriptSpan.java
@Override
public void updateMeasureState(TextPaint tp) {
    tp.baselineShift -= (int) (tp.ascent() / 2);
}
 
源代码19 项目: Ruisi   文件: Super.java
@Override
public void updateDrawState(TextPaint tp) {
    tp.baselineShift += (int) (tp.ascent() / 2);
}
 
源代码20 项目: DateTimePicker   文件: SimpleMonthView.java
/**
 * 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;
        }
    }
}