Search in sources :

Example 56 with TextPaint

use of android.text.TextPaint in project android_frameworks_base by DirtyUnicorns.

the class StaticLayoutTest method moveCursorToLeftCursorableOffset.

private void moveCursorToLeftCursorableOffset(EditorState state, TextPaint paint) {
    assertEquals("The editor has selection", state.mSelectionStart, state.mSelectionEnd);
    final Layout layout = builder().setText(state.mText.toString()).setPaint(paint).build();
    final int newOffset = layout.getOffsetToLeftOf(state.mSelectionStart);
    state.mSelectionStart = state.mSelectionEnd = newOffset;
}
Also used : TextPaint(android.text.TextPaint)

Example 57 with TextPaint

use of android.text.TextPaint in project android_frameworks_base by DirtyUnicorns.

the class StaticLayoutTest method testEmojiOffset.

/**
     * Tests for keycap, variation selectors, flags are in CTS.
     * See {@link android.text.cts.StaticLayoutTest}.
     */
public void testEmojiOffset() {
    EditorState state = new EditorState();
    TextPaint paint = new TextPaint();
    // Odd numbered regional indicator symbols.
    // U+1F1E6 is REGIONAL INDICATOR SYMBOL LETTER A, U+1F1E8 is REGIONAL INDICATOR SYMBOL
    // LETTER C.
    state.setByString("| U+1F1E6 U+1F1E8 U+1F1E6 U+1F1E8 U+1F1E6");
    moveCursorToRightCursorableOffset(state, paint);
    state.setByString("U+1F1E6 U+1F1E8 | U+1F1E6 U+1F1E8 U+1F1E6");
    moveCursorToRightCursorableOffset(state, paint);
    state.setByString("U+1F1E6 U+1F1E8 U+1F1E6 U+1F1E8 | U+1F1E6");
    moveCursorToRightCursorableOffset(state, paint);
    state.setByString("U+1F1E6 U+1F1E8 U+1F1E6 U+1F1E8 U+1F1E6 |");
    moveCursorToRightCursorableOffset(state, paint);
    state.setByString("U+1F1E6 U+1F1E8 U+1F1E6 U+1F1E8 U+1F1E6 |");
    moveCursorToLeftCursorableOffset(state, paint);
    state.setByString("U+1F1E6 U+1F1E8 U+1F1E6 U+1F1E8 | U+1F1E6");
    moveCursorToLeftCursorableOffset(state, paint);
    state.setByString("U+1F1E6 U+1F1E8 | U+1F1E6 U+1F1E8 U+1F1E6");
    moveCursorToLeftCursorableOffset(state, paint);
    state.setByString("| U+1F1E6 U+1F1E8 U+1F1E6 U+1F1E8 U+1F1E6");
    moveCursorToLeftCursorableOffset(state, paint);
    state.setByString("| U+1F1E6 U+1F1E8 U+1F1E6 U+1F1E8 U+1F1E6");
    moveCursorToLeftCursorableOffset(state, paint);
    // Zero width sequence
    final String zwjSequence = "U+1F468 U+200D U+2764 U+FE0F U+200D U+1F468";
    state.setByString("| " + zwjSequence + " " + zwjSequence + " " + zwjSequence);
    moveCursorToRightCursorableOffset(state, paint);
    state.assertEquals(zwjSequence + " | " + zwjSequence + " " + zwjSequence);
    moveCursorToRightCursorableOffset(state, paint);
    state.assertEquals(zwjSequence + " " + zwjSequence + " | " + zwjSequence);
    moveCursorToRightCursorableOffset(state, paint);
    state.assertEquals(zwjSequence + " " + zwjSequence + " " + zwjSequence + " |");
    moveCursorToRightCursorableOffset(state, paint);
    state.assertEquals(zwjSequence + " " + zwjSequence + " " + zwjSequence + " |");
    moveCursorToLeftCursorableOffset(state, paint);
    state.assertEquals(zwjSequence + " " + zwjSequence + " | " + zwjSequence);
    moveCursorToLeftCursorableOffset(state, paint);
    state.assertEquals(zwjSequence + " | " + zwjSequence + " " + zwjSequence);
    moveCursorToLeftCursorableOffset(state, paint);
    state.assertEquals("| " + zwjSequence + " " + zwjSequence + " " + zwjSequence);
    moveCursorToLeftCursorableOffset(state, paint);
    state.assertEquals("| " + zwjSequence + " " + zwjSequence + " " + zwjSequence);
    moveCursorToLeftCursorableOffset(state, paint);
    // Emoji modifiers
    // U+261D is WHITE UP POINTING INDEX, U+1F3FB is EMOJI MODIFIER FITZPATRICK TYPE-1-2.
    state.setByString("| U+261D U+1F3FB U+261D U+1F3FB U+261D U+1F3FB");
    moveCursorToRightCursorableOffset(state, paint);
    state.setByString("U+261D U+1F3FB | U+261D U+1F3FB U+261D U+1F3FB");
    moveCursorToRightCursorableOffset(state, paint);
    state.setByString("U+261D U+1F3FB U+261D U+1F3FB | U+261D U+1F3FB");
    moveCursorToRightCursorableOffset(state, paint);
    state.setByString("U+261D U+1F3FB U+261D U+1F3FB U+261D U+1F3FB |");
    moveCursorToRightCursorableOffset(state, paint);
    state.setByString("U+261D U+1F3FB U+261D U+1F3FB U+261D U+1F3FB |");
    moveCursorToLeftCursorableOffset(state, paint);
    state.setByString("U+261D U+1F3FB U+261D U+1F3FB | U+261D U+1F3FB");
    moveCursorToLeftCursorableOffset(state, paint);
    state.setByString("U+261D U+1F3FB | U+261D U+1F3FB U+261D U+1F3FB");
    moveCursorToLeftCursorableOffset(state, paint);
    state.setByString("| U+261D U+1F3FB U+261D U+1F3FB U+261D U+1F3FB");
    moveCursorToLeftCursorableOffset(state, paint);
    state.setByString("| U+261D U+1F3FB U+261D U+1F3FB U+261D U+1F3FB");
    moveCursorToLeftCursorableOffset(state, paint);
}
Also used : EditorState(android.text.method.EditorState) TextPaint(android.text.TextPaint)

