/// <summary> /// Triggers special UI to select a date (day/month/year) /// </summary> public void selectDate(string options) { try { try { this.dateTimePickerOptions = String.IsNullOrEmpty(options) ? new DateTimePickerOptions() : CordovaClassLib.Cordova.JSON.JsonHelper.Deserialize<DateTimePickerOptions>(options); } catch (Exception ex) { this.DispatchCommandResult(new CordovaClassLib.Cordova.PluginResult(CordovaClassLib.Cordova.PluginResult.Status.JSON_EXCEPTION, ex.Message)); return; } this.dateTimePickerTask = new DateTimePickerTask(); dateTimePickerTask.Value = dateTimePickerOptions.Value; dateTimePickerTask.Completed += this.dateTimePickerTask_Completed; dateTimePickerTask.Show(DateTimePickerTask.DateTimePickerType.Date); } catch (Exception e) { DispatchCommandResult(new CordovaClassLib.Cordova.PluginResult(CordovaClassLib.Cordova.PluginResult.Status.ERROR, e.Message)); } }
public void selectTime(string options) { try { if (ResultHandlers.ContainsKey(CurrentCommandCallbackId)) { mySavedHandler = ResultHandlers[CurrentCommandCallbackId]; } if (!GetDefaults(options)) { return; } _dateTimePickerTask = new DateTimePickerTask { Value = _dateTimePickerOptions.Value, Step = _dateTimePickerOptions.Step }; _dateTimePickerTask.Completed += dateTimePickerTask_Completed; _dateTimePickerTask.Show(DateTimePickerTask.DateTimePickerType.Time); } catch (Exception e) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, e.Message), _callbackId); } }
private void dateTimePickerTask_Completed(object sender, DateTimePickerTask.DateTimeResult e) { if (e.Error != null) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR), _callbackId); return; } switch (e.TaskResult) { case TaskResult.OK: try { var result = (long)e.Value.Value.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; if (!ResultHandlers.ContainsKey(CurrentCommandCallbackId)) { ResultHandlers.Add(CurrentCommandCallbackId, mySavedHandler); } DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result.ToString()), _callbackId); } catch (Exception ex) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Datetime picker error. " + ex.Message), _callbackId); } break; case TaskResult.Cancel: DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Cancelled."), _callbackId); break; } _dateTimePickerTask = null; }
/// <summary> /// Triggers special UI to select a time (hour/minute/am/pm). /// </summary> public void selectTime(string options) { try { try { this.dateTimePickerOptions = String.IsNullOrEmpty(options) ? new DateTimePickerOptions() : CordovaClassLib.Cordova.JSON.JsonHelper.Deserialize <DateTimePickerOptions>(options); } catch (Exception ex) { this.DispatchCommandResult(new CordovaClassLib.Cordova.PluginResult(CordovaClassLib.Cordova.PluginResult.Status.JSON_EXCEPTION, ex.Message)); return; } this.dateTimePickerTask = new DateTimePickerTask(); dateTimePickerTask.Value = dateTimePickerOptions.Value; dateTimePickerTask.Completed += this.dateTimePickerTask_Completed; dateTimePickerTask.Show(DateTimePickerTask.DateTimePickerType.Time); } catch (Exception e) { DispatchCommandResult(new CordovaClassLib.Cordova.PluginResult(CordovaClassLib.Cordova.PluginResult.Status.ERROR, e.Message)); } }
/// <summary> /// Handles datetime picker result /// </summary> /// <param name="sender"></param> /// <param name="e">stores information about current captured image</param> private void dateTimePickerTask_Completed(object sender, DateTimePickerTask.DateTimeResult e) { if (e.Error != null) { DispatchCommandResult(new CordovaClassLib.Cordova.PluginResult(CordovaClassLib.Cordova.PluginResult.Status.ERROR)); return; } switch (e.TaskResult) { case TaskResult.OK: try { DispatchCommandResult(new CordovaClassLib.Cordova.PluginResult(CordovaClassLib.Cordova.PluginResult.Status.OK, e.Value.Value.ToString())); } catch (Exception ex) { DispatchCommandResult(new CordovaClassLib.Cordova.PluginResult(CordovaClassLib.Cordova.PluginResult.Status.ERROR, "Datetime picker error. " + ex.Message)); } break; case TaskResult.Cancel: DispatchCommandResult(new CordovaClassLib.Cordova.PluginResult(CordovaClassLib.Cordova.PluginResult.Status.ERROR, "Canceled.")); break; } this.dateTimePickerTask = null; }