package de.phonostar;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

import android.content.Context;
import android.view.KeyEvent;
import android.view.inputmethod.InputMethodManager;

public class SoftKeyboard extends CordovaPlugin {

    public SoftKeyboard() {
    }

    public void showKeyBoard() {
      InputMethodManager mgr = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
      mgr.showSoftInput(webView, InputMethodManager.SHOW_IMPLICIT);

      ((InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(webView, 0);
    }

    public void hideKeyBoard() {
      InputMethodManager mgr = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
      mgr.hideSoftInputFromWindow(webView.getWindowToken(), 0);
    }

    public boolean isKeyBoardShowing() {
      int heightDiff = webView.getRootView().getHeight() - webView.getHeight();
      return (100 < heightDiff); // if more than 100 pixels, its probably a keyboard...
    }

    public boolean sendKey(final int keyCode, final CallbackContext callbackContext) {
      /**
       if (!isKeyBoardShowing()) {
        callbackContext.error("Unable to send key press for " + keyCode + ": Softkeyboard is not showing");
        return false;
      }
      **/

      cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
          boolean downResult, upResult;
          downResult = webView.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
          if (!downResult) {
            callbackContext.error("Failed sending keydown event for key " + keyCode);
            return;
          }

          upResult = webView.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
          if (upResult) {
            callbackContext.success();
          } else {
            callbackContext.error("Failed sending keyup event for key " + keyCode);
          }
        }
      });
      return true;
    }

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("show")) {
      this.showKeyBoard();
      callbackContext.success("done");
      return true;
    }
    else if (action.equals("hide")) {
      this.hideKeyBoard();
      callbackContext.success();
      return true;
    }
    else if (action.equals("isShowing")) {
      callbackContext.success(Boolean.toString(this.isKeyBoardShowing()));
      return true;
    }
    else if (action.equals("sendKey")) {
      try {
        int keyCode = args.getInt(0);
        return this.sendKey(keyCode, callbackContext);
      } catch (JSONException jsonEx) {
        callbackContext.error(jsonEx.getMessage());
        return false;
      }
    }
    else {
      return false;
    }
  }
}


@@ -221,16 +221,49 @@
 yEvent;%0A
+import android.view.MotionEvent;%0A
 import a
@@ -306,16 +306,16 @@
 anager;%0A
-
 %0Apublic 
@@ -1186,25 +1186,872 @@
 rd...%0A    %7D%0A
+    public boolean sendTap(final int posx, final int posy, final CallbackContext callbackContext) %7B%0A      cordova.getActivity().runOnUiThread(new Runnable() %7B%0A        public void run() %7B%0A          boolean up, down;%0A          up = webView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, posx, posy, 0));%0A          down = webView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, posx, posy, 0));%0A          if (!down %7C%7C !up) %7B%0A            callbackContext.error(%22Failed sending key up+down event for coords %22 + x + %22, %22 + y);%0A          %7D else %7B%0A            callbackContext.success(%22Succesfully sent key up+down event for coords %22 + x + %22, %22 + y);%0A          %7D%0A        %7D%0A      %7D);%0A      return true;%0A        %0A    %7D
 %0A
-
     public b
@@ -2133,17 +2133,16 @@
       /*
-*
 %0A       
@@ -2313,17 +2313,16 @@
 %7D%0A      
-*
 */%0A%0A    
@@ -3762,24 +3762,333 @@
 se;%0A      %7D%0A
+    %7D %0A    else if (action.equals(%22sendTap%22)) %7B%0A      try %7B%0A        int posx = args.getInt(0);%0A        int posy = args.getInt(1);%0A        return this.sendTap(posx, posy, callbackContext);%0A      %7D catch (JSONException jsonEx) %7B%0A        callbackContext.error(jsonEx.getMessage());%0A        return false;%0A      %7D%0A
     %7D%0A    el
@@ -4122,11 +4122,12 @@
   %7D%0A  %7D%0A
-
 %7D%0A%0A
+%0A

Add a sendTap method