List of usage examples for android.text TextPaint descent
public float descent()
From source file:com.appeaser.sublimepickerlibrary.datepicker.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 (SUtils.isLayoutRtlCompat(this)) { colCenterRtl = mPaddedWidth - colCenter; } else {//www .j ava 2s . com colCenterRtl = colCenter; } final int dayOfWeek = (col + mWeekStart) % DAYS_IN_WEEK; final String label = getDayOfWeekLabel(dayOfWeek); canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p); } }
From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.SimpleMonthView.java
/** * Draws the month days./*from w w w . j a va2 s .c o 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:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java
/** * Draws the month days.//from ww w . 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 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.android.ex.chips.RecipientEditTextView.java
private static float getTextYOffset(final String text, final TextPaint paint, final int height) { final Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); final int textHeight = bounds.bottom - bounds.top; return height - (height - textHeight) / 2 - (int) paint.descent(); }