| 15747 |
anikendra |
1 |
/*
|
|
|
2 |
* Copyright (c) 2013 BlackBerry Limited
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
#include <string>
|
|
|
18 |
#include "../public/tokenizer.h"
|
|
|
19 |
#include "keyboard_js.hpp"
|
|
|
20 |
#include "keyboard_ndk.hpp"
|
|
|
21 |
#include <sstream>
|
|
|
22 |
|
|
|
23 |
using namespace std;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Default constructor.
|
|
|
27 |
*/
|
|
|
28 |
Keyboard_JS::Keyboard_JS(const std::string& id) :
|
|
|
29 |
m_id(id) {
|
|
|
30 |
m_pLogger = new webworks::Logger("Keyboard_JS", this);
|
|
|
31 |
m_pKeyboardController = new webworks::Keyboard_NDK(this);
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Keyboard_JS destructor.
|
|
|
38 |
*/
|
|
|
39 |
Keyboard_JS::~Keyboard_JS() {
|
|
|
40 |
if (m_pKeyboardController)
|
|
|
41 |
delete m_pKeyboardController;
|
|
|
42 |
if (m_pLogger)
|
|
|
43 |
delete m_pLogger;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
webworks::Logger* Keyboard_JS::getLog() {
|
|
|
47 |
return m_pLogger;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* This method returns the list of objects implemented by this native
|
|
|
52 |
* extension.
|
|
|
53 |
*/
|
|
|
54 |
char* onGetObjList() {
|
|
|
55 |
static char name[] = "Keyboard_JS";
|
|
|
56 |
return name;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* This method is used by JNext to instantiate the Keyboard_JS object when
|
|
|
61 |
* an object is created on the JavaScript server side.
|
|
|
62 |
*/
|
|
|
63 |
JSExt* onCreateObject(const string& className, const string& id) {
|
|
|
64 |
if (className == "Keyboard_JS") {
|
|
|
65 |
return new Keyboard_JS(id);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
return NULL;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Method used by JNext to determine if the object can be deleted.
|
|
|
73 |
*/
|
|
|
74 |
bool Keyboard_JS::CanDelete() {
|
|
|
75 |
return true;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* It will be called from JNext JavaScript side with passed string.
|
|
|
80 |
* This method implements the interface for the JavaScript to native binding
|
|
|
81 |
* for invoking native code. This method is triggered when JNext.invoke is
|
|
|
82 |
* called on the JavaScript side with this native objects id.
|
|
|
83 |
*/
|
|
|
84 |
string Keyboard_JS::InvokeMethod(const string& command) {
|
|
|
85 |
// format must be: "command callbackId params"
|
|
|
86 |
size_t commandIndex = command.find_first_of(" ");
|
|
|
87 |
std::string strCommand = command.substr(0, commandIndex);
|
|
|
88 |
size_t callbackIndex = command.find_first_of(" ", commandIndex + 1);
|
|
|
89 |
std::string callbackId = command.substr(commandIndex + 1, callbackIndex - commandIndex - 1);
|
|
|
90 |
std::string arg = command.substr(callbackIndex + 1, command.length());
|
|
|
91 |
|
|
|
92 |
// based on the command given, run the appropriate method in keyboard_ndk.cpp
|
|
|
93 |
if (strCommand == "showKeyboard") {
|
|
|
94 |
m_pKeyboardController->callKeyboardEmail();
|
|
|
95 |
return "Show Keyboard";
|
|
|
96 |
} else if (strCommand == "closeKeyboard") {
|
|
|
97 |
m_pKeyboardController->cancelKeyboard();
|
|
|
98 |
return "Cancel Keyboard";
|
|
|
99 |
}
|
|
|
100 |
else if(strCommand == "startService"){
|
|
|
101 |
m_pKeyboardController->keyboardStartThread();
|
|
|
102 |
return "Starting Service";
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
strCommand.append(";");
|
|
|
106 |
strCommand.append(command);
|
|
|
107 |
return strCommand;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
// Notifies JavaScript of an event
|
|
|
111 |
void Keyboard_JS::NotifyEvent(const std::string& event) {
|
|
|
112 |
std::string eventString = m_id + " ";
|
|
|
113 |
eventString.append(event);
|
|
|
114 |
SendPluginEvent(eventString.c_str(), m_pContext);
|
|
|
115 |
|
|
|
116 |
}
|
|
|
117 |
|