Skip to content

Commit 895f158

Browse files
committed
Add colors as Theme and change Readme.md
1 parent 96fbf2e commit 895f158

File tree

11 files changed

+72
-21
lines changed

11 files changed

+72
-21
lines changed

ReadMe.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ SwitchDateTime Picker is a library for select a *Date* object in dialog with a D
88

99
<img src="https://raw.githubusercontent.com/J-Jamet/Android-SwitchDateTimePicker/master/art/demo2.gif">
1010

11-
For change color of title and icon, add
12-
`<color name="dateTimeColorAccent">#494949</color>` to your resources **colors.xml** file.
13-
1411
## Installation
1512
Add the JitPack repository in your build.gradle at the end of repositories:
1613
```
@@ -24,31 +21,60 @@ Add the JitPack repository in your build.gradle at the end of repositories:
2421
And add the dependency
2522
```
2623
dependencies {
27-
compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:v1.0-rc.3'
24+
compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:v1.0-rc.4'
2825
}
2926
```
3027

3128
## Usage
29+
30+
### Colors
31+
For colors, add attributes :
32+
`
33+
dateTimeColorBackground, dateTimeColorLabel, dateTimeColorValue, dateTimeColorIcon
34+
`
35+
in your **styles.xml**, for example :
36+
```
37+
<resources>
38+
<!-- Base application theme. -->
39+
<style name="SwitchDateTimeTheme" parent="Theme.AppCompat.Light.DarkActionBar">
40+
<!-- Customize your theme here. -->
41+
<item name="colorPrimary">@color/colorPrimary</item>
42+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
43+
<item name="colorAccent">@color/colorAccent</item>
44+
<item name="dateTimeColorBackground">@color/colorAccent</item>
45+
<item name="dateTimeColorLabel">#d7f7fc</item>
46+
<item name="dateTimeColorValue">#c4e4b3</item>
47+
<item name="dateTimeColorIcon">#ffffff</item>
48+
</style>
49+
</resources>
50+
```
51+
Note : *colorAccent* change DatePicker and TimePicker color.
52+
53+
### SimpleDateFormat
54+
You can specify a particular [*SimpleDateFormat*](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) for value of DateTime with **setSimpleDateFormat(SimpleDateFormat format)**
55+
56+
### Sample
3257
You can see
3358
https://github.com/J-Jamet/Android-SwitchDateTimePicker/blob/master/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java
3459
for complete sample.
35-
36-
3760
```
3861
// Initialize
3962
SwitchDateTimeDialogFragment dateTimeDialogFragment = SwitchDateTimeDialogFragment.newInstance(
4063
getString(R.string.label_datetime_dialog),
4164
getString(R.string.positive_button_datetime_picker),
4265
getString(R.string.negative_button_datetime_picker)
4366
);
67+
4468
// Assign values
4569
dateTimeDialogFragment.setYear(2016);
4670
dateTimeDialogFragment.setMonth(12);
47-
dateTimeDialogFragment.setMonth(10);
71+
dateTimeDialogFragment.setDay(1);
4872
dateTimeDialogFragment.setHour(1);
4973
dateTimeDialogFragment.setMinute(20);
74+
5075
// Set SimpleDateFormat
5176
dateTimeDialogFragment.setSimpleDateFormat(new SimpleDateFormat("d MMM yyyy HH:mm", java.util.Locale.getDefault()));
77+
5278
// Set listener
5379
dateTimeDialogFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {
5480
@Override
@@ -62,6 +88,7 @@ dateTimeDialogFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment
6288
// Date is get on negative button click
6389
}
6490
});
91+
6592
// Show
6693
dateTimeDialogFragment.show(getSupportFragmentManager(), "dialog_time");
6794
```

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
android:icon="@mipmap/ic_launcher"
88
android:label="@string/app_name"
99
android:supportsRtl="true"
10-
android:theme="@style/AppTheme2">
10+
android:theme="@style/SwitchDateTimeTheme">
1111
<activity android:name="com.kunzisoft.switchdatetimesample.Sample">
1212
<intent-filter>
1313
<action android:name="android.intent.action.MAIN" />

sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
4444
final SimpleDateFormat myDateFormat = new SimpleDateFormat("d MMM yyyy HH:mm", java.util.Locale.getDefault());
4545
dateTimeFragment.setSimpleDateFormat(myDateFormat);
4646
dateTimeFragment.setHour(0);
47+
dateTimeFragment.setDay(4);
4748
dateTimeFragment.setMinute(20);
4849
// Set listener for get Date
4950
dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {

sample/src/main/res/values/colors.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33
<color name="colorPrimary">#3F51B5</color>
44
<color name="colorPrimaryDark">#303F9F</color>
55
<color name="colorAccent">#FF4081</color>
6-
7-
<color name="dateTimeColorAccent">@color/colorAccent</color>
86
</resources>

sample/src/main/res/values/styles.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<resources>
22
<!-- Base application theme. -->
3-
<style name="AppTheme2" parent="Theme.AppCompat.Light.DarkActionBar">
3+
<style name="SwitchDateTimeTheme" parent="Theme.AppCompat.Light.DarkActionBar">
44
<!-- Customize your theme here. -->
55
<item name="colorPrimary">@color/colorPrimary</item>
66
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
77
<item name="colorAccent">@color/colorAccent</item>
8+
<item name="dateTimeColorBackground">@color/colorAccent</item>
9+
<item name="dateTimeColorLabel">#d7f7fc</item>
10+
<item name="dateTimeColorValue">#c4e4b3</item>
11+
<item name="dateTimeColorIcon">#ffffff</item>
812
</style>
913
</resources>

switchdatetime/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<application
55
android:allowBackup="true"
66
android:label="@string/app_name"
7-
android:supportsRtl="true">
7+
android:supportsRtl="true"
8+
android:theme="@style/SwitchDateTimeTheme">
89
</application>
910

1011
</manifest>

switchdatetime/src/main/res/layout-land/dialog_switch_datetime_picker.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626

2727
<RelativeLayout
2828
android:id="@+id/section_add"
29+
android:background="?attr/dateTimeColorBackground"
2930
android:layout_width="80dp"
30-
android:layout_height="wrap_content"
31+
android:layout_height="match_parent"
3132
android:layout_gravity="center"
3233
android:orientation="horizontal">
3334
<TextView
@@ -36,6 +37,7 @@
3637
android:layout_height="wrap_content"
3738
android:padding="5dp"
3839
android:gravity="center"
40+
android:textColor="?attr/dateTimeColorValue"
3941
android:layout_alignParentRight="true"
4042
android:layout_alignParentEnd="true"
4143
android:layout_alignParentLeft="true"
@@ -45,9 +47,10 @@
4547
android:id="@+id/button_switch"
4648
android:layout_width="wrap_content"
4749
android:layout_height="wrap_content"
50+
android:layout_marginTop="20dp"
4851
android:layout_marginBottom="20dp"
4952
android:src="@drawable/ic_calendar_32dp"
50-
android:tint="@color/dateTimeColorAccent"
53+
android:tint="?attr/dateTimeColorIcon"
5154
android:contentDescription="@string/img_datetime"
5255
android:layout_alignParentTop="true"
5356
android:layout_centerHorizontal="true" />
@@ -56,7 +59,7 @@
5659
android:layout_width="wrap_content"
5760
android:layout_height="wrap_content"
5861
android:text="@string/label_datetime_dialog"
59-
android:textColor="@color/dateTimeColorAccent"
62+
android:textColor="?attr/dateTimeColorLabel"
6063
android:textStyle="bold"
6164
android:padding="5dp"
6265
android:gravity="center"

switchdatetime/src/main/res/layout/dialog_switch_datetime_picker.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
android:orientation="vertical" >
77
<RelativeLayout
88
android:id="@+id/section_add"
9+
android:background="?attr/dateTimeColorBackground"
910
android:layout_width="match_parent"
1011
android:layout_height="50dp"
1112
android:orientation="horizontal">
@@ -14,7 +15,7 @@
1415
android:layout_width="wrap_content"
1516
android:layout_height="wrap_content"
1617
android:text="@string/label_datetime_dialog"
17-
android:textColor="@color/dateTimeColorAccent"
18+
android:textColor="?attr/dateTimeColorLabel"
1819
android:textStyle="bold"
1920
android:padding="5dp"
2021
android:layout_centerVertical="true"
@@ -28,6 +29,7 @@
2829
android:layout_width="wrap_content"
2930
android:layout_height="wrap_content"
3031
android:padding="5dp"
32+
android:textColor="?attr/dateTimeColorValue"
3133
android:layout_centerVertical="true"
3234
android:gravity="center_vertical"
3335
android:layout_toRightOf="@+id/label"
@@ -39,7 +41,7 @@
3941
android:layout_width="wrap_content"
4042
android:layout_height="wrap_content"
4143
android:src="@drawable/ic_calendar_32dp"
42-
android:tint="@color/dateTimeColorAccent"
44+
android:tint="?attr/dateTimeColorIcon"
4345
android:contentDescription="@string/img_datetime"
4446
android:layout_centerVertical="true"
4547
android:layout_alignParentRight="true"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<attr name="dateTimeColorBackground" format="reference|color" />
3+
<attr name="dateTimeColorLabel" format="reference|color" />
4+
<attr name="dateTimeColorValue" format="reference|color" />
5+
<attr name="dateTimeColorIcon" format="reference|color" />
6+
</resources>

switchdatetime/src/main/res/values/colors.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)