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

Commit 426467c6 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Android (Google) Code Review
Browse files

Merge "Add new attributes to <keyboard-layout> to provide layout type"

parents 0443023f d095d48c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -935,6 +935,8 @@ package android {
    field @Deprecated public static final int keyTextSize = 16843316; // 0x1010234
    field @Deprecated public static final int keyWidth = 16843325; // 0x101023d
    field public static final int keyboardLayout = 16843691; // 0x10103ab
    field public static final int keyboardLayoutType;
    field public static final int keyboardLocale;
    field @Deprecated public static final int keyboardMode = 16843341; // 0x101024d
    field public static final int keyboardNavigationCluster = 16844096; // 0x1010540
    field public static final int keycode = 16842949; // 0x10100c5
+1 −0
Original line number Diff line number Diff line
@@ -1299,6 +1299,7 @@ package android.hardware.input {
    method @RequiresPermission(android.Manifest.permission.REMAP_MODIFIER_KEYS) public void clearAllModifierKeyRemappings();
    method @Nullable public String getCurrentKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier);
    method @NonNull public java.util.List<java.lang.String> getKeyboardLayoutDescriptorsForInputDevice(@NonNull android.view.InputDevice);
    method @NonNull public String getKeyboardLayoutTypeForLayoutDescriptor(@NonNull String);
    method @NonNull @RequiresPermission(android.Manifest.permission.REMAP_MODIFIER_KEYS) public java.util.Map<java.lang.Integer,java.lang.Integer> getModifierKeyRemapping();
    method @RequiresPermission(android.Manifest.permission.REMAP_MODIFIER_KEYS) public void remapModifierKey(int, int);
    method @RequiresPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT) public void removeKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier, @NonNull String);
