List of usage examples for android.text TextPaint setColor
public void setColor(@ColorInt int color)
From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java
/** * Draws the month days.// w w w.j a v a2 s .co m */ @SuppressWarnings("ConstantConditions") private void drawDays(Canvas canvas) { final TextPaint p = mDayPaint; final int headerHeight = mMonthHeight + mDayOfWeekHeight; //final int rowHeight = mDayHeight; final float rowHeight = mDayHeight; //final int colWidth = mCellWidth; final float colWidth = mCellWidth; // Text is vertically centered within the row height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; //int rowCenter = headerHeight + rowHeight / 2; float rowCenter = headerHeight + rowHeight / 2f; for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) { //final int colCenter = colWidth * col + colWidth / 2; final float colCenter = colWidth * col + colWidth / 2f; //final int colCenterRtl; final float colCenterRtl; if (SUtils.isLayoutRtlCompat(this)) { colCenterRtl = mPaddedWidth - colCenter; } else { colCenterRtl = colCenter; } int stateMask = 0; final boolean isDayEnabled = isDayEnabled(day); if (isDayEnabled) { stateMask |= SUtils.STATE_ENABLED; } final boolean isDayInActivatedRange = mActivatedDays.isValid() && mActivatedDays.isActivated(day); final boolean isSelected = mActivatedDays.isSelected(day); if (isSelected) { stateMask |= SUtils.STATE_ACTIVATED; canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint); } else if (isDayInActivatedRange) { stateMask |= SUtils.STATE_ACTIVATED; int bgShape = DRAW_RECT; if (mActivatedDays.isSingleDay()) { if (mActivatedDays.isStartOfMonth()) { bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT; } else { bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT; } } else if (mActivatedDays.isStartingDayOfRange(day)) { bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT; } else if (mActivatedDays.isEndingDayOfRange(day)) { bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT; } // Use height to constrain the protrusion of the arc boolean constrainProtrusion = colWidth > (rowHeight - (2 * mPaddingRangeIndicator)); float horDistFromCenter = constrainProtrusion ? rowHeight / 2f - mPaddingRangeIndicator : colWidth / 2f; switch (bgShape) { case DRAW_RECT_WITH_CURVE_ON_LEFT: int leftRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1 ? (int) (colCenterRtl - horDistFromCenter) + 1 : (int) (colCenterRtl - horDistFromCenter); int leftRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1 ? (int) (colCenterRtl + horDistFromCenter) + 1 : (int) (colCenterRtl + horDistFromCenter); RectF leftArcRect = new RectF(leftRectArcLeft, rowCenter - rowHeight / 2f + mPaddingRangeIndicator, leftRectArcRight, rowCenter + rowHeight / 2f - mPaddingRangeIndicator); canvas.drawArc(leftArcRect, 90, 180, true, mDayRangeSelectorPaint); canvas.drawRect(new RectF(leftArcRect.centerX(), rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f, rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint); break; case DRAW_RECT_WITH_CURVE_ON_RIGHT: int rightRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1 ? (int) (colCenterRtl - horDistFromCenter) + 1 : (int) (colCenterRtl - horDistFromCenter); int rightRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1 ? (int) (colCenterRtl + horDistFromCenter) + 1 : (int) (colCenterRtl + horDistFromCenter); RectF rightArcRect = new RectF(rightRectArcLeft, rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightRectArcRight, rowCenter + rowHeight / 2f - mPaddingRangeIndicator); canvas.drawArc(rightArcRect, 270, 180, true, mDayRangeSelectorPaint); canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f, rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightArcRect.centerX(), rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint); break; default: canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f, rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f, rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint); break; } } if (mTouchedItem == day) { stateMask |= SUtils.STATE_PRESSED; if (isDayEnabled) { canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint); } } final boolean isDayToday = mToday == day; final int dayTextColor; if (isDayToday && !isDayInActivatedRange) { dayTextColor = mDaySelectorPaint.getColor(); } else { final int[] stateSet = SUtils.resolveStateSet(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; } } }
From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.SimpleMonthView.java
/** * Draws the month days.// w ww . j a v a 2 s.co m */ @SuppressWarnings("ConstantConditions") private void drawDays(Canvas canvas) { final TextPaint p = mDayPaint; final int headerHeight = mMonthHeight + mDayOfWeekHeight; final float rowHeight = mDayHeight; final float colWidth = mCellWidth; // Text is vertically centered within the row height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; // int rowCenter = headerHeight + rowHeight / 2; float rowCenter = headerHeight + rowHeight / 2f; //mDaysInMonth303129 for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) { final float colCenter = colWidth * col + colWidth / 2f; //final int colCenterRtl; final float colCenterRtl; if (SUtils.isLayoutRtlCompat(this)) { colCenterRtl = mPaddedWidth - colCenter; } else { colCenterRtl = colCenter; } int stateMask = 0; final boolean isDayEnabled = isDayEnabled(day); if (isDayEnabled) { stateMask |= SUtils.STATE_ENABLED; } final boolean isDayInActivatedRange = mActivatedDays.isValid() && mActivatedDays.isActivated(day); final boolean isSelected = mActivatedDays.isSelected(day); final boolean isSelectedAndTogether = mActivatedDays.isSelectedAndTogether(day); if (isSelectedAndTogether) { if ((!disable && !isDisable) || isFill) { stateMask |= SUtils.STATE_ACTIVATED; canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint); } } if (!isSelected && isDayInActivatedRange) { stateMask |= SUtils.STATE_ACTIVATED; int bgShape = DRAW_RECT; if (mActivatedDays.isSingleDay()) { if (mActivatedDays.isStartOfMonth()) { bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT; } else { bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT; } } else if (mActivatedDays.isStartingDayOfRange(day)) { bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT; } else if (mActivatedDays.isEndingDayOfRange(day)) { bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT; } // Use height to constrain the protrusion of the arc boolean constrainProtrusion = colWidth > (rowHeight - (2 * mPaddingRangeIndicator)); float horDistFromCenter = constrainProtrusion ? rowHeight / 2f - mPaddingRangeIndicator : colWidth / 2f; switch (bgShape) { case DRAW_RECT_WITH_CURVE_ON_LEFT: int leftRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1 ? (int) (colCenterRtl - horDistFromCenter) + 1 : (int) (colCenterRtl - horDistFromCenter); int leftRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1 ? (int) (colCenterRtl + horDistFromCenter) + 1 : (int) (colCenterRtl + horDistFromCenter); RectF leftArcRect = new RectF(leftRectArcLeft, rowCenter - rowHeight / 2f + mPaddingRangeIndicator, leftRectArcRight, rowCenter + rowHeight / 2f - mPaddingRangeIndicator); canvas.drawArc(leftArcRect, 90, 180, true, mDayRangeSelectorPaint); canvas.drawRect(new RectF(leftArcRect.centerX(), rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f, rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint); break; case DRAW_RECT_WITH_CURVE_ON_RIGHT: int rightRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1 ? (int) (colCenterRtl - horDistFromCenter) + 1 : (int) (colCenterRtl - horDistFromCenter); int rightRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1 ? (int) (colCenterRtl + horDistFromCenter) + 1 : (int) (colCenterRtl + horDistFromCenter); RectF rightArcRect = new RectF(rightRectArcLeft, rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightRectArcRight, rowCenter + rowHeight / 2f - mPaddingRangeIndicator); canvas.drawArc(rightArcRect, 270, 180, true, mDayRangeSelectorPaint); canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f, rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightArcRect.centerX(), rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint); break; default: canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f, rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f, rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint); break; } } final boolean isDayToday = mToday == day; final int dayTextColor; if (isDayToday) { if (mActivatedDays.isClick && isSelected) { final int[] stateSet = SUtils.resolveStateSet(stateMask); dayTextColor = mDayTextColor.getColorForState(stateSet, 0); } else { dayTextColor = mDaySelectorPaint.getColor(); } } else { final int[] stateSet = SUtils.resolveStateSet(stateMask); if (!mActivatedDays.isSingleDay()) { if (stateMask == 1) { dayTextColor = mContext.getResources().getColor(R.color.textDarkfour); } else { dayTextColor = mDayTextColor.getColorForState(stateSet, 0); } } else { 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; } if (mDaysInMonth == day) mOnRangeClickListener.onRangeSelected(calendars, position); } }
From source file:org.telegram.ui.ArticleViewer.java
private TextPaint getTextPaint(TLRPC.RichText parentRichText, TLRPC.RichText richText, TLRPC.PageBlock parentBlock) {//ww w . ja va 2 s . com int flags = getTextFlags(richText); HashMap<Integer, TextPaint> currentMap = null; int textSize = AndroidUtilities.dp(14); int textColor = 0xffff0000; if (parentBlock instanceof TLRPC.TL_pageBlockPhoto) { currentMap = captionTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockTitle) { currentMap = titleTextPaints; textSize = AndroidUtilities.dp(24); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockAuthorDate) { currentMap = authorTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockFooter) { currentMap = footerTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockSubtitle) { currentMap = subtitleTextPaints; textSize = AndroidUtilities.dp(21); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockHeader) { currentMap = headerTextPaints; textSize = AndroidUtilities.dp(21); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockSubheader) { currentMap = subheaderTextPaints; textSize = AndroidUtilities.dp(18); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockBlockquote || parentBlock instanceof TLRPC.TL_pageBlockPullquote) { if (parentBlock.text == parentRichText) { currentMap = quoteTextPaints; textSize = AndroidUtilities.dp(15); textColor = 0xff000000; } else if (parentBlock.caption == parentRichText) { currentMap = subquoteTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } } else if (parentBlock instanceof TLRPC.TL_pageBlockPreformatted) { currentMap = preformattedTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockParagraph) { if (parentBlock.caption == parentRichText) { currentMap = embedPostCaptionTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else { currentMap = paragraphTextPaints; textSize = AndroidUtilities.dp(16); textColor = 0xff000000; } } else if (parentBlock instanceof TLRPC.TL_pageBlockList) { currentMap = listTextPaints; textSize = AndroidUtilities.dp(15); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockEmbed) { currentMap = embedTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockSlideshow) { currentMap = slideshowTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockEmbedPost) { if (richText != null) { currentMap = embedPostTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } } else if (parentBlock instanceof TLRPC.TL_pageBlockVideo) { currentMap = videoTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } if (currentMap == null) { if (errorTextPaint == null) { errorTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); errorTextPaint.setColor(0xffff0000); } errorTextPaint.setTextSize(AndroidUtilities.dp(14)); return errorTextPaint; } TextPaint paint = currentMap.get(flags); if (paint == null) { paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); if ((flags & TEXT_FLAG_MONO) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmono.ttf")); } else { if (parentBlock instanceof TLRPC.TL_pageBlockTitle || parentBlock instanceof TLRPC.TL_pageBlockHeader || parentBlock instanceof TLRPC.TL_pageBlockSubtitle || parentBlock instanceof TLRPC.TL_pageBlockSubheader) { if ((flags & TEXT_FLAG_MEDIUM) != 0 && (flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.BOLD_ITALIC)); } else if ((flags & TEXT_FLAG_MEDIUM) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.BOLD)); } else if ((flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.ITALIC)); } else { paint.setTypeface(Typeface.create("serif", Typeface.NORMAL)); } } else { if ((flags & TEXT_FLAG_MEDIUM) != 0 && (flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmediumitalic.ttf")); } else if ((flags & TEXT_FLAG_MEDIUM) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); } else if ((flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/ritalic.ttf")); } } } if ((flags & TEXT_FLAG_STRIKE) != 0) { paint.setFlags(paint.getFlags() | TextPaint.STRIKE_THRU_TEXT_FLAG); } if ((flags & TEXT_FLAG_UNDERLINE) != 0) { paint.setFlags(paint.getFlags() | TextPaint.UNDERLINE_TEXT_FLAG); } if ((flags & TEXT_FLAG_URL) != 0) { textColor = 0xff4d83b3; } paint.setColor(textColor); currentMap.put(flags, paint); } paint.setTextSize(textSize); return paint; }