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