Skip to content

Commit e58f6f5

Browse files
minor tweaks to sample of the WholeViewSnappingActivity.
added a way to draw the line seperators horizontally&vertically in a way that makes them as in "checkers" (rectangles), by using isUsingCheckersStyle. This is demonstrated in WholeViewSnappingActivity.
1 parent b1a88c0 commit e58f6f5

File tree

6 files changed

+32
-25
lines changed

6 files changed

+32
-25
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
146146
private var mStartOriginForScroll = 0f
147147

148148
// Attributes and their default values.
149-
private var mHourHeight =TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50f, resources.displayMetrics).toInt()
149+
private var mHourHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50f, resources.displayMetrics).toInt()
150150
private var mNewHourHeight = -1
151151
var minHourHeight = 0
152152
//no minimum specified (will be dynamic, based on screen)
@@ -159,22 +159,22 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
159159
private var mHeaderColumnPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10f, resources.displayMetrics).toInt()
160160
private var mHeaderColumnTextColor = Color.BLACK
161161
private var mNumberOfVisibleDays = 3
162-
private var mHeaderRowPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5f, resources.displayMetrics).toInt()
162+
private var mHeaderRowPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10f, resources.displayMetrics).toInt()
163163
private var mHeaderRowBackgroundColor = Color.WHITE
164164
private var mDayBackgroundColor = Color.rgb(245, 245, 245)
165165
private var mPastBackgroundColor = Color.rgb(227, 227, 227)
166166
private var mFutureBackgroundColor = Color.rgb(245, 245, 245)
167167
private var mPastWeekendBackgroundColor = 0
168168
private var mFutureWeekendBackgroundColor = 0
169169
private var mNowLineColor = Color.rgb(102, 102, 102)
170-
private var mNowLineThickness = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2f, resources.displayMetrics).toInt()
170+
private var mNowLineThickness = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2f, resources.displayMetrics).toInt()
171171
private var mHourSeparatorColor = Color.rgb(230, 230, 230)
172172
private var mTodayBackgroundColor = Color.rgb(239, 247, 254)
173173
private var mHourSeparatorHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f, resources.displayMetrics).toInt()
174174
private var mTodayHeaderTextColor = Color.rgb(39, 137, 228)
175175
private var mEventTextSize = 12
176176
private var mEventTextColor = Color.BLACK
177-
private var mEventPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4f, resources.displayMetrics).toInt()
177+
private var mEventPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4f, resources.displayMetrics).toInt()
178178
private var mHeaderColumnBackgroundColor = Color.WHITE
179179
private var mDefaultEventColor: Int = 0
180180
private var mNewEventColor: Int = 0
@@ -1075,6 +1075,11 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
10751075

10761076
private val refreshRunnable: Runnable
10771077
private val uiHandler = Handler()
1078+
var isUsingCheckersStyle: Boolean = false
1079+
set(value) {
1080+
field = value
1081+
invalidate()
1082+
}
10781083

10791084
//endregion fields and properties
10801085

@@ -1151,6 +1156,7 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
11511156
minOverlappingMinutes = a.getInt(R.styleable.WeekView_minOverlappingMinutes, 0)
11521157
mIsScrollNumberOfVisibleDays = a.getBoolean(R.styleable.WeekView_isScrollNumberOfVisibleDays, false)
11531158
enableDrawHeaderBackgroundOnlyOnWeekDays = a.getBoolean(R.styleable.WeekView_enableDrawHeaderBackgroundOnlyOnWeekDays, false)
1159+
isUsingCheckersStyle = a.getBoolean(R.styleable.WeekView_isUsingCheckersStyle, false)
11541160
} finally {
11551161
a.recycle()
11561162
}
@@ -1522,15 +1528,20 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
15221528
if (top > mHeaderHeight + (mHeaderRowPadding * 2).toFloat() + mTimeTextHeight / 2 + mHeaderMarginBottom - mHourSeparatorHeight && top < height && startPixel + mWidthPerDay - start > 0) {
15231529
hourLines[i * 4] = start
15241530
hourLines[i * 4 + 1] = top
1525-
hourLines[i * 4 + 2] = startPixel + mWidthPerDay
1531+
hourLines[i * 4 + 2] = startPixel + mWidthPerDay + if (isUsingCheckersStyle) mColumnGap else 0
15261532
hourLines[i * 4 + 3] = top
15271533
i++
15281534
}
15291535
}
1530-
15311536
// Draw the lines for hours.
15321537
canvas.drawLines(hourLines, mHourSeparatorPaint)
15331538

1539+
// Draw line between days (before current one)
1540+
if (isUsingCheckersStyle) {
1541+
val x = if (dayNumber == leftDaysWithGaps + 1) start else start - mColumnGap / 2
1542+
canvas.drawLine(x, mHeaderHeight, x, height.toFloat(), mHourSeparatorPaint)
1543+
}
1544+
15341545
// Draw the events.
15351546
drawEvents(day, startPixel, canvas)
15361547

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@
6767
<attr name="dropListenerEnabled" format="boolean"/>
6868
<attr name="isScrollNumberOfVisibleDays" format="boolean"/>
6969
<attr name="enableDrawHeaderBackgroundOnlyOnWeekDays" format="boolean"/>
70+
<attr name="isUsingCheckersStyle" format="boolean"/>
7071
</declare-styleable>
7172
</resources>

