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