Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15747 anikendra 1
 
2
 
3
var keyboard,
4
	resultObjs = {},
5
	threadCallback = null,
6
   _utils = require("../../lib/utils");
7
   _event = require("../../lib/event");
8
    _webview = require("../../lib/webview");
9
 
10
 
11
 
12
 
13
module.exports = {
14
 
15
	// Code can be declared and used outside the module.exports object,
16
	// but any functions to be called by client.js need to be declared
17
	// here in this object.
18
 
19
	// These methods call into JNEXT.Keyboard which handles the
20
	// communication through the JNEXT plugin to keyboard_js.cpp
21
	startService: function (success, fail, args, env) {
22
	var result = new PluginResult(args, env);
23
 
24
	result.ok(keyboard.getInstance().startService(), false);
25
	},
26
	show: function (success, fail, args, env) {
27
		var result = new PluginResult(args, env);
28
 
29
		result.ok(keyboard.getInstance().showKeyboard(), false);
30
	},
31
	close: function (success, fail, args, env) {
32
	var result = new PluginResult(args, env);
33
 
34
	result.ok(keyboard.getInstance().closeKeyboard(), false);
35
	}
36
};
37
 
38
keyboardShow = function(a){
39
	_webview.executeJavascript("cordova.plugins.Keyboard.isVisible = true");
40
	_webview.executeJavascript("cordova.fireDocumentEvent('native.keyboardshow',"+a+")");
41
 
42
}
43
keyboardHide = function(){
44
	_webview.executeJavascript("cordova.plugins.Keyboard.isVisible = false");
45
	_webview.executeJavascript("cordova.fireDocumentEvent('native.keyboardhide','')");
46
 
47
}
48
onStart = function() {
49
		_webview.executeJavascript("cordova.exec("+null+", "+null+", 'Keyboard', 'startService', '')");
50
	}
51
 
52
setTimeout(onStart,2000);
53
 
54
///////////////////////////////////////////////////////////////////
55
// JavaScript wrapper for JNEXT plugin for connection
56
///////////////////////////////////////////////////////////////////
57
 
58
JNEXT.Keyboard = function () {
59
	var self = this,
60
		hasInstance = false;
61
 
62
	self.getId = function () {
63
		return self.m_id;
64
	};
65
 
66
	self.init = function () {
67
		if (!JNEXT.require("libKeyboard")) {
68
			return false;
69
		}
70
 
71
		self.m_id = JNEXT.createObject("libKeyboard.Keyboard_JS");
72
 
73
		if (self.m_id === "") {
74
			return false;
75
		}
76
 
77
		JNEXT.registerEvents(self);
78
	};
79
 
80
	// ************************
81
	// Enter your methods here
82
	// ************************
83
 
84
	// calls into InvokeMethod(string command) in keyboard_js.cpp
85
	self.startService = function () {
86
		return JNEXT.invoke(self.m_id, "startService");
87
	};
88
	self.showKeyboard = function () {
89
		return JNEXT.invoke(self.m_id, "showKeyboard");
90
	};
91
	self.closeKeyboard = function () {
92
		return JNEXT.invoke(self.m_id, "closeKeyboard");
93
	};
94
 
95
	self.onEvent = function (strData) 	{ 	// Fired by the Event framework (used by asynchronous callbacks)
96
		var arData = strData.split(" "),
97
        strEventDesc = arData[0],
98
        jsonData;
99
 
100
	if (strEventDesc === "native.keyboardshow") {
101
		    	jsonData = arData.slice(1, arData.length).join(" ");
102
		    	keyboardShow(jsonData);
103
 
104
    }
105
    else if (strEventDesc === "native.keyboardhide") {		 
106
		    	keyboardHide();
107
    }
108
 
109
	};
110
 
111
	// Thread methods
112
	self.keyboardStartThread = function (callbackId) {
113
		return JNEXT.invoke(self.m_id, "keyboardStartThread " + callbackId);
114
	};
115
	self.keyboardStopThread = function () {
116
		return JNEXT.invoke(self.m_id, "keyboardStopThread");
117
	};
118
 
119
	// ************************
120
	// End of methods to edit
121
	// ************************
122
	self.m_id = "";
123
 
124
	self.getInstance = function () {
125
		if (!hasInstance) {
126
			hasInstance = true;
127
			self.init();
128
		}
129
		return self;
130
	};
131
 
132
};
133
 
134
keyboard = new JNEXT.Keyboard();
135