use of android.text.TextPaint in project plaid by nickbutcher.
the class FabOverlapTextView method init.
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FabOverlapTextView);
float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP, getResources().getDisplayMetrics());
setFabOverlapGravity(a.getInt(R.styleable.FabOverlapTextView_fabGravity, Gravity.BOTTOM | Gravity.RIGHT));
setFabOverlapHeight(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayHeight, 0));
setFabOverlapWidth(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayWidth, 0));
if (a.hasValue(R.styleable.FabOverlapTextView_android_textAppearance)) {
final int textAppearance = a.getResourceId(R.styleable.FabOverlapTextView_android_textAppearance, android.R.style.TextAppearance);
TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.FontTextAppearance);
paint.setColor(atp.getColor(R.styleable.FontTextAppearance_android_textColor, Color.BLACK));
paint.setTextSize(atp.getDimensionPixelSize(R.styleable.FontTextAppearance_android_textSize, (int) defaultTextSize));
if (atp.hasValue(R.styleable.FontTextAppearance_font)) {
paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.FontTextAppearance_font)));
}
atp.recycle();
}
if (a.hasValue(R.styleable.FabOverlapTextView_font)) {
setFont(a.getString(R.styleable.FabOverlapTextView_font));
}
if (a.hasValue(R.styleable.FabOverlapTextView_android_textColor)) {
setTextColor(a.getColor(R.styleable.FabOverlapTextView_android_textColor, 0));
}
if (a.hasValue(R.styleable.FabOverlapTextView_android_textSize)) {
setTextSize(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_android_textSize, (int) defaultTextSize));
}
lineHeightHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_lineHeightHint, 0);
unalignedTopPadding = getPaddingTop();
unalignedBottomPadding = getPaddingBottom();
breakStrategy = a.getInt(R.styleable.FabOverlapTextView_android_breakStrategy, Layout.BREAK_STRATEGY_BALANCED);
a.recycle();
}
use of android.text.TextPaint in project android_frameworks_base by ResurrectionRemix.
the class TextLayoutTest method setUp.
protected void setUp() throws Exception {
super.setUp();
mString = "The quick brown fox";
mPaint = new TextPaint();
}
use of android.text.TextPaint in project android_frameworks_base by ResurrectionRemix.
the class StaticLayoutTest method moveCursorToRightCursorableOffset.
private void moveCursorToRightCursorableOffset(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.getOffsetToRightOf(state.mSelectionStart);
state.mSelectionStart = state.mSelectionEnd = newOffset;
}
use of android.text.TextPaint in project android_frameworks_base by ResurrectionRemix.
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;
}
}
}
use of android.text.TextPaint in project android_frameworks_base by ResurrectionRemix.
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;
}
}
Aggregations