Home | History | Annotate | Download | only in widget
      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          */
     90         void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth);
     91     }
     92 
     93     public CalendarView(@NonNull Context context) {
     94         this(context, null);
     95     }
     96 
     97     public CalendarView(@NonNull Context context, @Nullable AttributeSet attrs) {
     98         this(context, attrs, R.attr.calendarViewStyle);
     99     }
    100 
    101     public CalendarView(@NonNull Context context, @Nullable AttributeSet attrs,
    102             @AttrRes int defStyleAttr) {
    103         this(context, attrs, defStyleAttr, 0);
    104     }
    105 
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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      */
    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      */
    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      */
    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      */
    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      */
    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      */
    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      */
    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      */
    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
    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
    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      */
    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      */
    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      */
    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      */
    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      */
    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      */
    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
    559     public boolean getBoundsForDate(long date, Rect outBounds) {
    560         return mDelegate.getBoundsForDate(date, outBounds);
    561     }
    562 
    563     @Override
    564     protected void onConfigurationChanged(Configuration newConfig) {
    565         super.onConfigurationChanged(newConfig);
    566         mDelegate.onConfigurationChanged(newConfig);
    567     }
    568 
    569     @Override
    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 {
    580         void setShownWeekCount(int count);
    581         int getShownWeekCount();
    582 
    583         void setSelectedWeekBackgroundColor(@ColorInt int color);
    584         @ColorInt int getSelectedWeekBackgroundColor();
    585 
    586         void setFocusedMonthDateColor(@ColorInt int color);
    587         @ColorInt int getFocusedMonthDateColor();
    588 
    589         void setUnfocusedMonthDateColor(@ColorInt int color);
    590         @ColorInt int getUnfocusedMonthDateColor();
    591 
    592         void setWeekNumberColor(@ColorInt int color);
    593         @ColorInt int getWeekNumberColor();
    594 
    595         void setWeekSeparatorLineColor(@ColorInt int color);
    596         @ColorInt int getWeekSeparatorLineColor();
    597 
    598         void setSelectedDateVerticalBar(@DrawableRes int resourceId);
    599         void setSelectedDateVerticalBar(Drawable drawable);
    600         Drawable getSelectedDateVerticalBar();
    601 
    602         void setWeekDayTextAppearance(@StyleRes int resourceId);
    603         @StyleRes int getWeekDayTextAppearance();
    604 
    605         void setDateTextAppearance(@StyleRes int resourceId);
    606         @StyleRes int getDateTextAppearance();
    607 
    608         void setMinDate(long minDate);
    609         long getMinDate();
    610 
    611         void setMaxDate(long maxDate);
    612         long getMaxDate();
    613 
    614         void setShowWeekNumber(boolean showWeekNumber);
    615         boolean getShowWeekNumber();
    616 
    617         void setFirstDayOfWeek(int firstDayOfWeek);
    618         int getFirstDayOfWeek();
    619 
    620         void setDate(long date);
    621         void setDate(long date, boolean animate, boolean center);
    622         long getDate();
    623 
    624         boolean getBoundsForDate(long date, Rect outBounds);
    625 
    626         void setOnDateChangeListener(OnDateChangeListener listener);
    627 
    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 
    645         AbstractCalendarViewDelegate(CalendarView delegator, Context context) {
    646             mDelegator = delegator;
    647             mContext = context;
    648 
    649             // Initialization based on locale
    650             setCurrentLocale(Locale.getDefault());
    651         }
    652 
    653         protected void setCurrentLocale(Locale locale) {
    654             if (locale.equals(mCurrentLocale)) {
    655                 return;
    656             }
    657             mCurrentLocale = locale;
    658         }
    659 
    660         @Override
    661         public void setShownWeekCount(int count) {
    662             // Deprecated.
    663         }
    664 
    665         @Override
    666         public int getShownWeekCount() {
    667             // Deprecated.
    668             return 0;
    669         }
    670 
    671         @Override
    672         public void setSelectedWeekBackgroundColor(@ColorInt int color) {
    673             // Deprecated.
    674         }
    675 
    676         @ColorInt
    677         @Override
    678         public int getSelectedWeekBackgroundColor() {
    679             return 0;
    680         }
    681 
    682         @Override
    683         public void setFocusedMonthDateColor(@ColorInt int color) {
    684             // Deprecated.
    685         }
    686 
    687         @ColorInt
    688         @Override
    689         public int getFocusedMonthDateColor() {
    690             return 0;
    691         }
    692 
    693         @Override
    694         public void setUnfocusedMonthDateColor(@ColorInt int color) {
    695             // Deprecated.
    696         }
    697 
    698         @ColorInt
    699         @Override
    700         public int getUnfocusedMonthDateColor() {
    701             return 0;
    702         }
    703 
    704         @Override
    705         public void setWeekNumberColor(@ColorInt int color) {
    706             // Deprecated.
    707         }
    708 
    709         @ColorInt
    710         @Override
    711         public int getWeekNumberColor() {
    712             // Deprecated.
    713             return 0;
    714         }
    715 
    716         @Override
    717         public void setWeekSeparatorLineColor(@ColorInt int color) {
    718             // Deprecated.
    719         }
    720 
    721         @ColorInt
    722         @Override
    723         public int getWeekSeparatorLineColor() {
    724             // Deprecated.
    725             return 0;
    726         }
    727 
    728         @Override
    729         public void setSelectedDateVerticalBar(@DrawableRes int resId) {
    730             // Deprecated.
    731         }
    732 
    733         @Override
    734         public void setSelectedDateVerticalBar(Drawable drawable) {
    735             // Deprecated.
    736         }
    737 
    738         @Override
    739         public Drawable getSelectedDateVerticalBar() {
    740             // Deprecated.
    741             return null;
    742         }
    743 
    744         @Override
    745         public void setShowWeekNumber(boolean showWeekNumber) {
    746             // Deprecated.
    747         }
    748 
    749         @Override
    750         public boolean getShowWeekNumber() {
    751             // Deprecated.
    752             return false;
    753         }
    754 
    755         @Override
    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      */
    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