Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.98 KB | None | 0 0
  1. package com.forviz.input.keyboard {
  2.  
  3. import flash.display.Sprite;
  4. import flash.geom.Rectangle;
  5. import flash.geom.Point;
  6. import flash.utils.Dictionary;
  7. import flash.utils.ByteArray;
  8. import flash.display.Shape;
  9. import flash.events.Event;
  10. import flash.display.DisplayObject;
  11. import flash.text.TextFormat;
  12. import flash.text.TextField;
  13. import flash.geom.Point;
  14. import flash.media.Sound;
  15. import flash.net.URLRequest;
  16.  
  17.  
  18. import com.greensock.TweenMax;
  19. import com.greensock.easing.Expo;
  20.  
  21. import com.forviz.ui.UIControl;
  22. import com.forviz.ui.UIControlEvent;
  23. import com.forviz.ui.UITextField;
  24.  
  25.  
  26.  
  27.  
  28. public class TouchScreenKeyboard extends Sprite {
  29.  
  30. private var _theme:String = "dark";
  31. private var _mode:String = "default";
  32.  
  33.  
  34. private var _inputLang:String;
  35. private var _defaultLang:String = 'en';
  36.  
  37. public static var DEFAULT:String = "default";
  38. public static var NUMBER:String = "number";
  39. public static var EMAIL:String = "email";
  40.  
  41. private var _position:String = "bottom";
  42. private var _showPoint:Point;
  43.  
  44.  
  45. private var _rowHeight:int = 77;
  46.  
  47. private var _submitKey:KeyItem;
  48. private var _submitLabel:String = 'Go';
  49.  
  50. private var _boardStrokeColor:Number = 0x000000;
  51. private var _boardStrokeAlpha:Number = 1.0;
  52. private var _boardFillColor:Number = 0x000000;
  53. private var _boardFillAlpha:Number = 0.6;
  54.  
  55. private var _keyFillColor:Number = 0xCCCCCC
  56. private var _keyFillAlpha:Number = 1;
  57. private var _keyTextColor:Number = 0x000000;
  58. private var _keyTextAlpha:Number = 0;
  59.  
  60. private var _primaryKeyFillColor:uint = 0x333333;
  61. private var _primaryKeyFillAlpha:Number = 1;
  62. private var _primaryKeyTextColor:uint = 0x333333;
  63. private var _primaryKeyTextAlpha:Number = 0;
  64.  
  65.  
  66. private var _positionMode:String = "auto";
  67.  
  68. protected var _board:Sprite = new Sprite();
  69.  
  70. protected var _boardBG:Shape = new Shape();
  71. protected var _largestX:Number = 0;
  72. protected var _largestY:Number = 0;
  73.  
  74. protected var _keyWidth:Number = 72;
  75. protected var _keyHeight:Number = 70;
  76.  
  77. protected var _gutterX:Number = 8;
  78. protected var _gutterY:Number = 20;
  79.  
  80.  
  81.  
  82. protected var _boardWidth:Number;
  83. protected var _boardHeight:Number;
  84.  
  85. private var _elements:Array = new Array();
  86. private var _focusingElement:UIControl;
  87.  
  88. public var keyDict:Dictionary = new Dictionary();
  89.  
  90. private var _textFormatDict:Dictionary = new Dictionary();
  91.  
  92. private var _hidden:Boolean = true;
  93.  
  94. /* Event */
  95. private var touchScreenKeyboardPressedEvent:TouchScreenKeyboardEvent = new TouchScreenKeyboardEvent('onTouchScreenKeyPressed');
  96. private var keyboardWillAppearEvent:TouchScreenKeyboardEvent = new TouchScreenKeyboardEvent('keyboardWillAppear');
  97. private var keyboardWillDisappearEvent:TouchScreenKeyboardEvent = new TouchScreenKeyboardEvent('keyboardWillDisappear');
  98.  
  99. private var _touchedKeyItem:KeyItem;
  100.  
  101. //sound //add sound pin edit
  102. var soundClick:Sound;
  103.  
  104.  
  105. public function TouchScreenKeyboard() {
  106. init();
  107.  
  108.  
  109. //add sound pin edit
  110.  
  111. //soundClick = new Sound();
  112. //soundClick.load(new URLRequest('keyboard.mp3'));
  113. }
  114.  
  115.  
  116. public function setDefaultTextFormat():void
  117. {
  118. var _en:TextFormat = new TextFormat("DB FongNam X", 50, 0x000000, null, null, null, null, null, "center");
  119. _en.align = 'center';
  120.  
  121. var _th:TextFormat = new TextFormat("DB FongNam X", 50, 0x000000, null, null, null, null, null, "center"); //PSL Sirintr ExtraAD
  122. _th.align = 'center';
  123.  
  124. var _label:TextFormat = new TextFormat("DB FongNam X", 50, 0x000000, null, null, null, null, null, "center");
  125. _label.align = 'right';
  126.  
  127. _textFormatDict['en'] = _en;
  128. _textFormatDict['th'] = _th;
  129. _textFormatDict['label'] = _label;
  130.  
  131. }
  132.  
  133.  
  134. public function init():void
  135. {
  136. touchScreenKeyboardPressedEvent.from = this;
  137. keyboardWillAppearEvent.from = this;
  138. keyboardWillDisappearEvent.from = this;
  139.  
  140. this.addChild(_board);
  141.  
  142.  
  143. /* Default Layout */
  144. keyDict['default'] = defineKeysDefault();
  145. keyDict['number'] = defineKeysNumber();
  146. keyDict['email'] = defineKeysEmail();
  147. keyDict['phone'] = defineKeysPhone();
  148.  
  149.  
  150. setDefaultTextFormat();
  151.  
  152. createKeys('default');
  153.  
  154. }
  155.  
  156.  
  157. public function defineKeysDefault():Array
  158. {
  159. /* Default Layout */
  160.  
  161. var dr0:Array = new Array(); //Default row 0
  162. var dr1:Array = new Array(); //Default row 1
  163. var dr2:Array = new Array(); //Default row 2
  164. var dr3:Array = new Array(); //Default row 3
  165. var dr4:Array = new Array(); //Default row 4
  166.  
  167.  
  168. dr0.push({en:['`', '~']});
  169. dr0.push({en:['1', '!']});
  170. dr0.push({en:['2', '@'], th:['/', '๑']});
  171. dr0.push({en:['3', '#'], th:['_', '๒']});
  172. dr0.push({en:['4', '$'], th:['ภ', '๓']});
  173. dr0.push({en:['5', '%'], th:['ถ', '๔']});
  174. dr0.push({en:['6', '^'], th:['ุ', 'ู']});
  175. dr0.push({en:['7', '&'], th:['ึ', '฿']});
  176. dr0.push({en:['8', '*'], th:['ค', '๕']});
  177. dr0.push({en:['9', '('], th:['ต', '๖']});
  178. dr0.push({en:['0', ')'], th:['จ', '๗']});
  179. dr0.push({en:['-', '_'], th:['ข', '๘']});
  180. dr0.push({en:['=', '+'], th:['ช', '๙']});
  181. dr0.push({key:'backspace', width:(1.4 * _keyWidth) });
  182.  
  183. dr1.push({en:['q', 'Q'], th:['ๆ', '๐'], offsetX:(.4 * _keyWidth)});
  184. dr1.push({en:['w', 'W'], th:['ไ', '']});
  185. dr1.push({en:['e', 'E'], th:['ำ', 'ฎ']});
  186. dr1.push({en:['r', 'R'], th:['พ', 'ฑ']});
  187. dr1.push({en:['t', 'T'], th:['ะ', 'ธ']});
  188. dr1.push({en:['y', 'Y'], th:['ั', 'ํ']});
  189. dr1.push({en:['u', 'U'], th:['ี', '๊']});
  190. dr1.push({en:['i', 'I'], th:['ร', 'ณ']});
  191. dr1.push({en:['o', 'O'], th:['น', 'ฯ']});
  192. dr1.push({en:['p', 'P'], th:['ย', 'ญ']});
  193. dr1.push({en:['[', '{'], th:['บ', 'ฐ']});
  194. dr1.push({en:[']', '}'], th:['ล', ',']});
  195.  
  196. dr2.push({en:['a', 'A'], th:['ฟ', 'ฤ'], offsetX:(0.8 * _keyWidth)});
  197. dr2.push({en:['s', 'S'], th:['ห', 'ฆ']});
  198. dr2.push({en:['d', 'D'], th:['ก', 'ฏ']});
  199. dr2.push({en:['f', 'F'], th:['ด', 'โ']});
  200. dr2.push({en:['g', 'G'], th:['เ', 'ฌ']});
  201. dr2.push({en:['h', 'H'], th:['้', '็']});
  202. dr2.push({en:['j', 'J'], th:['่', '๋']});
  203. dr2.push({en:['k', 'K'], th:['า', 'ษ']});
  204. dr2.push({en:['l', 'L'], th:['ส', 'ศ']});
  205. dr2.push({en:[';', ':'], th:['ว', 'ซ']});
  206. dr2.push({en:['\'', '"'], th:['ง', '.']});
  207. dr2.push({key:'enter', width:(1.6 * _keyWidth)});
  208.  
  209.  
  210. dr3.push({key:'shift'});
  211. dr3.push({en:['z', 'Z'], th:['ผ', '(']});
  212. dr3.push({en:['x', 'X'], th:['ป', ')']});
  213. dr3.push({en:['c', 'C'], th:['แ', 'ฉ']});
  214. dr3.push({en:['v', 'V'], th:['อ', 'ฮ']});
  215. dr3.push({en:['b', 'B'], th:['ิ', 'ฺ']});
  216. dr3.push({en:['n', 'N'], th:['ื', '์']});
  217. dr3.push({en:['m', 'M'], th:['ท', '?']});
  218. dr3.push({en:[',', '<'], th:['ม', 'ฒ']});
  219. dr3.push({en:['.', '>'], th:['ใ', 'ฬ']});
  220. dr3.push({en:['/', '?'], th:['ฝ', 'ฦ']});
  221. dr3.push({en:['@', '@'], th:['@', '@']});
  222. dr3.push({key:'shift', width:(1.4 * _keyWidth)});
  223.  
  224. dr4.push({key:'switch_lang', width:(1.6 * _keyWidth), offsetX:(1.4 * _keyWidth)});
  225. dr4.push({key:'space', width:(6 * _keyWidth)});
  226.  
  227. dr4.push({key:'submit', width:(2.4 * _keyWidth), offsetX:(4 * _keyWidth)});
  228.  
  229. return [dr0, dr1, dr2, dr3, dr4];
  230. }
  231.  
  232.  
  233.  
  234. public function defineKeysEmail():Array
  235. {
  236. var er0:Array = new Array(); //Default row 0
  237. var er1:Array = new Array(); //Default row 1
  238. var er2:Array = new Array(); //Default row 2
  239. var er3:Array = new Array(); //Default row 3
  240. var er4:Array = new Array(); //Default row 4
  241. var er5:Array = new Array();
  242.  
  243. er0.push({en:'@gmail.com', width:120});
  244. er0.push({en:'@hotmail.com', width:150});
  245. er0.push({en:'@yahoo.com', width:120});
  246.  
  247. er1.push({en:['1', '']});
  248. er1.push({en:['2', ''], th:['/', '๑']});
  249. er1.push({en:['3', ''], th:['_', '๒']});
  250. er1.push({en:['4', ''], th:['ภ', '๓']});
  251. er1.push({en:['5', ''], th:['ถ', '๔']});
  252. er1.push({en:['6', ''], th:['ุ', 'ู']});
  253. er1.push({en:['7', ''], th:['ึ', '฿']});
  254. er1.push({en:['8', ''], th:['ค', '๕']});
  255. er1.push({en:['9', ''], th:['ต', '๖']});
  256. er1.push({en:['0', ''], th:['จ', '๗']});
  257. er1.push({en:['-', '_'], th:['ข', '๘']});
  258. er1.push({key:'backspace', width:70});
  259.  
  260. er2.push({en:['q', 'Q'], th:['ๆ', '๐'], offsetX:20});
  261. er2.push({en:['w', 'W'], th:['ไ', '']});
  262. er2.push({en:['e', 'E'], th:['ำ', 'ฎ']});
  263. er2.push({en:['r', 'R'], th:['พ', 'ฑ']});
  264. er2.push({en:['t', 'T'], th:['ะ', 'ธ']});
  265. er2.push({en:['y', 'Y'], th:['ั', 'ํ']});
  266. er2.push({en:['u', 'U'], th:['ี', '๊']});
  267. er2.push({en:['i', 'I'], th:['ร', 'ณ']});
  268. er2.push({en:['o', 'O'], th:['น', 'ฯ']});
  269. er2.push({en:['p', 'P'], th:['ย', 'ญ']});
  270.  
  271. er3.push({en:['a', 'A'], th:['ฟ', 'ฤ'], offsetX:40});
  272. er3.push({en:['s', 'S'], th:['ห', 'ฆ']});
  273. er3.push({en:['d', 'D'], th:['ก', 'ฏ']});
  274. er3.push({en:['f', 'F'], th:['ด', 'โ']});
  275. er3.push({en:['g', 'G'], th:['เ', 'ฌ']});
  276. er3.push({en:['h', 'H'], th:['้', '็']});
  277. er3.push({en:['j', 'J'], th:['่', '๋']});
  278. er3.push({en:['k', 'K'], th:['า', 'ษ']});
  279. er3.push({en:['l', 'L'], th:['ส', 'ศ']});
  280. er3.push({key:'enter', width:80});
  281.  
  282.  
  283. er4.push({key:'shift'});
  284. er4.push({en:['z', 'Z'], th:['ผ', '(']});
  285. er4.push({en:['x', 'X'], th:['ป', ')']});
  286. er4.push({en:['c', 'C'], th:['แ', 'ฉ']});
  287. er4.push({en:['v', 'V'], th:['อ', 'ฮ']});
  288. er4.push({en:['b', 'B'], th:['ิ', 'ฺ']});
  289. er4.push({en:['n', 'N'], th:['ื', '์']});
  290. er4.push({en:['m', 'M'], th:['ท', '?']});
  291. er4.push({en:['.', '>'], th:['ใ', 'ฬ']});
  292. er4.push({en:['@', '@'], th:['@', '@']});
  293. er4.push({en:'.com'});
  294. er4.push({key:'shift', width:70});
  295.  
  296. er5.push({key:'switch_lang', width:80, offsetX:70});
  297. er5.push({key:'space', width:300});
  298.  
  299. er5.push({key:'submit', width:120, offsetX:200});
  300.  
  301.  
  302.  
  303. return [er0, er1, er2, er3, er4, er5];
  304. }
  305.  
  306. public function defineKeysNumber():Array
  307. {
  308. /* Number */
  309. var nr0:Array = new Array(); //Number row 0
  310. var nr1:Array = new Array(); //Number row 1
  311. var nr2:Array = new Array(); //Number row 2
  312. var nr3:Array = new Array(); //Number row 3
  313.  
  314. nr0.push({en:7});
  315. nr0.push({en:8});
  316. nr0.push({en:9});
  317. nr1.push({en:4});
  318. nr1.push({en:5});
  319. nr1.push({en:6});
  320. nr2.push({en:1});
  321. nr2.push({en:2});
  322. nr2.push({en:3});
  323. nr2.push({key:'submit', 'height':105, primary : true});
  324. nr3.push({en:0, 'width' : 105});
  325. nr3.push({en:'.'});
  326.  
  327.  
  328. return [nr0, nr1, nr2, nr3];
  329. }
  330.  
  331. public function defineKeysPhone():Array
  332. {
  333. /* Number */
  334. var nr0:Array = new Array(); //Number row 0
  335. var nr1:Array = new Array(); //Number row 1
  336. var nr2:Array = new Array(); //Number row 2
  337. var nr3:Array = new Array(); //Number row 3
  338. var nr4:Array = new Array(); //Number row 4
  339.  
  340. nr0.push({en:['7', '7']});
  341. nr0.push({en:['8', '8']});
  342. nr0.push({en:['9', '9']});
  343. nr0.push({en:['+', '+'], height:105});
  344.  
  345. nr1.push({en:['4', '4']});
  346. nr1.push({en:['5', '5']});
  347. nr1.push({en:['6', '6']});
  348. nr2.push({en:['1', '1']});
  349. nr2.push({en:['2', '2']});
  350. nr2.push({en:['3', '3']});
  351. nr2.push({key:'submit', 'height':105, 'label' : 'Done', primary : true});
  352.  
  353. nr3.push({en:['0', '0'], 'width' : 105});
  354. nr3.push({key:'backspace','label' : '<'});
  355.  
  356.  
  357. return [nr0, nr1, nr2, nr3];
  358. }
  359.  
  360. public function set showPoint(thePoint:Point):void
  361. {
  362. if (!_showPoint) {
  363. _showPoint = thePoint;
  364. }
  365. }
  366.  
  367.  
  368. function clone(source:Object):*
  369. {
  370. var myBA:ByteArray = new ByteArray();
  371. myBA.writeObject(source);
  372. myBA.position = 0;
  373. return(myBA.readObject());
  374. }
  375.  
  376. public function createKey(obj:Object, options:Object = null):KeyItem
  377. {
  378. // {textFormatDict : this._textFormatDict}
  379. //trace("TouchScreenKeyboard. options " , options.keyFillColor);
  380. return new KeyItem(obj, options);
  381. }
  382.  
  383.  
  384. private function createKeys(theMode:String = 'default'):void
  385. {
  386. if (!theMode) return;
  387.  
  388. //trace("theMode", theMode);
  389. this._mode = theMode;
  390.  
  391. var keyOptions = {
  392. textFormatDict : this._textFormatDict,
  393. keyFillColor : this._keyFillColor,
  394. keyFillAlpha : this._keyFillAlpha,
  395. keyTextColor : this._keyTextColor,
  396. keyTextAlpha : this._keyTextAlpha,
  397. primaryKeyFillColor : this._primaryKeyFillColor,
  398. primaryKeyFillAlpha : this._primaryKeyFillAlpha,
  399. primaryKeyTextColor : this._primaryKeyTextColor,
  400. primaryKeyTextAlpha : this._primaryKeyTextAlpha
  401. };
  402.  
  403.  
  404. //clear all keys
  405. if (_board) {
  406. while(_board.numChildren) {
  407. _board.removeChildAt(0);
  408. }
  409. }
  410.  
  411.  
  412. var largestX:Number = 0;
  413. var largestY:Number = 0;
  414. var keyItem:KeyItem;
  415. //Create KeyItem
  416. for (var row:int=0; row< keyDict[theMode].length; row++)
  417. {
  418. var lastX:Number = 0;
  419.  
  420. for (var i:int=0; i< keyDict[theMode][row].length; i++)
  421. {
  422. keyOptions.row = row;
  423. keyItem = createKey(keyDict[theMode][row][i], keyOptions);
  424.  
  425.  
  426. keyItem.x = keyItem.offsetX + lastX;
  427. keyItem.y = row * (_rowHeight);
  428.  
  429. lastX += keyItem.keyWidth + keyItem.offsetX + _gutterX;
  430. _board.addChild(keyItem);
  431.  
  432. keyItem.addEventListener("click", onClickKeyItem);
  433.  
  434.  
  435. if (keyItem.keyID == "submit") {
  436. this._submitKey = keyItem;
  437. }
  438. }
  439.  
  440. largestY += (keyItem.keyHeight + _gutterY);
  441. if (lastX > largestX) largestX = lastX;
  442. }
  443.  
  444. _largestX = largestX;
  445. _largestY = largestY;
  446.  
  447. _board.x = -0.5 * largestX;
  448. _board.y = -0.5 * largestY;
  449.  
  450. this.drawBackground();
  451.  
  452.  
  453. this._inputLang = this._defaultLang;
  454. configureInputLang();
  455. }
  456.  
  457. /*
  458. * Getter / Setter
  459. ***************************************************************/
  460.  
  461. public function get board():Sprite
  462. {
  463. return this._board;
  464. }
  465.  
  466. public function set mode (theMode:String):void {
  467.  
  468. /*if (this._mode != theMode) {
  469. this._mode = theMode;
  470. this.createKeys(this._mode);
  471. }*/
  472. this._mode = theMode;
  473. this.createKeys(this._mode);
  474. }
  475.  
  476. public function get mode():String {
  477. return this._mode;
  478. }
  479.  
  480. public function set keyWidth(value:Number):void
  481. {
  482. this._keyWidth = value;
  483. }
  484.  
  485. public function set keyHeight(value:Number):void
  486. {
  487. this._keyHeight = value;
  488. this._rowHeight = _keyHeight + _gutterY;
  489. }
  490.  
  491. public function set gutterX(value:Number):void
  492. {
  493. this._gutterX = value;
  494. }
  495.  
  496. public function set gutterY(value:Number):void
  497. {
  498. this._gutterY = value;
  499. }
  500.  
  501. public function set submitLabel(theLabel:String):void
  502. {
  503. this._submitKey.label = theLabel;
  504. }
  505.  
  506. public function set backgroundColor(theColor:uint):void
  507. {
  508. _boardFillColor = theColor;
  509. drawBackground();
  510. }
  511.  
  512. public function set backgroundAlpha(theAlpha:Number):void
  513. {
  514. _boardFillAlpha = theAlpha;
  515. drawBackground();
  516. }
  517.  
  518.  
  519. public function set keyFillColor(theColor:uint):void
  520. {
  521. _keyFillColor = theColor;
  522.  
  523.  
  524. /*
  525. var tKey:KeyItem;
  526. if (!_board) return;
  527.  
  528. for (var i:int=0;i<_board.numChildren;i++) {
  529. if (_board.getChildAt(i) is KeyItem) {
  530. tKey = _board.getChildAt(i) as KeyItem;
  531. tKey.backgroundColor = _keyFillColor;
  532. }
  533. }*/
  534. this.createKeys(this._mode);
  535. }
  536.  
  537. public function set keyColor(theColor:uint):void
  538. {
  539. this.keyFillColor = theColor;
  540.  
  541. }
  542. /*
  543. private var _keyFillColor:Number = 0x000000;
  544. private var _keyFillAlpha:Number = 0.6;
  545. private var _keyTextColor:Number = 0x000000;
  546. private var _keyTextAlpha:Number = 1.0;
  547.  
  548. private var _primaryKeyFillColor:uint = 0xFFCC00;
  549. private var _primaryKeyFillAlpha:Number = 1;
  550. private var _primaryKeyTextColor:uint = 0xFFFFFF;
  551. private var _primaryKeyTextAlpha:Number = 1;
  552. */
  553.  
  554. public function set keyFillAlpha(theAlpha:Number):void
  555. {
  556. _keyFillAlpha = theAlpha;
  557. this.createKeys(this._mode);
  558. }
  559.  
  560. public function set primaryKeyFillColor(theColor:uint):void
  561. {
  562. this._primaryKeyFillColor = theColor;
  563. this.createKeys(this._mode);
  564. /*
  565. var tKey:KeyItem;
  566. if (this._submitKey) {
  567. this._submitKey.backgroundColor = theColor;
  568. }*/
  569. // drawBackground();
  570. }
  571.  
  572. public function get primaryKeyFillColor():uint
  573. {
  574. return this._primaryKeyFillColor;
  575. }
  576.  
  577. public function set primaryKeyTextColor(theColor:uint):void
  578. {
  579. this._primaryKeyTextColor = theColor;
  580. this.createKeys(this._mode);
  581.  
  582. }
  583.  
  584. public function get primaryKeyTextColor():uint
  585. {
  586. return this._primaryKeyTextColor;
  587. }
  588.  
  589. public function set primaryTextColor(theColor:uint):void
  590. {
  591. var tKey:KeyItem;
  592. if (this._submitKey) {
  593. this._submitKey.textColor = theColor;
  594. }
  595. // drawBackground();
  596. }
  597.  
  598. public function get primaryTextColor():uint
  599. {
  600. return this._primaryKeyTextColor;
  601. }
  602.  
  603.  
  604.  
  605. public function set keyTextColor(theColor:uint):void
  606. {
  607. _keyTextColor = theColor;
  608.  
  609. if (!_board) return;
  610.  
  611. var tKey:KeyItem;
  612. for (var i:int=0;i<_board.numChildren;i++) {
  613. if (_board.getChildAt(i) is KeyItem) {
  614. tKey = _board.getChildAt(i) as KeyItem;
  615. tKey.textColor = _keyTextColor;
  616. }
  617. }
  618. // drawBackground();
  619. }
  620.  
  621. public function set textColor(theColor:uint):void
  622. {
  623. this.keyTextColor = theColor;
  624. }
  625.  
  626.  
  627. public function set position(value:String):void
  628. {
  629. this._position = value;
  630.  
  631. }
  632.  
  633.  
  634. public function get boardWidth():Number
  635. {
  636. return this._boardWidth;
  637. }
  638.  
  639. public function get boardHeight():Number
  640. {
  641. return this._boardHeight;
  642. }
  643.  
  644.  
  645.  
  646. /*
  647. * Event
  648. ***************************************************************/
  649.  
  650. public function onClickKeyItem(evt:Event):void
  651. {
  652. _touchedKeyItem = evt.target as KeyItem;
  653.  
  654. //add sound pin edit
  655.  
  656. if (soundClick) soundClick.play();
  657.  
  658. switch (_touchedKeyItem.keyID) {
  659.  
  660. case 'shift' :
  661. this.shift();
  662. break;
  663. case 'switch_lang' :
  664. this._inputLang = (this._inputLang == 'en') ? 'th' : 'en';
  665. configureInputLang();
  666. break;
  667.  
  668. case 'return' :
  669. case 'enter' :
  670. touchScreenKeyboardPressedEvent.keyValue = "\n";
  671. dispatchEvent(touchScreenKeyboardPressedEvent);
  672.  
  673. break;
  674. case 'backspace' :
  675. case 'space' :
  676. default:
  677.  
  678. touchScreenKeyboardPressedEvent.keyID = _touchedKeyItem.keyID;
  679. touchScreenKeyboardPressedEvent.keyValue = _touchedKeyItem.keyValue;
  680. dispatchEvent(touchScreenKeyboardPressedEvent);
  681.  
  682. break;
  683. }
  684.  
  685.  
  686. }
  687.  
  688. public function addElement(element:UIControl):void
  689. {
  690. _elements.push(element);
  691. element.addEventListener("focus", onFocusElementHandler);
  692. }
  693.  
  694. private function onFocusElementHandler(evt:UIControlEvent):void
  695. {
  696. //FocusOut previous one
  697. if (this._focusingElement != null && this._focusingElement != evt.target) this._focusingElement.focus = false;
  698.  
  699. //Select new
  700. this._focusingElement = evt.target as UIControl;
  701. if (this._focusingElement) {
  702. showMe(this._focusingElement.frame);
  703. }
  704. }
  705.  
  706. public function get focusingElement():UIControl
  707. {
  708. return this._focusingElement;
  709. }
  710.  
  711. public function set focusingElement(el:UIControl):void
  712. {
  713. this._focusingElement = el;
  714. }
  715.  
  716.  
  717.  
  718.  
  719. var showX:Number = 0;
  720. var showY:Number = 0;
  721. public function showMe(fromRect:Rectangle = null):void
  722. {
  723. _board.x = -0.5 * _largestX;
  724. _board.y = -0.5 * _largestY;
  725. //Move Keyboard to top level
  726.  
  727. this.parent.addChild(this);
  728. //this.parent.swapChildren(this, this.parent.getChildAt(this.parent.numChildren-1));
  729.  
  730.  
  731. switch (_position) {
  732. case 'under' :
  733. if (fromRect) {
  734. showX = fromRect.x + .5 * fromRect.width;
  735. showY = fromRect.y + fromRect.height + .5 * _board.height + 10;
  736. } else {
  737. showX = 0.5 * this.stage.stageWidth;
  738. showY = this.stage.stageHeight - _board.height;
  739. }
  740. break;
  741.  
  742. case 'screenCenter' :
  743. showX = 0.5 * this.stage.stageWidth;
  744. showY = this.stage.stageHeight - _board.height;
  745. break;
  746.  
  747. case 'frameCenter' :
  748. showX = 0.5 * fromRect.x + .5 * fromRect.width;
  749. showY = 0.5 * fromRect.y + .5 * fromRect.height;
  750.  
  751. break;
  752.  
  753. case 'screenBottom' :
  754. showX = 0.5 * this.stage.stageWidth;
  755. showY = this.stage.stageHeight - _board.height;
  756. break;
  757.  
  758. }
  759.  
  760. dispatchEvent(keyboardWillAppearEvent);
  761.  
  762. animateShowMe(showX, showY);
  763.  
  764.  
  765. _hidden = false;
  766. }
  767.  
  768. public function animateShowMe(posX:Number, posY:Number):void
  769. {
  770. if (_showPoint) {
  771. posX = _showPoint.x;
  772. posY = _showPoint.y;
  773. }
  774.  
  775. TweenMax.to(this, 0.9, {x:posX, y:posY, alpha:1, ease:Expo.easeInOut, overwrite:true});
  776. }
  777.  
  778. public function hideMe():void
  779. {
  780. var targetX:int = -960;
  781. var targetY:int = 550;
  782.  
  783. dispatchEvent(keyboardWillDisappearEvent);
  784.  
  785. /*
  786. if (this._focusingElement && this._focusingElement is UITextField) {
  787. this._focusingElement.focus = false;
  788. }*/
  789.  
  790. animateHideMe(targetX, targetY);
  791.  
  792. _hidden = true;
  793.  
  794. }
  795.  
  796. public function animateHideMe(posX:Number, posY:Number):void
  797. {
  798. TweenMax.to(this, 0.5, {x:posX, y:posY, alpha:0, overwrite:true});
  799. }
  800.  
  801. public function get hidden():Boolean {
  802. return this._hidden;
  803. }
  804.  
  805.  
  806.  
  807.  
  808. protected function drawBackground():void
  809. {
  810. if (!_boardBG) _boardBG = new Shape();
  811.  
  812. _boardBG.graphics.clear();
  813. _boardBG.graphics.beginFill(_boardFillColor, _boardFillAlpha);
  814. _boardBG.graphics.lineStyle(1, _boardStrokeColor, _boardStrokeAlpha, true);
  815. _boardBG.graphics.drawRoundRect(-10,-10,_largestX+20,_largestY+20,6);
  816. _boardBG.graphics.endFill();
  817. _board.addChildAt(_boardBG, 0);
  818.  
  819. _boardWidth = _largestX;
  820. _boardHeight = _largestY;
  821. }
  822.  
  823. private function shift():void
  824. {
  825. var tKey:KeyItem;
  826. for (var i:int=0;i<_board.numChildren;i++) {
  827. if (_board.getChildAt(i) is KeyItem) {
  828. tKey = _board.getChildAt(i) as KeyItem;
  829. tKey.shift = !tKey.shift;
  830. }
  831. }
  832. }
  833. /*pin add more >>>>>>>>>>>>> 200657*/
  834. public function set Setlang(str:String):void{
  835. this._inputLang = str;
  836. configureInputLang();
  837. }
  838. /*end pin add more >>>>>>>>> 200657*/
  839.  
  840. private function configureInputLang():void
  841. {
  842. //trace("go in to configureInputLang >>>>>>>>>>>>> on TouchScreenKeyboard");
  843.  
  844. var tKey:KeyItem;
  845.  
  846. for (var i:int=0;i<_board.numChildren;i++) {
  847. if (_board.getChildAt(i) is KeyItem) {
  848. tKey = _board.getChildAt(i) as KeyItem;
  849. tKey.inputLang = this._inputLang;
  850. }
  851. }
  852. }
  853.  
  854. }
  855.  
  856. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement