1
0

Android: get rid of getInputDialogState

* backported b7c470ae92
* let workaround of getInputDialogState
This commit is contained in:
mckaygerhard 2024-06-01 23:43:02 -04:00
parent e21a1a6e62
commit 284a473584
6 changed files with 11 additions and 27 deletions

View File

@ -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")

View File

@ -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()) {

View File

@ -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();

View File

@ -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;

View File

@ -1,8 +1,8 @@
/*
Minetest
Copyright (C) 2014 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2014-2022 Maksim Gamarnik [MoNTE48] <Maksym48@pm.me>
Copyright (C) 2022 Dawid Gan <deveee@gmail.com>
Copyright (C) 2014-2023 Maksim Gamarnik [MoNTE48] <Maksym48@pm.me>
Copyright (C) 2023 Dawid Gan <deveee@gmail.com>
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

View File

@ -1,8 +1,8 @@
/*
Minetest
Copyright (C) 2014 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2014-2022 Maksim Gamarnik [MoNTE48] <Maksym48@pm.me>
Copyright (C) 2022 Dawid Gan <deveee@gmail.com>
Copyright (C) 2014-2023 Maksim Gamarnik [MoNTE48] <Maksym48@pm.me>
Copyright (C) 2023 Dawid Gan <deveee@gmail.com>
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();