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

Classes

interface  PointerChange
 
interface  PointerDeviceKind
 
interface  PointerSignalKind
 

Public Member Functions

 AndroidTouchProcessor (@NonNull FlutterRenderer renderer, boolean trackMotionEvents)
 
boolean onTouchEvent (@NonNull MotionEvent event)
 
boolean onTouchEvent (@NonNull MotionEvent event, @NonNull Matrix transformMatrix)
 
boolean onGenericMotionEvent (@NonNull MotionEvent event, @NonNull Context context)
 

Static Package Attributes

static final int BYTES_PER_FIELD = 8
 
static final int DEFAULT_VERTICAL_SCROLL_FACTOR = 48
 
static final int DEFAULT_HORIZONTAL_SCROLL_FACTOR = 48
 

Detailed Description

Sends touch information from Android to Flutter in a format that Flutter understands.

Definition at line 23 of file AndroidTouchProcessor.java.

Constructor & Destructor Documentation

◆ AndroidTouchProcessor()

io.flutter.embedding.android.AndroidTouchProcessor.AndroidTouchProcessor ( @NonNull FlutterRenderer  renderer,
boolean  trackMotionEvents 
)
inline

Constructs an AndroidTouchProcessor that will send touch event data to the Flutter execution context represented by the given FlutterRenderer.

Parameters
rendererThe object that manages textures for rendering.
trackMotionEventsThis is used to query motion events when platform views are rendered.

Definition at line 122 of file AndroidTouchProcessor.java.

122 {
123 this.renderer = renderer;
124 this.motionEventTracker = MotionEventTracker.getInstance();
125 this.trackMotionEvents = trackMotionEvents;
126 }

Member Function Documentation

◆ onGenericMotionEvent()

boolean io.flutter.embedding.android.AndroidTouchProcessor.onGenericMotionEvent ( @NonNull MotionEvent  event,
@NonNull Context  context 
)
inline

Sends the given generic MotionEvent data to Flutter in a format that Flutter understands.

Generic motion events include joystick movement, mouse hover, track pad touches, scroll wheel movements, etc.

Parameters
eventThe generic motion event being processed.
contextFor use by ViewConfiguration.get(context) to scale input.
Returns
True if the event was handled.

Definition at line 206 of file AndroidTouchProcessor.java.

206 {
207 // Method isFromSource is only available in API 18+ (Jelly Bean MR2)
208 // Mouse hover support is not implemented for API < 18.
209 boolean isPointerEvent = event.isFromSource(InputDevice.SOURCE_CLASS_POINTER);
210 boolean isMovementEvent =
211 (event.getActionMasked() == MotionEvent.ACTION_HOVER_MOVE
212 || event.getActionMasked() == MotionEvent.ACTION_SCROLL);
213 if (isPointerEvent && isMovementEvent) {
214 // Continue.
215 } else {
216 return false;
217 }
218
219 int pointerChange = getPointerChangeForAction(event.getActionMasked());
220 ByteBuffer packet =
221 ByteBuffer.allocateDirect(
222 event.getPointerCount() * POINTER_DATA_FIELD_COUNT * BYTES_PER_FIELD);
223 packet.order(ByteOrder.LITTLE_ENDIAN);
224
225 // ACTION_HOVER_MOVE always applies to a single pointer only.
226 addPointerForIndex(
227 event, event.getActionIndex(), pointerChange, 0, IDENTITY_TRANSFORM, packet, context);
228 if (packet.position() % (POINTER_DATA_FIELD_COUNT * BYTES_PER_FIELD) != 0) {
229 throw new AssertionError("Packet position is not on field boundary.");
230 }
231 renderer.dispatchPointerDataPacket(packet, packet.position());
232 return true;
233 }
FlKeyEvent * event

◆ onTouchEvent() [1/2]

boolean io.flutter.embedding.android.AndroidTouchProcessor.onTouchEvent ( @NonNull MotionEvent  event)
inline

Definition at line 128 of file AndroidTouchProcessor.java.

128 {
129 return onTouchEvent(event, IDENTITY_TRANSFORM);
130 }

◆ onTouchEvent() [2/2]