sample/src/main/AndroidManifest.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:tools="http://schemas.android.com/tools" package="com.alamkanak.weekview.sample" xmlns:android="http://schemas.android.com/apk/res/android">
2+
<manifest package="com.alamkanak.weekview.sample" xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
34

45
<uses-permission android:name="android.permission.INTERNET"/>
56

@@ -13,12 +14,16 @@
1314
<category android:name="android.intent.category.LAUNCHER"/>
1415
</intent-filter>
1516
</activity>
17+
1618
<activity
1719
android:name=".BasicActivity" android:label="@string/title_activity_basic"/>
20+
1821
<activity
1922
android:name=".AsynchronousActivity" android:label="@string/title_activity_asynchronous"/>
20-
<activity android:screenOrientation="userLandscape" android:theme="@style/AppTheme.FullScreen"
21-
android:name=".WholeViewSnappingActivity" android:label="@string/title_activity_whole_view_snap"/>
23+
24+
<activity
25+
android:name=".WholeViewSnappingActivity" android:label="@string/title_activity_whole_view_snap"
26+
android:screenOrientation="userLandscape" android:theme="@style/AppTheme.FullScreen"/>
2227
</application>
2328

2429
</manifest>

sample/src/main/java/com/alamkanak/weekview/sample/BaseActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ abstract class BaseActivity : AppCompatActivity(), WeekView.EventClickListener,
192192
}
193193

194194
override fun interpretDate(date: Calendar): String {
195-
return "a\nb" // if (shortDate) shortDateFormat.format(date.time) else normalDateFormat.format(date.time)
195+
return if (shortDate) shortDateFormat.format(date.time) else normalDateFormat.format(date.time)
196196
}
197197
}
198198
}

sample/src/main/java/com/alamkanak/weekview/sample/WholeViewSnappingActivity.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.alamkanak.weekview.sample
22

33
import android.graphics.RectF
44
import android.os.Bundle
5+
import android.util.TypedValue
56
import android.view.Menu
67
import android.view.MenuItem
78
import android.view.View
@@ -20,39 +21,33 @@ class WholeViewSnappingActivity : BasicActivity() {
2021
weekView.isShowNowLine = true
2122
// weekView.setAutoLimitTime(true)
2223
weekView.setLimitTime(0, 24)
24+
weekView.isUsingCheckersStyle = true
25+
weekView.columnGap = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f, resources.displayMetrics).toInt()
26+
weekView.hourSeparatorHeight = weekView.columnGap
2327
weekView.isScrollNumberOfVisibleDays = true
2428
setDayViewType(TYPE_WEEK_VIEW)
2529
val cal = Calendar.getInstance()
2630
val currentHour = cal.get(Calendar.HOUR_OF_DAY) + cal.get(Calendar.MINUTE) / 60.0
2731
weekView.goToHour(Math.max(currentHour - 1, 0.0))
2832
cal.set(Calendar.DAY_OF_WEEK, cal.firstDayOfWeek)
2933
weekView.goToDate(cal)
30-
// weekView.enableDrawHeaderBackgroundOnlyOnWeekDays = true
3134
// weekView.addEventClickListener = null
3235
// weekView.eventClickListener = object : WeekView.EventClickListener {
3336
// override fun onEventClick(event: WeekViewEvent, eventRect: RectF) {
3437
// }
3538
// }
36-
// weekView.columnGap
37-
// weekView.dayBackgroundColor=0xffffffff.toInt()
39+
3840
weekView.emptyViewClickListener = null
3941
weekView.emptyViewLongPressListener = null
4042
weekView.scrollListener = object : WeekView.ScrollListener {
4143
val monthFormatter = SimpleDateFormat("MMM", Locale.getDefault())
42-
4344
override fun onFirstVisibleDayChanged(newFirstVisibleDay: Calendar, oldFirstVisibleDay: Calendar?) {
4445
weekView.sideTitleText = monthFormatter.format(newFirstVisibleDay.time)
4546
}
46-
4747
}
48-
4948
draggable_view.visibility = View.GONE
5049

5150

52-
weekView.addEventClickListener = null
53-
weekView.headerRowBackgroundColor = 0xff242b3e.toInt()
54-
weekView.headerColumnTextColor = 0xc2c3c3c3.toInt()
55-
weekView.nowLineColor = 0xff112d71.toInt()
5651
weekView.eventClickListener = object : WeekView.EventClickListener {
5752
override fun onEventClick(event: WeekViewEvent, eventRect: RectF) {
5853
}

sample/src/main/res/layout/activity_base.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@
1111
android:layout_width="match_parent"
1212
android:layout_height="match_parent"
1313
app:eventTextColor="@android:color/white"
14-
app:textSize="12sp"
15-
app:hourHeight="60dp"
16-
app:headerColumnPadding="8dp"
1714
app:headerColumnTextColor="@color/toolbar_text"
18-
app:headerRowPadding="12dp"
19-
app:columnGap="8dp"
2015
app:noOfVisibleDays="3"
2116
app:minTime="4"
2217
app:maxTime="16"

0 commit comments

Comments
 (0)