Example 58 with TextPaint

use of android.text.TextPaint in project android_frameworks_base by DirtyUnicorns.

the class TextLayoutTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    mString = "The quick brown fox";
    mPaint = new TextPaint();
}
Also used : TextPaint(android.text.TextPaint)

Example 59 with TextPaint

use of android.text.TextPaint in project android_frameworks_base by DirtyUnicorns.

the class SimpleMonthView method drawDays.

/**
     * 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;
        }
    }
}
Also used : TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint)

Example 60 with TextPaint

use of android.text.TextPaint in project android_frameworks_base by DirtyUnicorns.

the class SimpleMonthView method findClosestRow.

/**
     * Returns the row (0 indexed) closest to previouslyFocusedRect or center if null.
     */
private int findClosestRow(@Nullable Rect previouslyFocusedRect) {
    if (previouslyFocusedRect == null) {
        return 3;
    } 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;
    }
}
Also used : TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint)

Aggregations

TextPaint (android.text.TextPaint)216 Paint (android.graphics.Paint)86 StaticLayout (android.text.StaticLayout)29 View (android.view.View)17 Bitmap (android.graphics.Bitmap)14 Typeface (android.graphics.Typeface)14 TypedArray (android.content.res.TypedArray)12 SpannableString (android.text.SpannableString)12 RectF (android.graphics.RectF)11 Spanned (android.text.Spanned)11 TextView (android.widget.TextView)11 Rect (android.graphics.Rect)8 StyleSpan (android.text.style.StyleSpan)8 ClickableSpan (android.text.style.ClickableSpan)7 PackageManager (android.content.pm.PackageManager)6 Canvas (android.graphics.Canvas)6 IBinder (android.os.IBinder)6 SpannableStringBuilder (android.text.SpannableStringBuilder)6 Context (android.content.Context)5 Resources (android.content.res.Resources)5