+32 −0
Original line number Diff line number Diff line
@@ -166,6 +166,14 @@ public final class InputManager {
     * The <code>android:keyboardLayout</code> attribute refers to a
     * <a href="http://source.android.com/tech/input/key-character-map-files.html">
     * key character map</a> resource that defines the keyboard layout.
     * The <code>android:keyboardLocale</code> attribute specifies a comma separated list of BCP 47
     * language tags depicting the locales supported by the keyboard layout. This attribute is
     * optional and will be used for auto layout selection for external physical keyboards.
     * The <code>android:keyboardLayoutType</code> attribute specifies the layoutType for the
     * keyboard layout. This can be either empty or one of the following supported layout types:
     * qwerty, qwertz, azerty, dvorak, colemak, workman, extended, turkish_q, turkish_f. This
     * attribute is optional and will be used for auto layout selection for external physical
     * keyboards.
     * </p>
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
@@ -704,6 +712,30 @@ public final class InputManager {
        return res;
    }

    /**
     * Returns the layout type of the queried layout
     * <p>
     * The input manager consults the built-in keyboard layouts as well as all keyboard layouts
     * advertised by applications using a {@link #ACTION_QUERY_KEYBOARD_LAYOUTS} broadcast receiver.
     * </p>
     *
     * @param layoutDescriptor The layout descriptor of the queried layout
     * @return layout type of the queried layout
     *
     * @hide
     */
    @TestApi
    @NonNull
    public String getKeyboardLayoutTypeForLayoutDescriptor(@NonNull String layoutDescriptor) {
        KeyboardLayout[] layouts = getKeyboardLayouts();
        for (KeyboardLayout kl : layouts) {
            if (layoutDescriptor.equals(kl.getDescriptor())) {
                return kl.getLayoutType();
            }
        }
        return "";
    }

    /**
     * Gets information about all supported keyboard layouts appropriate
     * for a specific input device.
+68 −5
Original line number Diff line number Diff line
@@ -21,24 +21,74 @@ import android.os.LocaleList;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.HashMap;
import java.util.Map;

/**
 * Describes a keyboard layout.
 *
 * @hide
 */
public final class KeyboardLayout implements Parcelable,
        Comparable<KeyboardLayout> {
public final class KeyboardLayout implements Parcelable, Comparable<KeyboardLayout> {
    private final String mDescriptor;
    private final String mLabel;
    private final String mCollection;
    private final int mPriority;
    @NonNull
    private final LocaleList mLocales;
    private final LayoutType mLayoutType;
    private final int mVendorId;
    private final int mProductId;

    public static final @android.annotation.NonNull Parcelable.Creator<KeyboardLayout> CREATOR =
            new Parcelable.Creator<KeyboardLayout>() {
    /** Currently supported Layout types in the KCM files */
    private enum LayoutType {
        UNDEFINED(0, "undefined"),
        QWERTY(1, "qwerty"),
        QWERTZ(2, "qwertz"),
        AZERTY(3, "azerty"),
        DVORAK(4, "dvorak"),
        COLEMAK(5, "colemak"),
        WORKMAN(6, "workman"),
        TURKISH_F(7, "turkish_f"),
        TURKISH_Q(8, "turkish_q"),
        EXTENDED(9, "extended");

        private final int mValue;
        private final String mName;
        private static final Map<Integer, LayoutType> VALUE_TO_ENUM_MAP = new HashMap<>();
        static {
            VALUE_TO_ENUM_MAP.put(UNDEFINED.mValue, UNDEFINED);
            VALUE_TO_ENUM_MAP.put(QWERTY.mValue, QWERTY);
            VALUE_TO_ENUM_MAP.put(QWERTZ.mValue, QWERTZ);
            VALUE_TO_ENUM_MAP.put(AZERTY.mValue, AZERTY);
            VALUE_TO_ENUM_MAP.put(DVORAK.mValue, DVORAK);
            VALUE_TO_ENUM_MAP.put(COLEMAK.mValue, COLEMAK);
            VALUE_TO_ENUM_MAP.put(WORKMAN.mValue, WORKMAN);
            VALUE_TO_ENUM_MAP.put(TURKISH_F.mValue, TURKISH_F);
            VALUE_TO_ENUM_MAP.put(TURKISH_Q.mValue, TURKISH_Q);
            VALUE_TO_ENUM_MAP.put(EXTENDED.mValue, EXTENDED);
        }

        private static LayoutType of(int value) {
            return VALUE_TO_ENUM_MAP.getOrDefault(value, UNDEFINED);
        }

        LayoutType(int value, String name) {
            this.mValue = value;
            this.mName = name;
        }

        private int getValue() {
            return mValue;
        }

        private String getName() {
            return mName;
        }
    }

    @NonNull
    public static final Parcelable.Creator<KeyboardLayout> CREATOR = new Parcelable.Creator<>() {
        public KeyboardLayout createFromParcel(Parcel source) {
            return new KeyboardLayout(source);
        }
@@ -48,12 +98,13 @@ public final class KeyboardLayout implements Parcelable,
    };

    public KeyboardLayout(String descriptor, String label, String collection, int priority,
            LocaleList locales, int vid, int pid) {
            LocaleList locales, int layoutValue, int vid, int pid) {
        mDescriptor = descriptor;
        mLabel = label;
        mCollection = collection;
        mPriority = priority;
        mLocales = locales;
        mLayoutType = LayoutType.of(layoutValue);
        mVendorId = vid;
        mProductId = pid;
    }
@@ -64,6 +115,7 @@ public final class KeyboardLayout implements Parcelable,
        mCollection = source.readString();
        mPriority = source.readInt();
        mLocales = LocaleList.CREATOR.createFromParcel(source);
        mLayoutType = LayoutType.of(source.readInt());
        mVendorId = source.readInt();
        mProductId = source.readInt();
    }
@@ -105,6 +157,15 @@ public final class KeyboardLayout implements Parcelable,
        return mLocales;
    }

    /**
     * Gets the layout type that this keyboard layout is intended for.
     * This may be "undefined" if a layoutType has not been assigned to this keyboard layout.
     * @return The keyboard layout's intended layout type.
     */
    public String getLayoutType() {
        return mLayoutType.getName();
    }

    /**
     * Gets the vendor ID of the hardware device this keyboard layout is intended for.
     * Returns -1 if this is not specific to any piece of hardware.
@@ -135,6 +196,7 @@ public final class KeyboardLayout implements Parcelable,
        dest.writeString(mCollection);
        dest.writeInt(mPriority);
        mLocales.writeToParcel(dest, 0);
        dest.writeInt(mLayoutType.getValue());
        dest.writeInt(mVendorId);
        dest.writeInt(mProductId);
    }
@@ -160,6 +222,7 @@ public final class KeyboardLayout implements Parcelable,
                + ", descriptor: " + mDescriptor
                + ", priority: " + mPriority
                + ", locales: " + mLocales.toString()
                + ", layout type: " + mLayoutType.getName()
                + ", vendorId: " + mVendorId
                + ", productId: " + mProductId;
    }
+28 −2
Original line number Diff line number Diff line
@@ -9401,8 +9401,34 @@
        <attr name="label" />
        <!-- The key character map file resource. -->
        <attr name="keyboardLayout" format="reference" />
        <!-- The locales the given keyboard layout corresponds to. -->
        <attr name="locale" format="string" />
        <!-- The locales the given keyboard layout corresponds to. This is a list of
             BCP-47 conformant language tags separated by the delimiter ',' or '|'.
             Some examples of language tags are: en-US, zh-Hans-CN, el-Grek-polyton.
             It includes information for language code, country code, variant, and script
             code like ‘Latn’, ‘Cyrl’, etc. -->
        <attr name="keyboardLocale" format="string"/>
        <!-- The layout type of the given keyboardLayout.
             NOTE: The enum to int value mapping must remain stable -->
        <attr name="keyboardLayoutType" format="enum">
            <!-- Qwerty-based keyboard layout. -->
            <enum name="qwerty" value="1" />
            <!-- Qwertz-based keyboard layout. -->
            <enum name="qwertz" value="2" />
            <!-- Azerty-based keyboard layout. -->
            <enum name="azerty" value="3" />
            <!-- Dvorak keyboard layout. -->
            <enum name="dvorak" value="4" />
            <!-- Colemak keyboard layout. -->
            <enum name="colemak" value="5" />
            <!-- Workman keyboard layout. -->
            <enum name="workman" value="6" />
            <!-- Turkish-Q keyboard layout. -->
            <enum name="turkish_q" value="7" />
            <!-- Turkish-F keyboard layout. -->
            <enum name="turkish_f" value="8" />
            <!-- Keyboard layout that has been enhanced with a large number of extra characters. -->
            <enum name="extended" value="9" />
        </attr>
        <!-- The vendor ID of the hardware the given layout corresponds to. @hide -->
        <attr name="vendorId" format="integer" />
        <!-- The product ID of the hardware the given layout corresponds to. @hide -->
Loading