Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a721827 authored by Josep del Rio's avatar Josep del Rio
Browse files

Support dead characters when key presses are shown

Got a crash while testing the German layout, and it seems like the
current "show key presses" functionality will crash when using
an unsupported Unicode character. This CL addresses this issue by
adding support for dead characters, pulling the actual combining
character from the KCM if needed.

Bug: 325420862
Test: Flashed on device
Flag: NONE
Change-Id: Ia70685fbfae5bf81a71b346a24ff0e73c8d8d932
parent c2471884
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -578,6 +578,17 @@ public class KeyCharacterMap implements Parcelable {
        return combined;
    }

    /**
     * Get the combining character that corresponds with the provided accent.
     *
     * @param accent The accent character.  eg. '`'
     * @return The combining character
     * @hide
     */
    public static int getCombiningChar(int accent) {
        return sAccentToCombining.get(accent);
    }

    /**
     * Describes the character mappings associated with a key.
     *
+10 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.util.Slog;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.InputDevice;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.RoundedCorner;
@@ -335,7 +336,15 @@ public class FocusEventDebugView extends RelativeLayout {

        final int unicodeChar = event.getUnicodeChar();
        if (unicodeChar != 0) {
            return new String(Character.toChars(unicodeChar));
            if ((unicodeChar & KeyCharacterMap.COMBINING_ACCENT) != 0) {
                // Show combining character
                final int combiningChar = KeyCharacterMap.getCombiningChar(
                        unicodeChar & KeyCharacterMap.COMBINING_ACCENT_MASK);
                // Return the Unicode dotted circle as part of the label as it is used is used to
                // illustrate the effect of a combining marks
                return "\u25cc" + String.valueOf((char) combiningChar);
            }
            return String.valueOf((char) unicodeChar);
        }

        final var label = KeyEvent.keyCodeToString(event.getKeyCode());