Back to project page Abstack-books-management.
The source code is released under:
MIT License
If you think the Android project Abstack-books-management listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.abstack.book.plugin; // w w w . j a v a 2 s. com import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CordovaPlugin; import org.json.JSONArray; import org.json.JSONException; import android.widget.Toast; public class ToastPlugin extends CordovaPlugin { private static final String TOAST = "toast"; @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (TOAST.equals(action)) { toast(args, callbackContext); } else { callbackContext.error("Methods that are not allowed!"); return false; } return true; } private void toast(JSONArray args, CallbackContext callbackContext) { int len = args.length(); Toast toast; int time = 2000; try { switch (len) { case 2: time = args.getInt(1); case 1: if("".equals(args.getString(0))) { callbackContext.error("Message info not null!"); return; } toast = Toast.makeText(this.cordova.getActivity(), args.getString(0), time); break; default: callbackContext.error("Number of parameters is not enough!"); return; } toast.show(); } catch (JSONException e) { callbackContext.error("Illegal json data!"); } } }