/** * Set the selected date of this DatePicker. * * @param day The day value of selected date. * @param month The month value of selected date. * @param year The year value of selected date. */ public void setDate(int day, int month, int year) { if (mAdapter.getYear() == year && mAdapter.getMonth() == month && mAdapter.getDay() == day) return; mAdapter.setDate(day, month, year, false); goTo(month, year); }
public void changeSelection(final int index, final int position) { for (int i = 0; i < days.lstDays.size(); i++) { if (index != monthIndex) { days.lstDays.get(i).selected = false; } else { days.lstDays.get(i).selected = (i == position); } } adapter.notifyDataSetChanged(); }
@Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Day d = days.lstDays.get(position); for (int i = 0; i < days.lstDays.size(); i++) { days.lstDays.get(i).selected = false; } days.lstDays.get(position).selected = true; adapter.notifyDataSetChanged(); if (listener != null) { listener.onDayClick(monthIndex, position, d); } }
public void setCalendarItem(List<CalendarItem> listItems) { adapter.setCalendarItem(listItems); }
/** * Get the formatted string of selected date. * * @param formatter The DateFormat used to format the date. * @return */ public String getFormattedDate(DateFormat formatter) { mCalendar.set(Calendar.YEAR, mAdapter.getYear()); mCalendar.set(Calendar.MONTH, mAdapter.getMonth()); mCalendar.set(Calendar.DAY_OF_MONTH, mAdapter.getDay()); return formatter.format(mCalendar.getTime()); }
/** @return The year value of selected date. */ public int getYear() { return mAdapter.getYear(); }
/** @return The month value of selected date. */ public int getMonth() { return mAdapter.getMonth(); }
/** @return The day value of selected date. */ public int getDay() { return mAdapter.getDay(); }
/** * Jump to the view of a specific month. * * @param month * @param year */ public void goTo(int month, int year) { int position = mAdapter.positionOfMonth(month, year); postSetSelectionFromTop(position, 0); }
/** * Set the range of selectable dates. * * @param minDay The day value of minimum date. * @param minMonth The month value of minimum date. * @param minYear The year value of minimum date. * @param maxDay The day value of maximum date. * @param maxMonth The month value of maximum date. * @param maxYear The year value of maximum date. */ public void setDateRange( int minDay, int minMonth, int minYear, int maxDay, int maxMonth, int maxYear) { mAdapter.setDateRange(minDay, minMonth, minYear, maxDay, maxMonth, maxYear); }
@Override protected void applyStyle( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super.applyStyle(context, attrs, defStyleAttr, defStyleRes); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePicker, defStyleAttr, defStyleRes); String familyName = null; int style = -1; int padding = -1; int paddingLeft = -1; int paddingRight = -1; int paddingTop = -1; int paddingBottom = -1; boolean paddingDefined = false; for (int i = 0, count = a.getIndexCount(); i < count; i++) { int attr = a.getIndex(i); if (attr == R.styleable.DatePicker_dp_dayTextSize) mTextSize = a.getDimensionPixelSize(attr, 0); else if (attr == R.styleable.DatePicker_dp_textColor) mTextColor = a.getColor(attr, 0); else if (attr == R.styleable.DatePicker_dp_textHighlightColor) mTextHighlightColor = a.getColor(attr, 0); else if (attr == R.styleable.DatePicker_dp_textLabelColor) mTextLabelColor = a.getColor(attr, 0); else if (attr == R.styleable.DatePicker_dp_textDisableColor) mTextDisableColor = a.getColor(attr, 0); else if (attr == R.styleable.DatePicker_dp_selectionColor) mSelectionColor = a.getColor(attr, 0); else if (attr == R.styleable.DatePicker_dp_animDuration) mAnimDuration = a.getInteger(attr, 0); else if (attr == R.styleable.DatePicker_dp_inInterpolator) mInInterpolator = AnimationUtils.loadInterpolator(context, a.getResourceId(attr, 0)); else if (attr == R.styleable.DatePicker_dp_outInterpolator) mOutInterpolator = AnimationUtils.loadInterpolator(context, a.getResourceId(attr, 0)); else if (attr == R.styleable.DatePicker_dp_fontFamily) familyName = a.getString(attr); else if (attr == R.styleable.DatePicker_dp_textStyle) style = a.getInteger(attr, 0); else if (attr == R.styleable.DatePicker_android_padding) { padding = a.getDimensionPixelSize(attr, 0); paddingDefined = true; } else if (attr == R.styleable.DatePicker_android_paddingLeft) { paddingLeft = a.getDimensionPixelSize(attr, 0); paddingDefined = true; } else if (attr == R.styleable.DatePicker_android_paddingTop) { paddingTop = a.getDimensionPixelSize(attr, 0); paddingDefined = true; } else if (attr == R.styleable.DatePicker_android_paddingRight) { paddingRight = a.getDimensionPixelSize(attr, 0); paddingDefined = true; } else if (attr == R.styleable.DatePicker_android_paddingBottom) { paddingBottom = a.getDimensionPixelSize(attr, 0); paddingDefined = true; } } if (mTextSize < 0) mTextSize = context.getResources().getDimensionPixelOffset(R.dimen.abc_text_size_caption_material); if (mAnimDuration < 0) mAnimDuration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime); if (mInInterpolator == null) mInInterpolator = new DecelerateInterpolator(); if (mOutInterpolator == null) mOutInterpolator = new DecelerateInterpolator(); if (familyName != null || style >= 0) mTypeface = TypefaceUtil.load(context, familyName, style); a.recycle(); if (paddingDefined) { if (padding >= 0) setContentPadding(padding, padding, padding, padding); if (paddingLeft >= 0) mPaddingLeft = paddingLeft; if (paddingTop >= 0) mPaddingTop = paddingTop; if (paddingRight >= 0) mPaddingRight = paddingRight; if (paddingBottom >= 0) mPaddingBottom = paddingBottom; } requestLayout(); mAdapter.notifyDataSetInvalidated(); }