diff options
author | Muhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com> | 2021-06-05 02:22:53 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-04 21:22:53 +0200 |
commit | 40acfc938ce2306dbf6704f8091a89817a73c71b (patch) | |
tree | e4c0ef49a9d52fb2a43be709f49e9cecc25dddfa /build/android/app | |
parent | 8f085e02a107dd8092393935bfa1bba71d2546d2 (diff) | |
download | minetest-40acfc938ce2306dbf6704f8091a89817a73c71b.tar.gz minetest-40acfc938ce2306dbf6704f8091a89817a73c71b.tar.bz2 minetest-40acfc938ce2306dbf6704f8091a89817a73c71b.zip |
Android: Do not submit text after pressing Enter key for multi-line text (#11298)
Regular EditText is used for multi-line text to not close the dialog after pressing back button.
New button is added for submitting multi-line text.
Diffstat (limited to 'build/android/app')
-rw-r--r-- | build/android/app/src/main/java/net/minetest/minetest/GameActivity.java | 33 | ||||
-rw-r--r-- | build/android/app/src/main/res/values/strings.xml | 1 |
2 files changed, 30 insertions, 4 deletions
diff --git a/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java b/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java index 38a388230..bdf764138 100644 --- a/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java +++ b/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java @@ -30,7 +30,9 @@ import android.view.KeyEvent; import android.view.View; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; +import android.widget.Button; import android.widget.EditText; +import android.widget.LinearLayout; import androidx.appcompat.app.AlertDialog; @@ -85,9 +87,19 @@ public class GameActivity extends NativeActivity { private void showDialogUI(String hint, String current, int editType) { final AlertDialog.Builder builder = new AlertDialog.Builder(this); - EditText editText = new CustomEditText(this); - builder.setView(editText); + LinearLayout container = new LinearLayout(this); + container.setOrientation(LinearLayout.VERTICAL); + builder.setView(container); AlertDialog alertDialog = builder.create(); + EditText editText; + // For multi-line, do not close the dialog after pressing back button + if (editType == 1) { + editText = new EditText(this); + } else { + editText = new CustomEditText(this); + } + container.addView(editText); + editText.setMaxLines(8); editText.requestFocus(); editText.setHint(hint); editText.setText(current); @@ -103,8 +115,9 @@ public class GameActivity extends NativeActivity { else editText.setInputType(InputType.TYPE_CLASS_TEXT); editText.setSelection(editText.getText().length()); - editText.setOnKeyListener((view, KeyCode, event) -> { - if (KeyCode == KeyEvent.KEYCODE_ENTER) { + editText.setOnKeyListener((view, keyCode, event) -> { + // For multi-line, do not submit the text after pressing Enter key + if (keyCode == KeyEvent.KEYCODE_ENTER && editType != 1) { imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); messageReturnCode = 0; messageReturnValue = editText.getText().toString(); @@ -113,6 +126,18 @@ public class GameActivity extends NativeActivity { } return false; }); + // For multi-line, add Done button since Enter key does not submit text + if (editType == 1) { + Button doneButton = new Button(this); + container.addView(doneButton); + doneButton.setText(R.string.ime_dialog_done); + doneButton.setOnClickListener((view -> { + imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); + messageReturnCode = 0; + messageReturnValue = editText.getText().toString(); + alertDialog.dismiss(); + })); + } alertDialog.show(); alertDialog.setOnCancelListener(dialog -> { getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); diff --git a/build/android/app/src/main/res/values/strings.xml b/build/android/app/src/main/res/values/strings.xml index a6fba70d5..85238117f 100644 --- a/build/android/app/src/main/res/values/strings.xml +++ b/build/android/app/src/main/res/values/strings.xml @@ -6,5 +6,6 @@ <string name="not_granted">Required permission wasn\'t granted, Minetest can\'t run without it</string> <string name="notification_title">Loading Minetest</string> <string name="notification_description">Less than 1 minute…</string> + <string name="ime_dialog_done">Done</string> </resources> |