Skip to content

Commit

Permalink
Add show/hide keyboard for android
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpearson committed Jul 6, 2015
1 parent e1f2b02 commit 7df4642
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-keyboard",
"version": "1.0.0",
"version": "1.1.0",
"description": "Cordova Keyboard Plugin",
"cordova": {
"id": "cordova-plugin-keyboard",
Expand All @@ -16,7 +16,8 @@
"cordova",
"keyboard",
"ecosystem:cordova",
"cordova-ios"
"cordova-ios",
"cordova-android"
],
"engines": [
{
Expand Down
23 changes: 15 additions & 8 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:rim="http://www.blackberry.com/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-keyboard"
version="0.1.2">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-keyboard" version="1.1.0">
<name>Keyboard</name>
<description>Cordova Keyboard Plugin</description>
<license>Apache 2.0</license>
<keywords>cordova,keyboard</keywords>

<engines>
<engine name="cordova" version=">=3.2.0" />
</engines>
<engines>
<engine name="cordova" version=">=3.2.0" />
</engines>

<js-module src="www/keyboard.js" name="keyboard">
<clobbers target="window.Keyboard" />
Expand All @@ -30,4 +26,15 @@
<source-file src="src/ios/CDVKeyboard.m" />
</platform>

<!-- android -->
<platform name="android">
<config-file target="config.xml" parent="/*">
<feature name="Keyboard">
<param name="android-package" value="org.apache.cordova.labs.keyboard.Keyboard" onload="true" />
</feature>
</config-file>

<source-file src="src/android/Keyboard.java" target-dir="src/org/apache/cordova/labs/keyboard" />
</platform>

</plugin>
30 changes: 30 additions & 0 deletions src/android/Keyboard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.apache.cordova.labs.keyboard;

import android.app.Activity;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;

public class Keyboard extends CordovaPlugin {

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
Activity activity = this.cordova.getActivity();
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);

if("show".equals(action)){
imm.showSoftInput(webView.getView(), 0);
callbackContext.success();
return true;
}
else if("hide".equals(action)){
imm.hideSoftInputFromWindow(webView.getView().getWindowToken(), 0);
callbackContext.success();
return true;
}
callbackContext.error(action + " is not a supported action");
return false;
}
}
8 changes: 8 additions & 0 deletions www/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ Keyboard.fireOnHeightChange = function() {

};

Keyboard.show = function() {
exec(null, null, "Keyboard", "show", []);
};

Keyboard.hide = function() {
exec(null, null, "Keyboard", "hide", []);
};

Keyboard.isVisible = false;
Keyboard.automaticScrollToTopOnHiding = false;

Expand Down

0 comments on commit 7df4642

Please sign in to comment.