Skip to content

Commit

Permalink
Add colors as Theme and change Readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Nov 3, 2016
1 parent 96fbf2e commit 895f158
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 21 deletions.
41 changes: 34 additions & 7 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ SwitchDateTime Picker is a library for select a *Date* object in dialog with a D

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

For change color of title and icon, add
`<color name="dateTimeColorAccent">#494949</color>` to your resources **colors.xml** file.

## Installation
Add the JitPack repository in your build.gradle at the end of repositories:
```
Expand All @@ -24,31 +21,60 @@ Add the JitPack repository in your build.gradle at the end of repositories:
And add the dependency
```
dependencies {
compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:v1.0-rc.3'
compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:v1.0-rc.4'
}
```

## Usage

### Colors
For colors, add attributes :
`
dateTimeColorBackground, dateTimeColorLabel, dateTimeColorValue, dateTimeColorIcon
`
in your **styles.xml**, for example :
```
<resources>
<!-- Base application theme. -->
<style name="SwitchDateTimeTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="dateTimeColorBackground">@color/colorAccent</item>
<item name="dateTimeColorLabel">#d7f7fc</item>
<item name="dateTimeColorValue">#c4e4b3</item>
<item name="dateTimeColorIcon">#ffffff</item>
</style>
</resources>
```
Note : *colorAccent* change DatePicker and TimePicker color.

### SimpleDateFormat
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)**

### Sample
You can see
https://github.com/J-Jamet/Android-SwitchDateTimePicker/blob/master/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java
for complete sample.


```
// Initialize
SwitchDateTimeDialogFragment dateTimeDialogFragment = SwitchDateTimeDialogFragment.newInstance(
getString(R.string.label_datetime_dialog),
getString(R.string.positive_button_datetime_picker),
getString(R.string.negative_button_datetime_picker)
);
// Assign values
dateTimeDialogFragment.setYear(2016);
dateTimeDialogFragment.setMonth(12);
dateTimeDialogFragment.setMonth(10);
dateTimeDialogFragment.setDay(1);
dateTimeDialogFragment.setHour(1);
dateTimeDialogFragment.setMinute(20);
// Set SimpleDateFormat
dateTimeDialogFragment.setSimpleDateFormat(new SimpleDateFormat("d MMM yyyy HH:mm", java.util.Locale.getDefault()));
// Set listener
dateTimeDialogFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {
@Override
Expand All @@ -62,6 +88,7 @@ dateTimeDialogFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment
// Date is get on negative button click
}
});
// Show
dateTimeDialogFragment.show(getSupportFragmentManager(), "dialog_time");
```
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme2">
android:theme="@style/SwitchDateTimeTheme">
<activity android:name="com.kunzisoft.switchdatetimesample.Sample">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
final SimpleDateFormat myDateFormat = new SimpleDateFormat("d MMM yyyy HH:mm", java.util.Locale.getDefault());
dateTimeFragment.setSimpleDateFormat(myDateFormat);
dateTimeFragment.setHour(0);
dateTimeFragment.setDay(4);
dateTimeFragment.setMinute(20);
// Set listener for get Date
dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {
Expand Down
2 changes: 0 additions & 2 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>

<color name="dateTimeColorAccent">@color/colorAccent</color>
</resources>
6 changes: 5 additions & 1 deletion sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme2" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="SwitchDateTimeTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="dateTimeColorBackground">@color/colorAccent</item>
<item name="dateTimeColorLabel">#d7f7fc</item>
<item name="dateTimeColorValue">#c4e4b3</item>
<item name="dateTimeColorIcon">#ffffff</item>
</style>
</resources>
3 changes: 2 additions & 1 deletion switchdatetime/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
android:supportsRtl="true"
android:theme="@style/SwitchDateTimeTheme">
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@

<RelativeLayout
android:id="@+id/section_add"
android:background="?attr/dateTimeColorBackground"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
Expand All @@ -36,6 +37,7 @@
android:layout_height="wrap_content"
android:padding="5dp"
android:gravity="center"
android:textColor="?attr/dateTimeColorValue"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
Expand All @@ -45,9 +47,10 @@
android:id="@+id/button_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:src="@drawable/ic_calendar_32dp"
android:tint="@color/dateTimeColorAccent"
android:tint="?attr/dateTimeColorIcon"
android:contentDescription="@string/img_datetime"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
Expand All @@ -56,7 +59,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_datetime_dialog"
android:textColor="@color/dateTimeColorAccent"
android:textColor="?attr/dateTimeColorLabel"
android:textStyle="bold"
android:padding="5dp"
android:gravity="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/section_add"
android:background="?attr/dateTimeColorBackground"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
Expand All @@ -14,7 +15,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_datetime_dialog"
android:textColor="@color/dateTimeColorAccent"
android:textColor="?attr/dateTimeColorLabel"
android:textStyle="bold"
android:padding="5dp"
android:layout_centerVertical="true"
Expand All @@ -28,6 +29,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColor="?attr/dateTimeColorValue"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_toRightOf="@+id/label"
Expand All @@ -39,7 +41,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_calendar_32dp"
android:tint="@color/dateTimeColorAccent"
android:tint="?attr/dateTimeColorIcon"
android:contentDescription="@string/img_datetime"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
Expand Down
6 changes: 6 additions & 0 deletions switchdatetime/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<attr name="dateTimeColorBackground" format="reference|color" />
<attr name="dateTimeColorLabel" format="reference|color" />
<attr name="dateTimeColorValue" format="reference|color" />
<attr name="dateTimeColorIcon" format="reference|color" />
</resources>
4 changes: 0 additions & 4 deletions switchdatetime/src/main/res/values/colors.xml

This file was deleted.

13 changes: 13 additions & 0 deletions switchdatetime/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<resources>
<!-- Base application theme. -->
<style name="SwitchDateTimeTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#3F51B5</item>
<item name="colorPrimaryDark">#303F9F</item>
<item name="colorAccent">#a72a2a</item>
<item name="dateTimeColorBackground">#a72a2a</item>
<item name="dateTimeColorLabel">#d7f7fc</item>
<item name="dateTimeColorValue">#e3f7d9</item>
<item name="dateTimeColorIcon">#ffffff</item>
</style>
</resources>

0 comments on commit 895f158

Please sign in to comment.