From 284a473584afb37e79b3301b7908dde4800ab44b Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Sat, 1 Jun 2024 23:43:02 -0400 Subject: [PATCH] Android: get rid of `getInputDialogState` * backported https://github.com/MultiCraft/MultiCraft/commit/b7c470ae9222d453551727a06252f3a2fcfb7285 * let workaround of getInputDialogState --- .../java/com/multicraft/game/GameActivity.kt | 23 ++++--------------- src/client/game.cpp | 2 +- src/gui/guiConfirmRegistration.cpp | 2 +- src/gui/guiFormSpecMenu.cpp | 2 +- src/porting_android.cpp | 4 ++-- src/porting_android.h | 5 ++-- 6 files changed, 11 insertions(+), 27 deletions(-) diff --git a/Android/app/src/main/java/com/multicraft/game/GameActivity.kt b/Android/app/src/main/java/com/multicraft/game/GameActivity.kt index 822bee9de..371783a38 100644 --- a/Android/app/src/main/java/com/multicraft/game/GameActivity.kt +++ b/Android/app/src/main/java/com/multicraft/game/GameActivity.kt @@ -52,7 +52,6 @@ class GameActivity : SDLActivity() { external fun keyboardEvent(keyboard: Boolean) } - private var messageReturnCode = -1 private var messageReturnValue = "" private var hasKeyboard = false @@ -106,8 +105,8 @@ class GameActivity : SDLActivity() { @Suppress("unused") fun showDialog(hint: String?, current: String?, editType: Int) { + isInputActive = true messageReturnValue = "" - messageReturnCode = -1 if (editType == 1) runOnUiThread { showMultiLineDialog(hint, current) } else @@ -115,7 +114,6 @@ class GameActivity : SDLActivity() { } private fun showSingleDialog(hint: String?, current: String?, editType: Int) { - isInputActive = true val builder = AlertDialog.Builder(this, R.style.FullScreenDialogStyle) val binding = InputTextBinding.inflate(layoutInflater) var hintText: String = hint?.ifEmpty { @@ -143,7 +141,6 @@ class GameActivity : SDLActivity() { if (KeyCode == KeyEvent.KEYCODE_ENTER || KeyCode == KeyEvent.KEYCODE_ENDCALL) { imm.hideSoftInputFromWindow(editText.windowToken, 0) messageReturnValue = editText.text.toString() - messageReturnCode = 0 alertDialog.dismiss() isInputActive = false return@setOnEditorActionListener true @@ -155,7 +152,6 @@ class GameActivity : SDLActivity() { if (KeyCode == KeyEvent.KEYCODE_ENTER || KeyCode == KeyEvent.KEYCODE_ENDCALL) { imm.hideSoftInputFromWindow(editText.windowToken, 0) messageReturnValue = editText.text.toString() - messageReturnCode = 0 alertDialog.dismiss() isInputActive = false return@setOnKeyListener true @@ -165,14 +161,12 @@ class GameActivity : SDLActivity() { binding.input.setEndIconOnClickListener { imm.hideSoftInputFromWindow(editText.windowToken, 0) messageReturnValue = editText.text.toString() - messageReturnCode = 0 alertDialog.dismiss() isInputActive = false } binding.rl.setOnClickListener { window.setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_HIDDEN) messageReturnValue = current.toString() - messageReturnCode = 0 alertDialog.dismiss() isInputActive = false } @@ -185,13 +179,11 @@ class GameActivity : SDLActivity() { alertDialog.setOnCancelListener { window.setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_HIDDEN) messageReturnValue = current.toString() - messageReturnCode = 0 isInputActive = false } } private fun showMultiLineDialog(hint: String?, current: String?) { - isInputActive = true val builder = AlertDialog.Builder(this, R.style.FullScreenDialogStyle) val binding = MultilineInputBinding.inflate(layoutInflater) var hintText: String = hint?.ifEmpty { @@ -212,7 +204,6 @@ class GameActivity : SDLActivity() { if (KeyCode == KeyEvent.KEYCODE_ENTER || KeyCode == KeyEvent.KEYCODE_ENDCALL) { imm.hideSoftInputFromWindow(editText.windowToken, 0) messageReturnValue = editText.text.toString() - messageReturnCode = 0 alertDialog.dismiss() isInputActive = false return@setOnEditorActionListener true @@ -224,7 +215,6 @@ class GameActivity : SDLActivity() { if (KeyCode == KeyEvent.KEYCODE_ENTER || KeyCode == KeyEvent.KEYCODE_ENDCALL) { imm.hideSoftInputFromWindow(editText.windowToken, 0) messageReturnValue = editText.text.toString() - messageReturnCode = 0 alertDialog.dismiss() isInputActive = false return@setOnKeyListener true @@ -234,14 +224,12 @@ class GameActivity : SDLActivity() { binding.multiInput.setEndIconOnClickListener { imm.hideSoftInputFromWindow(editText.windowToken, 0) messageReturnValue = editText.text.toString() - messageReturnCode = 0 alertDialog.dismiss() isInputActive = false } binding.multiRl.setOnClickListener { window.setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_HIDDEN) messageReturnValue = current.toString() - messageReturnCode = -1 alertDialog.dismiss() isInputActive = false } @@ -254,7 +242,6 @@ class GameActivity : SDLActivity() { alertDialog.setOnCancelListener { window.setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_HIDDEN) messageReturnValue = current.toString() - messageReturnCode = -1 isInputActive = false } } @@ -262,13 +249,11 @@ class GameActivity : SDLActivity() { @Suppress("unused") fun isDialogActive() = isInputActive - @Suppress("unused") - fun getDialogState() = messageReturnCode - @Suppress("unused") fun getDialogValue(): String { - messageReturnCode = -1 - return messageReturnValue + val value = messageReturnValue + messageReturnValue = "" + return value } @Suppress("unused") diff --git a/src/client/game.cpp b/src/client/game.cpp index 12152e38d..6baf2bf25 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2166,7 +2166,7 @@ void Game::openConsole(float scale, const wchar_t *line) void Game::handleTouchChatInput() { if (porting::getInputDialogOwner() == "chat" && - porting::getInputDialogState() == 0) { + !porting::isInputDialogActive()) { std::string text = porting::getInputDialogValue(); client->typeChatMessage(utf8_to_wide(text)); if (!text.empty() && gui_chat_console->isOpen()) { diff --git a/src/gui/guiConfirmRegistration.cpp b/src/gui/guiConfirmRegistration.cpp index 04f2eb463..c9936fa94 100644 --- a/src/gui/guiConfirmRegistration.cpp +++ b/src/gui/guiConfirmRegistration.cpp @@ -317,7 +317,7 @@ bool GUIConfirmRegistration::getTouchUIInput() return false; // still waiting - if (porting::getInputDialogState() == -1) + if (porting::isInputDialogActive()) return true; m_jni_field_name.clear(); diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index b3a687adc..472536263 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3611,7 +3611,7 @@ bool GUIFormSpecMenu::getTouchUIInput() return false; // still waiting - if (porting::getInputDialogState() == -1) + if (porting::isInputDialogActive()) return true; std::string fieldname = m_jni_field_name; diff --git a/src/porting_android.cpp b/src/porting_android.cpp index 37187d58f..1a699bc24 100644 --- a/src/porting_android.cpp +++ b/src/porting_android.cpp @@ -1,8 +1,8 @@ /* Minetest Copyright (C) 2014 celeron55, Perttu Ahola -Copyright (C) 2014-2022 Maksim Gamarnik [MoNTE48] -Copyright (C) 2022 Dawid Gan +Copyright (C) 2014-2023 Maksim Gamarnik [MoNTE48] +Copyright (C) 2023 Dawid Gan This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/src/porting_android.h b/src/porting_android.h index 39fb0dc92..204b8636d 100644 --- a/src/porting_android.h +++ b/src/porting_android.h @@ -1,8 +1,8 @@ /* Minetest Copyright (C) 2014 celeron55, Perttu Ahola -Copyright (C) 2014-2022 Maksim Gamarnik [MoNTE48] -Copyright (C) 2022 Dawid Gan +Copyright (C) 2014-2023 Maksim Gamarnik [MoNTE48] +Copyright (C) 2023 Dawid Gan This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -68,7 +68,6 @@ void openURIAndroid(const std::string &url); int getInputDialogState(); /** - * WORKAROUND for not working callbacks from java -> c++ * get text in current input dialog */ std::string getInputDialogValue();