Skip to content

Commit 99d8918

Browse files
committed
Update some attributes for coloring days
1 parent f4b4e67 commit 99d8918

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

library/src/main/java/com/alamkanak/weekview/WeekView.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public class WeekView extends View {
7979
private int mFetchedPeriod = -1; // the middle period the calendar has fetched.
8080
private boolean mRefreshEvents = false;
8181
private Direction mCurrentFlingDirection = Direction.NONE;
82+
private ScaleGestureDetector mScaleDetector;
83+
private boolean mIsZooming;
84+
private Calendar mFirstVisibleDay;
85+
private Calendar mLastVisibleDay;
86+
private int mDefaultEventColor;
8287

8388
// Attributes and their default values.
8489
private int mHourHeight = 50;
@@ -101,7 +106,6 @@ public class WeekView extends View {
101106
private int mFutureWeekendBackgroundColor = 0;
102107
private int mNowLineColor = Color.rgb(102, 102, 102);
103108
private int mNowLineThickness = 5;
104-
private boolean mUseNewColoring = false;
105109
private int mHourSeparatorColor = Color.rgb(230, 230, 230);
106110
private int mTodayBackgroundColor = Color.rgb(239, 247, 254);
107111
private int mHourSeparatorHeight = 2;
@@ -110,20 +114,20 @@ public class WeekView extends View {
110114
private int mEventTextColor = Color.BLACK;
111115
private int mEventPadding = 8;
112116
private int mHeaderColumnBackgroundColor = Color.WHITE;
113-
private int mDefaultEventColor;
114117
private boolean mIsFirstDraw = true;
115118
private boolean mAreDimensionsInvalid = true;
116119
@Deprecated private int mDayNameLength = LENGTH_LONG;
117120
private int mOverlappingEventGap = 0;
118121
private int mEventMarginVertical = 0;
119122
private float mXScrollingSpeed = 1f;
120-
private Calendar mFirstVisibleDay;
121-
private Calendar mLastVisibleDay;
122123
private Calendar mScrollToDay = null;
123124
private double mScrollToHour = -1;
124-
private ScaleGestureDetector mScaleDetector;
125-
private boolean mIsZooming;
126125
private int mEventCornerRadius = 0;
126+
private boolean mUseDifferentPastBackgroundColor = false;
127+
private boolean mUseDifferentFutureWeekendBackgroundColor = false;
128+
private boolean mShowDistinctWeekendColor = false;
129+
private boolean mShowNowLine = false;
130+
private boolean mShowDistinctPastFutureColor = false;
127131

128132
// Listeners.
129133
private EventClickListener mEventClickListener;
@@ -284,7 +288,6 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
284288
mPastWeekendBackgroundColor = a.getColor(R.styleable.WeekView_pastWeekendBackgroundColor, mPastBackgroundColor);
285289
mNowLineColor = a.getColor(R.styleable.WeekView_nowLineColor, mNowLineColor);
286290
mNowLineThickness = a.getDimensionPixelSize(R.styleable.WeekView_nowLineThickness, mNowLineThickness);
287-
mUseNewColoring = a.getBoolean(R.styleable.WeekView_useNewColoringStyle, mUseNewColoring);
288291
mHourSeparatorColor = a.getColor(R.styleable.WeekView_hourSeparatorColor, mHourSeparatorColor);
289292
mTodayBackgroundColor = a.getColor(R.styleable.WeekView_todayBackgroundColor, mTodayBackgroundColor);
290293
mHourSeparatorHeight = a.getDimensionPixelSize(R.styleable.WeekView_hourSeparatorHeight, mHourSeparatorHeight);
@@ -298,6 +301,10 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
298301
mEventMarginVertical = a.getDimensionPixelSize(R.styleable.WeekView_eventMarginVertical, mEventMarginVertical);
299302
mXScrollingSpeed = a.getFloat(R.styleable.WeekView_xScrollingSpeed, mXScrollingSpeed);
300303
mEventCornerRadius = a.getDimensionPixelSize(R.styleable.WeekView_eventCornerRadius, mEventCornerRadius);
304+
mShowDistinctPastFutureColor = a.getBoolean(R.styleable.WeekView_showDistinctPastFutureColor, mShowDistinctPastFutureColor);
305+
mShowDistinctWeekendColor = a.getBoolean(R.styleable.WeekView_showDistinctWeekendColor, mShowDistinctWeekendColor);
306+
mShowNowLine = a.getBoolean(R.styleable.WeekView_showNowLine, mShowNowLine);
307+
301308
} finally {
302309
a.recycle();
303310
}
@@ -568,10 +575,10 @@ else if (mNewHourHeight > mMaxHourHeight)
568575
// Draw background color for each day.
569576
float start = (startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel);
570577
if (mWidthPerDay + startPixel - start > 0){
571-
if (mUseNewColoring){
572-
boolean isWeekend = (day.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || day.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY);
573-
Paint pastPaint = isWeekend ? mPastWeekendBackgroundPaint : mPastBackgroundPaint;
574-
Paint futurePaint = isWeekend ? mFutureWeekendBackgroundPaint : mFutureBackgroundPaint;
578+
if (mShowDistinctPastFutureColor){
579+
boolean isWeekend = day.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || day.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
580+
Paint pastPaint = isWeekend && mShowDistinctWeekendColor ? mPastWeekendBackgroundPaint : mPastBackgroundPaint;
581+
Paint futurePaint = isWeekend && mShowDistinctWeekendColor ? mFutureWeekendBackgroundPaint : mFutureBackgroundPaint;
575582
float startY = mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom + mCurrentOrigin.y;
576583

577584
if (sameDay){
@@ -612,7 +619,7 @@ else if (day.before(today)) {
612619
drawEvents(day, startPixel, canvas);
613620

614621
// Draw the line at the current time.
615-
if (mUseNewColoring && sameDay){
622+
if (mShowNowLine && sameDay){
616623
float startY = mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom + mCurrentOrigin.y;
617624
Calendar now = Calendar.getInstance();
618625
float beforeNow = (now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE)/60.0f) * mHourHeight;

library/src/main/res/values/attrs.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
<attr name="pastBackgroundColor" format="color"/>
2727
<attr name="futureWeekendBackgroundColor" format="color"/>
2828
<attr name="pastWeekendBackgroundColor" format="color"/>
29-
<attr name="nowLineColor" format="color"/>
30-
<attr name="nowLineThickness" format="dimension"/>
31-
<attr name="useNewColoringStyle" format="boolean"/>
3229
<attr name="hourSeparatorColor" format="color"/>
3330
<attr name="todayBackgroundColor" format="color"/>
3431
<attr name="todayHeaderTextColor" format="color"/>
@@ -44,5 +41,19 @@
4441
<attr name="eventMarginVertical" format="dimension"/>
4542
<attr name="xScrollingSpeed" format="float"/>
4643
<attr name="eventCornerRadius" format="dimension"/>
44+
<attr name="showDistinctPastFutureColor" format="boolean"/>
45+
<attr name="showDistinctWeekendColor" format="boolean"/>
46+
<attr name="showNowLine" format="boolean"/>
47+
<attr name="nowLineColor" format="color"/>
48+
<attr name="nowLineThickness" format="dimension"/>
49+
<attr name="weekends" format="enum">
50+
<enum name="sunday" value="1"/>
51+
<enum name="monday" value="2"/>
52+
<enum name="tuesday" value="3"/>
53+
<enum name="wednesday" value="4"/>
54+
<enum name="thursday" value="5"/>
55+
<enum name="friday" value="6"/>
56+
<enum name="saturday" value="7"/>
57+
</attr>
4758
</declare-styleable>
4859
</resources>

0 commit comments

Comments
 (0)