@@ -106,12 +106,15 @@ public class WeekView extends View {
106
106
private int mHeaderColumnBackgroundColor = Color .WHITE ;
107
107
private int mDefaultEventColor ;
108
108
private boolean mIsFirstDraw = true ;
109
+ private boolean mAreDimensionsInvalid = true ;
109
110
@ Deprecated private int mDayNameLength = LENGTH_LONG ;
110
111
private int mOverlappingEventGap = 0 ;
111
112
private int mEventMarginVertical = 0 ;
112
113
private float mXScrollingSpeed = 1f ;
113
114
private Calendar mFirstVisibleDay ;
114
115
private Calendar mLastVisibleDay ;
116
+ private Calendar mScrollToDay = null ;
117
+ private double mScrollToHour = -1 ;
115
118
116
119
// Listeners.
117
120
private EventClickListener mEventClickListener ;
@@ -413,13 +416,22 @@ private void drawHeaderRowAndEvents(Canvas canvas) {
413
416
414
417
Calendar today = today ();
415
418
416
- // If the week view is being drawn for the first time, then consider the first day of week.
417
- if (mIsFirstDraw && mNumberOfVisibleDays >= 7 ) {
418
- if (today .get (Calendar .DAY_OF_WEEK ) != mFirstDayOfWeek ) {
419
+ if (mAreDimensionsInvalid ) {
420
+ mAreDimensionsInvalid = false ;
421
+
422
+ if (mScrollToDay != null )
423
+ goToDate (mScrollToDay );
424
+ if (mScrollToHour >= 0 )
425
+ goToHour (mScrollToHour );
426
+ }
427
+ if (mIsFirstDraw ){
428
+ mIsFirstDraw = false ;
429
+
430
+ // If the week view is being drawn for the first time, then consider the first day of the week.
431
+ if (mNumberOfVisibleDays >= 7 && today .get (Calendar .DAY_OF_WEEK ) != mFirstDayOfWeek ) {
419
432
int difference = 7 + (today .get (Calendar .DAY_OF_WEEK ) - mFirstDayOfWeek );
420
433
mCurrentOrigin .x += (mWidthPerDay + mColumnGap ) * difference ;
421
434
}
422
- mIsFirstDraw = false ;
423
435
}
424
436
425
437
// Consider scroll offset.
@@ -980,6 +992,13 @@ private void deleteFarMonths(Calendar currentDay) {
980
992
mEventRects .addAll (newEvents );
981
993
}
982
994
995
+ @ Override
996
+ public void invalidate () {
997
+ super .invalidate ();
998
+ mAreDimensionsInvalid = true ;
999
+ mScrollToDay = null ;
1000
+ mScrollToHour = -1 ;
1001
+ }
983
1002
984
1003
/////////////////////////////////////////////////////////////////
985
1004
//
@@ -1441,6 +1460,11 @@ public void goToDate(Calendar date) {
1441
1460
date .set (Calendar .SECOND , 0 );
1442
1461
date .set (Calendar .MILLISECOND , 0 );
1443
1462
1463
+ if (mAreDimensionsInvalid ) {
1464
+ mScrollToDay = date ;
1465
+ return ;
1466
+ }
1467
+
1444
1468
mRefreshEvents = true ;
1445
1469
1446
1470
Calendar today = Calendar .getInstance ();
@@ -1450,8 +1474,7 @@ public void goToDate(Calendar date) {
1450
1474
today .set (Calendar .MILLISECOND , 0 );
1451
1475
1452
1476
int dateDifference = (int ) ((date .getTimeInMillis () - today .getTimeInMillis ()) / (1000 * 60 * 60 * 24 ));
1453
- mCurrentOrigin .x = - dateDifference * (mWidthPerDay + mColumnGap );
1454
-
1477
+ mStickyScroller .startScroll ((int ) mCurrentOrigin .x , 0 , (int ) (-dateDifference *(mWidthPerDay + mColumnGap )-mCurrentOrigin .x ), 0 );
1455
1478
invalidate ();
1456
1479
}
1457
1480
@@ -1468,14 +1491,18 @@ public void notifyDatasetChanged(){
1468
1491
* @param hour The hour to scroll to in 24-hour format. Supported values are 0-24.
1469
1492
*/
1470
1493
public void goToHour (double hour ){
1494
+ int verticalOffset = (int ) (mHourHeight * hour );
1471
1495
if (hour < 0 )
1472
- throw new IllegalArgumentException ( "Cannot scroll to an hour of negative value." ) ;
1496
+ verticalOffset = 0 ;
1473
1497
else if (hour > 24 )
1474
- throw new IllegalArgumentException ("Cannot scroll to an hour of value greater than 24." );
1475
- else if (hour * mHourHeight > mHourHeight * 24 - getHeight () + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom )
1476
- throw new IllegalArgumentException ("Cannot scroll to an hour which will result the calendar to go off the screen." );
1498
+ verticalOffset = mHourHeight * 24 ;
1499
+
1500
+ if (mAreDimensionsInvalid ) {
1501
+ mScrollToHour = hour ;
1502
+ return ;
1503
+ } else if (verticalOffset > mHourHeight * 24 - getHeight () + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom )
1504
+ verticalOffset = (int )(mHourHeight * 24 - getHeight () + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom );
1477
1505
1478
- int verticalOffset = (int ) (mHourHeight * hour );
1479
1506
mCurrentOrigin .y = -verticalOffset ;
1480
1507
invalidate ();
1481
1508
}
0 commit comments