Skip to content

Commit 1bf72d5

Browse files
KeyCode on TextArea DoneEvent (#3816)
Added the keycode that triggered the done event to the ActionEvent that is sent.
1 parent fd6752a commit 1bf72d5

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

CodenameOne/src/com/codename1/ui/TextArea.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -2197,17 +2197,20 @@ public ActionListener getDoneListener() {
21972197
* Fire the done event to done listener
21982198
*/
21992199
public void fireDoneEvent() {
2200+
fireDoneEvent(-1);
2201+
}
2202+
public void fireDoneEvent(final int keyEvent) {
22002203
if (doneListener != null) {
22012204
if (!Display.getInstance().isEdt()) {
22022205
Display.getInstance().callSerially(new Runnable() {
2203-
2206+
22042207
public void run() {
2205-
fireDoneEvent();
2208+
fireDoneEvent(keyEvent);
22062209
}
22072210
});
22082211
return;
22092212
}
2210-
doneListener.actionPerformed(new ActionEvent(this,ActionEvent.Type.Done));
2213+
doneListener.actionPerformed(new ActionEvent(this,ActionEvent.Type.Done,keyEvent));
22112214
}
22122215
}
22132216

Ports/Android/src/com/codename1/impl/android/InPlaceEditView.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -1105,10 +1105,6 @@ private boolean editorContains(int x, int y) {
11051105
return mIsEditing && mEditText != null && mEditText.mTextArea != null && mEditText.mTextArea.contains(x, y);
11061106
}
11071107

1108-
private synchronized void endEditing(int reason, boolean forceVKBOpen, int actionCode) {
1109-
endEditing(reason, forceVKBOpen, false, actionCode);
1110-
}
1111-
11121108
private Component getNextComponent(Component curr) {
11131109
Form f = curr.getComponentForm();
11141110
if (f != null) {
@@ -1117,11 +1113,19 @@ private Component getNextComponent(Component curr) {
11171113
return null;
11181114
}
11191115

1116+
private synchronized void endEditing(int reason, boolean forceVKBOpen, int actionCode) {
1117+
endEditing(reason, forceVKBOpen, false, actionCode);
1118+
}
1119+
1120+
private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode) {
1121+
endEditing(reason, forceVKBOpen, false, actionCode, -1);
1122+
}
1123+
11201124
/**
11211125
* Finish the in-place editing of the given text area, release the edit lock, and allow the synchronous call
11221126
* to 'edit' to return.
11231127
*/
1124-
private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode) {
1128+
private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode, int keyEvent) {
11251129
//if (cursorTimer != null) {
11261130
// cursorTimer.cancel();
11271131
//}
@@ -1167,11 +1171,9 @@ private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean f
11671171
if (reason == REASON_IME_ACTION
11681172
&& ((TextArea) mEditText.mTextArea).getDoneListener() != null
11691173
&& (actionCode == EditorInfo.IME_ACTION_DONE)|| actionCode == EditorInfo.IME_ACTION_SEARCH || actionCode == EditorInfo.IME_ACTION_SEND || actionCode == EditorInfo.IME_ACTION_GO) {
1170-
((TextArea) mEditText.mTextArea).fireDoneEvent();
1171-
1174+
((TextArea) mEditText.mTextArea).fireDoneEvent(keyEvent);
11721175
}
11731176

1174-
11751177
// Call this in onComplete instead
11761178
//mIsEditing = false;
11771179
mLastEditText = mEditText;
@@ -2157,6 +2159,12 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
21572159
case KeyEvent.KEYCODE_MENU:
21582160
endEditing(InPlaceEditView.REASON_SYSTEM_KEY, false, true, 0);
21592161
break;
2162+
case KeyEvent.KEYCODE_ENTER:
2163+
onEditorAction(EditorInfo.IME_ACTION_DONE);
2164+
break;
2165+
case KeyEvent.KEYCODE_ESCAPE:
2166+
endEditing(InPlaceEditView.REASON_IME_ACTION, false, true, EditorInfo.IME_ACTION_DONE, keyCode);
2167+
break;
21602168
case KeyEvent.KEYCODE_TAB:
21612169
onEditorAction(EditorInfo.IME_ACTION_NEXT);
21622170
break;

0 commit comments

Comments
 (0)