()
| 233 | } |
| 234 | |
| 235 | public boolean startEdit() { |
| 236 | if (readOnly) { return false; } |
| 237 | Forge.setOnScreenKeyboard(true, isNumeric); |
| 238 | if (isEditing) { return true; } //do nothing if already editing |
| 239 | |
| 240 | selStart = 0; //select all before starting input |
| 241 | selLength = text.length(); |
| 242 | textBeforeKeyInput = text; //backup text before input to detect changes |
| 243 | |
| 244 | Forge.startKeyInput(new KeyInputAdapter() { |
| 245 | @Override |
| 246 | public FDisplayObject getOwner() { |
| 247 | return FTextField.this; |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public boolean allowTouchInput() { |
| 252 | return true; |
| 253 | } |
| 254 | |
| 255 | @Override |
| 256 | public boolean keyTyped(char ch) { |
| 257 | insertText(String.valueOf(ch)); |
| 258 | return true; |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public boolean keyDown(int keyCode) { |
| 263 | switch (keyCode) { |
| 264 | case Keys.TAB: |
| 265 | case Keys.ENTER: //end key input on Tab or Enter |
| 266 | Forge.endKeyInput(); |
| 267 | return true; |
| 268 | case Keys.ESCAPE: |
| 269 | setText(textBeforeKeyInput); //cancel edit on Escape |
| 270 | Forge.endKeyInput(); |
| 271 | return true; |
| 272 | case Keys.BACKSPACE: //also handles Delete since those are processed the same by libgdx |
| 273 | if (text.length() > 0) { |
| 274 | if (selLength == 0) { //delete previous or next character if selection empty |
| 275 | if (selStart > 0) { |
| 276 | selStart--; |
| 277 | } |
| 278 | selLength = 1; |
| 279 | } |
| 280 | insertText(""); |
| 281 | } |
| 282 | return true; |
| 283 | case Keys.LEFT: |
| 284 | if (selLength == 0) { |
| 285 | if (selStart > 0) { |
| 286 | selStart--; |
| 287 | } |
| 288 | } |
| 289 | else { |
| 290 | selLength = 0; |
| 291 | } |
| 292 | return true; |
no test coverage detected