Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ import helium314.keyboard.settings.CloseIcon
import helium314.keyboard.settings.SearchIcon
import kotlin.properties.Delegates

private const val TAG = "emoji-search"
const val TAG = "emoji-search"

/**
* This activity is displayed in a gap created for it above the keyboard and below the host app, and disables the host app.
Expand Down Expand Up @@ -260,20 +260,22 @@ class EmojiSearchActivity : ComponentActivity() {
}

override fun onStop() {
Log.d(TAG, "search ending. Selected emoji: ${pressedKey?.let { getEmoji(it) }}. imeClosed: $imeClosed")
val intent = Intent(this, LatinIME::class.java).setAction(EMOJI_SEARCH_DONE_ACTION)
.putExtra(IME_CLOSED_KEY, imeClosed)
pressedKey?.let {
intent.putExtra(EMOJI_KEY, if (it.code == KeyCode.MULTIPLE_CODE_POINTS)
it.getOutputText()
else
Character.toString(it.code))

intent.putExtra(EMOJI_KEY, getEmoji(it))
KeyboardSwitcher.getInstance().emojiPalettesView.addRecentKey(it)
}
startService(intent)
super.onStop()
}

private fun getEmoji(key: Key): String? = if (key.code == KeyCode.MULTIPLE_CODE_POINTS)
key.getOutputText()
else
Character.toString(key.code)

private fun init() {
Log.d(TAG, "init start")
@Suppress("DEPRECATION")
Expand Down
25 changes: 19 additions & 6 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import helium314.keyboard.keyboard.KeyboardActionListenerImpl;
import helium314.keyboard.keyboard.emoji.EmojiPalettesView;
import helium314.keyboard.keyboard.emoji.EmojiSearchActivity;
import helium314.keyboard.keyboard.emoji.EmojiSearchActivityKt;
import helium314.keyboard.keyboard.internal.KeyboardIconsSet;
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode;
import helium314.keyboard.latin.common.InsetsOutlineProvider;
Expand Down Expand Up @@ -1712,21 +1713,25 @@ void launchSettings() {
}

public void launchEmojiSearch() {
Log.d("emoji-search", "before activity launch");
Log.d(EmojiSearchActivityKt.TAG, "before activity launch");
startActivity(new Intent().setClass(this, EmojiSearchActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_MULTIPLE_TASK));
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(EmojiSearchActivityKt.TAG, "after activity closing. isEmojiSearch: " + isEmojiSearch() + ". Intent: " + intent +
(intent != null ? ". imeClosed: " + isImeClosed(intent) + ". selected emoji: " + getSelectedEmoji(intent) : ""));
if (intent != null && EmojiSearchActivity.EMOJI_SEARCH_DONE_ACTION.equals(intent.getAction()) && ! isEmojiSearch()) {
if (intent.getBooleanExtra(EmojiSearchActivity.IME_CLOSED_KEY, false)) {
if (isImeClosed(intent)) {
requestHideSelf(0);
} else {
mHandler.postDelayed(() -> KeyboardSwitcher.getInstance().setEmojiKeyboard(), 100);
if (intent.hasExtra(EmojiSearchActivity.EMOJI_KEY)) {
onTextInput(intent.getStringExtra(EmojiSearchActivity.EMOJI_KEY));
}
mHandler.postDelayed(() -> {
if (intent.hasExtra(EmojiSearchActivity.EMOJI_KEY)) {
onTextInput(getSelectedEmoji(intent));
}
KeyboardSwitcher.getInstance().setEmojiKeyboard();
}, 100);
}

stopSelf(startId); // Allow the service to be destroyed when unbound
Expand All @@ -1736,6 +1741,14 @@ public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}

private static boolean isImeClosed(Intent intent) {
return intent.getBooleanExtra(EmojiSearchActivity.IME_CLOSED_KEY, false);
}

private static String getSelectedEmoji(Intent intent) {
return intent.getStringExtra(EmojiSearchActivity.EMOJI_KEY);
}

public boolean isEmojiSearch() {
return getEmojiSearchActivityHeight() > 0;
}
Expand Down