我如何知道我的 onResume 是否从 “emoji 弹出” 中调用?

huangapple go评论49阅读模式
英文:

Chromebook. How do I know if my onResume is being called from the "emoji popup"?

问题

我有一个用于Chromebook的聊天应用。
我在聊天中按下搜索 + Shift + Enter -> 弹出“表情符号弹出窗口”。
这会调用我的应用程序的“onPause”,因为对话框在应用程序上方。
在我选择表情符号后,我的应用程序的“onResume”被调用。

我在检查这个问题:

try {
    var newText = inputManager?.inputText
    if (newText != null && inputOnPause != null && newText.length > inputOnPause?.length ?: 0) {
        val new = newText.replace(inputOnPause!!, "")
        hasEmojis(new)
    } else false
} catch (e: Exception) {
    false
}

但是出于某种原因,现在“表情符号”加载得太慢,所以我无法检查我的“onResume”是否是由于表情符号弹出对话框而调用的。
是否有更好的方法来确定我的“onResume”是否是由于表情符号弹出对话框而调用的?
我检查了我的活动onIntent和Data/Action都是null
所以不知道我的文本视图从哪里获取文本。

英文:

I have a chat app for chromebook.
I am in the chat and I press Search + Shift + Enter -> which brings up the "emoji popup"
This calls my apps "onPause" as the dialog is on top of the app.
After I select an emoji, my apps "onResume" is being called.

I was checking this:

 try {
            var newText = inputManager?.inputText
            if (newText != null && inputOnPause != null && newText.length > inputOnPause?.length ?: 0) {
                val new = newText.replace(inputOnPause!!, "")
                hasEmojis(new)
            } else false
        } catch (e: Exception) {
            false
        }

But for some reason now the "emoji" is loaded too slow so I cannot check if my onResume is being from an emoji or not.
Is there a better way to know if my onResume is called due to emoji popup dialog?
I checked my activity onIntent and Data/Action are null
So no idea from where my textview takes the text from neither

答案1

得分: 0

如果您无法确定您的onResume方法是否因表情符号弹出对话框而被调用,您可以尝试另一种方法来检测表情符号输入。不要依赖于对newText和inputOnPause进行比较来检查表情符号输入,您可以利用inputManager直接检查输入是否包含表情符号字符。

try {
    val newText = inputManager?.inputText
    if (newText != null && hasEmojis(newText)) {
        // 检测到表情符号输入
        // 根据需要处理
    } else {
        // 没有表情符号输入
    }
} catch (e: Exception) {
    // 错误处理
}

在这个代码中,hasEmojis 函数负责确定输入文本是否包含任何表情符号字符。您可以使用各种方法来实现这个函数,比如使用正则表达式或检查与表情符号相关的特定Unicode范围。

英文:

If you're unable to determine if your onResume method is called specifically due to the emoji popup dialog, you can try an alternative approach to detect the emoji input. Instead of relying on the comparison of newText and inputOnPause to check for emoji input, you can utilize the inputManager to directly check if the input contains emoji characters.

try {
    val newText = inputManager?.inputText
    if (newText != null && hasEmojis(newText)) {
        // Emoji input detected
        // Handle accordingly
    } else {
        // No emoji input
    }
} catch (e: Exception) {
    // Error handling
}

In this code, the hasEmojis function is responsible for determining whether the input text contains any emoji characters. You can implement this function using various approaches, such as regular expressions or checking for specific Unicode ranges associated with emojis.

huangapple
  • 本文由 发表于 2023年6月8日 20:17:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76431789.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定