@@ -136,6 +136,8 @@ private enum Direction {
136
136
private boolean mShowDistinctWeekendColor = false ;
137
137
private boolean mShowNowLine = false ;
138
138
private boolean mShowDistinctPastFutureColor = false ;
139
+ private boolean mHorizontalFlingEnabled = true ;
140
+ private boolean mVerticalFlingEnabled = true ;
139
141
140
142
// Listeners.
141
143
private EventClickListener mEventClickListener ;
@@ -210,6 +212,12 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
210
212
if (mIsZooming )
211
213
return true ;
212
214
215
+ if ((mCurrentFlingDirection == Direction .LEFT && !mHorizontalFlingEnabled ) ||
216
+ (mCurrentFlingDirection == Direction .RIGHT && !mHorizontalFlingEnabled ) ||
217
+ (mCurrentFlingDirection == Direction .VERTICAL && !mVerticalFlingEnabled )) {
218
+ return true ;
219
+ }
220
+
213
221
mScroller .forceFinished (true );
214
222
215
223
mCurrentFlingDirection = mCurrentScrollDirection ;
@@ -324,7 +332,7 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
324
332
mTodayHeaderTextColor = a .getColor (R .styleable .WeekView_todayHeaderTextColor , mTodayHeaderTextColor );
325
333
mEventTextSize = a .getDimensionPixelSize (R .styleable .WeekView_eventTextSize , (int ) TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_SP , mEventTextSize , context .getResources ().getDisplayMetrics ()));
326
334
mEventTextColor = a .getColor (R .styleable .WeekView_eventTextColor , mEventTextColor );
327
- mEventPadding = a .getDimensionPixelSize (R .styleable .WeekView_hourSeparatorHeight , mEventPadding );
335
+ mEventPadding = a .getDimensionPixelSize (R .styleable .WeekView_eventPadding , mEventPadding );
328
336
mHeaderColumnBackgroundColor = a .getColor (R .styleable .WeekView_headerColumnBackground , mHeaderColumnBackgroundColor );
329
337
mDayNameLength = a .getInteger (R .styleable .WeekView_dayNameLength , mDayNameLength );
330
338
mOverlappingEventGap = a .getDimensionPixelSize (R .styleable .WeekView_overlappingEventGap , mOverlappingEventGap );
@@ -334,7 +342,8 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
334
342
mShowDistinctPastFutureColor = a .getBoolean (R .styleable .WeekView_showDistinctPastFutureColor , mShowDistinctPastFutureColor );
335
343
mShowDistinctWeekendColor = a .getBoolean (R .styleable .WeekView_showDistinctWeekendColor , mShowDistinctWeekendColor );
336
344
mShowNowLine = a .getBoolean (R .styleable .WeekView_showNowLine , mShowNowLine );
337
-
345
+ mHorizontalFlingEnabled = a .getBoolean (R .styleable .WeekView_horizontalFlingEnabled , mHorizontalFlingEnabled );
346
+ mVerticalFlingEnabled = a .getBoolean (R .styleable .WeekView_verticalFlingEnabled , mVerticalFlingEnabled );
338
347
} finally {
339
348
a .recycle ();
340
349
}
@@ -748,15 +757,13 @@ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) {
748
757
right -= mOverlappingEventGap ;
749
758
750
759
// Draw the event and the event name on top of it.
751
- RectF eventRectF = new RectF (left , top , right , bottom );
752
- if (bottom > mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight /2 && left < right &&
753
- eventRectF .right > mHeaderColumnWidth &&
754
- eventRectF .left < getWidth () &&
755
- eventRectF .bottom > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom &&
756
- eventRectF .top < getHeight () &&
757
- left < right
760
+ if (left < right &&
761
+ left < getWidth () &&
762
+ top < getHeight () &&
763
+ right > mHeaderColumnWidth &&
764
+ bottom > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom
758
765
) {
759
- mEventRects .get (i ).rectF = eventRectF ;
766
+ mEventRects .get (i ).rectF = new RectF ( left , top , right , bottom ) ;
760
767
mEventBackgroundPaint .setColor (mEventRects .get (i ).event .getColor () == 0 ? mDefaultEventColor : mEventRects .get (i ).event .getColor ());
761
768
canvas .drawRoundRect (mEventRects .get (i ).rectF , mEventCornerRadius , mEventCornerRadius , mEventBackgroundPaint );
762
769
drawEventTitle (mEventRects .get (i ).event , mEventRects .get (i ).rectF , canvas , top , left );
@@ -1359,6 +1366,8 @@ public int getHeaderColumnTextColor() {
1359
1366
1360
1367
public void setHeaderColumnTextColor (int headerColumnTextColor ) {
1361
1368
mHeaderColumnTextColor = headerColumnTextColor ;
1369
+ mHeaderTextPaint .setColor (mHeaderColumnTextColor );
1370
+ mTimeTextPaint .setColor (mHeaderColumnTextColor );
1362
1371
invalidate ();
1363
1372
}
1364
1373
@@ -1377,6 +1386,7 @@ public int getHeaderRowBackgroundColor() {
1377
1386
1378
1387
public void setHeaderRowBackgroundColor (int headerRowBackgroundColor ) {
1379
1388
mHeaderRowBackgroundColor = headerRowBackgroundColor ;
1389
+ mHeaderBackgroundPaint .setColor (mHeaderRowBackgroundColor );
1380
1390
invalidate ();
1381
1391
}
1382
1392
@@ -1386,6 +1396,7 @@ public int getDayBackgroundColor() {
1386
1396
1387
1397
public void setDayBackgroundColor (int dayBackgroundColor ) {
1388
1398
mDayBackgroundColor = dayBackgroundColor ;
1399
+ mDayBackgroundPaint .setColor (mDayBackgroundColor );
1389
1400
invalidate ();
1390
1401
}
1391
1402
@@ -1395,6 +1406,7 @@ public int getHourSeparatorColor() {
1395
1406
1396
1407
public void setHourSeparatorColor (int hourSeparatorColor ) {
1397
1408
mHourSeparatorColor = hourSeparatorColor ;
1409
+ mHourSeparatorPaint .setColor (mHourSeparatorColor );
1398
1410
invalidate ();
1399
1411
}
1400
1412
@@ -1404,6 +1416,7 @@ public int getTodayBackgroundColor() {
1404
1416
1405
1417
public void setTodayBackgroundColor (int todayBackgroundColor ) {
1406
1418
mTodayBackgroundColor = todayBackgroundColor ;
1419
+ mTodayBackgroundPaint .setColor (mTodayBackgroundColor );
1407
1420
invalidate ();
1408
1421
}
1409
1422
@@ -1413,6 +1426,7 @@ public int getHourSeparatorHeight() {
1413
1426
1414
1427
public void setHourSeparatorHeight (int hourSeparatorHeight ) {
1415
1428
mHourSeparatorHeight = hourSeparatorHeight ;
1429
+ mHourSeparatorPaint .setStrokeWidth (mHourSeparatorHeight );
1416
1430
invalidate ();
1417
1431
}
1418
1432
@@ -1422,6 +1436,7 @@ public int getTodayHeaderTextColor() {
1422
1436
1423
1437
public void setTodayHeaderTextColor (int todayHeaderTextColor ) {
1424
1438
mTodayHeaderTextColor = todayHeaderTextColor ;
1439
+ mTodayHeaderTextPaint .setColor (mTodayHeaderTextColor );
1425
1440
invalidate ();
1426
1441
}
1427
1442
@@ -1441,6 +1456,7 @@ public int getEventTextColor() {
1441
1456
1442
1457
public void setEventTextColor (int eventTextColor ) {
1443
1458
mEventTextColor = eventTextColor ;
1459
+ mEventTextPaint .setColor (mEventTextColor );
1444
1460
invalidate ();
1445
1461
}
1446
1462
@@ -1459,6 +1475,7 @@ public int getHeaderColumnBackgroundColor() {
1459
1475
1460
1476
public void setHeaderColumnBackgroundColor (int headerColumnBackgroundColor ) {
1461
1477
mHeaderColumnBackgroundColor = headerColumnBackgroundColor ;
1478
+ mHeaderColumnBackgroundPaint .setColor (mHeaderColumnBackgroundColor );
1462
1479
invalidate ();
1463
1480
}
1464
1481
@@ -1666,6 +1683,38 @@ public void setNowLineThickness(int nowLineThickness) {
1666
1683
invalidate ();
1667
1684
}
1668
1685
1686
+ /**
1687
+ * Get whether the week view should fling horizontally.
1688
+ * @return True if the week view has horizontal fling enabled.
1689
+ */
1690
+ public boolean isHorizontalFlingEnabled () {
1691
+ return mHorizontalFlingEnabled ;
1692
+ }
1693
+
1694
+ /**
1695
+ * Set whether the week view should fling horizontally.
1696
+ * @return True if it should have horizontal fling enabled.
1697
+ */
1698
+ public void setHorizontalFlingEnabled (boolean enabled ) {
1699
+ mHorizontalFlingEnabled = enabled ;
1700
+ }
1701
+
1702
+ /**
1703
+ * Get whether the week view should fling vertically.
1704
+ * @return True if the week view has vertical fling enabled.
1705
+ */
1706
+ public boolean isVerticalFlingEnabled () {
1707
+ return mVerticalFlingEnabled ;
1708
+ }
1709
+
1710
+ /**
1711
+ * Set whether the week view should fling vertically.
1712
+ * @return True if it should have vertical fling enabled.
1713
+ */
1714
+ public void setVerticalFlingEnabled (boolean enabled ) {
1715
+ mVerticalFlingEnabled = enabled ;
1716
+ }
1717
+
1669
1718
/////////////////////////////////////////////////////////////////
1670
1719
//
1671
1720
// Functions related to scrolling.
0 commit comments