[Keyboard, Android] Generate keyboard codes (#104032)
This commit is contained in:
@@ -11,9 +11,64 @@ package io.flutter.embedding.android;
|
||||
// Edit the template dev/tools/gen_keycodes/data/android_keyboard_map_java.tmpl instead.
|
||||
// See dev/tools/gen_keycodes/README.md for more information.
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import java.util.HashMap;
|
||||
|
||||
/** Static information used by {@link KeyEmbedderResponder}. */
|
||||
public class KeyboardMap {
|
||||
/** A physicalKey-logicalKey pair used to define mappings. */
|
||||
public static class KeyPair {
|
||||
public KeyPair(long physicalKey, long logicalKey) {
|
||||
this.physicalKey = physicalKey;
|
||||
this.logicalKey = logicalKey;
|
||||
}
|
||||
|
||||
public long physicalKey;
|
||||
public long logicalKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* An immutable configuration item that defines how to synchronize pressing modifiers (such as
|
||||
* Shift or Ctrl), so that the {@link KeyEmbedderResponder} must synthesize events until the
|
||||
* combined pressing state of {@link keys} matches the true meta state masked by {@link mask}.
|
||||
*/
|
||||
public static class PressingGoal {
|
||||
public PressingGoal(int mask, KeyPair[] keys) {
|
||||
this.mask = mask;
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
public final int mask;
|
||||
public final KeyPair[] keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* A configuration item that defines how to synchronize toggling modifiers (such as CapsLock), so
|
||||
* that the {@link KeyEmbedderResponder} must synthesize events until the enabling state of the
|
||||
* key matches the true meta state masked by {@link #mask}.
|
||||
*
|
||||
* <p>The objects of this class are mutable. The {@link #enabled} field will be used to store the
|
||||
* current enabling state.
|
||||
*/
|
||||
public static class TogglingGoal {
|
||||
public TogglingGoal(int mask, long physicalKey, long logicalKey) {
|
||||
this.mask = mask;
|
||||
this.physicalKey = physicalKey;
|
||||
this.logicalKey = logicalKey;
|
||||
}
|
||||
|
||||
public final int mask;
|
||||
public final long physicalKey;
|
||||
public final long logicalKey;
|
||||
/**
|
||||
* Used by {@link KeyEmbedderResponder} to store the current enabling state of this modifier.
|
||||
*
|
||||
* <p>Initialized as false.
|
||||
*/
|
||||
public boolean enabled = false;
|
||||
}
|
||||
|
||||
/** Maps from Android scan codes {@link KeyEvent#getScanCode()} to Flutter physical keys. */
|
||||
public static final HashMap<Long, Long> scanCodeToPhysical =
|
||||
new HashMap<Long, Long>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -23,6 +78,7 @@ public class KeyboardMap {
|
||||
}
|
||||
};
|
||||
|
||||
/** Maps from Android key codes {@link KeyEvent#getKeyCode()} to Flutter logical keys. */
|
||||
public static final HashMap<Long, Long> keyCodeToLogical =
|
||||
new HashMap<Long, Long>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -31,4 +87,23 @@ public class KeyboardMap {
|
||||
@@@ANDROID_KEY_CODE_MAP@@@
|
||||
}
|
||||
};
|
||||
|
||||
public static final PressingGoal[] pressingGoals =
|
||||
new PressingGoal[] {
|
||||
@@@PRESSING_GOALS@@@
|
||||
};
|
||||
|
||||
/**
|
||||
* A list of toggling modifiers that must be synchronized on each key event.
|
||||
*
|
||||
* <p>The list is not a static variable but constructed by a function, because {@link
|
||||
* TogglingGoal} is mutable.
|
||||
*/
|
||||
public static TogglingGoal[] getTogglingGoals() {
|
||||
return new TogglingGoal[] {
|
||||
@@@TOGGLING_GOALS@@@
|
||||
};
|
||||
}
|
||||
|
||||
@@@MASK_CONSTANTS@@@
|
||||
}
|
||||
|
||||
22
dev/tools/gen_keycodes/data/key_codes_java.tmpl
Normal file
22
dev/tools/gen_keycodes/data/key_codes_java.tmpl
Normal file
@@ -0,0 +1,22 @@
|
||||
package io.flutter.util;
|
||||
|
||||
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
|
||||
// This file is generated by
|
||||
// flutter/flutter:dev/tools/gen_keycodes/bin/gen_keycodes.dart and should not
|
||||
// be edited directly.
|
||||
//
|
||||
// Edit the template
|
||||
// flutter/flutter:dev/tools/gen_keycodes/data/key_codes_java.tmpl
|
||||
// instead.
|
||||
//
|
||||
// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information.
|
||||
|
||||
/**
|
||||
* This class contains keyboard constants to be used in unit tests. They should not be used in
|
||||
* production code.
|
||||
*/
|
||||
public class KeyCodes {
|
||||
@@@PHYSICAL_KEY_DEFINITIONS@@@
|
||||
|
||||
@@@LOGICAL_KEY_DEFINITIONS@@@
|
||||
}
|
||||
@@ -48,7 +48,7 @@ abstract class KeyboardKey with Diagnosticable {
|
||||
///
|
||||
/// {@tool dartpad}
|
||||
/// This example shows how to detect if the user has selected the logical "Q"
|
||||
/// key.
|
||||
/// key and handle the key if they have.
|
||||
///
|
||||
/// ** See code in examples/api/lib/services/keyboard_key/logical_keyboard_key.0.dart **
|
||||
/// {@end-tool}
|
||||
@@ -56,8 +56,9 @@ abstract class KeyboardKey with Diagnosticable {
|
||||
///
|
||||
/// * [RawKeyEvent], the keyboard event object received by widgets that listen
|
||||
/// to keyboard events.
|
||||
/// * [RawKeyboardListener], a widget used to listen to and supply handlers for
|
||||
/// keyboard events.
|
||||
/// * [Focus.onKey], the handler on a widget that lets you handle key events.
|
||||
/// * [RawKeyboardListener], a widget used to listen to keyboard events (but
|
||||
/// not handle them).
|
||||
@immutable
|
||||
class LogicalKeyboardKey extends KeyboardKey {
|
||||
/// Creates a new LogicalKeyboardKey object for a key ID.
|
||||
@@ -312,8 +313,9 @@ class LogicalKeyboardKey extends KeyboardKey {
|
||||
///
|
||||
/// * [RawKeyEvent], the keyboard event object received by widgets that listen
|
||||
/// to keyboard events.
|
||||
/// * [RawKeyboardListener], a widget used to listen to and supply handlers for
|
||||
/// keyboard events.
|
||||
/// * [Focus.onKey], the handler on a widget that lets you handle key events.
|
||||
/// * [RawKeyboardListener], a widget used to listen to keyboard events (but
|
||||
/// not handle them).
|
||||
@immutable
|
||||
class PhysicalKeyboardKey extends KeyboardKey {
|
||||
/// Creates a new PhysicalKeyboardKey object for a USB HID usage.
|
||||
|
||||
Reference in New Issue
Block a user