From 382c59edb2887c327f403af98a60900fbc0f8030 Mon Sep 17 00:00:00 2001 From: Clara Bayarri Date: Wed, 18 May 2016 12:19:17 +0100 Subject: [PATCH] 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 --- .../systemui/statusbar/KeyboardShortcuts.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java index 79e06c639af28..7f16c699efcf1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java @@ -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; + } } }