Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
Expand Down Expand Up @@ -137,9 +139,9 @@ public abstract class MonthView extends View {
protected int mSelectedDayTextColor;
protected int mMonthDayTextColor;
protected int mTodayNumberColor;
protected int mMonthTitleColor;
protected int mHighlightedDayTextColor;
protected int mDisabledDayTextColor;
protected int mMonthTitleColor;

private SimpleDateFormat weekDayLabelFormatter;

Expand All @@ -158,30 +160,27 @@ public MonthView(Context context, AttributeSet attr, DatePickerController contro
mDayOfWeekTypeface = res.getString(R.string.mdtp_day_of_week_label_typeface);
mMonthTitleTypeface = res.getString(R.string.mdtp_sans_serif);

boolean darkTheme = mController != null && mController.isThemeDark();
if (darkTheme) {
mDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_normal_dark_theme);
mMonthDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_month_day_dark_theme);
mDisabledDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled_dark_theme);
mHighlightedDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_highlighted_dark_theme);
} else {
mDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_normal);
mMonthDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_month_day);
mDisabledDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled);
mHighlightedDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_highlighted);
}
TypedArray typedArray = context.obtainStyledAttributes(attr, R.styleable.MonthView, R.attr.mdtp_monthViewTheme, R.style.MonthView);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by default it uses MonthView style if it cannot find a style applied with attribute mdtp_monthViewTheme


mDayTextColor = typedArray.getColor(R.styleable.MonthView_dayTextColor, Color.BLACK);
mHighlightedDayTextColor = typedArray.getColor(R.styleable.MonthView_dayHighlightedTextColor, Color.BLACK);
mDisabledDayTextColor = typedArray.getColor(R.styleable.MonthView_dayDisabledTextColor, Color.BLACK);
mMonthDayTextColor = typedArray.getColor(R.styleable.MonthView_monthDayTextColor, Color.BLACK);

MINI_DAY_NUMBER_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.MonthView_miniDayNumberTextSize, 0);
MONTH_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.MonthView_monthLabelTextSize, 0);
MONTH_DAY_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.MonthView_monthDayTextSize, 0);
MONTH_HEADER_SIZE = typedArray.getDimensionPixelOffset(R.styleable.MonthView_monthHeaderSize, 0);
DAY_SELECTED_CIRCLE_SIZE = typedArray.getDimensionPixelSize(R.styleable.MonthView_daySelectedCircleSize, 0);

typedArray.recycle();

mSelectedDayTextColor = ContextCompat.getColor(context, R.color.mdtp_white);
mTodayNumberColor = mController.getAccentColor();
mMonthTitleColor = ContextCompat.getColor(context, R.color.mdtp_white);

mStringBuilder = new StringBuilder(50);

MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_size);
MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_label_size);
MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_day_label_text_size);
MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.mdtp_month_list_item_header_height);
DAY_SELECTED_CIRCLE_SIZE = res
.getDimensionPixelSize(R.dimen.mdtp_day_number_select_circle_radius);

mRowHeight = (res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
- getMonthHeaderSize()) / MAX_NUM_ROWS;
Expand Down
19 changes: 19 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<attr name="mdtp_theme_dark" format="boolean" />
<attr name="mdtp_monthViewTheme" format="reference" />

<declare-styleable name="MonthView">
<attr name="dayTextColor" format="color" />
<attr name="dayHighlightedTextColor" format="color" />
<attr name="dayDisabledTextColor" format="color" />
<attr name="monthDayTextColor" format="color" />
<attr name="miniDayNumberTextSize" format="dimension" />
<attr name="monthLabelTextSize" format="dimension" />
<attr name="monthDayTextSize" format="dimension" />
<attr name="monthHeaderSize" format="dimension" />
<attr name="daySelectedCircleSize" format="dimension" />
</declare-styleable>

</resources>
3 changes: 1 addition & 2 deletions library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2013 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
23 changes: 20 additions & 3 deletions library/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 The Android Open Source Project
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2013 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,7 +14,25 @@
-->

<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<attr name="mdtp_theme_dark" format="boolean">false</attr>

<style name="MonthView">
<item name="dayTextColor">@color/mdtp_date_picker_text_normal</item>
<item name="dayHighlightedTextColor">@color/mdtp_date_picker_text_highlighted</item>
<item name="dayDisabledTextColor">@color/mdtp_date_picker_text_disabled</item>
<item name="monthDayTextColor">@color/mdtp_date_picker_month_day</item>
<item name="miniDayNumberTextSize">@dimen/mdtp_day_number_size</item>
<item name="monthLabelTextSize">@dimen/mdtp_month_label_size</item>
<item name="monthDayTextSize">@dimen/mdtp_month_day_label_text_size</item>
<item name="monthHeaderSize">@dimen/mdtp_month_list_item_header_height</item>
<item name="daySelectedCircleSize">@dimen/mdtp_day_number_select_circle_radius</item>
</style>

<style name="MonthView.Dark">

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dark theme, its an actual theme now

<item name="dayTextColor">@color/mdtp_date_picker_text_normal_dark_theme</item>
<item name="dayDisabledTextColor">@color/mdtp_date_picker_text_disabled_dark_theme</item>
<item name="dayHighlightedTextColor">@color/mdtp_date_picker_text_highlighted_dark_theme</item>
<item name="monthDayTextColor">@color/mdtp_date_picker_month_day_dark_theme</item>
</style>

<style name="mdtp_time_label">
<item name="android:textSize">@dimen/mdtp_time_label_size</item>
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<item name="colorAccent">#ff4081</item>
<!-- Customize picker mode here. -->
<item name="mdtp_theme_dark">true</item>
<item name="mdtp_monthViewTheme">@style/MonthView</item>
</style>

</resources>