From b1933257a9a35855af88487d357d001ba84f96a9 Mon Sep 17 00:00:00 2001 From: Sylvain Mantha-Favreau Date: Wed, 17 May 2017 11:22:05 -0400 Subject: [PATCH 1/4] Added AlertStyle for the internal AlertDialog --- .../SwitchDateTimeDialogFragment.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java index fbd412e..e581e93 100644 --- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java +++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java @@ -5,6 +5,7 @@ import android.graphics.Color; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.StyleRes; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; @@ -61,6 +62,7 @@ public class SwitchDateTimeDialogFragment extends DialogFragment { private boolean is24HoursMode = false; private int startAtPosition = 0; + private int alertStyleId; private SimpleDateFormat dayAndMonthSimpleDate; private SimpleDateFormat yearSimpleDate; @@ -301,7 +303,12 @@ public void onYearSelected(View view, int yearPicker) { }); // Assign buttons - AlertDialog.Builder db = new AlertDialog.Builder(getContext()); + AlertDialog.Builder db; + if (alertStyleId != 0) { + db = new AlertDialog.Builder(getContext(), alertStyleId); + } else { + db = new AlertDialog.Builder(getContext()); + } db.setView(dateTimeLayout); if(mPositiveButton == null) mPositiveButton = getString(R.string.positive_button_datetime_picker); @@ -552,13 +559,21 @@ public void setSimpleDateMonthAndDayFormat(SimpleDateFormat simpleDateFormat) th } /** - * Define if time miust be in 24 hours mode or in 12 hours, must be applied before "show" + * Define if time must be in 24 hours mode or in 12 hours, must be applied before "show" * @param is24HoursMode */ public void set24HoursMode(boolean is24HoursMode) { this.is24HoursMode = is24HoursMode; } + /** + * Define if the AlertDialog must be styled, must be applied before "show" + * @param styleId + */ + public void setAlertStyle(@StyleRes int styleId) { + this.alertStyleId = styleId; + } + /** * Class exception if SimpleDateFormat contains something else that "d" or/and "M" */ From fbab567cc16642a648550bb8655124ce709c400b Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Fri, 19 May 2017 15:31:23 +0200 Subject: [PATCH 2/4] Add setAlertStyle in Readme --- ReadMe.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ReadMe.md b/ReadMe.md index aaa0296..efee2b2 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -84,6 +84,10 @@ In your *styles.xml*, you can redefine each style separately, but you must keep ``` Styles elements : https://github.com/Kunzisoft/Android-SwitchDateTimePicker/blob/master/switchdatetime/src/main/res/values/styles.xml +#### AlertStyle +To customize the AlertDialog that is shown, use : +`void setAlertStyle(@StyleRes int styleId)` + ### Sample You can see https://github.com/J-Jamet/Android-SwitchDateTimePicker/blob/master/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java From f73eee62970f07e0b356c614e950edd5657e036c Mon Sep 17 00:00:00 2001 From: tahmid Date: Sun, 30 Apr 2017 01:39:48 +0600 Subject: [PATCH 3/4] Add feature in pull request #18 and upgrade gradle --- build.gradle | 2 +- .../switchdatetimesample/Sample.java | 6 +++--- .../src/main/res/layout/activity_sample.xml | 1 - .../SwitchDateTimeDialogFragment.java | 20 +++++++++++-------- .../src/main/res/values/strings.xml | 1 + 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 1ea4bd0..c2eea8e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:2.3.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java b/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java index 7d2f747..600ef06 100644 --- a/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java +++ b/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java @@ -46,8 +46,8 @@ protected void onCreate(Bundle savedInstanceState) { if(dateTimeFragment == null) { dateTimeFragment = SwitchDateTimeDialogFragment.newInstance( getString(R.string.label_datetime_dialog), - getString(R.string.positive_button_datetime_picker), - getString(R.string.negative_button_datetime_picker) + getString(android.R.string.ok), + getString(android.R.string.cancel) ); } @@ -100,4 +100,4 @@ public void onSaveInstanceState(Bundle savedInstanceState) { savedInstanceState.putCharSequence(STATE_TEXTVIEW, textView.getText()); super.onSaveInstanceState(savedInstanceState); } -} +} \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_sample.xml b/sample/src/main/res/layout/activity_sample.xml index 17cd091..696c0f6 100644 --- a/sample/src/main/res/layout/activity_sample.xml +++ b/sample/src/main/res/layout/activity_sample.xml @@ -23,5 +23,4 @@ android:layout_below="@+id/button" android:layout_centerHorizontal="true" /> - diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java index e581e93..d3c0ccd 100644 --- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java +++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java @@ -59,6 +59,7 @@ public class SwitchDateTimeDialogFragment extends DialogFragment { private int day = UNDEFINED_TIME_VALUE; private int hourOfDay = UNDEFINED_TIME_VALUE; private int minute = UNDEFINED_TIME_VALUE; + private boolean assignDefaultDateTimeCalendar; private boolean is24HoursMode = false; private int startAtPosition = 0; @@ -124,24 +125,26 @@ public void onSaveInstanceState(Bundle savedInstanceState) { mNegativeButton = getArguments().getString(TAG_NEGATIVE_BUTTON); } - if (savedInstanceState != null) { + if (!assignDefaultDateTimeCalendar && savedInstanceState != null) { // Restore value from saved state dateTimeCalendar.setTime(new Date(savedInstanceState.getLong(STATE_DATETIME))); } // Init values with current time if setDefault is not used - if(year == UNDEFINED_TIME_VALUE) + if(assignDefaultDateTimeCalendar || year == UNDEFINED_TIME_VALUE) year = dateTimeCalendar.get(Calendar.YEAR); - if(month == UNDEFINED_TIME_VALUE) + if(assignDefaultDateTimeCalendar || month == UNDEFINED_TIME_VALUE) month = dateTimeCalendar.get(Calendar.MONTH); - if(day == UNDEFINED_TIME_VALUE) + if(assignDefaultDateTimeCalendar || day == UNDEFINED_TIME_VALUE) day = dateTimeCalendar.get(Calendar.DAY_OF_MONTH); - if(hourOfDay == UNDEFINED_TIME_VALUE) + if(assignDefaultDateTimeCalendar || hourOfDay == UNDEFINED_TIME_VALUE) hourOfDay = dateTimeCalendar.get(Calendar.HOUR_OF_DAY); - if(minute == UNDEFINED_TIME_VALUE) + if(assignDefaultDateTimeCalendar || minute == UNDEFINED_TIME_VALUE) minute = dateTimeCalendar.get(Calendar.MINUTE); assignAllValuesToCalendar(); + assignDefaultDateTimeCalendar = false; + // Throw exception if default select date isn't between minimumDateTime and maximumDateTime if(dateTimeCalendar.before(minimumDateTime) || dateTimeCalendar.after(maximumDateTime)) throw new RuntimeException("Default date " + dateTimeCalendar.getTime() + " must be between " @@ -311,7 +314,7 @@ public void onYearSelected(View view, int yearPicker) { } db.setView(dateTimeLayout); if(mPositiveButton == null) - mPositiveButton = getString(R.string.positive_button_datetime_picker); + mPositiveButton = getString(android.R.string.ok); db.setPositiveButton(mPositiveButton, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { @@ -322,7 +325,7 @@ public void onClick(DialogInterface dialog, int which) { } }); if(mNegativeButton == null) - mNegativeButton = getString(R.string.negative_button_datetime_picker); + mNegativeButton = getString(android.R.string.cancel); db.setNegativeButton(mNegativeButton, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { @@ -503,6 +506,7 @@ public int getMinute() { */ public void setDefaultDateTime(Date date) { this.dateTimeCalendar.setTime(date); + this.assignDefaultDateTimeCalendar = true; } /** diff --git a/switchdatetime/src/main/res/values/strings.xml b/switchdatetime/src/main/res/values/strings.xml index 99965a0..eb6a599 100644 --- a/switchdatetime/src/main/res/values/strings.xml +++ b/switchdatetime/src/main/res/values/strings.xml @@ -5,6 +5,7 @@ DateTime + OK Cancel From 9b8b2d43ce6fd5e402467b2b3988edc37604c7fb Mon Sep 17 00:00:00 2001 From: JJamet Date: Mon, 12 Jun 2017 12:15:30 +0200 Subject: [PATCH 4/4] Add feature in pull request #18 and upgrade gradle --- ReadMe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReadMe.md b/ReadMe.md index efee2b2..dc43d4b 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -28,7 +28,7 @@ Add the JitPack repository in your build.gradle at the end of repositories: And add the dependency ``` dependencies { - compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.6' + compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.7' } ```