Skip to content

Commit d021bc1

Browse files
moved implementation of textColorPicker to default one of WeekView.
1 parent 0be8d77 commit d021bc1

File tree

4 files changed

+21
-40
lines changed

4 files changed

+21
-40
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,13 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
985985
}
986986

987987
init {
988+
textColorPicker = object : TextColorPicker {
989+
override fun getTextColor(event: WeekViewEvent): Int {
990+
val color = event.color
991+
val a = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255
992+
return if (a < 0.2) Color.BLACK else Color.WHITE
993+
}
994+
}
988995
refreshRunnable = object : Runnable {
989996
override fun run() {
990997
invalidate()

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.alamkanak.weekview.sample
22

3-
import android.graphics.Color
43
import android.os.Bundle
54
import android.support.v4.content.res.ResourcesCompat
6-
import com.alamkanak.weekview.TextColorPicker
75
import com.alamkanak.weekview.WeekViewEvent
86
import kotlinx.android.synthetic.main.activity_base.*
97
import java.util.*
@@ -20,13 +18,6 @@ open class BasicActivity : BaseActivity() {
2018
super.onCreate(savedInstanceState)
2119

2220
weekView.typeface = ResourcesCompat.getFont(this, R.font.lato)
23-
weekView.textColorPicker = object : TextColorPicker {
24-
override fun getTextColor(event: WeekViewEvent): Int {
25-
val color = event.color
26-
val a = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255
27-
return if (a < 0.2) Color.BLACK else Color.WHITE
28-
}
29-
}
3021
}
3122

3223
override fun onMonthChange(newYear: Int, newMonth: Int): MutableList<WeekViewEvent>? {
Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
1-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2-
xmlns:tools="http://schemas.android.com/tools"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
android:layout_width="match_parent"
5-
android:layout_height="match_parent"
6-
tools:context=".BaseActivity">
1+
<RelativeLayout
2+
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
3+
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
4+
android:layout_height="match_parent" tools:context=".BaseActivity">
75

86
<com.alamkanak.weekview.WeekView
9-
android:id="@+id/weekView"
10-
android:layout_width="match_parent"
11-
android:layout_height="match_parent"
12-
app:eventTextColor="@android:color/white"
13-
app:headerColumnTextColor="@color/toolbar_text"
14-
app:noOfVisibleDays="3"
15-
app:minTime="4"
16-
app:maxTime="16"
17-
app:autoLimitTime="false"
18-
app:headerRowBackgroundColor="@color/toolbar"
19-
app:dayBackgroundColor="#05000000"
20-
app:todayColumnBackgroundColor="#1848adff"
21-
app:todayHeaderTextColor="@color/accent"
22-
app:newEventTimeResolutionInMinutes="15"
23-
app:timeColumnResolution="60"
24-
app:minOverlappingMinutes="5" />
7+
android:id="@+id/weekView" android:layout_width="match_parent" android:layout_height="match_parent"
8+
app:autoLimitTime="false" app:dayBackgroundColor="#05000000" app:headerColumnTextColor="@color/toolbar_text" app:headerRowBackgroundColor="@color/toolbar"
9+
app:maxTime="16" app:minOverlappingMinutes="5" app:minTime="4"
10+
app:newEventTimeResolutionInMinutes="15" app:noOfVisibleDays="3"
11+
app:timeColumnResolution="60" app:todayColumnBackgroundColor="#1848adff" app:todayHeaderTextColor="@color/accent"/>
2512

2613
<TextView
27-
android:id="@+id/draggable_view"
28-
android:layout_width="wrap_content"
29-
android:layout_height="wrap_content"
30-
android:textColor="@android:color/white"
31-
android:background="#ffff0000"
32-
android:padding="3dp"
33-
android:text="@string/drag_me" />
14+
android:id="@+id/draggable_view" android:layout_width="wrap_content" android:layout_height="wrap_content"
15+
android:background="#ffff0000" android:padding="3dp" android:text="@string/drag_me"
16+
android:textColor="@android:color/white"/>
3417

3518
</RelativeLayout>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<LinearLayout
22
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
3-
android:layout_width="match_parent" android:layout_height="match_parent"
4-
android:orientation="vertical" tools:context=".MainActivity">
3+
android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"
4+
tools:context=".MainActivity">
55

66
<Button
77
android:id="@+id/buttonBasic" style="@style/Button" android:layout_width="match_parent"

0 commit comments

Comments
 (0)