Fix Backslash not showing with paired keyboard
Our current label retrieving flow is 1. Special cased drawables (e.g. backspace) 2. Special cased names (e.g. F2) 3. Device KeyCharacterMap getLabel For single character keys such as '\', we reach the end of 3. with no result if the main device doesn't have the key. This change uses the virtual keyboard map as a backup to retrieve labels for these last resort cases. Bug: 28830189 Change-Id: I69cc82a11e7b803db7f60ea07d34c59f6000149e
This commit is contained in:
@@ -111,6 +111,7 @@ public final class KeyboardShortcuts {
|
||||
|
||||
private Dialog mKeyboardShortcutsDialog;
|
||||
private KeyCharacterMap mKeyCharacterMap;
|
||||
private KeyCharacterMap mBackupKeyCharacterMap;
|
||||
|
||||
private KeyboardShortcuts(Context context) {
|
||||
this.mContext = new ContextThemeWrapper(context, android.R.style.Theme_Material_Light);
|
||||
@@ -326,6 +327,7 @@ public final class KeyboardShortcuts {
|
||||
*/
|
||||
private void retrieveKeyCharacterMap(int deviceId) {
|
||||
final InputManager inputManager = InputManager.getInstance();
|
||||
mBackupKeyCharacterMap = inputManager.getInputDevice(-1).getKeyCharacterMap();
|
||||
if (deviceId != -1) {
|
||||
final InputDevice inputDevice = inputManager.getInputDevice(deviceId);
|
||||
if (inputDevice != null) {
|
||||
@@ -343,8 +345,8 @@ public final class KeyboardShortcuts {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final InputDevice inputDevice = inputManager.getInputDevice(-1);
|
||||
mKeyCharacterMap = inputDevice.getKeyCharacterMap();
|
||||
// Fall back to -1, the virtual keyboard.
|
||||
mKeyCharacterMap = mBackupKeyCharacterMap;
|
||||
}
|
||||
|
||||
private void showKeyboardShortcuts(int deviceId) {
|
||||
@@ -675,7 +677,12 @@ public final class KeyboardShortcuts {
|
||||
if (displayLabel != 0) {
|
||||
displayLabelString = String.valueOf(displayLabel);
|
||||
} else {
|
||||
return null;
|
||||
displayLabel = mBackupKeyCharacterMap.getDisplayLabel(info.getKeycode());
|
||||
if (displayLabel != 0) {
|
||||
displayLabelString = String.valueOf(displayLabel);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user