-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change(android): smoother keyboard initialization ✨ #10022
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.keyman.engine; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.os.Build; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
|
@@ -20,6 +21,7 @@ | |
import static android.content.Context.VIBRATOR_SERVICE; | ||
|
||
import com.keyman.engine.KMManager.KeyboardType; | ||
import com.keyman.engine.data.Keyboard; | ||
import com.keyman.engine.util.CharSequenceUtil; | ||
import com.keyman.engine.util.KMLog; | ||
|
||
|
@@ -62,6 +64,21 @@ public int getKeyboardWidth() { | |
return kbWidth; | ||
} | ||
|
||
@JavascriptInterface | ||
public String initialKeyboard() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we wanted to adopt something kinda similar for iOS: https://developer.apple.com/documentation/webkit/wkscriptmessagehandlerwithreply We could then But... this is only available with iOS 14.0+. |
||
// Note: KMManager.getCurrentKeyboard() (and similar) will throw errors until the host-page is first fully | ||
// loaded and has set a keyboard. To allow the host-page to have earlier access, we instead get the stored | ||
// keyboard index directly. | ||
SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); | ||
int index = prefs.getInt(KMManager.KMKey_UserKeyboardIndex, 0); | ||
if (index < 0) { | ||
index = 0; | ||
} | ||
|
||
Keyboard kbd = KMManager.getKeyboardInfo(this.context, index); | ||
return kbd.toStub(context); | ||
} | ||
|
||
// This annotation is required in Jelly Bean and later: | ||
@JavascriptInterface | ||
public void beepKeyboard() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uses the function defined within this PR within the Java
KMKeyboardJSHandler
class. See other comment (re https://developer.apple.com/documentation/webkit/wkscriptmessagehandlerwithreply) on how this could look for iOS if we wanted to go that route.That said, I don't see the problem this PR addresses on my personal iOS device. So, adopting this code for use on iOS can probably be low-priority for now.