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

Commit 7d15fae5 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Add support for Keyboard layout preview

Screenshot for drawable: https://screenshot.googleplex.com/9hBauxZB9asdmNN
Flag: com.android.hardware.input.keyboardLayoutPreviewFlag
Test: atest KeyboardLayoutPreviewTests
Test: atest KeyboardLayoutPreviewScreenshotTests
Bug: 293579375

Change-Id: If66c2108c3a65986278d8d332533fb9d1ca6b266
parent 05605b25
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.view.InputDevice;
import android.view.InputEvent;
import android.view.InputMonitor;
import android.view.PointerIcon;
import android.view.KeyCharacterMap;
import android.view.VerifiedInputEvent;

/** @hide */
@@ -63,6 +64,8 @@ interface IInputManager {
    // active keyboard layout.
    int getKeyCodeForKeyLocation(int deviceId, in int locationKeyCode);

    KeyCharacterMap getKeyCharacterMap(String layoutDescriptor);

    // Temporarily changes the pointer speed.
    void tryPointerSpeed(int speed);

+28 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.hardware.input;

import static com.android.hardware.input.Flags.keyboardLayoutPreviewFlag;

import android.Manifest;
import android.annotation.FloatRange;
import android.annotation.IntDef;
@@ -31,6 +33,7 @@ import android.app.ActivityThread;
import android.compat.annotation.ChangeId;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.hardware.BatteryState;
import android.os.Build;
import android.os.Handler;
@@ -930,6 +933,31 @@ public final class InputManager {
        return mGlobal.getKeyCodeForKeyLocation(deviceId, locationKeyCode);
    }

    /**
     * Provides a Keyboard layout preview of a particular dimension.
     *
     * @param keyboardLayout Layout whose preview is requested. If null, will return preview of
     *                       the default Keyboard layout defined by {@code Generic.kl}.
     * @param width Expected width of the drawable
     * @param height Expected height of the drawable
     *
     * NOTE: Width and height will auto-adjust to the width and height of the ImageView that
     * shows the drawable but this allows the caller to provide an intrinsic width and height of
     * the drawable allowing the ImageView to properly wrap the drawable content.
     *
     * @hide
     */
    @Nullable
    public Drawable getKeyboardLayoutPreview(@Nullable KeyboardLayout keyboardLayout, int width,
            int height) {
        if (!keyboardLayoutPreviewFlag()) {
            return null;
        }
        PhysicalKeyLayout keyLayout = new PhysicalKeyLayout(
                mGlobal.getKeyCharacterMap(keyboardLayout), keyboardLayout);
        return new KeyboardLayoutPreviewDrawable(mContext, keyLayout, width, height);
    }

    /**
     * Injects an input event into the event system, targeting windows owned by the provided uid.
     *
+16 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.view.Display;
import android.view.InputDevice;
import android.view.InputEvent;
import android.view.InputMonitor;
import android.view.KeyCharacterMap;
import android.view.PointerIcon;

import com.android.internal.annotations.GuardedBy;
@@ -1205,6 +1206,21 @@ public final class InputManagerGlobal {
        }
    }

    /**
     * Returns KeyCharacterMap for the provided Keyboard layout. If provided layout is null it will
     * return KeyCharacter map for the default layout {@code Generic.kl}.
     */
    public KeyCharacterMap getKeyCharacterMap(@Nullable KeyboardLayout keyboardLayout) {
        if (keyboardLayout == null) {
            return KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        }
        try {
            return mIm.getKeyCharacterMap(keyboardLayout.getDescriptor());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * @see InputManager#injectInputEvent(InputEvent, int, int)
     */
+28 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Parcel;
import android.os.Parcelable;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

@@ -230,6 +231,33 @@ public final class KeyboardLayout implements Parcelable, Comparable<KeyboardLayo
        return mProductId;
    }

    /**
     * Returns if the Keyboard layout follows the ANSI Physical key layout.
     */
    public boolean isAnsiLayout() {
        for (int i = 0; i < mLocales.size(); i++) {
            Locale locale = mLocales.get(i);
            if (locale != null && locale.getCountry().equalsIgnoreCase("us")
                    && mLayoutType != LayoutType.EXTENDED) {
                return true;
            }
        }
        return false;
    }

    /**
     * Returns if the Keyboard layout follows the JIS Physical key layout.
     */
    public boolean isJisLayout() {
        for (int i = 0; i < mLocales.size(); i++) {
            Locale locale = mLocales.get(i);
            if (locale != null && locale.getCountry().equalsIgnoreCase("jp")) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int describeContents() {
        return 0;
+504 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading