Skip to content

Commit

Permalink
Fix - Support Theme Attributes For setDayTextColor()
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Colle committed Jan 14, 2022
1 parent 7f2f3ca commit f17075f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
Expand Up @@ -10,6 +10,8 @@
import android.view.View;
import android.view.ViewGroup;

import static android.os.Build.VERSION;
import static android.os.Build.VERSION_CODES;
import static android.view.View.MeasureSpec.AT_MOST;
import static android.view.View.MeasureSpec.EXACTLY;
import static android.view.View.MeasureSpec.makeMeasureSpec;
Expand Down Expand Up @@ -52,7 +54,12 @@ public void setDayBackground(int resId) {

public void setDayTextColor(int resId) {
for (int i = 0; i < getChildCount(); i++) {
ColorStateList colors = getResources().getColorStateList(resId);
ColorStateList colors;
if (VERSION.SDK_INT >= VERSION_CODES.M) {
colors = getContext().getColorStateList(resId);
} else {
colors = getResources().getColorStateList(resId);
}
((CalendarRowView) getChildAt(i)).setCellTextColor(colors);
}
}
Expand Down
12 changes: 6 additions & 6 deletions sample/src/main/res/color/custom_calendar_text_selector.xml
Expand Up @@ -3,10 +3,10 @@

<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:state_selected="true" android:color="@color/custom_text_selected"/>
<item android:state_pressed="true" android:color="@color/custom_text_selected"/>
<item app:tsquare_state_current_month="false" android:color="@color/custom_text_inactive"/>
<item app:tsquare_state_today="true" android:color="@color/custom_text_selected"/>
<item app:tsquare_state_selectable="false" android:color="@color/custom_text_inactive" />
<item android:color="@color/custom_background_today"/>
<item android:state_selected="true" android:color="?textSelected"/>
<item android:state_pressed="true" android:color="?textSelected"/>
<item app:tsquare_state_current_month="false" android:color="?textDisabled"/>
<item app:tsquare_state_today="true" android:color="?textSelected"/>
<item app:tsquare_state_selectable="false" android:color="?textDisabled" />
<item android:color="?textDefault"/>
</selector>
9 changes: 4 additions & 5 deletions sample/src/main/res/layout/dialog_customized.xml
@@ -1,19 +1,18 @@
<com.squareup.timessquare.CalendarPickerView
xmlns:android="http://schemas.android.com/apk/res/android"
<com.squareup.timessquare.CalendarPickerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/custom_background"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
android:scrollbarStyle="outsideOverlay"
android:theme="@style/MyTheme"
app:tsquare_dayBackground="@drawable/custom_calendar_bg_selector"
app:tsquare_dayTextColor="@color/custom_calendar_text_selector"
app:tsquare_displayDayNamesHeaderRow="false"
app:tsquare_dividerColor="@color/transparent"
app:tsquare_headerTextColor="@color/custom_header_text"
app:tsquare_titleTextStyle="@style/CustomCalendarTitle"
/>
app:tsquare_titleTextStyle="@style/CustomCalendarTitle" />
11 changes: 11 additions & 0 deletions sample/src/main/res/values-night/themes.xml
@@ -0,0 +1,11 @@
<!-- Copyright 2012 Square, Inc. -->
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="MyTheme">

<item name="textDefault">#FFFFFF</item>
<item name="textDisabled">#AAAAAA</item>
<item name="textSelected">#FFFFFF</item>

</style>
</resources>
6 changes: 6 additions & 0 deletions sample/src/main/res/values/attrs.xml
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="textDefault" format="color" />
<attr name="textDisabled" format="color" />
<attr name="textSelected" format="color" />
</resources>
11 changes: 11 additions & 0 deletions sample/src/main/res/values/themes.xml
@@ -0,0 +1,11 @@
<!-- Copyright 2012 Square, Inc. -->
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="MyTheme">

<item name="textDefault">#000000</item>
<item name="textDisabled">#CCCCCC</item>
<item name="textSelected">#FFFFFFFF</item>

</style>
</resources>

0 comments on commit f17075f

Please sign in to comment.