From be1c632543c64d18d642f532a5a7f9463b5f7a1a Mon Sep 17 00:00:00 2001 From: njleonzhang Date: Wed, 29 Jun 2016 14:36:51 +0800 Subject: [PATCH] errorCb is not invoked in android 6.0.1 --- src/android/DatePickerPlugin.java | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/android/DatePickerPlugin.java b/src/android/DatePickerPlugin.java index b76edcc..e36e76e 100644 --- a/src/android/DatePickerPlugin.java +++ b/src/android/DatePickerPlugin.java @@ -27,12 +27,14 @@ import android.annotation.SuppressLint; import android.app.DatePickerDialog; import android.app.DatePickerDialog.OnDateSetListener; +import android.app.Dialog; import android.app.TimePickerDialog; import android.app.TimePickerDialog.OnTimeSetListener; import android.content.Context; import android.content.DialogInterface; import android.os.Build; import android.util.Log; +import android.view.KeyEvent; import android.widget.DatePicker; import android.widget.DatePicker.OnDateChangedListener; import android.widget.TimePicker; @@ -129,6 +131,19 @@ public void onClick(DialogInterface dialog, int which) { callbackContext.error(RESULT_CANCEL); } }); + + timeDialog.setOnKeyListener(new Dialog.OnKeyListener() { + @Override + public boolean onKey(DialogInterface arg0, int keyCode, + KeyEvent event) { + // TODO Auto-generated method stub + if (keyCode == KeyEvent.KEYCODE_BACK) { + callbackContext.error(RESULT_CANCEL); + } + return false; + } + }); + String labelOk = jsonDate.okText.isEmpty() ? currentCtx.getString(android.R.string.ok) : jsonDate.okText; timeDialog.setButton(DialogInterface.BUTTON_POSITIVE, labelOk, timeDialog); } @@ -195,7 +210,20 @@ public void onClick(DialogInterface dialog, int which) { dateListener.onDateSet(datePicker, datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); } }); - + + dateDialog.setOnKeyListener(new Dialog.OnKeyListener() { + @Override + public boolean onKey(DialogInterface arg0, int keyCode, + KeyEvent event) { + // TODO Auto-generated method stub + Log.i(pluginName, "dateDialog onKey"); + if (keyCode == KeyEvent.KEYCODE_BACK) { + callbackContext.error(RESULT_CANCEL); + } + return false; + } + }); + DatePicker dp = dateDialog.getDatePicker(); if(jsonDate.minDate > 0) { dp.setMinDate(jsonDate.minDate);