mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-29 11:47:39 +00:00
feat(android): Refactor globe key functions
This commit is contained in:
parent
d2dc6145a2
commit
a9eb8863ce
2 changed files with 71 additions and 55 deletions
|
|
@ -271,13 +271,15 @@
|
|||
// legacy function name for globe key down
|
||||
function showMenu() {
|
||||
fragmentToggle = (fragmentToggle + 1) % 100;
|
||||
window.location.hash = 'globeKeyAction-' + fragmentToggle + '&keydown=true';
|
||||
var hash = 'globeKeyAction&fragmentToggle=' + fragmentToggle + '&keydown=true';
|
||||
window.location.hash = hash;
|
||||
}
|
||||
|
||||
// legacy function name for globe key up
|
||||
function menuKeyUp() {
|
||||
fragmentToggle = (fragmentToggle + 1) % 100;
|
||||
window.location.hash = 'globeKeyAction-' + fragmentToggle + '&keydown=false';
|
||||
var hash = 'globeKeyAction&fragmentToggle=' + fragmentToggle + '&keydown=false';
|
||||
window.location.hash = hash;
|
||||
}
|
||||
|
||||
function hideKeyboard() {
|
||||
|
|
|
|||
|
|
@ -450,6 +450,36 @@ public final class KMManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the globe key longpress action. Currently just for INAPP only
|
||||
* @param context
|
||||
* @param keyboard
|
||||
*/
|
||||
private static void doGlobeKeyLongpressAction(Context context, KeyboardType keyboard) {
|
||||
if (keyboard == KeyboardType.KEYBOARD_TYPE_INAPP && InAppKeyboard != null) {
|
||||
if (InAppKeyboard.keyboardPickerEnabled) {
|
||||
showKeyboardPicker(context, keyboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the globe key shortpress action. Currently just for INAPP only
|
||||
* @param context
|
||||
* @param keyboard
|
||||
*/
|
||||
private static void doGlobeKeyShortpressAction(Context context, KeyboardType keyboard) {
|
||||
if (keyboard == KeyboardType.KEYBOARD_TYPE_INAPP && InAppKeyboard != null) {
|
||||
if (InAppKeyboard.keyboardPickerEnabled && inappKbGlobeKeyAction == GlobeKeyAction.GLOBE_KEY_ACTION_SHOW_MENU) {
|
||||
showKeyboardPicker(context, KeyboardType.KEYBOARD_TYPE_INAPP);
|
||||
} else if (inappKbGlobeKeyAction == GlobeKeyAction.GLOBE_KEY_ACTION_SWITCH_TO_NEXT_KEYBOARD) {
|
||||
switchToNextKeyboard(context);
|
||||
} else {
|
||||
switchToNextKeyboard(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust the keyboard dimensions. If the suggestion banner is active, use the
|
||||
* combined banner height and keyboard height
|
||||
|
|
@ -1976,6 +2006,12 @@ public final class KMManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
// URL has actual path to the keyboard.html file as a prefix! We need to replace
|
||||
// just the first intended '#' to get URI-based query param processing.
|
||||
// At some point, other parts of the function should be redone to allow use of ? instead
|
||||
// of # in our WebView command "queries" entirely.
|
||||
String cmd = url.replace("keyboard.html#", "keyboard.html?");
|
||||
Uri urlCommand = Uri.parse(cmd);
|
||||
if(url.indexOf("pageLoaded") >= 0) {
|
||||
pageLoaded(view, url);
|
||||
} else if (url.indexOf("hideKeyboard") >= 0) {
|
||||
|
|
@ -1984,7 +2020,7 @@ public final class KMManager {
|
|||
KMTextView textView = (KMTextView) KMTextView.activeView;
|
||||
textView.dismissKeyboard();
|
||||
}
|
||||
} else if (url.indexOf("globeKeyAction") >= 0) {
|
||||
} else if (urlCommand.getQueryParameter("globeKeyAction") != null) {
|
||||
InAppKeyboard.dismissHelpBubble();
|
||||
if (!InAppKeyboard.isHelpBubbleEnabled) {
|
||||
return false;
|
||||
|
|
@ -1995,38 +2031,7 @@ public final class KMManager {
|
|||
editor.putBoolean(KMManager.KMKey_ShouldShowHelpBubble, false);
|
||||
editor.commit();
|
||||
|
||||
// Update globeKeyState
|
||||
int start = url.indexOf("keydown=") + 8;
|
||||
String value = url.substring(start);
|
||||
boolean globeKeyDown = !value.isEmpty() && Boolean.valueOf(value);
|
||||
if (globeKeyState != GlobeKeyState.GLOBE_KEY_STATE_LONGPRESS) {
|
||||
if (globeKeyDown) {
|
||||
globeKeyState = GlobeKeyState.GLOBE_KEY_STATE_DOWN;
|
||||
} else {
|
||||
globeKeyState = GlobeKeyState.GLOBE_KEY_STATE_UP;
|
||||
}
|
||||
}
|
||||
|
||||
if (KMManager.shouldAllowSetKeyboard()) {
|
||||
if (globeKeyState == GlobeKeyState.GLOBE_KEY_STATE_LONGPRESS) {
|
||||
// Longpress globe
|
||||
if (InAppKeyboard.keyboardPickerEnabled) {
|
||||
showKeyboardPicker(context, KeyboardType.KEYBOARD_TYPE_INAPP);
|
||||
globeKeyState = GlobeKeyState.GLOBE_KEY_STATE_UP;
|
||||
}
|
||||
} else if (globeKeyState == GlobeKeyState.GLOBE_KEY_STATE_UP) {
|
||||
// Handle shortpress globe
|
||||
if (InAppKeyboard.keyboardPickerEnabled) {
|
||||
if (inappKbGlobeKeyAction == GlobeKeyAction.GLOBE_KEY_ACTION_SHOW_MENU) {
|
||||
showKeyboardPicker(context, KeyboardType.KEYBOARD_TYPE_INAPP);
|
||||
} else if (inappKbGlobeKeyAction == GlobeKeyAction.GLOBE_KEY_ACTION_SWITCH_TO_NEXT_KEYBOARD) {
|
||||
switchToNextKeyboard(context);
|
||||
}
|
||||
} else {
|
||||
switchToNextKeyboard(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
handleGlobeKeyAction(urlCommand.getBooleanQueryParameter("keydown", false));
|
||||
} else if (url.indexOf("showHelpBubble") >= 0) {
|
||||
int start = url.indexOf("keyPos=") + 7;
|
||||
String value = url.substring(start);
|
||||
|
|
@ -2123,14 +2128,6 @@ public final class KMManager {
|
|||
RelativeLayout.LayoutParams params = getKeyboardLayoutParams();
|
||||
InAppKeyboard.setLayoutParams(params);
|
||||
} else if (url.indexOf("suggestPopup") >= 0) {
|
||||
// URL has actual path to the keyboard.html file as a prefix! We need to replace
|
||||
// just the first intended '#' to get URI-based query param processing.
|
||||
|
||||
// At some point, other parts of the function should be redone to allow use of ? instead
|
||||
// of # in our WebView command "queries" entirely.
|
||||
String cmd = url.replace("keyboard.html#", "keyboard.html?");
|
||||
Uri urlCommand = Uri.parse(cmd);
|
||||
|
||||
double x = Float.parseFloat(urlCommand.getQueryParameter("x"));
|
||||
double y = Float.parseFloat(urlCommand.getQueryParameter("y"));
|
||||
double width = Float.parseFloat(urlCommand.getQueryParameter("w"));
|
||||
|
|
@ -2156,6 +2153,26 @@ public final class KMManager {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleGlobeKeyAction(boolean globeKeyDown) {
|
||||
// Update globeKeyState
|
||||
if (globeKeyState != GlobeKeyState.GLOBE_KEY_STATE_LONGPRESS) {
|
||||
globeKeyState = globeKeyDown ? GlobeKeyState.GLOBE_KEY_STATE_DOWN : GlobeKeyState.GLOBE_KEY_STATE_UP;
|
||||
}
|
||||
|
||||
if (KMManager.shouldAllowSetKeyboard()) {
|
||||
if (globeKeyState == GlobeKeyState.GLOBE_KEY_STATE_LONGPRESS) {
|
||||
// Longpress globe
|
||||
doGlobeKeyLongpressAction(context, KeyboardType.KEYBOARD_TYPE_INAPP);
|
||||
|
||||
// clear globeKeyState
|
||||
globeKeyState = GlobeKeyState.GLOBE_KEY_STATE_UP;
|
||||
} else if (globeKeyState == GlobeKeyState.GLOBE_KEY_STATE_UP) {
|
||||
// Shortpress globe
|
||||
doGlobeKeyShortpressAction(context, KeyboardType.KEYBOARD_TYPE_INAPP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static final class KMSystemKeyboardWebViewClient extends WebViewClient {
|
||||
|
|
@ -2238,12 +2255,19 @@ public final class KMManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
// URL has actual path to the keyboard.html file as a prefix! We need to replace
|
||||
// just the first intended '#' to get URI-based query param processing.
|
||||
|
||||
// At some point, other parts of the function should be redone to allow use of ? instead
|
||||
// of # in our WebView command "queries" entirely.
|
||||
String cmd = url.replace("keyboard.html#", "keyboard.html?");
|
||||
Uri urlCommand = Uri.parse(cmd);
|
||||
if(url.indexOf("pageLoaded") >= 0) {
|
||||
pageLoaded(view, url);
|
||||
} else if (url.indexOf("hideKeyboard") >= 0) {
|
||||
SystemKeyboard.dismissHelpBubble();
|
||||
IMService.requestHideSelf(0);
|
||||
} else if (url.indexOf("globeKeyAction") >= 0) {
|
||||
} else if (urlCommand.getQueryParameter("globeKeyAction") != null) {
|
||||
SystemKeyboard.dismissHelpBubble();
|
||||
if (!SystemKeyboard.isHelpBubbleEnabled) {
|
||||
return false;
|
||||
|
|
@ -2255,9 +2279,7 @@ public final class KMManager {
|
|||
editor.commit();
|
||||
|
||||
// Update globeKeyState
|
||||
int start = url.indexOf("keydown=") + 8;
|
||||
String value = url.substring(start);
|
||||
boolean globeKeyDown = !value.isEmpty() && Boolean.valueOf(value);
|
||||
boolean globeKeyDown = urlCommand.getBooleanQueryParameter("keydown", false);
|
||||
if (globeKeyState != GlobeKeyState.GLOBE_KEY_STATE_LONGPRESS) {
|
||||
globeKeyState = globeKeyDown ? GlobeKeyState.GLOBE_KEY_STATE_DOWN : GlobeKeyState.GLOBE_KEY_STATE_UP;
|
||||
}
|
||||
|
|
@ -2412,14 +2434,6 @@ public final class KMManager {
|
|||
RelativeLayout.LayoutParams params = getKeyboardLayoutParams();
|
||||
SystemKeyboard.setLayoutParams(params);
|
||||
} else if (url.indexOf("suggestPopup") >= 0) {
|
||||
// URL has actual path to the keyboard.html file as a prefix! We need to replace
|
||||
// just the first intended '#' to get URI-based query param processing.
|
||||
|
||||
// At some point, other parts of the function should be redone to allow use of ? instead
|
||||
// of # in our WebView command "queries" entirely.
|
||||
String cmd = url.replace("keyboard.html#", "keyboard.html?");
|
||||
Uri urlCommand = Uri.parse(cmd);
|
||||
|
||||
double x = Float.parseFloat(urlCommand.getQueryParameter("x"));
|
||||
double y = Float.parseFloat(urlCommand.getQueryParameter("y"));
|
||||
double width = Float.parseFloat(urlCommand.getQueryParameter("w"));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue