| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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.compat.annotation.UnsupportedAppUsage; |
| 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 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 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 |
|
| 82 |
|
| 83 |
public interface OnDateChangeListener { |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 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 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
@Deprecated |
| 143 |
public void setShownWeekCount(int count) { |
| 144 |
mDelegate.setShownWeekCount(count); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
@InspectableProperty |
| 156 |
@Deprecated |
| 157 |
public int getShownWeekCount() { |
| 158 |
return mDelegate.getShownWeekCount(); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
@Deprecated |
| 170 |
public void setSelectedWeekBackgroundColor(@ColorInt int color) { |
| 171 |
mDelegate.setSelectedWeekBackgroundColor(color); |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
@InspectableProperty |
| 183 |
@ColorInt |
| 184 |
@Deprecated |
| 185 |
public int getSelectedWeekBackgroundColor() { |
| 186 |
return mDelegate.getSelectedWeekBackgroundColor(); |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
@Deprecated |
| 198 |
public void setFocusedMonthDateColor(@ColorInt int color) { |
| 199 |
mDelegate.setFocusedMonthDateColor(color); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
@InspectableProperty |
| 211 |
@ColorInt |
| 212 |
@Deprecated |
| 213 |
public int getFocusedMonthDateColor() { |
| 214 |
return mDelegate.getFocusedMonthDateColor(); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
@Deprecated |
| 226 |
public void setUnfocusedMonthDateColor(@ColorInt int color) { |
| 227 |
mDelegate.setUnfocusedMonthDateColor(color); |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
@InspectableProperty |
| 239 |
@ColorInt |
| 240 |
@Deprecated |
| 241 |
public int getUnfocusedMonthDateColor() { |
| 242 |
return mDelegate.getUnfocusedMonthDateColor(); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
@Deprecated |
| 254 |
public void setWeekNumberColor(@ColorInt int color) { |
| 255 |
mDelegate.setWeekNumberColor(color); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
@InspectableProperty |
| 267 |
@ColorInt |
| 268 |
@Deprecated |
| 269 |
public int getWeekNumberColor() { |
| 270 |
return mDelegate.getWeekNumberColor(); |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
@Deprecated |
| 282 |
public void setWeekSeparatorLineColor(@ColorInt int color) { |
| 283 |
mDelegate.setWeekSeparatorLineColor(color); |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
@ColorInt |
| 295 |
@Deprecated |
| 296 |
@InspectableProperty |
| 297 |
public int getWeekSeparatorLineColor() { |
| 298 |
return mDelegate.getWeekSeparatorLineColor(); |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
@Deprecated |
| 311 |
public void setSelectedDateVerticalBar(@DrawableRes int resourceId) { |
| 312 |
mDelegate.setSelectedDateVerticalBar(resourceId); |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
@Deprecated |
| 325 |
public void setSelectedDateVerticalBar(Drawable drawable) { |
| 326 |
mDelegate.setSelectedDateVerticalBar(drawable); |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
@InspectableProperty |
| 337 |
@Deprecated |
| 338 |
public Drawable getSelectedDateVerticalBar() { |
| 339 |
return mDelegate.getSelectedDateVerticalBar(); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
public void setWeekDayTextAppearance(@StyleRes int resourceId) { |
| 350 |
mDelegate.setWeekDayTextAppearance(resourceId); |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
@InspectableProperty |
| 361 |
public @StyleRes int getWeekDayTextAppearance() { |
| 362 |
return mDelegate.getWeekDayTextAppearance(); |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
public void setDateTextAppearance(@StyleRes int resourceId) { |
| 373 |
mDelegate.setDateTextAppearance(resourceId); |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
@InspectableProperty |
| 384 |
public @StyleRes int getDateTextAppearance() { |
| 385 |
return mDelegate.getDateTextAppearance(); |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
@InspectableProperty |
| 401 |
public long getMinDate() { |
| 402 |
return mDelegate.getMinDate(); |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
public void setMinDate(long minDate) { |
| 415 |
mDelegate.setMinDate(minDate); |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
@InspectableProperty |
| 431 |
public long getMaxDate() { |
| 432 |
return mDelegate.getMaxDate(); |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
public void setMaxDate(long maxDate) { |
| 445 |
mDelegate.setMaxDate(maxDate); |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
@Deprecated |
| 457 |
public void setShowWeekNumber(boolean showWeekNumber) { |
| 458 |
mDelegate.setShowWeekNumber(showWeekNumber); |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
@InspectableProperty |
| 470 |
@Deprecated |
| 471 |
public boolean getShowWeekNumber() { |
| 472 |
return mDelegate.getShowWeekNumber(); |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
@InspectableProperty |
| 491 |
public int getFirstDayOfWeek() { |
| 492 |
return mDelegate.getFirstDayOfWeek(); |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
public void setFirstDayOfWeek(int firstDayOfWeek) { |
| 511 |
mDelegate.setFirstDayOfWeek(firstDayOfWeek); |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
public void setOnDateChangeListener(OnDateChangeListener listener) { |
| 520 |
mDelegate.setOnDateChangeListener(listener); |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
public long getDate() { |
| 530 |
return mDelegate.getDate(); |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
public void setDate(long date) { |
| 547 |
mDelegate.setDate(date); |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
public void setDate(long date, boolean animate, boolean center) { |
| 565 |
mDelegate.setDate(date, animate, center); |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 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 |
|
| 594 |
|
| 595 |
|
| 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 |
|
| 651 |
|
| 652 |
abstract static class AbstractCalendarViewDelegate implements CalendarViewDelegate { |
| 653 |
|
| 654 |
protected static final String DEFAULT_MIN_DATE = "01/01/1900"; |
| 655 |
|
| 656 |
|
| 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 |
|
| 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 |
|
| 681 |
} |
| 682 |
|
| 683 |
@Override |
| 684 |
public int getShownWeekCount() { |
| 685 |
|
| 686 |
return 0; |
| 687 |
} |
| 688 |
|
| 689 |
@Override |
| 690 |
public void setSelectedWeekBackgroundColor(@ColorInt int color) { |
| 691 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 725 |
} |
| 726 |
|
| 727 |
@ColorInt |
| 728 |
@Override |
| 729 |
public int getWeekNumberColor() { |
| 730 |
|
| 731 |
return 0; |
| 732 |
} |
| 733 |
|
| 734 |
@Override |
| 735 |
public void setWeekSeparatorLineColor(@ColorInt int color) { |
| 736 |
|
| 737 |
} |
| 738 |
|
| 739 |
@ColorInt |
| 740 |
@Override |
| 741 |
public int getWeekSeparatorLineColor() { |
| 742 |
|
| 743 |
return 0; |
| 744 |
} |
| 745 |
|
| 746 |
@Override |
| 747 |
public void setSelectedDateVerticalBar(@DrawableRes int resId) { |
| 748 |
|
| 749 |
} |
| 750 |
|
| 751 |
@Override |
| 752 |
public void setSelectedDateVerticalBar(Drawable drawable) { |
| 753 |
|
| 754 |
} |
| 755 |
|
| 756 |
@Override |
| 757 |
public Drawable getSelectedDateVerticalBar() { |
| 758 |
|
| 759 |
return null; |
| 760 |
} |
| 761 |
|
| 762 |
@Override |
| 763 |
public void setShowWeekNumber(boolean showWeekNumber) { |
| 764 |
|
| 765 |
} |
| 766 |
|
| 767 |
@Override |
| 768 |
public boolean getShowWeekNumber() { |
| 769 |
|
| 770 |
return false; |
| 771 |
} |
| 772 |
|
| 773 |
@Override |
| 774 |
public void onConfigurationChanged(Configuration newConfig) { |
| 775 |
|
| 776 |
|
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
private static final String DATE_FORMAT = "MM/dd/yyyy"; |
| 782 |
|
| 783 |
|
| 784 |
private static final DateFormat DATE_FORMATTER = new SimpleDateFormat(DATE_FORMAT); |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 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 |
} |