1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.widget; 18 19 import android.annotation.AttrRes; 20 import android.annotation.ColorInt; 21 import android.annotation.DrawableRes; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.annotation.StyleRes; 25 import android.annotation.TestApi; 26 import android.annotation.Widget; 27 import android.content.Context; 28 import android.content.res.Configuration; 29 import android.content.res.TypedArray; 30 import android.graphics.Rect; 31 import android.graphics.drawable.Drawable; 32 import android.icu.util.Calendar; 33 import android.icu.util.TimeZone; 34 import android.util.AttributeSet; 35 import android.util.Log; 36 37 import com.android.internal.R; 38 39 import java.text.DateFormat; 40 import java.text.ParseException; 41 import java.text.SimpleDateFormat; 42 import java.util.Date; 43 import java.util.Locale; 44 45 /** 46 * This class is a calendar widget for displaying and selecting dates. The 47 * range of dates supported by this calendar is configurable. 48 * <p> 49 * The exact appearance and interaction model of this widget may vary between 50 * OS versions and themes (e.g. Holo versus Material), but in general a user 51 * can select a date by tapping on it and can scroll or fling the calendar to a 52 * desired date. 53 * 54 * @attr ref android.R.styleable#CalendarView_showWeekNumber 55 * @attr ref android.R.styleable#CalendarView_firstDayOfWeek 56 * @attr ref android.R.styleable#CalendarView_minDate 57 * @attr ref android.R.styleable#CalendarView_maxDate 58 * @attr ref android.R.styleable#CalendarView_shownWeekCount 59 * @attr ref android.R.styleable#CalendarView_selectedWeekBackgroundColor 60 * @attr ref android.R.styleable#CalendarView_focusedMonthDateColor 61 * @attr ref android.R.styleable#CalendarView_unfocusedMonthDateColor 62 * @attr ref android.R.styleable#CalendarView_weekNumberColor 63 * @attr ref android.R.styleable#CalendarView_weekSeparatorLineColor 64 * @attr ref android.R.styleable#CalendarView_selectedDateVerticalBar 65 * @attr ref android.R.styleable#CalendarView_weekDayTextAppearance 66 * @attr ref android.R.styleable#CalendarView_dateTextAppearance 67 */ 68 @Widget 69 public class CalendarView extends FrameLayout { 70 private static final String LOG_TAG = "CalendarView"; 71 72 private static final int MODE_HOLO = 0; 73 private static final int MODE_MATERIAL = 1; 74 75 private final CalendarViewDelegate mDelegate; 76 77 /** 78 * The callback used to indicate the user changes the date. 79 */ 80 public interface OnDateChangeListener { 81 82 /** 83 * Called upon change of the selected day. 84 * 85 * @param view The view associated with this listener. 86 * @param year The year that was set. 87 * @param month The month that was set [0-11]. 88 * @param dayOfMonth The day of the month that was set. 89 */ onSelectedDayChange(@onNull CalendarView view, int year, int month, int dayOfMonth)90 void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth); 91 } 92 CalendarView(@onNull Context context)93 public CalendarView(@NonNull Context context) { 94 this(context, null); 95 } 96 CalendarView(@onNull Context context, @Nullable AttributeSet attrs)97 public CalendarView(@NonNull Context context, @Nullable AttributeSet attrs) { 98 this(context, attrs, R.attr.calendarViewStyle); 99 } 100 CalendarView(@onNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr)101 public CalendarView(@NonNull Context context, @Nullable AttributeSet attrs, 102 @AttrRes int defStyleAttr) { 103 this(context, attrs, defStyleAttr, 0); 104 } 105 CalendarView(@onNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes)106 public CalendarView(@NonNull Context context, @Nullable AttributeSet attrs, 107 @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { 108 super(context, attrs, defStyleAttr, defStyleRes); 109 110 final TypedArray a = context.obtainStyledAttributes( 111 attrs, R.styleable.CalendarView, defStyleAttr, defStyleRes); 112 final int mode = a.getInt(R.styleable.CalendarView_calendarViewMode, MODE_HOLO); 113 a.recycle(); 114 115 switch (mode) { 116 case MODE_HOLO: 117 mDelegate = new CalendarViewLegacyDelegate( 118 this, context, attrs, defStyleAttr, defStyleRes); 119 break; 120 case MODE_MATERIAL: 121 mDelegate = new CalendarViewMaterialDelegate( 122 this, context, attrs, defStyleAttr, defStyleRes); 123 break; 124 default: 125 throw new IllegalArgumentException("invalid calendarViewMode attribute"); 126 } 127 } 128 129 /** 130 * Sets the number of weeks to be shown. 131 * 132 * @param count The shown week count. 133 * 134 * @attr ref android.R.styleable#CalendarView_shownWeekCount 135 * @deprecated No longer used by Material-style CalendarView. 136 */ 137 @Deprecated setShownWeekCount(int count)138 public void setShownWeekCount(int count) { 139 mDelegate.setShownWeekCount(count); 140 } 141 142 /** 143 * Gets the number of weeks to be shown. 144 * 145 * @return The shown week count. 146 * 147 * @attr ref android.R.styleable#CalendarView_shownWeekCount 148 * @deprecated No longer used by Material-style CalendarView. 149 */ 150 @Deprecated getShownWeekCount()151 public int getShownWeekCount() { 152 return mDelegate.getShownWeekCount(); 153 } 154 155 /** 156 * Sets the background color for the selected week. 157 * 158 * @param color The week background color. 159 * 160 * @attr ref android.R.styleable#CalendarView_selectedWeekBackgroundColor 161 * @deprecated No longer used by Material-style CalendarView. 162 */ 163 @Deprecated setSelectedWeekBackgroundColor(@olorInt int color)164 public void setSelectedWeekBackgroundColor(@ColorInt int color) { 165 mDelegate.setSelectedWeekBackgroundColor(color); 166 } 167 168 /** 169 * Gets the background color for the selected week. 170 * 171 * @return The week background color. 172 * 173 * @attr ref android.R.styleable#CalendarView_selectedWeekBackgroundColor 174 * @deprecated No longer used by Material-style CalendarView. 175 */ 176 @ColorInt 177 @Deprecated getSelectedWeekBackgroundColor()178 public int getSelectedWeekBackgroundColor() { 179 return mDelegate.getSelectedWeekBackgroundColor(); 180 } 181 182 /** 183 * Sets the color for the dates of the focused month. 184 * 185 * @param color The focused month date color. 186 * 187 * @attr ref android.R.styleable#CalendarView_focusedMonthDateColor 188 * @deprecated No longer used by Material-style CalendarView. 189 */ 190 @Deprecated setFocusedMonthDateColor(@olorInt int color)191 public void setFocusedMonthDateColor(@ColorInt int color) { 192 mDelegate.setFocusedMonthDateColor(color); 193 } 194 195 /** 196 * Gets the color for the dates in the focused month. 197 * 198 * @return The focused month date color. 199 * 200 * @attr ref android.R.styleable#CalendarView_focusedMonthDateColor 201 * @deprecated No longer used by Material-style CalendarView. 202 */ 203 @ColorInt 204 @Deprecated getFocusedMonthDateColor()205 public int getFocusedMonthDateColor() { 206 return mDelegate.getFocusedMonthDateColor(); 207 } 208 209 /** 210 * Sets the color for the dates of a not focused month. 211 * 212 * @param color A not focused month date color. 213 * 214 * @attr ref android.R.styleable#CalendarView_unfocusedMonthDateColor 215 * @deprecated No longer used by Material-style CalendarView. 216 */ 217 @Deprecated setUnfocusedMonthDateColor(@olorInt int color)218 public void setUnfocusedMonthDateColor(@ColorInt int color) { 219 mDelegate.setUnfocusedMonthDateColor(color); 220 } 221 222 /** 223 * Gets the color for the dates in a not focused month. 224 * 225 * @return A not focused month date color. 226 * 227 * @attr ref android.R.styleable#CalendarView_unfocusedMonthDateColor 228 * @deprecated No longer used by Material-style CalendarView. 229 */ 230 @ColorInt 231 @Deprecated getUnfocusedMonthDateColor()232 public int getUnfocusedMonthDateColor() { 233 return mDelegate.getUnfocusedMonthDateColor(); 234 } 235 236 /** 237 * Sets the color for the week numbers. 238 * 239 * @param color The week number color. 240 * 241 * @attr ref android.R.styleable#CalendarView_weekNumberColor 242 * @deprecated No longer used by Material-style CalendarView. 243 */ 244 @Deprecated setWeekNumberColor(@olorInt int color)245 public void setWeekNumberColor(@ColorInt int color) { 246 mDelegate.setWeekNumberColor(color); 247 } 248 249 /** 250 * Gets the color for the week numbers. 251 * 252 * @return The week number color. 253 * 254 * @attr ref android.R.styleable#CalendarView_weekNumberColor 255 * @deprecated No longer used by Material-style CalendarView. 256 */ 257 @ColorInt 258 @Deprecated getWeekNumberColor()259 public int getWeekNumberColor() { 260 return mDelegate.getWeekNumberColor(); 261 } 262 263 /** 264 * Sets the color for the separator line between weeks. 265 * 266 * @param color The week separator color. 267 * 268 * @attr ref android.R.styleable#CalendarView_weekSeparatorLineColor 269 * @deprecated No longer used by Material-style CalendarView. 270 */ 271 @Deprecated setWeekSeparatorLineColor(@olorInt int color)272 public void setWeekSeparatorLineColor(@ColorInt int color) { 273 mDelegate.setWeekSeparatorLineColor(color); 274 } 275 276 /** 277 * Gets the color for the separator line between weeks. 278 * 279 * @return The week separator color. 280 * 281 * @attr ref android.R.styleable#CalendarView_weekSeparatorLineColor 282 * @deprecated No longer used by Material-style CalendarView. 283 */ 284 @ColorInt 285 @Deprecated getWeekSeparatorLineColor()286 public int getWeekSeparatorLineColor() { 287 return mDelegate.getWeekSeparatorLineColor(); 288 } 289 290 /** 291 * Sets the drawable for the vertical bar shown at the beginning and at 292 * the end of the selected date. 293 * 294 * @param resourceId The vertical bar drawable resource id. 295 * 296 * @attr ref android.R.styleable#CalendarView_selectedDateVerticalBar 297 * @deprecated No longer used by Material-style CalendarView. 298 */ 299 @Deprecated setSelectedDateVerticalBar(@rawableRes int resourceId)300 public void setSelectedDateVerticalBar(@DrawableRes int resourceId) { 301 mDelegate.setSelectedDateVerticalBar(resourceId); 302 } 303 304 /** 305 * Sets the drawable for the vertical bar shown at the beginning and at 306 * the end of the selected date. 307 * 308 * @param drawable The vertical bar drawable. 309 * 310 * @attr ref android.R.styleable#CalendarView_selectedDateVerticalBar 311 * @deprecated No longer used by Material-style CalendarView. 312 */ 313 @Deprecated setSelectedDateVerticalBar(Drawable drawable)314 public void setSelectedDateVerticalBar(Drawable drawable) { 315 mDelegate.setSelectedDateVerticalBar(drawable); 316 } 317 318 /** 319 * Gets the drawable for the vertical bar shown at the beginning and at 320 * the end of the selected date. 321 * 322 * @return The vertical bar drawable. 323 * @deprecated No longer used by Material-style CalendarView. 324 */ 325 @Deprecated getSelectedDateVerticalBar()326 public Drawable getSelectedDateVerticalBar() { 327 return mDelegate.getSelectedDateVerticalBar(); 328 } 329 330 /** 331 * Sets the text appearance for the week day abbreviation of the calendar header. 332 * 333 * @param resourceId The text appearance resource id. 334 * 335 * @attr ref android.R.styleable#CalendarView_weekDayTextAppearance 336 */ setWeekDayTextAppearance(@tyleRes int resourceId)337 public void setWeekDayTextAppearance(@StyleRes int resourceId) { 338 mDelegate.setWeekDayTextAppearance(resourceId); 339 } 340 341 /** 342 * Gets the text appearance for the week day abbreviation of the calendar header. 343 * 344 * @return The text appearance resource id. 345 * 346 * @attr ref android.R.styleable#CalendarView_weekDayTextAppearance 347 */ getWeekDayTextAppearance()348 public @StyleRes int getWeekDayTextAppearance() { 349 return mDelegate.getWeekDayTextAppearance(); 350 } 351 352 /** 353 * Sets the text appearance for the calendar dates. 354 * 355 * @param resourceId The text appearance resource id. 356 * 357 * @attr ref android.R.styleable#CalendarView_dateTextAppearance 358 */ setDateTextAppearance(@tyleRes int resourceId)359 public void setDateTextAppearance(@StyleRes int resourceId) { 360 mDelegate.setDateTextAppearance(resourceId); 361 } 362 363 /** 364 * Gets the text appearance for the calendar dates. 365 * 366 * @return The text appearance resource id. 367 * 368 * @attr ref android.R.styleable#CalendarView_dateTextAppearance 369 */ getDateTextAppearance()370 public @StyleRes int getDateTextAppearance() { 371 return mDelegate.getDateTextAppearance(); 372 } 373 374 /** 375 * Gets the minimal date supported by this {@link CalendarView} in milliseconds 376 * since January 1, 1970 00:00:00 in {@link TimeZone#getDefault()} time 377 * zone. 378 * <p> 379 * Note: The default minimal date is 01/01/1900. 380 * <p> 381 * 382 * @return The minimal supported date. 383 * 384 * @attr ref android.R.styleable#CalendarView_minDate 385 */ getMinDate()386 public long getMinDate() { 387 return mDelegate.getMinDate(); 388 } 389 390 /** 391 * Sets the minimal date supported by this {@link CalendarView} in milliseconds 392 * since January 1, 1970 00:00:00 in {@link TimeZone#getDefault()} time 393 * zone. 394 * 395 * @param minDate The minimal supported date. 396 * 397 * @attr ref android.R.styleable#CalendarView_minDate 398 */ setMinDate(long minDate)399 public void setMinDate(long minDate) { 400 mDelegate.setMinDate(minDate); 401 } 402 403 /** 404 * Gets the maximal date supported by this {@link CalendarView} in milliseconds 405 * since January 1, 1970 00:00:00 in {@link TimeZone#getDefault()} time 406 * zone. 407 * <p> 408 * Note: The default maximal date is 01/01/2100. 409 * <p> 410 * 411 * @return The maximal supported date. 412 * 413 * @attr ref android.R.styleable#CalendarView_maxDate 414 */ getMaxDate()415 public long getMaxDate() { 416 return mDelegate.getMaxDate(); 417 } 418 419 /** 420 * Sets the maximal date supported by this {@link CalendarView} in milliseconds 421 * since January 1, 1970 00:00:00 in {@link TimeZone#getDefault()} time 422 * zone. 423 * 424 * @param maxDate The maximal supported date. 425 * 426 * @attr ref android.R.styleable#CalendarView_maxDate 427 */ setMaxDate(long maxDate)428 public void setMaxDate(long maxDate) { 429 mDelegate.setMaxDate(maxDate); 430 } 431 432 /** 433 * Sets whether to show the week number. 434 * 435 * @param showWeekNumber True to show the week number. 436 * @deprecated No longer used by Material-style CalendarView. 437 * 438 * @attr ref android.R.styleable#CalendarView_showWeekNumber 439 */ 440 @Deprecated setShowWeekNumber(boolean showWeekNumber)441 public void setShowWeekNumber(boolean showWeekNumber) { 442 mDelegate.setShowWeekNumber(showWeekNumber); 443 } 444 445 /** 446 * Gets whether to show the week number. 447 * 448 * @return True if showing the week number. 449 * @deprecated No longer used by Material-style CalendarView. 450 * 451 * @attr ref android.R.styleable#CalendarView_showWeekNumber 452 */ 453 @Deprecated getShowWeekNumber()454 public boolean getShowWeekNumber() { 455 return mDelegate.getShowWeekNumber(); 456 } 457 458 /** 459 * Gets the first day of week. 460 * 461 * @return The first day of the week conforming to the {@link CalendarView} 462 * APIs. 463 * @see Calendar#MONDAY 464 * @see Calendar#TUESDAY 465 * @see Calendar#WEDNESDAY 466 * @see Calendar#THURSDAY 467 * @see Calendar#FRIDAY 468 * @see Calendar#SATURDAY 469 * @see Calendar#SUNDAY 470 * 471 * @attr ref android.R.styleable#CalendarView_firstDayOfWeek 472 */ getFirstDayOfWeek()473 public int getFirstDayOfWeek() { 474 return mDelegate.getFirstDayOfWeek(); 475 } 476 477 /** 478 * Sets the first day of week. 479 * 480 * @param firstDayOfWeek The first day of the week conforming to the 481 * {@link CalendarView} APIs. 482 * @see Calendar#MONDAY 483 * @see Calendar#TUESDAY 484 * @see Calendar#WEDNESDAY 485 * @see Calendar#THURSDAY 486 * @see Calendar#FRIDAY 487 * @see Calendar#SATURDAY 488 * @see Calendar#SUNDAY 489 * 490 * @attr ref android.R.styleable#CalendarView_firstDayOfWeek 491 */ setFirstDayOfWeek(int firstDayOfWeek)492 public void setFirstDayOfWeek(int firstDayOfWeek) { 493 mDelegate.setFirstDayOfWeek(firstDayOfWeek); 494 } 495 496 /** 497 * Sets the listener to be notified upon selected date change. 498 * 499 * @param listener The listener to be notified. 500 */ setOnDateChangeListener(OnDateChangeListener listener)501 public void setOnDateChangeListener(OnDateChangeListener listener) { 502 mDelegate.setOnDateChangeListener(listener); 503 } 504 505 /** 506 * Gets the selected date in milliseconds since January 1, 1970 00:00:00 in 507 * {@link TimeZone#getDefault()} time zone. 508 * 509 * @return The selected date. 510 */ getDate()511 public long getDate() { 512 return mDelegate.getDate(); 513 } 514 515 /** 516 * Sets the selected date in milliseconds since January 1, 1970 00:00:00 in 517 * {@link TimeZone#getDefault()} time zone. 518 * 519 * @param date The selected date. 520 * 521 * @throws IllegalArgumentException of the provided date is before the 522 * minimal or after the maximal date. 523 * 524 * @see #setDate(long, boolean, boolean) 525 * @see #setMinDate(long) 526 * @see #setMaxDate(long) 527 */ setDate(long date)528 public void setDate(long date) { 529 mDelegate.setDate(date); 530 } 531 532 /** 533 * Sets the selected date in milliseconds since January 1, 1970 00:00:00 in 534 * {@link TimeZone#getDefault()} time zone. 535 * 536 * @param date The date. 537 * @param animate Whether to animate the scroll to the current date. 538 * @param center Whether to center the current date even if it is already visible. 539 * 540 * @throws IllegalArgumentException of the provided date is before the 541 * minimal or after the maximal date. 542 * 543 * @see #setMinDate(long) 544 * @see #setMaxDate(long) 545 */ setDate(long date, boolean animate, boolean center)546 public void setDate(long date, boolean animate, boolean center) { 547 mDelegate.setDate(date, animate, center); 548 } 549 550 /** 551 * Retrieves the screen bounds for the specific date in the coordinate system of this 552 * view. If the passed date is being currently displayed, this method returns true and 553 * the caller can query the fields of the passed {@link Rect} object. Otherwise the 554 * method returns false and does not touch the passed {@link Rect} object. 555 * 556 * @hide 557 */ 558 @TestApi getBoundsForDate(long date, Rect outBounds)559 public boolean getBoundsForDate(long date, Rect outBounds) { 560 return mDelegate.getBoundsForDate(date, outBounds); 561 } 562 563 @Override onConfigurationChanged(Configuration newConfig)564 protected void onConfigurationChanged(Configuration newConfig) { 565 super.onConfigurationChanged(newConfig); 566 mDelegate.onConfigurationChanged(newConfig); 567 } 568 569 @Override getAccessibilityClassName()570 public CharSequence getAccessibilityClassName() { 571 return CalendarView.class.getName(); 572 } 573 574 /** 575 * A delegate interface that defined the public API of the CalendarView. Allows different 576 * CalendarView implementations. This would need to be implemented by the CalendarView delegates 577 * for the real behavior. 578 */ 579 private interface CalendarViewDelegate { setShownWeekCount(int count)580 void setShownWeekCount(int count); getShownWeekCount()581 int getShownWeekCount(); 582 setSelectedWeekBackgroundColor(@olorInt int color)583 void setSelectedWeekBackgroundColor(@ColorInt int color); getSelectedWeekBackgroundColor()584 @ColorInt int getSelectedWeekBackgroundColor(); 585 setFocusedMonthDateColor(@olorInt int color)586 void setFocusedMonthDateColor(@ColorInt int color); getFocusedMonthDateColor()587 @ColorInt int getFocusedMonthDateColor(); 588 setUnfocusedMonthDateColor(@olorInt int color)589 void setUnfocusedMonthDateColor(@ColorInt int color); getUnfocusedMonthDateColor()590 @ColorInt int getUnfocusedMonthDateColor(); 591 setWeekNumberColor(@olorInt int color)592 void setWeekNumberColor(@ColorInt int color); getWeekNumberColor()593 @ColorInt int getWeekNumberColor(); 594 setWeekSeparatorLineColor(@olorInt int color)595 void setWeekSeparatorLineColor(@ColorInt int color); getWeekSeparatorLineColor()596 @ColorInt int getWeekSeparatorLineColor(); 597 setSelectedDateVerticalBar(@rawableRes int resourceId)598 void setSelectedDateVerticalBar(@DrawableRes int resourceId); setSelectedDateVerticalBar(Drawable drawable)599 void setSelectedDateVerticalBar(Drawable drawable); getSelectedDateVerticalBar()600 Drawable getSelectedDateVerticalBar(); 601 setWeekDayTextAppearance(@tyleRes int resourceId)602 void setWeekDayTextAppearance(@StyleRes int resourceId); getWeekDayTextAppearance()603 @StyleRes int getWeekDayTextAppearance(); 604 setDateTextAppearance(@tyleRes int resourceId)605 void setDateTextAppearance(@StyleRes int resourceId); getDateTextAppearance()606 @StyleRes int getDateTextAppearance(); 607 setMinDate(long minDate)608 void setMinDate(long minDate); getMinDate()609 long getMinDate(); 610 setMaxDate(long maxDate)611 void setMaxDate(long maxDate); getMaxDate()612 long getMaxDate(); 613 setShowWeekNumber(boolean showWeekNumber)614 void setShowWeekNumber(boolean showWeekNumber); getShowWeekNumber()615 boolean getShowWeekNumber(); 616 setFirstDayOfWeek(int firstDayOfWeek)617 void setFirstDayOfWeek(int firstDayOfWeek); getFirstDayOfWeek()618 int getFirstDayOfWeek(); 619 setDate(long date)620 void setDate(long date); setDate(long date, boolean animate, boolean center)621 void setDate(long date, boolean animate, boolean center); getDate()622 long getDate(); 623 getBoundsForDate(long date, Rect outBounds)624 boolean getBoundsForDate(long date, Rect outBounds); 625 setOnDateChangeListener(OnDateChangeListener listener)626 void setOnDateChangeListener(OnDateChangeListener listener); 627 onConfigurationChanged(Configuration newConfig)628 void onConfigurationChanged(Configuration newConfig); 629 } 630 631 /** 632 * An abstract class which can be used as a start for CalendarView implementations 633 */ 634 abstract static class AbstractCalendarViewDelegate implements CalendarViewDelegate { 635 /** The default minimal date. */ 636 protected static final String DEFAULT_MIN_DATE = "01/01/1900"; 637 638 /** The default maximal date. */ 639 protected static final String DEFAULT_MAX_DATE = "01/01/2100"; 640 641 protected CalendarView mDelegator; 642 protected Context mContext; 643 protected Locale mCurrentLocale; 644 AbstractCalendarViewDelegate(CalendarView delegator, Context context)645 AbstractCalendarViewDelegate(CalendarView delegator, Context context) { 646 mDelegator = delegator; 647 mContext = context; 648 649 // Initialization based on locale 650 setCurrentLocale(Locale.getDefault()); 651 } 652 setCurrentLocale(Locale locale)653 protected void setCurrentLocale(Locale locale) { 654 if (locale.equals(mCurrentLocale)) { 655 return; 656 } 657 mCurrentLocale = locale; 658 } 659 660 @Override setShownWeekCount(int count)661 public void setShownWeekCount(int count) { 662 // Deprecated. 663 } 664 665 @Override getShownWeekCount()666 public int getShownWeekCount() { 667 // Deprecated. 668 return 0; 669 } 670 671 @Override setSelectedWeekBackgroundColor(@olorInt int color)672 public void setSelectedWeekBackgroundColor(@ColorInt int color) { 673 // Deprecated. 674 } 675 676 @ColorInt 677 @Override getSelectedWeekBackgroundColor()678 public int getSelectedWeekBackgroundColor() { 679 return 0; 680 } 681 682 @Override setFocusedMonthDateColor(@olorInt int color)683 public void setFocusedMonthDateColor(@ColorInt int color) { 684 // Deprecated. 685 } 686 687 @ColorInt 688 @Override getFocusedMonthDateColor()689 public int getFocusedMonthDateColor() { 690 return 0; 691 } 692 693 @Override setUnfocusedMonthDateColor(@olorInt int color)694 public void setUnfocusedMonthDateColor(@ColorInt int color) { 695 // Deprecated. 696 } 697 698 @ColorInt 699 @Override getUnfocusedMonthDateColor()700 public int getUnfocusedMonthDateColor() { 701 return 0; 702 } 703 704 @Override setWeekNumberColor(@olorInt int color)705 public void setWeekNumberColor(@ColorInt int color) { 706 // Deprecated. 707 } 708 709 @ColorInt 710 @Override getWeekNumberColor()711 public int getWeekNumberColor() { 712 // Deprecated. 713 return 0; 714 } 715 716 @Override setWeekSeparatorLineColor(@olorInt int color)717 public void setWeekSeparatorLineColor(@ColorInt int color) { 718 // Deprecated. 719 } 720 721 @ColorInt 722 @Override getWeekSeparatorLineColor()723 public int getWeekSeparatorLineColor() { 724 // Deprecated. 725 return 0; 726 } 727 728 @Override setSelectedDateVerticalBar(@rawableRes int resId)729 public void setSelectedDateVerticalBar(@DrawableRes int resId) { 730 // Deprecated. 731 } 732 733 @Override setSelectedDateVerticalBar(Drawable drawable)734 public void setSelectedDateVerticalBar(Drawable drawable) { 735 // Deprecated. 736 } 737 738 @Override getSelectedDateVerticalBar()739 public Drawable getSelectedDateVerticalBar() { 740 // Deprecated. 741 return null; 742 } 743 744 @Override setShowWeekNumber(boolean showWeekNumber)745 public void setShowWeekNumber(boolean showWeekNumber) { 746 // Deprecated. 747 } 748 749 @Override getShowWeekNumber()750 public boolean getShowWeekNumber() { 751 // Deprecated. 752 return false; 753 } 754 755 @Override onConfigurationChanged(Configuration newConfig)756 public void onConfigurationChanged(Configuration newConfig) { 757 // Nothing to do here, configuration changes are already propagated 758 // by ViewGroup. 759 } 760 } 761 762 /** String for parsing dates. */ 763 private static final String DATE_FORMAT = "MM/dd/yyyy"; 764 765 /** Date format for parsing dates. */ 766 private static final DateFormat DATE_FORMATTER = new SimpleDateFormat(DATE_FORMAT); 767 768 /** 769 * Utility method for the date format used by CalendarView's min/max date. 770 * 771 * @hide Use only as directed. For internal use only. 772 */ parseDate(String date, Calendar outDate)773 public static boolean parseDate(String date, Calendar outDate) { 774 if (date == null || date.isEmpty()) { 775 return false; 776 } 777 778 try { 779 final Date parsedDate = DATE_FORMATTER.parse(date); 780 outDate.setTime(parsedDate); 781 return true; 782 } catch (ParseException e) { 783 Log.w(LOG_TAG, "Date: " + date + " not in format: " + DATE_FORMAT); 784 return false; 785 } 786 } 787 } 788