From 5717f07f882387d7bf9c15159aa9e45e335cd178 Mon Sep 17 00:00:00 2001 From: pprodel Date: Wed, 5 Apr 2017 11:30:00 +0200 Subject: [PATCH 1/6] Add interval timepicker --- plugin.xml | 1 + src/android/CustomTimePickerDialog.java | 74 +++++++++++++++++++++++++ src/android/DatePickerPlugin.java | 4 +- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 src/android/CustomTimePickerDialog.java diff --git a/plugin.xml b/plugin.xml index 3a23c2c..1db8b11 100644 --- a/plugin.xml +++ b/plugin.xml @@ -28,6 +28,7 @@ + diff --git a/src/android/CustomTimePickerDialog.java b/src/android/CustomTimePickerDialog.java new file mode 100644 index 0000000..63022b8 --- /dev/null +++ b/src/android/CustomTimePickerDialog.java @@ -0,0 +1,74 @@ +package com.plugin.datepicker; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import android.app.TimePickerDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.widget.NumberPicker; +import android.widget.TimePicker; +import android.os.Bundle; + +public class CustomTimePickerDialog extends TimePickerDialog { + + final OnTimeSetListener mCallback; + TimePicker mTimePicker; + final int increment; + + public CustomTimePickerDialog(Context context, int theme, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView, int increment) + { + super(context, theme, callBack, hourOfDay, minute/increment, is24HourView); + this.mCallback = callBack; + this.increment = increment; + } + + @Override + public void onClick(DialogInterface dialog, int which) { + if (mCallback != null && mTimePicker!=null) { + mTimePicker.clearFocus(); + mCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(), + mTimePicker.getCurrentMinute()*increment); + } + } + + @Override + public void updateTime(int hourOfDay, int minuteOfHour) { + mTimePicker.setCurrentHour(hourOfDay); + mTimePicker.setCurrentMinute(minuteOfHour/increment); + } + + @Override + protected void onStop() + { + // override and do nothing + } + + @Override + protected void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + try + { + Class rClass = Class.forName("com.android.internal.R$id"); + Field timePicker = rClass.getField("timePicker"); + this.mTimePicker = (TimePicker)findViewById(timePicker.getInt(null)); + Field m = rClass.getField("minute"); + + NumberPicker mMinuteSpinner = (NumberPicker)mTimePicker.findViewById(m.getInt(null)); + mMinuteSpinner.setMinValue(0); + mMinuteSpinner.setMaxValue((60/increment)-1); + List displayedValues = new ArrayList(); + for(int i=0;i<60;i+=increment) + { + displayedValues.add(String.format("%02d", i)); + } + mMinuteSpinner.setDisplayedValues(displayedValues.toArray(new String[0])); + } + catch (Exception e) + { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/android/DatePickerPlugin.java b/src/android/DatePickerPlugin.java index b76edcc..a4c7566 100644 --- a/src/android/DatePickerPlugin.java +++ b/src/android/DatePickerPlugin.java @@ -95,8 +95,8 @@ private Runnable runnableTimeDialog(final DatePickerPlugin datePickerPlugin, @Override public void run() { final TimeSetListener timeSetListener = new TimeSetListener(datePickerPlugin, callbackContext, calendarDate); - final TimePickerDialog timeDialog = new TimePickerDialog(currentCtx, theme, timeSetListener, jsonDate.hour, - jsonDate.minutes, jsonDate.is24Hour) { + final TimePickerDialog timeDialog = new CustomTimePickerDialog(currentCtx, theme, timeSetListener, jsonDate.hour, + jsonDate.minutes, jsonDate.is24Hour, 15) { public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { timePicker = view; timePickerHour = hourOfDay; From f139cd65a5f01133b55b7d2425f983b3790f9a9f Mon Sep 17 00:00:00 2001 From: pprodel Date: Wed, 5 Apr 2017 11:33:12 +0200 Subject: [PATCH 2/6] Add interval timepicker --- src/android/DatePickerPlugin.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/android/DatePickerPlugin.java b/src/android/DatePickerPlugin.java index a4c7566..d5d0fe5 100644 --- a/src/android/DatePickerPlugin.java +++ b/src/android/DatePickerPlugin.java @@ -96,7 +96,7 @@ private Runnable runnableTimeDialog(final DatePickerPlugin datePickerPlugin, public void run() { final TimeSetListener timeSetListener = new TimeSetListener(datePickerPlugin, callbackContext, calendarDate); final TimePickerDialog timeDialog = new CustomTimePickerDialog(currentCtx, theme, timeSetListener, jsonDate.hour, - jsonDate.minutes, jsonDate.is24Hour, 15) { + jsonDate.minutes, jsonDate.is24Hour, jsonDate.minuteInterval) { public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { timePicker = view; timePickerHour = hourOfDay; @@ -380,6 +380,8 @@ public JsonDate fromJson(JSONArray data) { : ""; is24Hour = isNotEmpty(obj, "is24Hour") ? obj.getBoolean("is24Hour") : false; + minuteInterval = isNotEmpty(obj, "minuteInterval") ? obj.getInt("minuteInterval") + : 1; String optionDate = obj.getString("date"); From b8e8f5e108f5ea026e0a78dd220a23d06467d494 Mon Sep 17 00:00:00 2001 From: pprodel Date: Wed, 5 Apr 2017 11:49:56 +0200 Subject: [PATCH 3/6] Add interval timepicker --- src/android/DatePickerPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/android/DatePickerPlugin.java b/src/android/DatePickerPlugin.java index d5d0fe5..d9197f4 100644 --- a/src/android/DatePickerPlugin.java +++ b/src/android/DatePickerPlugin.java @@ -348,6 +348,7 @@ private final class JsonDate { private int hour = 0; private int minutes = 0; private boolean is24Hour = false; + private int minuteInterval = 1; public JsonDate() { reset(Calendar.getInstance()); From 34ec6ddc1f007736c1c9406d8241b9223775f04f Mon Sep 17 00:00:00 2001 From: pprodel Date: Thu, 6 Apr 2017 09:38:10 +0200 Subject: [PATCH 4/6] Add interval timepicker + limit hour when current day --- src/android/CustomTimePickerDialog.java | 63 ++++++++-- src/android/DatePickerPlugin.java | 154 +++++++++++++----------- www/android/DatePicker.js | 1 + 3 files changed, 138 insertions(+), 80 deletions(-) diff --git a/src/android/CustomTimePickerDialog.java b/src/android/CustomTimePickerDialog.java index 63022b8..2c5fd41 100644 --- a/src/android/CustomTimePickerDialog.java +++ b/src/android/CustomTimePickerDialog.java @@ -16,6 +16,30 @@ public class CustomTimePickerDialog extends TimePickerDialog { final OnTimeSetListener mCallback; TimePicker mTimePicker; final int increment; + private int minHour = 0; + private int maxHour = 24; + private int minMinute = 0; + private int maxMinute = 60; + + public int getMinHour() { + return minHour; + } + + public void setMinHour(int minHour) { + this.minHour = minHour; + } + + public void setMaxHour(int maxHour) { + this.maxHour = maxHour; + } + + public void setMinMinute(int minMinute) { + this.minMinute = minMinute; + } + + public void setMaxMinute(int maxMinute) { + this.maxMinute = maxMinute; + } public CustomTimePickerDialog(Context context, int theme, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView, int increment) { @@ -36,7 +60,7 @@ public void onClick(DialogInterface dialog, int which) { @Override public void updateTime(int hourOfDay, int minuteOfHour) { mTimePicker.setCurrentHour(hourOfDay); - mTimePicker.setCurrentMinute(minuteOfHour/increment); + mTimePicker.setCurrentMinute((minuteOfHour-minMinute)/increment); } @Override @@ -45,6 +69,31 @@ protected void onStop() // override and do nothing } + private void setHourSpinner(TimePicker timePicker, Field hour) throws IllegalAccessException{ + NumberPicker mHourSpinner = (NumberPicker)timePicker.findViewById(hour.getInt(null)); + mHourSpinner.setMinValue(minHour); + mHourSpinner.setMaxValue(maxHour-1); + List displayedHoursValues = new ArrayList(); + for(int i=minHour;i displayedMinutesValues = new ArrayList(); + for(int i=newMin;i displayedValues = new ArrayList(); - for(int i=0;i<60;i+=increment) - { - displayedValues.add(String.format("%02d", i)); - } - mMinuteSpinner.setDisplayedValues(displayedValues.toArray(new String[0])); + setHourSpinner(this.mTimePicker, h); + setMinuteSpinner(this.mTimePicker, m); } catch (Exception e) { diff --git a/src/android/DatePickerPlugin.java b/src/android/DatePickerPlugin.java index d9197f4..b6879df 100644 --- a/src/android/DatePickerPlugin.java +++ b/src/android/DatePickerPlugin.java @@ -16,7 +16,6 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.TimeZone; -import java.util.Random; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; @@ -27,7 +26,6 @@ import android.annotation.SuppressLint; import android.app.DatePickerDialog; import android.app.DatePickerDialog.OnDateSetListener; -import android.app.TimePickerDialog; import android.app.TimePickerDialog.OnTimeSetListener; import android.content.Context; import android.content.DialogInterface; @@ -45,7 +43,7 @@ public class DatePickerPlugin extends CordovaPlugin { private static final String RESULT_ERROR = "error"; private static final String RESULT_CANCEL = "cancel"; private final String pluginName = "DatePickerPlugin"; - + // On some devices, onDateSet or onTimeSet are being called twice private boolean called = false; private boolean canceled = false; @@ -68,10 +66,10 @@ public synchronized void show(final JSONArray data, final CallbackContext callba Context currentCtx = cordova.getActivity(); Runnable runnable; JsonDate jsonDate = new JsonDate().fromJson(data); - - // Retrieve Android theme - JSONObject options = data.optJSONObject(0); - int theme = options.optInt("androidTheme", 1); + + // Retrieve Android theme + JSONObject options = data.optJSONObject(0); + int theme = options.optInt("androidTheme", 1); if (ACTION_TIME.equalsIgnoreCase(jsonDate.action)) { runnable = runnableTimeDialog(datePickerPlugin, theme, currentCtx, @@ -83,19 +81,19 @@ public synchronized void show(final JSONArray data, final CallbackContext callba cordova.getActivity().runOnUiThread(runnable); } - + private TimePicker timePicker; private int timePickerHour = 0; private int timePickerMinute = 0; - + private Runnable runnableTimeDialog(final DatePickerPlugin datePickerPlugin, - final int theme, final Context currentCtx, final CallbackContext callbackContext, - final JsonDate jsonDate, final Calendar calendarDate) { + final int theme, final Context currentCtx, final CallbackContext callbackContext, + final JsonDate jsonDate, final Calendar calendarDate) { return new Runnable() { @Override public void run() { final TimeSetListener timeSetListener = new TimeSetListener(datePickerPlugin, callbackContext, calendarDate); - final TimePickerDialog timeDialog = new CustomTimePickerDialog(currentCtx, theme, timeSetListener, jsonDate.hour, + final CustomTimePickerDialog timeDialog = new CustomTimePickerDialog(currentCtx, theme, timeSetListener, jsonDate.hour, jsonDate.minutes, jsonDate.is24Hour, jsonDate.minuteInterval) { public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { timePicker = view; @@ -106,7 +104,7 @@ public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { timeDialog.setCancelable(true); timeDialog.setCanceledOnTouchOutside(false); - + if (!jsonDate.titleText.isEmpty()){ timeDialog.setTitle(jsonDate.titleText); } @@ -120,8 +118,8 @@ public void onClick(DialogInterface dialog, int which) { } } }); - } - String labelCancel = jsonDate.cancelText.isEmpty() ? currentCtx.getString(android.R.string.cancel) : jsonDate.cancelText; + } + String labelCancel = jsonDate.cancelText.isEmpty() ? currentCtx.getString(android.R.string.cancel) : jsonDate.cancelText; timeDialog.setButton(DialogInterface.BUTTON_NEGATIVE, labelCancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -132,13 +130,29 @@ public void onClick(DialogInterface dialog, int which) { String labelOk = jsonDate.okText.isEmpty() ? currentCtx.getString(android.R.string.ok) : jsonDate.okText; timeDialog.setButton(DialogInterface.BUTTON_POSITIVE, labelOk, timeDialog); } + + Calendar todayDate = calendarDate.getInstance(); + todayDate.set(Calendar.MINUTE, 0); + todayDate.set(Calendar.SECOND, 0); + todayDate.set(Calendar.MILLISECOND, 0); + + calendarDate.set(Calendar.MINUTE, 0); + calendarDate.set(Calendar.SECOND, 0); + calendarDate.set(Calendar.MILLISECOND, 0); + + if (todayDate.getTime().compareTo(calendarDate.getTime()) == 0) + { + timeDialog.setMinHour(calendarDate.get(Calendar.HOUR_OF_DAY)); + } else { + timeDialog.setMinHour(0); + } + timeDialog.show(); - timeDialog.updateTime(new Random().nextInt(23), new Random().nextInt(59)); timeDialog.updateTime(jsonDate.hour, jsonDate.minutes); } }; } - + private Runnable runnableDatePicker( final DatePickerPlugin datePickerPlugin, final int theme, final Context currentCtx, @@ -155,48 +169,48 @@ public void run() { else { prepareDialogPreHoneycomb(dateDialog, callbackContext, currentCtx, jsonDate); } - + dateDialog.show(); } }; } - - private void prepareDialog(final DatePickerDialog dateDialog, final OnDateSetListener dateListener, - final CallbackContext callbackContext, Context currentCtx, JsonDate jsonDate) { + + private void prepareDialog(final DatePickerDialog dateDialog, final OnDateSetListener dateListener, + final CallbackContext callbackContext, Context currentCtx, JsonDate jsonDate) { dateDialog.setCancelable(true); dateDialog.setCanceledOnTouchOutside(false); if (!jsonDate.titleText.isEmpty()){ dateDialog.setTitle(jsonDate.titleText); } if (!jsonDate.todayText.isEmpty()){ - dateDialog.setButton(DialogInterface.BUTTON_NEUTRAL, jsonDate.todayText, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Calendar now = Calendar.getInstance(); - DatePicker datePicker = dateDialog.getDatePicker(); + dateDialog.setButton(DialogInterface.BUTTON_NEUTRAL, jsonDate.todayText, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Calendar now = Calendar.getInstance(); + DatePicker datePicker = dateDialog.getDatePicker(); dateListener.onDateSet(datePicker, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); - } - }); - } - String labelCancel = jsonDate.cancelText.isEmpty() ? currentCtx.getString(android.R.string.cancel) : jsonDate.cancelText; + } + }); + } + String labelCancel = jsonDate.cancelText.isEmpty() ? currentCtx.getString(android.R.string.cancel) : jsonDate.cancelText; dateDialog.setButton(DialogInterface.BUTTON_NEGATIVE, labelCancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { + @Override + public void onClick(DialogInterface dialog, int which) { canceled = true; callbackContext.error(RESULT_CANCEL); - } - }); + } + }); String labelOk = jsonDate.okText.isEmpty() ? currentCtx.getString(android.R.string.ok) : jsonDate.okText; dateDialog.setButton(DialogInterface.BUTTON_POSITIVE, labelOk, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { + @Override + public void onClick(DialogInterface dialog, int which) { DatePicker datePicker = dateDialog.getDatePicker(); datePicker.clearFocus(); dateListener.onDateSet(datePicker, datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); - } - }); - - DatePicker dp = dateDialog.getDatePicker(); + } + }); + + DatePicker dp = dateDialog.getDatePicker(); if(jsonDate.minDate > 0) { dp.setMinDate(jsonDate.minDate); } @@ -204,9 +218,9 @@ public void onClick(DialogInterface dialog, int which) { dp.setMaxDate(jsonDate.maxDate); } } - + private void prepareDialogPreHoneycomb(DatePickerDialog dateDialog, - final CallbackContext callbackContext, Context currentCtx, final JsonDate jsonDate){ + final CallbackContext callbackContext, Context currentCtx, final JsonDate jsonDate){ java.lang.reflect.Field mDatePickerField = null; try { mDatePickerField = dateDialog.getClass().getDeclaredField("mDatePicker"); @@ -229,28 +243,28 @@ private void prepareDialogPreHoneycomb(DatePickerDialog dateDialog, endDate.setTimeInMillis(jsonDate.maxDate); final int minYear = startDate.get(Calendar.YEAR); - final int minMonth = startDate.get(Calendar.MONTH); - final int minDay = startDate.get(Calendar.DAY_OF_MONTH); - final int maxYear = endDate.get(Calendar.YEAR); - final int maxMonth = endDate.get(Calendar.MONTH); - final int maxDay = endDate.get(Calendar.DAY_OF_MONTH); + final int minMonth = startDate.get(Calendar.MONTH); + final int minDay = startDate.get(Calendar.DAY_OF_MONTH); + final int maxYear = endDate.get(Calendar.YEAR); + final int maxMonth = endDate.get(Calendar.MONTH); + final int maxDay = endDate.get(Calendar.DAY_OF_MONTH); if(startDate !=null || endDate != null) { pickerView.init(jsonDate.year, jsonDate.month, jsonDate.day, new OnDateChangedListener() { - @Override + @Override public void onDateChanged(DatePicker view, int year, int month, int day) { - if(jsonDate.maxDate > 0 && jsonDate.maxDate > jsonDate.minDate) { - if(year > maxYear || month > maxMonth && year == maxYear || day > maxDay && year == maxYear && month == maxMonth){ - view.updateDate(maxYear, maxMonth, maxDay); - } - } - if(jsonDate.minDate > 0) { - if(year < minYear || month < minMonth && year == minYear || day < minDay && year == minYear && month == minMonth) { - view.updateDate(minYear, minMonth, minDay); - } - } - } - }); + if(jsonDate.maxDate > 0 && jsonDate.maxDate > jsonDate.minDate) { + if(year > maxYear || month > maxMonth && year == maxYear || day > maxDay && year == maxYear && month == maxMonth){ + view.updateDate(maxYear, maxMonth, maxDay); + } + } + if(jsonDate.minDate > 0) { + if(year < minYear || month < minMonth && year == minYear || day < minDay && year == minYear && month == minMonth) { + view.updateDate(minYear, minMonth, minDay); + } + } + } + }); } } @@ -264,7 +278,7 @@ private DateSetListener(DatePickerPlugin datePickerPlugin, int theme, CallbackCo this.datePickerPlugin = datePickerPlugin; this.callbackContext = callbackContext; this.jsonDate = jsonDate; - this.theme = theme; + this.theme = theme; } /** @@ -277,24 +291,24 @@ public void onDateSet(final DatePicker view, final int year, final int monthOfYe } called = true; canceled = false; - + Log.d("onDateSet", "called: " + called); Log.d("onDateSet", "canceled: " + canceled); Log.d("onDateSet", "mode: " + jsonDate.action); - + if (ACTION_DATE.equalsIgnoreCase(jsonDate.action)) { String returnDate = year + "/" + (monthOfYear + 1) + "/" + dayOfMonth; Log.d("onDateSet", "returnDate: " + returnDate); - + callbackContext.success(returnDate); - + } else { // Open time dialog Calendar selectedDate = Calendar.getInstance(); selectedDate.set(Calendar.YEAR, year); selectedDate.set(Calendar.MONTH, monthOfYear); selectedDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); - + cordova.getActivity().runOnUiThread(runnableTimeDialog(datePickerPlugin, theme, cordova.getActivity(), callbackContext, jsonDate, selectedDate)); } @@ -319,7 +333,7 @@ public void onTimeSet(final TimePicker view, final int hourOfDay, final int minu if (canceled) { return; } - + calendarDate.set(Calendar.HOUR_OF_DAY, hourOfDay); calendarDate.set(Calendar.MINUTE, minute); calendarDate.set(Calendar.SECOND, 0); @@ -331,9 +345,9 @@ public void onTimeSet(final TimePicker view, final int hourOfDay, final int minu callbackContext.success(toReturn); } } - + private final class JsonDate { - + private String action = ACTION_DATE; private String titleText = ""; private String okText = ""; @@ -406,7 +420,7 @@ public boolean isNotEmpty(JSONObject object, String key) && !object.isNull(key) && object.get(key).toString().length() > 0 && !JSONObject.NULL.toString().equals( - object.get(key).toString()); + object.get(key).toString()); } } diff --git a/www/android/DatePicker.js b/www/android/DatePicker.js index 3ba4c22..ed71a95 100644 --- a/www/android/DatePicker.js +++ b/www/android/DatePicker.js @@ -45,6 +45,7 @@ DatePicker.prototype.show = function(options, cb, errCb) { todayText: '', nowText: '', is24Hour: false, + minuteInterval: 1, androidTheme : window.datePicker.ANDROID_THEMES.THEME_TRADITIONAL, // Default theme }; From c5ce7f86b7fb51cce5ab3557cdf1faac98b8aae1 Mon Sep 17 00:00:00 2001 From: pprodel Date: Thu, 6 Apr 2017 18:11:26 +0200 Subject: [PATCH 5/6] Fix crash when minDate > current date --- src/android/DatePickerPlugin.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/android/DatePickerPlugin.java b/src/android/DatePickerPlugin.java index b6879df..64dc738 100644 --- a/src/android/DatePickerPlugin.java +++ b/src/android/DatePickerPlugin.java @@ -212,10 +212,24 @@ public void onClick(DialogInterface dialog, int which) { DatePicker dp = dateDialog.getDatePicker(); if(jsonDate.minDate > 0) { - dp.setMinDate(jsonDate.minDate); + final Calendar minDate = Calendar.getInstance(); + minDate.setTimeInMillis(jsonDate.minDate); + minDate.set(Calendar.HOUR_OF_DAY, minDate.getMinimum(Calendar.HOUR_OF_DAY)); + minDate.set(Calendar.MINUTE, minDate.getMinimum(Calendar.MINUTE)); + minDate.set(Calendar.SECOND, minDate.getMinimum(Calendar.SECOND)); + minDate.set(Calendar.MILLISECOND, minDate.getMinimum(Calendar.MILLISECOND)); + + dp.setMinDate(minDate.getTimeInMillis()); } if(jsonDate.maxDate > 0 && jsonDate.maxDate > jsonDate.minDate) { - dp.setMaxDate(jsonDate.maxDate); + final Calendar maxDate = Calendar.getInstance(); + maxDate.setTimeInMillis(jsonDate.maxDate); + maxDate.set(Calendar.HOUR_OF_DAY, maxDate.getMaximum(Calendar.HOUR_OF_DAY)); + maxDate.set(Calendar.MINUTE, maxDate.getMaximum(Calendar.MINUTE)); + maxDate.set(Calendar.SECOND, maxDate.getMaximum(Calendar.SECOND)); + maxDate.set(Calendar.MILLISECOND, maxDate.getMaximum(Calendar.MILLISECOND)); + + dp.setMaxDate(maxDate.getTimeInMillis()); } } From 1e61725ed8802701e41ab1ec7eabc0f5f9fcf8fe Mon Sep 17 00:00:00 2001 From: pprodel Date: Thu, 19 Oct 2017 11:59:19 +0200 Subject: [PATCH 6/6] Fix timepicker android 7.0 --- src/android/CustomTimePickerDialog.java | 15 +++++++++++++-- src/android/DatePickerPlugin.java | 8 +++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/android/CustomTimePickerDialog.java b/src/android/CustomTimePickerDialog.java index 2c5fd41..d9e4804 100644 --- a/src/android/CustomTimePickerDialog.java +++ b/src/android/CustomTimePickerDialog.java @@ -16,6 +16,7 @@ public class CustomTimePickerDialog extends TimePickerDialog { final OnTimeSetListener mCallback; TimePicker mTimePicker; final int increment; + final int theme; private int minHour = 0; private int maxHour = 24; private int minMinute = 0; @@ -46,14 +47,16 @@ public CustomTimePickerDialog(Context context, int theme, OnTimeSetListener call super(context, theme, callBack, hourOfDay, minute/increment, is24HourView); this.mCallback = callBack; this.increment = increment; + this.theme = theme; } @Override public void onClick(DialogInterface dialog, int which) { if (mCallback != null && mTimePicker!=null) { mTimePicker.clearFocus(); + int minutes = theme != 2 ? mTimePicker.getCurrentMinute(): mTimePicker.getCurrentMinute()*increment; mCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(), - mTimePicker.getCurrentMinute()*increment); + minutes); } } @@ -63,6 +66,14 @@ public void updateTime(int hourOfDay, int minuteOfHour) { mTimePicker.setCurrentMinute((minuteOfHour-minMinute)/increment); } + public void updateTimeClock(int hourOfDay, int minuteOfHour) { + if(minuteOfHour == maxMinute){ + minuteOfHour = 0; + } + mTimePicker.setCurrentHour(hourOfDay); + mTimePicker.setCurrentMinute(minuteOfHour); + } + @Override protected void onStop() { @@ -114,4 +125,4 @@ protected void onCreate(Bundle savedInstanceState) e.printStackTrace(); } } -} \ No newline at end of file +} diff --git a/src/android/DatePickerPlugin.java b/src/android/DatePickerPlugin.java index 64dc738..1e1a1f6 100644 --- a/src/android/DatePickerPlugin.java +++ b/src/android/DatePickerPlugin.java @@ -98,7 +98,13 @@ public void run() { public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { timePicker = view; timePickerHour = hourOfDay; - timePickerMinute = minute; + if(theme != 2){ + int offset = minute%jsonDate.minuteInterval != 0 ? jsonDate.minuteInterval: 0; + timePickerMinute = (minute/jsonDate.minuteInterval)*jsonDate.minuteInterval + offset; + updateTimeClock(timePickerHour, timePickerMinute); + } else { + timePickerMinute = minute; + } } }; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {