blob: bb52d55f968cf9f8f18c0385ec2e8b8f347f2a71 [file] [log] [blame]
Dees Troy3be70a82013-10-22 14:25:12 +00001/*
2 Copyright 2012 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
Dees_Troy51a0e822012-09-05 15:24:24 -040018
19#include <stdarg.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <fcntl.h>
24#include <sys/reboot.h>
25#include <sys/stat.h>
26#include <sys/time.h>
27#include <sys/mman.h>
28#include <sys/types.h>
29#include <sys/ioctl.h>
30#include <time.h>
31#include <unistd.h>
32#include <stdlib.h>
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +000033#include "../data.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040034
35#include <string>
36
37extern "C" {
Dees_Troy2673cec2013-04-02 20:22:16 +000038#include "../twcommon.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040039#include "../minuitwrp/minui.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040040}
41
42#include "rapidxml.hpp"
43#include "objects.hpp"
44
45GUIKeyboard::GUIKeyboard(xml_node<>* node)
Vojtech Bocekede51c52014-02-07 23:58:09 +010046 : GUIObject(node)
Dees_Troy51a0e822012-09-05 15:24:24 -040047{
48 int layoutindex, rowindex, keyindex, Xindex, Yindex, keyHeight = 0, keyWidth = 0;
Dees_Troy30b962e2012-10-19 20:48:59 -040049 rowY = colX = -1;
Ethan Yonkerc3120d42014-02-17 07:55:00 -060050 highlightRenderCount = hasHighlight = hasCapsHighlight = 0;
Dees_Troy3a16cb52013-01-10 15:16:02 +000051 char resource[10], layout[8], row[5], key[6], longpress[7];
Dees_Troy51a0e822012-09-05 15:24:24 -040052 xml_attribute<>* attr;
53 xml_node<>* child;
54 xml_node<>* keylayout;
55 xml_node<>* keyrow;
56
57 for (layoutindex=0; layoutindex<MAX_KEYBOARD_LAYOUTS; layoutindex++)
58 keyboardImg[layoutindex] = NULL;
59
60 mRendered = false;
61 currentLayout = 1;
62 mAction = NULL;
63 KeyboardHeight = KeyboardWidth = cursorLocation = 0;
64
65 if (!node) return;
66
67 // Load the action
68 child = node->first_node("action");
69 if (child)
70 {
71 mAction = new GUIAction(node);
72 }
73
Dees_Troy30b962e2012-10-19 20:48:59 -040074 memset(&mHighlightColor, 0, sizeof(COLOR));
75 child = node->first_node("highlight");
76 if (child) {
77 attr = child->first_attribute("color");
78 if (attr) {
79 hasHighlight = 1;
80 std::string color = attr->value();
81 ConvertStrToColor(color, &mHighlightColor);
82 }
83 }
84
Ethan Yonkerc3120d42014-02-17 07:55:00 -060085 memset(&mCapsHighlightColor, 0, sizeof(COLOR));
86 child = node->first_node("capshighlight");
87 if (child) {
88 attr = child->first_attribute("color");
89 if (attr) {
90 hasCapsHighlight = 1;
91 std::string color = attr->value();
92 ConvertStrToColor(color, &mCapsHighlightColor);
93 }
94 }
95
Dees_Troy51a0e822012-09-05 15:24:24 -040096 // Load the images for the different layouts
97 child = node->first_node("layout");
98 if (child)
99 {
100 layoutindex = 1;
101 strcpy(resource, "resource1");
102 attr = child->first_attribute(resource);
103 while (attr && layoutindex < (MAX_KEYBOARD_LAYOUTS + 1)) {
104 keyboardImg[layoutindex - 1] = PageManager::FindResource(attr->value());
105
106 layoutindex++;
107 resource[8] = (char)(layoutindex + 48);
108 attr = child->first_attribute(resource);
109 }
110 }
111
112 // Check the first image to get height and width
113 if (keyboardImg[0] && keyboardImg[0]->GetResource())
114 {
115 KeyboardWidth = gr_get_width(keyboardImg[0]->GetResource());
116 KeyboardHeight = gr_get_height(keyboardImg[0]->GetResource());
117 }
118
119 // Load all of the layout maps
120 layoutindex = 1;
121 strcpy(layout, "layout1");
122 keylayout = node->first_node(layout);
123 while (keylayout)
124 {
125 if (layoutindex > MAX_KEYBOARD_LAYOUTS) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000126 LOGERR("Too many layouts defined in keyboard.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400127 return;
128 }
129
130 child = keylayout->first_node("keysize");
131 if (child) {
132 attr = child->first_attribute("height");
133 if (attr)
134 keyHeight = atoi(attr->value());
135 else
136 keyHeight = 0;
137 attr = child->first_attribute("width");
138 if (attr)
139 keyWidth = atoi(attr->value());
140 else
141 keyWidth = 0;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600142 attr = child->first_attribute("capslock");
143 if (attr)
144 caps_tracking[layoutindex - 1].capslock = atoi(attr->value());
145 else
146 caps_tracking[layoutindex - 1].capslock = 1;
147 attr = child->first_attribute("revert_layout");
148 if (attr)
149 caps_tracking[layoutindex - 1].revert_layout = atoi(attr->value());
150 else
151 caps_tracking[layoutindex - 1].revert_layout = -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400152 }
153
154 rowindex = 1;
155 Yindex = 0;
156 strcpy(row, "row1");
157 keyrow = keylayout->first_node(row);
158 while (keyrow)
159 {
160 if (rowindex > MAX_KEYBOARD_ROWS) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000161 LOGERR("Too many rows defined in keyboard.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400162 return;
163 }
164
165 Yindex += keyHeight;
166 row_heights[layoutindex - 1][rowindex - 1] = Yindex;
167
168 keyindex = 1;
169 Xindex = 0;
170 strcpy(key, "key01");
171 attr = keyrow->first_attribute(key);
172
173 while (attr) {
174 string stratt;
175 char keyinfo[255];
176
177 if (keyindex > MAX_KEYBOARD_KEYS) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000178 LOGERR("Too many keys defined in a keyboard row.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400179 return;
180 }
181
182 stratt = attr->value();
183 if (strlen(stratt.c_str()) >= 255) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000184 LOGERR("Key info on layout%i, row%i, key%dd is too long.\n", layoutindex, rowindex, keyindex);
Dees_Troy51a0e822012-09-05 15:24:24 -0400185 return;
186 }
187
188 strcpy(keyinfo, stratt.c_str());
189
190 if (strlen(keyinfo) == 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000191 LOGERR("No key info on layout%i, row%i, key%dd.\n", layoutindex, rowindex, keyindex);
Dees_Troy51a0e822012-09-05 15:24:24 -0400192 return;
193 }
194
195 if (strlen(keyinfo) == 1) {
196 // This is a single key, simple definition
197 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].key = keyinfo[0];
198 Xindex += keyWidth;
199 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].end_x = Xindex - 1;
200 } else {
201 // This key has extra data
202 char* ptr;
203 char* offset;
204 char* keyitem;
205 char foratoi[10];
206
207 ptr = keyinfo;
208 offset = keyinfo;
209 while (*ptr > 32 && *ptr != ':')
210 ptr++;
211 if (*ptr != 0)
212 *ptr = 0;
213
214 strcpy(foratoi, offset);
215 Xindex += atoi(foratoi);
216 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].end_x = Xindex - 1;
217
218 ptr++;
219 if (*ptr == 0) {
220 // This is an empty area
221 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].key = 0;
222 } else if (strlen(ptr) == 1) {
223 // This is the character that this key uses
224 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].key = *ptr;
225 } else if (*ptr == 'c') {
226 // This is an ASCII character code
227 keyitem = ptr + 2;
228 strcpy(foratoi, keyitem);
229 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].key = atoi(foratoi);
230 } else if (*ptr == 'l') {
231 // This is a different layout
232 keyitem = ptr + 6;
233 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].key = KEYBOARD_LAYOUT;
234 strcpy(foratoi, keyitem);
235 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].layout = atoi(foratoi);
236 } else if (*ptr == 'a') {
237 // This is an action
238 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].key = KEYBOARD_ACTION;
239 } else
Dees_Troy2673cec2013-04-02 20:22:16 +0000240 LOGERR("Invalid key info on layout%i, row%i, key%02i.\n", layoutindex, rowindex, keyindex);
Dees_Troy51a0e822012-09-05 15:24:24 -0400241 }
242
243 // PROCESS LONG PRESS INFO IF EXISTS
244 sprintf(longpress, "long%02i", keyindex);
245 attr = keyrow->first_attribute(longpress);
246 if (attr) {
247 stratt = attr->value();
248 if (strlen(stratt.c_str()) >= 255) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000249 LOGERR("Key info on layout%i, row%i, key%dd is too long.\n", layoutindex, rowindex, keyindex);
Dees_Troy51a0e822012-09-05 15:24:24 -0400250 return;
251 }
252
253 strcpy(keyinfo, stratt.c_str());
254
255 if (strlen(keyinfo) == 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000256 LOGERR("No long press info on layout%i, row%i, long%dd.\n", layoutindex, rowindex, keyindex);
Dees_Troy51a0e822012-09-05 15:24:24 -0400257 return;
258 }
259
260 if (strlen(keyinfo) == 1) {
261 // This is a single key, simple definition
262 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].longpresskey = keyinfo[0];
263 } else {
264 // This key has extra data
265 char* ptr;
266 char* offset;
267 char* keyitem;
268 char foratoi[10];
269
270 ptr = keyinfo;
271 offset = keyinfo;
272 while (*ptr > 32 && *ptr != ':')
273 ptr++;
274 if (*ptr != 0)
275 *ptr = 0;
276
277 strcpy(foratoi, offset);
278 Xindex += atoi(foratoi);
279
280 ptr++;
281 if (*ptr == 0) {
282 // This is an empty area
283 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].longpresskey = 0;
284 } else if (strlen(ptr) == 1) {
285 // This is the character that this key uses
286 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].longpresskey = *ptr;
287 } else if (*ptr == 'c') {
288 // This is an ASCII character code
289 keyitem = ptr + 2;
290 strcpy(foratoi, keyitem);
291 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].longpresskey = atoi(foratoi);
292 } else if (*ptr == 'l') {
293 // This is a different layout
294 keyitem = ptr + 6;
295 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].longpresskey = KEYBOARD_LAYOUT;
296 strcpy(foratoi, keyitem);
297 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].layout = atoi(foratoi);
298 } else if (*ptr == 'a') {
299 // This is an action
300 keyboard_keys[layoutindex - 1][rowindex - 1][keyindex - 1].longpresskey = KEYBOARD_ACTION;
301 } else
Dees_Troy2673cec2013-04-02 20:22:16 +0000302 LOGERR("Invalid long press key info on layout%i, row%i, long%02i.\n", layoutindex, rowindex, keyindex);
Dees_Troy51a0e822012-09-05 15:24:24 -0400303 }
304 }
305 keyindex++;
306 sprintf(key, "key%02i", keyindex);
307 attr = keyrow->first_attribute(key);
308 }
309 rowindex++;
310 row[3] = (char)(rowindex + 48);
311 keyrow = keylayout->first_node(row);
312 }
313 layoutindex++;
314 layout[6] = (char)(layoutindex + 48);
315 keylayout = node->first_node(layout);
316 }
317
318 int x, y, w, h;
319 // Load the placement
320 LoadPlacement(node->first_node("placement"), &x, &y, &w, &h);
321 SetActionPos(x, y, KeyboardWidth, KeyboardHeight);
322 SetRenderPos(x, y, w, h);
323 return;
324}
325
326GUIKeyboard::~GUIKeyboard()
327{
Dees_Troy51a0e822012-09-05 15:24:24 -0400328
Dees_Troy51a0e822012-09-05 15:24:24 -0400329}
330
331int GUIKeyboard::Render(void)
332{
333 if (!isConditionTrue())
334 {
335 mRendered = false;
336 return 0;
337 }
338
339 int ret = 0;
340
341 if (keyboardImg[currentLayout - 1] && keyboardImg[currentLayout - 1]->GetResource())
342 gr_blit(keyboardImg[currentLayout - 1]->GetResource(), 0, 0, KeyboardWidth, KeyboardHeight, mRenderX, mRenderY);
343
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600344 // Draw highlight for capslock
345 if (hasCapsHighlight && caps_tracking[currentLayout - 1].capslock == 0 && caps_tracking[currentLayout - 1].set_capslock) {
346 int boxheight, boxwidth, x;
347 gr_color(mCapsHighlightColor.red, mCapsHighlightColor.green, mCapsHighlightColor.blue, mCapsHighlightColor.alpha);
348 for (int indexy=0; indexy<MAX_KEYBOARD_ROWS; indexy++) {
349 for (int indexx=0; indexx<MAX_KEYBOARD_KEYS; indexx++) {
350 if ((int)keyboard_keys[currentLayout - 1][indexy][indexx].key == KEYBOARD_LAYOUT && (int)keyboard_keys[currentLayout - 1][indexy][indexx].layout == caps_tracking[currentLayout - 1].revert_layout) {
351 if (indexy == 0)
352 boxheight = row_heights[currentLayout - 1][indexy];
353 else
354 boxheight = row_heights[currentLayout - 1][indexy] - row_heights[currentLayout - 1][indexy - 1];
355 if (indexx == 0) {
356 x = mRenderX;
357 boxwidth = keyboard_keys[currentLayout - 1][indexy][indexx].end_x;
358 } else {
359 x = mRenderX + keyboard_keys[currentLayout - 1][indexy][indexx - 1].end_x;
360 boxwidth = keyboard_keys[currentLayout - 1][indexy][indexx].end_x - keyboard_keys[currentLayout - 1][indexy][indexx - 1].end_x;
361 }
362 gr_fill(x, mRenderY + row_heights[currentLayout - 1][indexy - 1], boxwidth, boxheight);
363 }
364 }
365 }
366 }
367
Dees_Troy30b962e2012-10-19 20:48:59 -0400368 if (hasHighlight && highlightRenderCount != 0) {
369 int boxheight, boxwidth, x;
370 if (rowY == 0)
371 boxheight = row_heights[currentLayout - 1][rowY];
372 else
373 boxheight = row_heights[currentLayout - 1][rowY] - row_heights[currentLayout - 1][rowY - 1];
374 if (colX == 0) {
375 x = mRenderX;
376 boxwidth = keyboard_keys[currentLayout - 1][rowY][colX].end_x;
377 } else {
378 x = mRenderX + keyboard_keys[currentLayout - 1][rowY][colX - 1].end_x;
379 boxwidth = keyboard_keys[currentLayout - 1][rowY][colX].end_x - keyboard_keys[currentLayout - 1][rowY][colX - 1].end_x;
380 }
381 gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha);
382 gr_fill(x, mRenderY + row_heights[currentLayout - 1][rowY - 1], boxwidth, boxheight);
383 if (highlightRenderCount > 0)
384 highlightRenderCount--;
385 } else
386 mRendered = true;
387
Dees_Troy51a0e822012-09-05 15:24:24 -0400388 return ret;
389}
390
391int GUIKeyboard::Update(void)
392{
393 if (!isConditionTrue()) return (mRendered ? 2 : 0);
394 if (!mRendered) return 2;
395
396 return 0;
397}
398
399int GUIKeyboard::SetRenderPos(int x, int y, int w, int h)
400{
401 mRenderX = x;
402 mRenderY = y;
403 if (w || h)
404 {
405 mRenderW = KeyboardWidth;
406 mRenderH = KeyboardHeight;
407 }
408
409 if (mAction) mAction->SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
410 SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
411 return 0;
412}
413
414int GUIKeyboard::GetSelection(int x, int y)
415{
Dees_Troy30b962e2012-10-19 20:48:59 -0400416 if (x < mRenderX || x - mRenderX > (int)KeyboardWidth || y < mRenderY || y - mRenderY > (int)KeyboardHeight) return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400417 return 0;
418}
419
420int GUIKeyboard::NotifyTouch(TOUCH_STATE state, int x, int y)
421{
422 static int startSelection = -1, was_held = 0, startX = 0;
423 static unsigned char initial_key = 0;
424 unsigned int indexy, indexx, rely, relx, rowIndex = 0;
425
426 rely = y - mRenderY;
427 relx = x - mRenderX;
428
429 if (!isConditionTrue()) return -1;
430
431 switch (state)
432 {
433 case TOUCH_START:
434 if (GetSelection(x, y) == 0) {
435 startSelection = -1;
436 was_held = 0;
437 startX = x;
438 // Find the correct row
439 for (indexy=0; indexy<MAX_KEYBOARD_ROWS; indexy++) {
440 if (row_heights[currentLayout - 1][indexy] > rely) {
441 rowIndex = indexy;
Dees_Troy30b962e2012-10-19 20:48:59 -0400442 rowY = indexy;
Dees_Troy51a0e822012-09-05 15:24:24 -0400443 indexy = MAX_KEYBOARD_ROWS;
444 }
445 }
446
447 // Find the correct key (column)
448 for (indexx=0; indexx<MAX_KEYBOARD_KEYS; indexx++) {
449 if (keyboard_keys[currentLayout - 1][rowIndex][indexx].end_x > relx) {
450 // This is the key that was pressed!
451 initial_key = keyboard_keys[currentLayout - 1][rowIndex][indexx].key;
Dees_Troy30b962e2012-10-19 20:48:59 -0400452 colX = indexx;
Dees_Troy51a0e822012-09-05 15:24:24 -0400453 indexx = MAX_KEYBOARD_KEYS;
454 }
455 }
Dees_Troy30b962e2012-10-19 20:48:59 -0400456 if (initial_key != 0)
457 highlightRenderCount = -1;
458 else
459 highlightRenderCount = 0;
460 mRendered = false;
Dees_Troy51a0e822012-09-05 15:24:24 -0400461 } else {
Dees_Troy30b962e2012-10-19 20:48:59 -0400462 if (highlightRenderCount != 0)
463 mRendered = false;
464 highlightRenderCount = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400465 startSelection = 0;
466 }
467 break;
468 case TOUCH_DRAG:
469 break;
470 case TOUCH_RELEASE:
Dees_Troy0cb64e52012-10-15 15:56:10 -0400471 if (x < startX - (KeyboardWidth * 0.5)) {
Dees_Troy30b962e2012-10-19 20:48:59 -0400472 if (highlightRenderCount != 0) {
473 highlightRenderCount = 0;
474 mRendered = false;
475 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400476 PageManager::NotifyKeyboard(KEYBOARD_SWIPE_LEFT);
477 return 0;
Dees_Troy0cb64e52012-10-15 15:56:10 -0400478 } else if (x > startX + (KeyboardWidth * 0.5)) {
Dees_Troy30b962e2012-10-19 20:48:59 -0400479 if (highlightRenderCount != 0) {
480 highlightRenderCount = 0;
481 mRendered = false;
482 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400483 PageManager::NotifyKeyboard(KEYBOARD_SWIPE_RIGHT);
484 return 0;
485 }
486
487 case TOUCH_HOLD:
488 case TOUCH_REPEAT:
489
Dees_Troy30b962e2012-10-19 20:48:59 -0400490 if (startSelection == 0 || GetSelection(x, y) == -1) {
491 if (highlightRenderCount != 0) {
492 highlightRenderCount = 0;
493 mRendered = false;
494 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400495 return 0;
Dees_Troy30b962e2012-10-19 20:48:59 -0400496 } else if (highlightRenderCount != 0) {
497 if (state == TOUCH_RELEASE)
498 highlightRenderCount = 2;
499 else
500 highlightRenderCount = -1;
501 mRendered = false;
502 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400503
504 // Find the correct row
505 for (indexy=0; indexy<MAX_KEYBOARD_ROWS; indexy++) {
506 if (row_heights[currentLayout - 1][indexy] > rely) {
507 rowIndex = indexy;
508 indexy = MAX_KEYBOARD_ROWS;
509 }
510 }
511
512 // Find the correct key (column)
513 for (indexx=0; indexx<MAX_KEYBOARD_KEYS; indexx++) {
514 if (keyboard_keys[currentLayout - 1][rowIndex][indexx].end_x > relx) {
515 // This is the key that was pressed!
516 if (keyboard_keys[currentLayout - 1][rowIndex][indexx].key != initial_key) {
517 // We dragged off of the starting key
518 startSelection = 0;
519 break;
520 } else if (state == TOUCH_RELEASE && was_held == 0) {
Ethan Yonker03db3262014-02-05 08:02:06 -0600521 DataManager::Vibrate("tw_keyboard_vibrate");
Dees_Troy51a0e822012-09-05 15:24:24 -0400522 if ((int)keyboard_keys[currentLayout - 1][rowIndex][indexx].key < KEYBOARD_SPECIAL_KEYS && (int)keyboard_keys[currentLayout - 1][rowIndex][indexx].key > 0) {
523 // Regular key
524 PageManager::NotifyKeyboard(keyboard_keys[currentLayout - 1][rowIndex][indexx].key);
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600525 if (caps_tracking[currentLayout - 1].capslock == 0 && !caps_tracking[currentLayout - 1].set_capslock) {
526 // caps lock was not set, change layouts
527 currentLayout = caps_tracking[currentLayout - 1].revert_layout;
528 mRendered = false;
529 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400530 } else if ((int)keyboard_keys[currentLayout - 1][rowIndex][indexx].key == KEYBOARD_LAYOUT) {
531 // Switch layouts
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600532 if (caps_tracking[currentLayout - 1].capslock == 0 && keyboard_keys[currentLayout - 1][rowIndex][indexx].layout == caps_tracking[currentLayout - 1].revert_layout) {
533 if (!caps_tracking[currentLayout - 1].set_capslock) {
534 caps_tracking[currentLayout - 1].set_capslock = 1; // Set the caps lock
535 } else {
536 caps_tracking[currentLayout - 1].set_capslock = 0; // Unset the caps lock and change layouts
537 currentLayout = keyboard_keys[currentLayout - 1][rowIndex][indexx].layout;
538 }
539 } else {
540 currentLayout = keyboard_keys[currentLayout - 1][rowIndex][indexx].layout;
541 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400542 mRendered = false;
543 } else if ((int)keyboard_keys[currentLayout - 1][rowIndex][indexx].key == KEYBOARD_ACTION) {
544 // Action
Dees_Troy30b962e2012-10-19 20:48:59 -0400545 highlightRenderCount = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400546 if (mAction) {
547 // Keyboard has its own action defined
548 return (mAction ? mAction->NotifyTouch(state, x, y) : 1);
549 } else {
550 // Send action notification
551 PageManager::NotifyKeyboard(keyboard_keys[currentLayout - 1][rowIndex][indexx].key);
552 }
553 }
554 } else if (state == TOUCH_HOLD) {
555 was_held = 1;
556 if ((int)keyboard_keys[currentLayout - 1][rowIndex][indexx].key == KEYBOARD_BACKSPACE) {
557 // Repeat backspace
558 PageManager::NotifyKeyboard(keyboard_keys[currentLayout - 1][rowIndex][indexx].key);
559 } else if ((int)keyboard_keys[currentLayout - 1][rowIndex][indexx].longpresskey < KEYBOARD_SPECIAL_KEYS && (int)keyboard_keys[currentLayout - 1][rowIndex][indexx].longpresskey > 0) {
560 // Long Press Key
Ethan Yonker03db3262014-02-05 08:02:06 -0600561 DataManager::Vibrate("tw_keyboard_vibrate");
Dees_Troy51a0e822012-09-05 15:24:24 -0400562 PageManager::NotifyKeyboard(keyboard_keys[currentLayout - 1][rowIndex][indexx].longpresskey);
563 }
564 } else if (state == TOUCH_REPEAT) {
565 was_held = 1;
566 if ((int)keyboard_keys[currentLayout - 1][rowIndex][indexx].key == KEYBOARD_BACKSPACE) {
567 // Repeat backspace
568 PageManager::NotifyKeyboard(keyboard_keys[currentLayout - 1][rowIndex][indexx].key);
569 }
570 }
571 indexx = MAX_KEYBOARD_KEYS;
572 }
573 }
574 break;
575 }
576
577 return 0;
578}