Methods Summary |
---|
private int | calculateNumRows()
int offset = findDayOffset();
int dividend = (offset + mNumCells) / mNumDays;
int remainder = (offset + mNumCells) % mNumDays;
return (dividend + (remainder > 0 ? 1 : 0));
|
public void | clearAccessibilityFocus()Clears accessibility focus within the view. No-op if the view does not
contain accessibility focus.
mTouchHelper.clearFocusedVirtualView();
|
public boolean | dispatchHoverEvent(android.view.MotionEvent event)
// First right-of-refusal goes the touch exploration helper.
if (mTouchHelper.dispatchHoverEvent(event)) {
return true;
}
return super.dispatchHoverEvent(event);
|
private void | drawDays(android.graphics.Canvas canvas)Draws the month days.
int y = (((mRowHeight + mMiniDayNumberTextSize) / 2) - DAY_SEPARATOR_WIDTH)
+ mMonthHeaderSize;
int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);
int j = findDayOffset();
for (int day = 1; day <= mNumCells; day++) {
int x = (2 * j + 1) * dayWidthHalf + mPadding;
if (mSelectedDay == day) {
canvas.drawCircle(x, y - (mMiniDayNumberTextSize / 3), mDaySelectedCircleSize,
mDayNumberSelectedPaint);
}
if (mHasToday && mToday == day) {
mDayNumberPaint.setColor(mSelectedDayColor);
} else {
mDayNumberPaint.setColor(mNormalTextColor);
}
final Paint paint = (day < mEnabledDayStart || day > mEnabledDayEnd) ?
mDayNumberDisabledPaint : mDayNumberPaint;
canvas.drawText(String.format("%d", day), x, y, paint);
j++;
if (j == mNumDays) {
j = 0;
y += mRowHeight;
}
}
|
private void | drawMonthTitle(android.graphics.Canvas canvas)
final float x = (mWidth + 2 * mPadding) / 2f;
final float y = (mMonthHeaderSize - mMonthDayLabelTextSize) / 2f;
canvas.drawText(getMonthAndYearString(), x, y, mMonthTitlePaint);
|
private void | drawWeekDayLabels(android.graphics.Canvas canvas)
final int y = mMonthHeaderSize - (mMonthDayLabelTextSize / 2);
final int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);
for (int i = 0; i < mNumDays; i++) {
final int calendarDay = (i + mWeekStart) % mNumDays;
mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);
final String dayLabel = mDayFormatter.format(mDayLabelCalendar.getTime());
final int x = (2 * i + 1) * dayWidthHalf + mPadding;
canvas.drawText(dayLabel, x, y, mMonthDayLabelPaint);
}
|
private int | findDayOffset()
return (mDayOfWeekStart < mWeekStart ? (mDayOfWeekStart + mNumDays) : mDayOfWeekStart)
- mWeekStart;
|
java.util.Calendar | getAccessibilityFocus()
final int day = mTouchHelper.getFocusedVirtualView();
Calendar date = null;
if (day >= 0) {
date = Calendar.getInstance();
date.set(mYear, mMonth, day);
}
return date;
|
private int | getDayFromLocation(float x, float y)Calculates the day that the given x position is in, accounting for week
number. Returns the day or -1 if the position wasn't in a day.
int dayStart = mPadding;
if (x < dayStart || x > mWidth - mPadding) {
return -1;
}
// Selection is (x - start) / (pixels/day) == (x -s) * day / pixels
int row = (int) (y - mMonthHeaderSize) / mRowHeight;
int column = (int) ((x - dayStart) * mNumDays / (mWidth - dayStart - mPadding));
int day = column - findDayOffset() + 1;
day += row * mNumDays;
if (day < 1 || day > mNumCells) {
return -1;
}
return day;
|
private static int | getDaysInMonth(int month, int year)
switch (month) {
case Calendar.JANUARY:
case Calendar.MARCH:
case Calendar.MAY:
case Calendar.JULY:
case Calendar.AUGUST:
case Calendar.OCTOBER:
case Calendar.DECEMBER:
return 31;
case Calendar.APRIL:
case Calendar.JUNE:
case Calendar.SEPTEMBER:
case Calendar.NOVEMBER:
return 30;
case Calendar.FEBRUARY:
return (year % 4 == 0) ? 29 : 28;
default:
throw new IllegalArgumentException("Invalid Month");
}
|
private java.lang.String | getMonthAndYearString()
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR
| DateUtils.FORMAT_NO_MONTH_DAY;
mStringBuilder.setLength(0);
long millis = mCalendar.getTimeInMillis();
return DateUtils.formatDateRange(getContext(), mFormatter, millis, millis, flags,
Time.getCurrentTimezone()).toString();
|
private void | initView()Sets up the text and style properties for painting.
mMonthTitlePaint = new Paint();
mMonthTitlePaint.setAntiAlias(true);
mMonthTitlePaint.setColor(mNormalTextColor);
mMonthTitlePaint.setTextSize(mMonthLabelTextSize);
mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
mMonthTitlePaint.setTextAlign(Align.CENTER);
mMonthTitlePaint.setStyle(Style.FILL);
mMonthTitlePaint.setFakeBoldText(true);
mMonthDayLabelPaint = new Paint();
mMonthDayLabelPaint.setAntiAlias(true);
mMonthDayLabelPaint.setColor(mNormalTextColor);
mMonthDayLabelPaint.setTextSize(mMonthDayLabelTextSize);
mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
mMonthDayLabelPaint.setTextAlign(Align.CENTER);
mMonthDayLabelPaint.setStyle(Style.FILL);
mMonthDayLabelPaint.setFakeBoldText(true);
mDayNumberSelectedPaint = new Paint();
mDayNumberSelectedPaint.setAntiAlias(true);
mDayNumberSelectedPaint.setColor(mSelectedDayColor);
mDayNumberSelectedPaint.setAlpha(SELECTED_CIRCLE_ALPHA);
mDayNumberSelectedPaint.setTextAlign(Align.CENTER);
mDayNumberSelectedPaint.setStyle(Style.FILL);
mDayNumberSelectedPaint.setFakeBoldText(true);
mDayNumberPaint = new Paint();
mDayNumberPaint.setAntiAlias(true);
mDayNumberPaint.setTextSize(mMiniDayNumberTextSize);
mDayNumberPaint.setTextAlign(Align.CENTER);
mDayNumberPaint.setStyle(Style.FILL);
mDayNumberPaint.setFakeBoldText(false);
mDayNumberDisabledPaint = new Paint();
mDayNumberDisabledPaint.setAntiAlias(true);
mDayNumberDisabledPaint.setColor(mDisabledTextColor);
mDayNumberDisabledPaint.setTextSize(mMiniDayNumberTextSize);
mDayNumberDisabledPaint.setTextAlign(Align.CENTER);
mDayNumberDisabledPaint.setStyle(Style.FILL);
mDayNumberDisabledPaint.setFakeBoldText(false);
|
private static boolean | isValidDayOfWeek(int day)
return day >= Calendar.SUNDAY && day <= Calendar.SATURDAY;
|
private static boolean | isValidMonth(int month)
return month >= Calendar.JANUARY && month <= Calendar.DECEMBER;
|
protected void | onConfigurationChanged(android.content.res.Configuration newConfig)
super.onConfigurationChanged(newConfig);
mDayFormatter = new SimpleDateFormat("EEEEE", newConfig.locale);
|
private void | onDayClick(int day)Called when the user clicks on a day. Handles callbacks to the
{@link OnDayClickListener} if one is set.
if (mOnDayClickListener != null) {
Calendar date = Calendar.getInstance();
date.set(mYear, mMonth, day);
mOnDayClickListener.onDayClick(this, date);
}
// This is a no-op if accessibility is turned off.
mTouchHelper.sendEventForVirtualView(day, AccessibilityEvent.TYPE_VIEW_CLICKED);
|
protected void | onDraw(android.graphics.Canvas canvas)
drawMonthTitle(canvas);
drawWeekDayLabels(canvas);
drawDays(canvas);
|
protected void | onMeasure(int widthMeasureSpec, int heightMeasureSpec)
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mRowHeight * mNumRows
+ mMonthHeaderSize);
|
protected void | onSizeChanged(int w, int h, int oldw, int oldh)
mWidth = w;
// Invalidate cached accessibility information.
mTouchHelper.invalidateRoot();
|
public boolean | onTouchEvent(android.view.MotionEvent event)
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
final int day = getDayFromLocation(event.getX(), event.getY());
if (day >= 0) {
onDayClick(day);
}
break;
}
return true;
|
boolean | restoreAccessibilityFocus(java.util.Calendar day)Attempts to restore accessibility focus to the specified date.
if ((day.get(Calendar.YEAR) != mYear) || (day.get(Calendar.MONTH) != mMonth) ||
(day.get(Calendar.DAY_OF_MONTH) > mNumCells)) {
return false;
}
mTouchHelper.setFocusedVirtualView(day.get(Calendar.DAY_OF_MONTH));
return true;
|
public void | reuse()
mNumRows = DEFAULT_NUM_ROWS;
requestLayout();
|
private boolean | sameDay(int day, android.text.format.Time today)
return mYear == today.year &&
mMonth == today.month &&
day == today.monthDay;
|
public void | setAccessibilityDelegate(AccessibilityDelegate delegate)
// Workaround for a JB MR1 issue where accessibility delegates on
// top-level ListView items are overwritten.
if (!mLockAccessibilityDelegate) {
super.setAccessibilityDelegate(delegate);
}
|
void | setMonthParams(int selectedDay, int month, int year, int weekStart, int enabledDayStart, int enabledDayEnd)Sets all the parameters for displaying this week. Parameters have a default value and
will only update if a new value is included, except for focus month, which will always
default to no focus month if no value is passed in. The only required parameter is the
week start.
if (mRowHeight < MIN_HEIGHT) {
mRowHeight = MIN_HEIGHT;
}
mSelectedDay = selectedDay;
if (isValidMonth(month)) {
mMonth = month;
}
mYear = year;
// Figure out what day today is
final Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
mHasToday = false;
mToday = -1;
mCalendar.set(Calendar.MONTH, mMonth);
mCalendar.set(Calendar.YEAR, mYear);
mCalendar.set(Calendar.DAY_OF_MONTH, 1);
mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);
if (isValidDayOfWeek(weekStart)) {
mWeekStart = weekStart;
} else {
mWeekStart = mCalendar.getFirstDayOfWeek();
}
if (enabledDayStart > 0 && enabledDayEnd < 32) {
mEnabledDayStart = enabledDayStart;
}
if (enabledDayEnd > 0 && enabledDayEnd < 32 && enabledDayEnd >= enabledDayStart) {
mEnabledDayEnd = enabledDayEnd;
}
mNumCells = getDaysInMonth(mMonth, mYear);
for (int i = 0; i < mNumCells; i++) {
final int day = i + 1;
if (sameDay(day, today)) {
mHasToday = true;
mToday = day;
}
}
mNumRows = calculateNumRows();
// Invalidate cached accessibility information.
mTouchHelper.invalidateRoot();
|
public void | setOnDayClickListener(android.widget.SimpleMonthView$OnDayClickListener listener)
mOnDayClickListener = listener;
|
void | setTextColor(android.content.res.ColorStateList colors)
final Resources res = getContext().getResources();
mNormalTextColor = colors.getColorForState(ENABLED_STATE_SET,
res.getColor(R.color.datepicker_default_normal_text_color_holo_light));
mMonthTitlePaint.setColor(mNormalTextColor);
mMonthDayLabelPaint.setColor(mNormalTextColor);
mDisabledTextColor = colors.getColorForState(EMPTY_STATE_SET,
res.getColor(R.color.datepicker_default_disabled_text_color_holo_light));
mDayNumberDisabledPaint.setColor(mDisabledTextColor);
mSelectedDayColor = colors.getColorForState(ENABLED_SELECTED_STATE_SET,
res.getColor(R.color.holo_blue_light));
mDayNumberSelectedPaint.setColor(mSelectedDayColor);
mDayNumberSelectedPaint.setAlpha(SELECTED_CIRCLE_ALPHA);
|