Add a time control in worklight and a time control in worklight

Source: Internet
Author: User

Add a time control in worklight and a time control in worklight

In the process of using worklight for development, due to the lack of open-source documentation and plug-ins, we always think about many things by ourselves and have more winners.

You need to call the source code to implement some functions that are not easy to implement. Paste the implemented function code here. If there are any shortcomings, I hope to correct them!

The implementation steps are not described much.

Implement date plug-in

1 public class DatePickerPlugin extends CordovaPlugin {2 3 private static final CordovaActivity ctx = null; 4 private static final String ACTION_DATE = "date"; 5 private static final String ACTION_TIME = "time "; 6 7 @ Override 8 public boolean execute (String action, JSONArray args, 9 CallbackContext callbackContext) throws JSONException {10 Log. d ("DatePickerPlugin", "Plugin Called"); 11 PluginResult result = null; 12 if (ACTION_DATE.equalsIgnoreCase (action) {13 Log. d ("DatePickerPluginListener execute", ACTION_DATE); 14 this. showDatePicker (callbackContext. getCallbackId (), callbackContext); 15 result = new PluginResult (16 PluginResult. status. NO_RESULT); 17 result. setKeepCallback (true); 18} else if (ACTION_TIME.equalsIgnoreCase (action) {19 Log. d ("DatePickerPluginListener execute", ACTION_TIME); 20 this. showTimePicker (callbackContext. getCallbackId (), callbackContext); 21 result = new PluginResult (22 PluginResult. status. NO_RESULT); 23 result. setKeepCallback (true); 24} else {25 result = new PluginResult (Status. INVALID_ACTION); 26 Log. d ("DatePickerPlugin", "Invalid action:" + action + "passed"); 27} 28 return false; 29} 30/** 31 * realize 32 * @ param callBackId 33 * @ param callbackContext 34 */35 public synchronized void showTimePicker (final String callBackId, final CallbackContext callbackContext) {36 final Calendar c = Calendar. getInstance (); 37 final int mWhen = c. get (Calendar. HOUR_OF_DAY); 38 final int mMin = c. get (Calendar. MINUTE); 39 40 final Runnable runnable = new Runnable () {41 public void run () {42 final timepickerditpd tpd = new TimePickerDialog (cordova. getActivity (), 43 new OnTimeSetListener () {44 45 public void onTimeSet (final TimePicker view, 46 final int hourOfDay, final int minute) {47 final JSONObject userChoice = new JSONObject (); 48 try {49 userChoice. put ("hour", hourOfDay); 50 userChoice. put ("min", minute); 51} catch (final JSONException jsonEx) {52 Log. e ("showDatePicker", 53 "Got JSON Exception" 54 + jsonEx. getMessage (); 55 callbackContext. sendPluginResult (new PluginResult (56 Status. JSON_EXCEPTION); 57} 58 callbackContext. sendPluginResult (new PluginResult (PluginResult. status. OK, 59 userChoice); 60} 61}, mWhen, mMin, true); 62 63 tpd. show (); 64} 65}; 66 this. cordova. getActivity (). runOnUiThread (runnable); 67} 68/** 69 * year-month-day implementation 70 * @ param callBackId 71 * @ param callbackContext 72 */73 public synchronized void showDatePicker (final String callBackId, final CallbackContext callbackContext) {74 75 final Calendar c = Calendar. getInstance (); 76 final int mYear = c. get (Calendar. YEAR); 77 final int mMonth = c. get (Calendar. MONTH); 78 final int mDay = c. get (Calendar. DAY_OF_MONTH); 79 80 final Runnable runnable = new Runnable () {81 82 public void run () {83 final DatePickerDialog dpd = new DatePickerDialog (cordova. getActivity (), 84 new OnDateSetListener () {85 86 public void onDateSet (final DatePicker view, 87 final int year, final int monthOfYear, 88 final int dayOfMonth) {89 90 final JSONObject userChoice = new JSONObject (); 91 92 try {93 userChoice. put ("year", year); 94 userChoice. put ("month", monthOfYear); 95 userChoice. put ("day", dayOfMonth); 96} catch (final JSONException jsonEx) {97 Log. e ("showDatePicker", 98 "Got JSON Exception" 99 + jsonEx. getMessage (); 100 callbackContext. sendPluginResult (new PluginResult (101 Status. JSON_EXCEPTION, userChoice); 102} 103 callbackContext. sendPluginResult (new PluginResult (104 PluginResult. status. OK, userChoice); 105 106} 107}, mYear, mMonth, mDay); 108 109 dpd. show (); 110} 111}; 112 this. cordova. getActivity (). runOnUiThread (runnable); 113} 114}

Of course, the implementation class must be configured in config. xml.

1 var DatePicker = function () {2}; 3 DatePicker. prototype. showDateOrTime = function (action, failed, failureCallback) {4 cordova.exe c (5 seconds, 6 failureCallback, 7 'dateickerin in', // Tell PhoneGap to run "DatePickerPlugin" Plugin 8 action, // Tell plugin, which action we want to perform 9 [] // paramter10); // Passing list of args to the plugin 11}; 12 cordova. addConstructor ( Function () {13 // if window. plugins is not supported, create and set 14 if (! Window. plugins) {15 window. plugins = {}; 16} 17 window. plugins. datePickerPlugin = new DatePicker (); 18 cordova. addPlugin ('dateickerplugin', new DatePicker (); 19 PluginManager. addService ("DatePickerPlugin", 20 "cn. gcsts. plugin. datePickerPlugin "); 21 });

Display

 


Q: Install the eclipse plug-in worklight.

The simplest Installation Method: Open the Eclipse official website, search for the workight icon, and drag it directly to eclipse. Then, you will install it on your own! Thank you for the simplest method. The best method has been passed on to you! Add points! If not, let me know!

How to add a time control in MFC

Are you talking about Timer like in delphi? There is no basic Timer control in MFC. If you want to use it, you must first settimer and then add the statement in the ontimer function. When the program ends, killtimer does not add personal taste, there are many examples in the library. I also have a stopwatch program. If you want to leave a message

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.