@@ -136,6 +136,8 @@ private enum Direction {
136136 private boolean mShowDistinctWeekendColor = false ;
137137 private boolean mShowNowLine = false ;
138138 private boolean mShowDistinctPastFutureColor = false ;
139+ private boolean mHorizontalFlingEnabled = true ;
140+ private boolean mVerticalFlingEnabled = true ;
139141
140142 // Listeners.
141143 private EventClickListener mEventClickListener ;
@@ -210,6 +212,12 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
210212 if (mIsZooming )
211213 return true ;
212214
215+ if ((mCurrentFlingDirection == Direction .LEFT && !mHorizontalFlingEnabled ) ||
216+ (mCurrentFlingDirection == Direction .RIGHT && !mHorizontalFlingEnabled ) ||
217+ (mCurrentFlingDirection == Direction .VERTICAL && !mVerticalFlingEnabled )) {
218+ return true ;
219+ }
220+
213221 mScroller .forceFinished (true );
214222
215223 mCurrentFlingDirection = mCurrentScrollDirection ;
@@ -324,7 +332,7 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
324332 mTodayHeaderTextColor = a .getColor (R .styleable .WeekView_todayHeaderTextColor , mTodayHeaderTextColor );
325333 mEventTextSize = a .getDimensionPixelSize (R .styleable .WeekView_eventTextSize , (int ) TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_SP , mEventTextSize , context .getResources ().getDisplayMetrics ()));
326334 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 );
328336 mHeaderColumnBackgroundColor = a .getColor (R .styleable .WeekView_headerColumnBackground , mHeaderColumnBackgroundColor );
329337 mDayNameLength = a .getInteger (R .styleable .WeekView_dayNameLength , mDayNameLength );
330338 mOverlappingEventGap = a .getDimensionPixelSize (R .styleable .WeekView_overlappingEventGap , mOverlappingEventGap );
@@ -334,7 +342,8 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
334342 mShowDistinctPastFutureColor = a .getBoolean (R .styleable .WeekView_showDistinctPastFutureColor , mShowDistinctPastFutureColor );
335343 mShowDistinctWeekendColor = a .getBoolean (R .styleable .WeekView_showDistinctWeekendColor , mShowDistinctWeekendColor );
336344 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 );
338347 } finally {
339348 a .recycle ();
340349 }
@@ -748,15 +757,13 @@ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) {
748757 right -= mOverlappingEventGap ;
749758
750759 // 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
758765 ) {
759- mEventRects .get (i ).rectF = eventRectF ;
766+ mEventRects .get (i ).rectF = new RectF ( left , top , right , bottom ) ;
760767 mEventBackgroundPaint .setColor (mEventRects .get (i ).event .getColor () == 0 ? mDefaultEventColor : mEventRects .get (i ).event .getColor ());
761768 canvas .drawRoundRect (mEventRects .get (i ).rectF , mEventCornerRadius , mEventCornerRadius , mEventBackgroundPaint );
762769 drawEventTitle (mEventRects .get (i ).event , mEventRects .get (i ).rectF , canvas , top , left );
@@ -1359,6 +1366,8 @@ public int getHeaderColumnTextColor() {
13591366
13601367 public void setHeaderColumnTextColor (int headerColumnTextColor ) {
13611368 mHeaderColumnTextColor = headerColumnTextColor ;
1369+ mHeaderTextPaint .setColor (mHeaderColumnTextColor );
1370+ mTimeTextPaint .setColor (mHeaderColumnTextColor );
13621371 invalidate ();
13631372 }
13641373
@@ -1377,6 +1386,7 @@ public int getHeaderRowBackgroundColor() {
13771386
13781387 public void setHeaderRowBackgroundColor (int headerRowBackgroundColor ) {
13791388 mHeaderRowBackgroundColor = headerRowBackgroundColor ;
1389+ mHeaderBackgroundPaint .setColor (mHeaderRowBackgroundColor );
13801390 invalidate ();
13811391 }
13821392
@@ -1386,6 +1396,7 @@ public int getDayBackgroundColor() {
13861396
13871397 public void setDayBackgroundColor (int dayBackgroundColor ) {
13881398 mDayBackgroundColor = dayBackgroundColor ;
1399+ mDayBackgroundPaint .setColor (mDayBackgroundColor );
13891400 invalidate ();
13901401 }
13911402
@@ -1395,6 +1406,7 @@ public int getHourSeparatorColor() {
13951406
13961407 public void setHourSeparatorColor (int hourSeparatorColor ) {
13971408 mHourSeparatorColor = hourSeparatorColor ;
1409+ mHourSeparatorPaint .setColor (mHourSeparatorColor );
13981410 invalidate ();
13991411 }
14001412
@@ -1404,6 +1416,7 @@ public int getTodayBackgroundColor() {
14041416
14051417 public void setTodayBackgroundColor (int todayBackgroundColor ) {
14061418 mTodayBackgroundColor = todayBackgroundColor ;
1419+ mTodayBackgroundPaint .setColor (mTodayBackgroundColor );
14071420 invalidate ();
14081421 }
14091422
@@ -1413,6 +1426,7 @@ public int getHourSeparatorHeight() {
14131426
14141427 public void setHourSeparatorHeight (int hourSeparatorHeight ) {
14151428 mHourSeparatorHeight = hourSeparatorHeight ;
1429+ mHourSeparatorPaint .setStrokeWidth (mHourSeparatorHeight );
14161430 invalidate ();
14171431 }
14181432
@@ -1422,6 +1436,7 @@ public int getTodayHeaderTextColor() {
14221436
14231437 public void setTodayHeaderTextColor (int todayHeaderTextColor ) {
14241438 mTodayHeaderTextColor = todayHeaderTextColor ;
1439+ mTodayHeaderTextPaint .setColor (mTodayHeaderTextColor );
14251440 invalidate ();
14261441 }
14271442
@@ -1441,6 +1456,7 @@ public int getEventTextColor() {
14411456
14421457 public void setEventTextColor (int eventTextColor ) {
14431458 mEventTextColor = eventTextColor ;
1459+ mEventTextPaint .setColor (mEventTextColor );
14441460 invalidate ();
14451461 }
14461462
@@ -1459,6 +1475,7 @@ public int getHeaderColumnBackgroundColor() {
14591475
14601476 public void setHeaderColumnBackgroundColor (int headerColumnBackgroundColor ) {
14611477 mHeaderColumnBackgroundColor = headerColumnBackgroundColor ;
1478+ mHeaderColumnBackgroundPaint .setColor (mHeaderColumnBackgroundColor );
14621479 invalidate ();
14631480 }
14641481
@@ -1666,6 +1683,38 @@ public void setNowLineThickness(int nowLineThickness) {
16661683 invalidate ();
16671684 }
16681685
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+
16691718 /////////////////////////////////////////////////////////////////
16701719 //
16711720 // Functions related to scrolling.
0 commit comments