From 39f31327b9573e524d33ddf1018614c38b15a4b4 Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Sat, 21 Oct 2023 07:26:05 -0700 Subject: [PATCH] fix: date time picker minute step support Previously the minute step setting was ignored in the picker for DateTime types. This is corrected now. https://github.com/codenameone/CodenameOne/issues/3737 --- .../ui/spinner/DateTimeSpinner3D.java | 22 +++++++++++++------ .../src/com/codename1/ui/spinner/Picker.java | 5 ++--- .../codename1/ui/spinner/TimeSpinner3D.java | 11 ++++++++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/CodenameOne/src/com/codename1/ui/spinner/DateTimeSpinner3D.java b/CodenameOne/src/com/codename1/ui/spinner/DateTimeSpinner3D.java index 45e75d1afe..bace57b9da 100644 --- a/CodenameOne/src/com/codename1/ui/spinner/DateTimeSpinner3D.java +++ b/CodenameOne/src/com/codename1/ui/spinner/DateTimeSpinner3D.java @@ -59,12 +59,16 @@ class DateTimeSpinner3D extends Container implements InternalPickerWidget { /** * Default constructor */ - public DateTimeSpinner3D() { + public DateTimeSpinner3D(int minuteStep) { off = 0; - initSpinner(); + initSpinner(minuteStep); + } + + public DateTimeSpinner3D() { + this(TimeSpinner3D.DEFAULT_MINUTE_STEP); } - void initSpinner() { + void initSpinner(int minuteStep) { if(date == null) { date = Spinner3D.createDate(startDate.getTime() + off, endDate.getTime() + off, currentDate.getTime()); date.setPreferredW((int)(new Label("Thu Dec 27", "Spinner3DRow").getPreferredW() * 1.5f )); @@ -76,13 +80,17 @@ void initSpinner() { this.setStartDate(startDate); this.setEndDate(endDate); - time = new TimeSpinner3D(); - //getUnselectedStyle().setBgColor(date.getUnselectedStyle().getBgColor()); - //getUnselectedStyle().setBgTransparency(255); + time = new TimeSpinner3D(minuteStep); addComponents(); - } + } + + public int getMinuteStep() { + return time.getMinuteStep(); + } + public void setMinuteStep(int minuteStep) { + time.setMinuteStep(minuteStep); } @Override diff --git a/CodenameOne/src/com/codename1/ui/spinner/Picker.java b/CodenameOne/src/com/codename1/ui/spinner/Picker.java index 853e3fccbd..a7d2c7fe86 100644 --- a/CodenameOne/src/com/codename1/ui/spinner/Picker.java +++ b/CodenameOne/src/com/codename1/ui/spinner/Picker.java @@ -527,8 +527,7 @@ private CalendarPicker createCalendarPicker() { } private TimeSpinner3D createTimePicker3D() { - TimeSpinner3D out = new TimeSpinner3D(); - out.setMinuteStep(minuteStep); + TimeSpinner3D out = new TimeSpinner3D(minuteStep); out.setShowMeridiem(showMeridiem); if (minHour >= 0 && minHour < 24 && maxHour > minHour) { out.setHourRange(minHour, maxHour); @@ -542,7 +541,7 @@ private TimeSpinner3D createTimePicker3D() { } private DateTimeSpinner3D createDateTimePicker3D() { - DateTimeSpinner3D out = new DateTimeSpinner3D(); + DateTimeSpinner3D out = new DateTimeSpinner3D(minuteStep); out.setShowMeridiem(showMeridiem); if (startDate != null) { out.setStartDate(startDate); diff --git a/CodenameOne/src/com/codename1/ui/spinner/TimeSpinner3D.java b/CodenameOne/src/com/codename1/ui/spinner/TimeSpinner3D.java index a488dfc8fe..3f60a64e36 100644 --- a/CodenameOne/src/com/codename1/ui/spinner/TimeSpinner3D.java +++ b/CodenameOne/src/com/codename1/ui/spinner/TimeSpinner3D.java @@ -46,6 +46,8 @@ * @author Steve Hannah */ class TimeSpinner3D extends Container implements InternalPickerWidget { + + static final int DEFAULT_MINUTE_STEP = 5; private Spinner3D hour; private Spinner3D minute; private Spinner3D amPM; @@ -55,7 +57,7 @@ class TimeSpinner3D extends Container implements InternalPickerWidget { private int startHour = 1; private int endHour = 12; - private int minuteStep = 5; + private int minuteStep = DEFAULT_MINUTE_STEP; private boolean durationMode; private boolean showHours=true; @@ -68,9 +70,14 @@ class TimeSpinner3D extends Container implements InternalPickerWidget { /** * Default constructor */ - public TimeSpinner3D() { + public TimeSpinner3D(int minuteStep) { + this.minuteStep = minuteStep; initSpinner(); } + + public TimeSpinner3D() { + this(DEFAULT_MINUTE_STEP); + } /** * Default constructor