Fields Summary |
---|
private static final String | TAG |
public static final String | VIEW_PARAMS_HEIGHTThis sets the height of this week in pixels |
public static final String | VIEW_PARAMS_MONTHThis specifies the position (or weeks since the epoch) of this week,
calculated using {@link Utils#getWeeksSinceEpochFromJulianDay} |
public static final String | VIEW_PARAMS_YEARThis specifies the position (or weeks since the epoch) of this week,
calculated using {@link Utils#getWeeksSinceEpochFromJulianDay} |
public static final String | VIEW_PARAMS_SELECTED_DAYThis sets one of the days in this view as selected {@link Time#SUNDAY}
through {@link Time#SATURDAY}. |
public static final String | VIEW_PARAMS_WEEK_STARTWhich day the week should start on. {@link Time#SUNDAY} through
{@link Time#SATURDAY}. |
public static final String | VIEW_PARAMS_NUM_DAYSHow many days to display at a time. Days will be displayed starting with
{@link #mWeekStart}. |
public static final String | VIEW_PARAMS_FOCUS_MONTHWhich month is currently in focus, as defined by {@link Time#month}
[0-11]. |
public static final String | VIEW_PARAMS_SHOW_WK_NUMIf this month should display week numbers. false if 0, true otherwise. |
protected static int | DEFAULT_HEIGHT |
protected static int | MIN_HEIGHT |
protected static final int | DEFAULT_SELECTED_DAY |
protected static final int | DEFAULT_WEEK_START |
protected static final int | DEFAULT_NUM_DAYS |
protected static final int | DEFAULT_SHOW_WK_NUM |
protected static final int | DEFAULT_FOCUS_MONTH |
protected static final int | DEFAULT_NUM_ROWS |
protected static final int | MAX_NUM_ROWS |
private static final int | SELECTED_CIRCLE_ALPHA |
protected static int | DAY_SEPARATOR_WIDTH |
protected static int | MINI_DAY_NUMBER_TEXT_SIZE |
protected static int | MONTH_LABEL_TEXT_SIZE |
protected static int | MONTH_DAY_LABEL_TEXT_SIZE |
protected static int | MONTH_HEADER_SIZE |
protected static int | DAY_SELECTED_CIRCLE_SIZE |
protected static float | mScale |
protected DatePickerController | mController |
protected int | mEdgePadding |
private String | mDayOfWeekTypeface |
private String | mMonthTitleTypeface |
protected android.graphics.Paint | mMonthNumPaint |
protected android.graphics.Paint | mMonthTitlePaint |
protected android.graphics.Paint | mMonthTitleBGPaint |
protected android.graphics.Paint | mSelectedCirclePaint |
protected android.graphics.Paint | mMonthDayLabelPaint |
private final Formatter | mFormatter |
private final StringBuilder | mStringBuilder |
protected int | mFirstJulianDay |
protected int | mFirstMonth |
protected int | mLastMonth |
protected int | mMonth |
protected int | mYear |
protected int | mWidth |
protected int | mRowHeight |
protected boolean | mHasToday |
protected int | mSelectedDay |
protected int | mToday |
protected int | mWeekStart |
protected int | mNumDays |
protected int | mNumCells |
protected int | mSelectedLeft |
protected int | mSelectedRight |
private final Calendar | mCalendar |
protected final Calendar | mDayLabelCalendar |
private final MonthViewTouchHelper | mTouchHelper |
protected int | mNumRows |
protected OnDayClickListener | mOnDayClickListener |
private boolean | mLockAccessibilityDelegate |
protected int | mDayTextColor |
protected int | mTodayNumberColor |
protected int | mDisabledDayTextColor |
protected int | mMonthTitleColor |
protected int | mMonthTitleBGColor |
private int | mDayOfWeekStart |
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);
|
public abstract void | drawMonthDay(android.graphics.Canvas canvas, int year, int month, int day, int x, int y, int startX, int stopX, int startY, int stopY)This method should draw the month day. Implemented by sub-classes to allow customization.
|
protected void | drawMonthDayLabels(android.graphics.Canvas canvas)
int y = getMonthHeaderSize() - (MONTH_DAY_LABEL_TEXT_SIZE / 2);
int dayWidthHalf = (mWidth - mEdgePadding * 2) / (mNumDays * 2);
for (int i = 0; i < mNumDays; i++) {
int calendarDay = (i + mWeekStart) % mNumDays;
int x = (2 * i + 1) * dayWidthHalf + mEdgePadding;
mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);
canvas.drawText(mDayLabelCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT,
Locale.getDefault()).toUpperCase(Locale.getDefault()), x, y,
mMonthDayLabelPaint);
}
|
protected void | drawMonthNums(android.graphics.Canvas canvas)Draws the week and month day numbers for this week. Override this method
if you need different placement.
int y = (((mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2) - DAY_SEPARATOR_WIDTH)
+ getMonthHeaderSize();
final float dayWidthHalf = (mWidth - mEdgePadding * 2) / (mNumDays * 2.0f);
int j = findDayOffset();
for (int dayNumber = 1; dayNumber <= mNumCells; dayNumber++) {
final int x = (int)((2 * j + 1) * dayWidthHalf + mEdgePadding);
int yRelativeToDay = (mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2 - DAY_SEPARATOR_WIDTH;
final int startX = (int)(x - dayWidthHalf);
final int stopX = (int)(x + dayWidthHalf);
final int startY = (int)(y - yRelativeToDay);
final int stopY = (int)(startY + mRowHeight);
drawMonthDay(canvas, mYear, mMonth, dayNumber, x, y, startX, stopX, startY, stopY);
j++;
if (j == mNumDays) {
j = 0;
y += mRowHeight;
}
}
|
protected void | drawMonthTitle(android.graphics.Canvas canvas)
int x = (mWidth + 2 * mEdgePadding) / 2;
int y = (getMonthHeaderSize() - MONTH_DAY_LABEL_TEXT_SIZE) / 2 + (MONTH_LABEL_TEXT_SIZE / 3);
canvas.drawText(getMonthAndYearString(), x, y, mMonthTitlePaint);
|
protected int | findDayOffset()
return (mDayOfWeekStart < mWeekStart ? (mDayOfWeekStart + mNumDays) : mDayOfWeekStart)
- mWeekStart;
|
public com.android.datetimepicker.date.MonthAdapter.CalendarDay | getAccessibilityFocus()
final int day = mTouchHelper.getFocusedVirtualView();
if (day >= 0) {
return new CalendarDay(mYear, mMonth, day);
}
return null;
|
public 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.
final int day = getInternalDayFromLocation(x, y);
if (day < 1 || day > mNumCells) {
return -1;
}
return day;
|
protected int | getInternalDayFromLocation(float x, float y)Calculates the day that the given x position is in, accounting for week
number.
int dayStart = mEdgePadding;
if (x < dayStart || x > mWidth - mEdgePadding) {
return -1;
}
// Selection is (x - start) / (pixels/day) == (x -s) * day / pixels
int row = (int) (y - getMonthHeaderSize()) / mRowHeight;
int column = (int) ((x - dayStart) * mNumDays / (mWidth - dayStart - mEdgePadding));
int day = column - findDayOffset() + 1;
day += row * mNumDays;
return day;
|
public int | getMonth()
return mMonth;
|
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();
|
protected int | getMonthHeaderSize()A wrapper to the MonthHeaderSize to allow override it in children
return MONTH_HEADER_SIZE;
|
protected com.android.datetimepicker.date.MonthView$MonthViewTouchHelper | getMonthViewTouchHelper()
return new MonthViewTouchHelper(this);
|
public int | getYear()
return mYear;
|
protected void | initView()Sets up the text and style properties for painting. Override this if you
want to use a different paint.
mMonthTitlePaint = new Paint();
mMonthTitlePaint.setFakeBoldText(true);
mMonthTitlePaint.setAntiAlias(true);
mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
mMonthTitlePaint.setColor(mDayTextColor);
mMonthTitlePaint.setTextAlign(Align.CENTER);
mMonthTitlePaint.setStyle(Style.FILL);
mMonthTitleBGPaint = new Paint();
mMonthTitleBGPaint.setFakeBoldText(true);
mMonthTitleBGPaint.setAntiAlias(true);
mMonthTitleBGPaint.setColor(mMonthTitleBGColor);
mMonthTitleBGPaint.setTextAlign(Align.CENTER);
mMonthTitleBGPaint.setStyle(Style.FILL);
mSelectedCirclePaint = new Paint();
mSelectedCirclePaint.setFakeBoldText(true);
mSelectedCirclePaint.setAntiAlias(true);
mSelectedCirclePaint.setColor(mTodayNumberColor);
mSelectedCirclePaint.setTextAlign(Align.CENTER);
mSelectedCirclePaint.setStyle(Style.FILL);
mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);
mMonthDayLabelPaint = new Paint();
mMonthDayLabelPaint.setAntiAlias(true);
mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
mMonthDayLabelPaint.setColor(mDayTextColor);
mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
mMonthDayLabelPaint.setStyle(Style.FILL);
mMonthDayLabelPaint.setTextAlign(Align.CENTER);
mMonthDayLabelPaint.setFakeBoldText(true);
mMonthNumPaint = new Paint();
mMonthNumPaint.setAntiAlias(true);
mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
mMonthNumPaint.setStyle(Style.FILL);
mMonthNumPaint.setTextAlign(Align.CENTER);
mMonthNumPaint.setFakeBoldText(false);
|
private boolean | isAfterMax(int year, int month, int day)
if (mController == null) {
return false;
}
Calendar maxDate = mController.getMaxDate();
if (maxDate == null) {
return false;
}
if (year > maxDate.get(Calendar.YEAR)) {
return true;
} else if (year < maxDate.get(Calendar.YEAR)) {
return false;
}
if (month > maxDate.get(Calendar.MONTH)) {
return true;
} else if (month < maxDate.get(Calendar.MONTH)) {
return false;
}
if (day > maxDate.get(Calendar.DAY_OF_MONTH)) {
return true;
} else {
return false;
}
|
private boolean | isBeforeMin(int year, int month, int day)
if (mController == null) {
return false;
}
Calendar minDate = mController.getMinDate();
if (minDate == null) {
return false;
}
if (year < minDate.get(Calendar.YEAR)) {
return true;
} else if (year > minDate.get(Calendar.YEAR)) {
return false;
}
if (month < minDate.get(Calendar.MONTH)) {
return true;
} else if (month > minDate.get(Calendar.MONTH)) {
return false;
}
if (day < minDate.get(Calendar.DAY_OF_MONTH)) {
return true;
} else {
return false;
}
|
protected boolean | isOutOfRange(int year, int month, int day)
if (isBeforeMin(year, month, day)) {
return true;
} else if (isAfterMax(year, month, day)) {
return true;
}
return false;
|
private void | onDayClick(int day)Called when the user clicks on a day. Handles callbacks to the
{@link OnDayClickListener} if one is set.
If the day is out of the range set by minDate and/or maxDate, this is a no-op.
// If the min / max date are set, only process the click if it's a valid selection.
if (isOutOfRange(mYear, mMonth, day)) {
return;
}
if (mOnDayClickListener != null) {
mOnDayClickListener.onDayClick(this, new CalendarDay(mYear, mMonth, day));
}
// 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);
drawMonthDayLabels(canvas);
drawMonthNums(canvas);
|
protected void | onMeasure(int widthMeasureSpec, int heightMeasureSpec)
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mRowHeight * mNumRows
+ getMonthHeaderSize());
|
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;
|
public boolean | restoreAccessibilityFocus(com.android.datetimepicker.date.MonthAdapter.CalendarDay day)Attempts to restore accessibility focus to the specified date.
if ((day.year != mYear) || (day.month != mMonth) || (day.day > mNumCells)) {
return false;
}
mTouchHelper.setFocusedVirtualView(day.day);
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);
}
|
public void | setDatePickerController(DatePickerController controller)
mController = controller;
|
public void | setMonthParams(java.util.HashMap params)Sets all the parameters for displaying this week. The only required
parameter is the week number. Other 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. See
{@link #VIEW_PARAMS_HEIGHT} for more info on parameters.
if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
throw new InvalidParameterException("You must specify month and year for this view");
}
setTag(params);
// We keep the current value for any params not present
if (params.containsKey(VIEW_PARAMS_HEIGHT)) {
mRowHeight = params.get(VIEW_PARAMS_HEIGHT);
if (mRowHeight < MIN_HEIGHT) {
mRowHeight = MIN_HEIGHT;
}
}
if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) {
mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY);
}
// Allocate space for caching the day numbers and focus values
mMonth = params.get(VIEW_PARAMS_MONTH);
mYear = params.get(VIEW_PARAMS_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 (params.containsKey(VIEW_PARAMS_WEEK_START)) {
mWeekStart = params.get(VIEW_PARAMS_WEEK_START);
} else {
mWeekStart = mCalendar.getFirstDayOfWeek();
}
mNumCells = Utils.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(com.android.datetimepicker.date.MonthView$OnDayClickListener listener)
mOnDayClickListener = listener;
|
public void | setSelectedDay(int day)
mSelectedDay = day;
|