Merge pull request #1709 from keymanapp/android-lock-screen

[Android] Allow user to switch keyboard  on lock screen
This commit is contained in:
Darcy Wong 2019-06-27 23:30:58 +07:00 committed by GitHub
commit c19b448a4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import java.util.HashMap;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -82,7 +83,8 @@ public final class KMManager {
// Globe key actions
public enum GlobeKeyAction {
GLOBE_KEY_ACTION_SHOW_MENU,
GLOBE_KEY_ACTION_SWITCH_TO_NEXT_KEYBOARD,
GLOBE_KEY_ACTION_SWITCH_TO_NEXT_KEYBOARD, // Switch to next Keyman keyboard
GLOBE_KEY_ACTION_ADVANCE_TO_NEXT_SYSTEM_KEYBOARD, // Advance to next system keyboard
GLOBE_KEY_ACTION_DO_NOTHING,
}
@ -92,6 +94,7 @@ public final class KMManager {
private static boolean didCopyAssets = false;
private static GlobeKeyAction inappKbGlobeKeyAction = GlobeKeyAction.GLOBE_KEY_ACTION_SHOW_MENU;
private static GlobeKeyAction sysKbGlobeKeyAction = GlobeKeyAction.GLOBE_KEY_ACTION_SHOW_MENU;
private static int sysKbIndexOnLockScreen = -1;
protected static boolean InAppKeyboardLoaded = false;
protected static boolean SystemKeyboardLoaded = false;
@ -1364,10 +1367,29 @@ public final class KMManager {
if (KMManager.shouldAllowSetKeyboard()) {
if (SystemKeyboard.keyboardPickerEnabled) {
KeyguardManager km = (KeyguardManager) appContext.getSystemService(Context.KEYGUARD_SERVICE);
if(km.inKeyguardRestrictedInputMode()) {
// Override system keyboard globe key action if screen is locked:
// 1. Switch to next Keyman keyboard (no menu)
// 2. When all the Keyman keyboards have been cycled through, advance to the next system keyboard
if (sysKbIndexOnLockScreen == -1) {
sysKbIndexOnLockScreen = getCurrentKeyboardIndex(context);
sysKbGlobeKeyAction = GlobeKeyAction.GLOBE_KEY_ACTION_SWITCH_TO_NEXT_KEYBOARD;
} else if (sysKbIndexOnLockScreen == getCurrentKeyboardIndex(context)) {
sysKbGlobeKeyAction = GlobeKeyAction.GLOBE_KEY_ACTION_ADVANCE_TO_NEXT_SYSTEM_KEYBOARD;
}
} else {
// If screen isn't locked, revert to default system globe key action
sysKbIndexOnLockScreen = -1;
sysKbGlobeKeyAction = GlobeKeyAction.GLOBE_KEY_ACTION_SHOW_MENU;
}
if (sysKbGlobeKeyAction == GlobeKeyAction.GLOBE_KEY_ACTION_SHOW_MENU) {
showKeyboardPicker(context, KeyboardType.KEYBOARD_TYPE_SYSTEM);
} else if (sysKbGlobeKeyAction == GlobeKeyAction.GLOBE_KEY_ACTION_SWITCH_TO_NEXT_KEYBOARD) {
switchToNextKeyboard(context);
} else if (sysKbGlobeKeyAction == GlobeKeyAction.GLOBE_KEY_ACTION_ADVANCE_TO_NEXT_SYSTEM_KEYBOARD) {
advanceToNextInputMode();
}
} else {
switchToNextKeyboard(context);

View file

@ -1,5 +1,9 @@
# Keyman for Android
## 2019-06-28 11.0.2103 stable
* Changes:
* Allow user to change keyboard from lock screen (#1709)
## 2019-02-27 11.0.2102 stable
* Bug fix:
* Fix crash from language picker trying to show error dialog (#1634)