Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | Package Functions | Package Attributes | List of all members
io.flutter.embedding.android.KeyData Class Reference

Classes

enum  DeviceType
 
enum  Type
 

Public Member Functions

 KeyData ()
 
 KeyData (@NonNull ByteBuffer buffer)
 

Static Public Attributes

static final String CHANNEL = "flutter/keydata"
 

Package Functions

ByteBuffer toBytes ()
 

Package Attributes

long timestamp
 
Type type
 
long physicalKey
 
long logicalKey
 
boolean synthesized
 
DeviceType deviceType
 
String character
 

Detailed Description

The resulting Flutter key events generated by KeyEmbedderResponder, and are sent through the messenger after being marshalled with toBytes().

This class is the Java adaption of KeyData and KeyDataPacket in the C engine. Changes made to either side must also be made to the other.

Each KeyData corresponds to a ui.KeyData in the framework.

Definition at line 22 of file KeyData.java.

Constructor & Destructor Documentation

◆ KeyData() [1/2]

io.flutter.embedding.android.KeyData.KeyData ( )
inline

Creates an empty KeyData.

Definition at line 107 of file KeyData.java.

107{}

◆ KeyData() [2/2]

io.flutter.embedding.android.KeyData.KeyData ( @NonNull ByteBuffer  buffer)
inline

Unmarshal fields from a buffer.

For the binary format, see lib/ui/window/key_data_packet.h.

Definition at line 114 of file KeyData.java.

114 {
115 final long charSize = buffer.getLong();
116 this.timestamp = buffer.getLong();
117 this.type = Type.fromLong(buffer.getLong());
118 this.physicalKey = buffer.getLong();
119 this.logicalKey = buffer.getLong();
120 this.synthesized = buffer.getLong() != 0;
121 this.deviceType = DeviceType.fromLong(buffer.getLong());
122
123 if (buffer.remaining() != charSize) {
124 throw new AssertionError(
125 String.format(
126 "Unexpected char length: charSize is %d while buffer has position %d, capacity %d, limit %d",
127 charSize, buffer.position(), buffer.capacity(), buffer.limit()));
128 }
129 this.character = null;
130 if (charSize != 0) {
131 final byte[] strBytes = new byte[(int) charSize];
132 buffer.get(strBytes, 0, (int) charSize);
133 try {
134 this.character = new String(strBytes, "UTF-8");
135 } catch (UnsupportedEncodingException e) {
136 throw new AssertionError("UTF-8 unsupported");
137 }
138 }
139 }
Type::kYUV Type::kRGBA() int(0.7 *637)
static const uint8_t buffer[]

Member Function Documentation

◆ toBytes()

ByteBuffer io.flutter.embedding.android.KeyData.toBytes ( )
inlinepackage

Marshal the key data to a new byte buffer.

For the binary format, see lib/ui/window/key_data_packet.h.

Returns
the marshalled bytes.

Definition at line 158 of file KeyData.java.

158 {
159 byte[] charBytes;
160 try {
161 charBytes = character == null ? null : character.getBytes("UTF-8");
162 } catch (UnsupportedEncodingException e) {
163 throw new AssertionError("UTF-8 not supported");
164 }
165 final int charSize = charBytes == null ? 0 : charBytes.length;
166 final ByteBuffer packet =
167 ByteBuffer.allocateDirect((1 + FIELD_COUNT) * BYTES_PER_FIELD + charSize);
168 packet.order(ByteOrder.LITTLE_ENDIAN);
169
170 packet.putLong(charSize);
171 packet.putLong(timestamp);
172 packet.putLong(type.getValue());
173 packet.putLong(physicalKey);
174 packet.putLong(logicalKey);
175 packet.putLong(synthesized ? 1L : 0L);
176 packet.putLong(deviceType.getValue());
177 if (charBytes != null) {
178 packet.put(charBytes);
179 }
180
181 return packet;
182 }

Member Data Documentation

◆ CHANNEL

final String io.flutter.embedding.android.KeyData.CHANNEL = "flutter/keydata"
static

The channel that key data should be sent through.

Must be kept in sync with kFlutterKeyDataChannel in embedder.cc

Definition at line 30 of file KeyData.java.

◆ character

String io.flutter.embedding.android.KeyData.character
package

The character of this key data encoded in UTF-8.

Definition at line 149 of file KeyData.java.

◆ deviceType

DeviceType io.flutter.embedding.android.KeyData.deviceType
package

Definition at line 146 of file KeyData.java.

◆ logicalKey

long io.flutter.embedding.android.KeyData.logicalKey
package

Definition at line 144 of file KeyData.java.

◆ physicalKey

long io.flutter.embedding.android.KeyData.physicalKey
package

Definition at line 143 of file KeyData.java.

◆ synthesized

boolean io.flutter.embedding.android.KeyData.synthesized
package

Definition at line 145 of file KeyData.java.

◆ timestamp

long io.flutter.embedding.android.KeyData.timestamp
package

Definition at line 141 of file KeyData.java.

◆ type

Type io.flutter.embedding.android.KeyData.type
package

Definition at line 142 of file KeyData.java.


The documentation for this class was generated from the following file: