From b17cc9b3304c7e54496e9a6c3851de86090009c3 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Tue, 29 Nov 2016 17:08:15 +0100 Subject: [PATCH] Add start with specific view, change theme declaration --- ReadMe.md | 10 ++++++-- sample/src/main/AndroidManifest.xml | 8 ++++--- .../switchdatetimesample/Sample.java | 1 + switchdatetime/src/main/AndroidManifest.xml | 3 +-- .../SwitchDateTimeDialogFragment.java | 23 +++++++++++++++++++ 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 7a78c42..2145be5 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -27,14 +27,14 @@ 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.0' + compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.1' } ``` ## Usage ### SimpleDateFormat for Day and Month -You can specify a particular [*SimpleDateFormat*](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) for value of Day and Month with **setSimpleDateFormat(SimpleDateFormat format)** +You can specify a particular [*SimpleDateFormat*](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) for value of Day and Month with **setSimpleDateMonthAndDayFormat(SimpleDateFormat format)** Warning, the format must satisfy the regular expression : **(M|w|W|D|d|F|E|u|\s)*** , for example *dd MMMM* @@ -43,6 +43,11 @@ By default, time is in 12 hours mode, If you want a 24-hour display, use: `dateTimeFragment.set24HoursMode(true);` before the "show" +### Start with a specific view +For launch Dialog with a specific view, call : +`dateTimeFragment.startAtTimeView();`, `dateTimeFragment.startAtCalendarView();` or `dateTimeFragment.startAtYearView();` +before the "show" + ### Style You can customize the style to change color, bold, etc... of each element. In your *styles.xml*, for example @@ -137,6 +142,7 @@ SwitchDateTimeDialogFragment dateTimeDialogFragment = SwitchDateTimeDialogFragme ); // Assign values +dateTimeFragment.startAtCalendarView(); dateTimeFragment.set24HoursMode(true); dateTimeFragment.setDefaultHourOfDay(15); dateTimeFragment.setDefaultMinute(20); diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 6ee28bf..251f789 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ - - + - diff --git a/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java b/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java index 978c886..bc76203 100644 --- a/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java +++ b/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java @@ -52,6 +52,7 @@ protected void onCreate(Bundle savedInstanceState) { // Assign values we want final SimpleDateFormat myDateFormat = new SimpleDateFormat("d MMM yyyy HH:mm", java.util.Locale.getDefault()); + dateTimeFragment.startAtCalendarView(); dateTimeFragment.set24HoursMode(true); dateTimeFragment.setDefaultHourOfDay(15); dateTimeFragment.setDefaultMinute(20); diff --git a/switchdatetime/src/main/AndroidManifest.xml b/switchdatetime/src/main/AndroidManifest.xml index ed2ef38..40503df 100644 --- a/switchdatetime/src/main/AndroidManifest.xml +++ b/switchdatetime/src/main/AndroidManifest.xml @@ -4,8 +4,7 @@ + android:supportsRtl="true"> diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java index 7aaabb4..bc21284 100644 --- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java +++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java @@ -58,6 +58,7 @@ public class SwitchDateTimeDialogFragment extends DialogFragment { private int minute = UNDEFINED_TIME_VALUE; private boolean is24HoursMode = false; + private int startAtPosition = 0; private SimpleDateFormat dayAndMonthSimpleDate; private SimpleDateFormat yearSimpleDate; @@ -184,6 +185,7 @@ public void onAnimationEnd(Animation animation) { @Override public void onAnimationRepeat(Animation animation) {} }); + viewSwitcher.setDisplayedChild(startAtPosition); // Button for switch between Hours/Minutes, Calendar and YearList ImageButton buttonSwitch = (ImageButton) dateTimeLayout.findViewById(R.id.button_switch); @@ -329,6 +331,27 @@ private void assignAllValuesToCalendar() { dateTimeCalendar.set(Calendar.SECOND, 0); } + /** + * Define "Time" as the first view to show + */ + public void startAtTimeView() { + startAtPosition = 0; + } + + /** + * Define "Calendar" as the first view to show + */ + public void startAtCalendarView() { + startAtPosition = 1; + } + + /** + * Define "Year" as the first view to show + */ + public void startAtYearView() { + startAtPosition = 2; + } + /** * Assign default year at start * @param year