boolean io.flutter.embedding.android.AndroidTouchProcessor.onTouchEvent ( @NonNull MotionEvent  event,
@NonNull Matrix  transformMatrix 
)
inline

Sends the given MotionEvent data to Flutter in a format that Flutter understands.

Parameters
eventThe motion event from the view.
transformMatrixApplies to the view that originated the event. It's used to transform the gesture pointers into screen coordinates.
Returns
True if the event was handled.

Definition at line 140 of file AndroidTouchProcessor.java.

140 {
141 int pointerCount = event.getPointerCount();
142
143 // The following packing code must match the struct in pointer_data.h.
144
145 // Prepare a data packet of the appropriate size and order.
146 ByteBuffer packet =
147 ByteBuffer.allocateDirect(pointerCount * POINTER_DATA_FIELD_COUNT * BYTES_PER_FIELD);
148 packet.order(ByteOrder.LITTLE_ENDIAN);
149
150 int maskedAction = event.getActionMasked();
151 int pointerChange = getPointerChangeForAction(event.getActionMasked());
152 boolean updateForSinglePointer =
153 maskedAction == MotionEvent.ACTION_DOWN || maskedAction == MotionEvent.ACTION_POINTER_DOWN;
154 boolean updateForMultiplePointers =
155 !updateForSinglePointer
156 && (maskedAction == MotionEvent.ACTION_UP
157 || maskedAction == MotionEvent.ACTION_POINTER_UP);
158 if (updateForSinglePointer) {
159 // ACTION_DOWN and ACTION_POINTER_DOWN always apply to a single pointer only.
160 addPointerForIndex(event, event.getActionIndex(), pointerChange, 0, transformMatrix, packet);
161 } else if (updateForMultiplePointers) {
162 // ACTION_UP and ACTION_POINTER_UP may contain position updates for other pointers.
163 // We are converting these updates to move events here in order to preserve this data.
164 // We also mark these events with a flag in order to help the framework reassemble
165 // the original Android event later, should it need to forward it to a PlatformView.
166 for (int p = 0; p < pointerCount; p++) {
167 if (p != event.getActionIndex() && event.getToolType(p) == MotionEvent.TOOL_TYPE_FINGER) {
168 addPointerForIndex(
169 event, p, PointerChange.MOVE, POINTER_DATA_FLAG_BATCHED, transformMatrix, packet);
170 }
171 }
172 // It's important that we're sending the UP event last. This allows PlatformView
173 // to correctly batch everything back into the original Android event if needed.
174 addPointerForIndex(event, event.getActionIndex(), pointerChange, 0, transformMatrix, packet);
175 } else {
176 // ACTION_MOVE may not actually mean all pointers have moved
177 // but it's the responsibility of a later part of the system to
178 // ignore 0-deltas if desired.
179 for (int p = 0; p < pointerCount; p++) {
180 addPointerForIndex(event, p, pointerChange, 0, transformMatrix, packet);
181 }
182 }
183
184 // Verify that the packet is the expected size.
185 if (packet.position() % (POINTER_DATA_FIELD_COUNT * BYTES_PER_FIELD) != 0) {
186 throw new AssertionError("Packet position is not on field boundary");
187 }
188
189 // Send the packet to Flutter.
190 renderer.dispatchPointerDataPacket(packet, packet.position());
191
192 return true;
193 }

Member Data Documentation

◆ BYTES_PER_FIELD

final int io.flutter.embedding.android.AndroidTouchProcessor.BYTES_PER_FIELD = 8
staticpackage

Definition at line 88 of file AndroidTouchProcessor.java.

◆ DEFAULT_HORIZONTAL_SCROLL_FACTOR

final int io.flutter.embedding.android.AndroidTouchProcessor.DEFAULT_HORIZONTAL_SCROLL_FACTOR = 48
staticpackage

Definition at line 92 of file AndroidTouchProcessor.java.

◆ DEFAULT_VERTICAL_SCROLL_FACTOR

final int io.flutter.embedding.android.AndroidTouchProcessor.DEFAULT_VERTICAL_SCROLL_FACTOR = 48
staticpackage

Definition at line 91 of file AndroidTouchProcessor.java.


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