From 1bf72d567fedebc8ed6169def0fa80fd75d7c328 Mon Sep 17 00:00:00 2001 From: ImmediandoSrl Date: Mon, 17 Jun 2024 11:19:07 +0200 Subject: [PATCH] KeyCode on TextArea DoneEvent (#3816) Added the keycode that triggered the done event to the ActionEvent that is sent. --- .../src/com/codename1/ui/TextArea.java | 9 ++++--- .../impl/android/InPlaceEditView.java | 24 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CodenameOne/src/com/codename1/ui/TextArea.java b/CodenameOne/src/com/codename1/ui/TextArea.java index 25f710b901..aa07240721 100644 --- a/CodenameOne/src/com/codename1/ui/TextArea.java +++ b/CodenameOne/src/com/codename1/ui/TextArea.java @@ -2197,17 +2197,20 @@ public ActionListener getDoneListener() { * Fire the done event to done listener */ public void fireDoneEvent() { + fireDoneEvent(-1); + } + public void fireDoneEvent(final int keyEvent) { if (doneListener != null) { if (!Display.getInstance().isEdt()) { Display.getInstance().callSerially(new Runnable() { - + public void run() { - fireDoneEvent(); + fireDoneEvent(keyEvent); } }); return; } - doneListener.actionPerformed(new ActionEvent(this,ActionEvent.Type.Done)); + doneListener.actionPerformed(new ActionEvent(this,ActionEvent.Type.Done,keyEvent)); } } diff --git a/Ports/Android/src/com/codename1/impl/android/InPlaceEditView.java b/Ports/Android/src/com/codename1/impl/android/InPlaceEditView.java index 916b931cab..ca0bc39960 100644 --- a/Ports/Android/src/com/codename1/impl/android/InPlaceEditView.java +++ b/Ports/Android/src/com/codename1/impl/android/InPlaceEditView.java @@ -1105,10 +1105,6 @@ private boolean editorContains(int x, int y) { return mIsEditing && mEditText != null && mEditText.mTextArea != null && mEditText.mTextArea.contains(x, y); } - private synchronized void endEditing(int reason, boolean forceVKBOpen, int actionCode) { - endEditing(reason, forceVKBOpen, false, actionCode); - } - private Component getNextComponent(Component curr) { Form f = curr.getComponentForm(); if (f != null) { @@ -1117,11 +1113,19 @@ private Component getNextComponent(Component curr) { return null; } + private synchronized void endEditing(int reason, boolean forceVKBOpen, int actionCode) { + endEditing(reason, forceVKBOpen, false, actionCode); + } + + private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode) { + endEditing(reason, forceVKBOpen, false, actionCode, -1); + } + /** * Finish the in-place editing of the given text area, release the edit lock, and allow the synchronous call * to 'edit' to return. */ - private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode) { + private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode, int keyEvent) { //if (cursorTimer != null) { // cursorTimer.cancel(); //} @@ -1167,11 +1171,9 @@ private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean f if (reason == REASON_IME_ACTION && ((TextArea) mEditText.mTextArea).getDoneListener() != null && (actionCode == EditorInfo.IME_ACTION_DONE)|| actionCode == EditorInfo.IME_ACTION_SEARCH || actionCode == EditorInfo.IME_ACTION_SEND || actionCode == EditorInfo.IME_ACTION_GO) { - ((TextArea) mEditText.mTextArea).fireDoneEvent(); - + ((TextArea) mEditText.mTextArea).fireDoneEvent(keyEvent); } - // Call this in onComplete instead //mIsEditing = false; mLastEditText = mEditText; @@ -2157,6 +2159,12 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { case KeyEvent.KEYCODE_MENU: endEditing(InPlaceEditView.REASON_SYSTEM_KEY, false, true, 0); break; + case KeyEvent.KEYCODE_ENTER: + onEditorAction(EditorInfo.IME_ACTION_DONE); + break; + case KeyEvent.KEYCODE_ESCAPE: + endEditing(InPlaceEditView.REASON_IME_ACTION, false, true, EditorInfo.IME_ACTION_DONE, keyCode); + break; case KeyEvent.KEYCODE_TAB: onEditorAction(EditorInfo.IME_ACTION_NEXT); break;