Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate pointer size from Android MotionEvent #6662

Merged
merged 2 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void _invoke3<A1, A2, A3>(void callback(A1 a1, A2 a2, A3 a3), Zone zone, A1 arg1
//
// * pointer_data.cc
// * FlutterView.java
const int _kPointerDataFieldCount = 19;
const int _kPointerDataFieldCount = 20;

PointerDataPacket _unpackPointerDataPacket(ByteData packet) {
const int kStride = Int64List.bytesPerElement;
Expand All @@ -220,6 +220,7 @@ PointerDataPacket _unpackPointerDataPacket(ByteData packet) {
pressureMax: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
distance: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
distanceMax: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
size: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
radiusMajor: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
radiusMinor: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
radiusMin: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
Expand Down
10 changes: 10 additions & 0 deletions lib/ui/pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class PointerData {
this.pressureMax: 0.0,
this.distance: 0.0,
this.distanceMax: 0.0,
this.size: 0.0,
this.radiusMajor: 0.0,
this.radiusMinor: 0.0,
this.radiusMin: 0.0,
Expand Down Expand Up @@ -137,6 +138,14 @@ class PointerData {
/// 0.0.
final double distanceMax;

/// The area of the screen being pressed, scaled to a value between 0 and 1.
/// The value of size can be used to determine fat touch events. This value
/// is only set on Android, and is a device specific approximation within
/// the range of detectable values. So, for example, the value of 0.1 could
/// mean a touch with the tip of the finger, 0.2 a touch with full finger,
/// and 0.3 the full palm.
final double size;

/// The radius of the contact ellipse along the major axis, in logical pixels.
final double radiusMajor;

Expand Down Expand Up @@ -208,6 +217,7 @@ class PointerData {
'pressureMax: $pressureMax, '
'distance: $distance, '
'distanceMax: $distanceMax, '
'size: $size, '
'radiusMajor: $radiusMajor, '
'radiusMinor: $radiusMinor, '
'radiusMin: $radiusMin, '
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/window/pointer_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace blink {

// If this value changes, update the pointer data unpacking code in hooks.dart.
static constexpr int kPointerDataFieldCount = 19;
static constexpr int kPointerDataFieldCount = 20;

static_assert(sizeof(PointerData) == sizeof(int64_t) * kPointerDataFieldCount,
"PointerData has the wrong size");
Expand Down
1 change: 1 addition & 0 deletions lib/ui/window/pointer_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct alignas(8) PointerData {
double pressure_max;
double distance;
double distance_max;
double size;
double radius_major;
double radius_minor;
double radius_min;
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/android/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer
packet.putDouble(0.0); // distance_max
}

packet.putDouble(event.getSize(pointerIndex)); // size

packet.putDouble(event.getToolMajor(pointerIndex)); // radius_major
packet.putDouble(event.getToolMinor(pointerIndex)); // radius_minor

Expand Down Expand Up @@ -519,7 +521,7 @@ public boolean onTouchEvent(MotionEvent event) {
}

// These values must match the unpacking code in hooks.dart.
final int kPointerDataFieldCount = 19;
final int kPointerDataFieldCount = 20;
final int kBytePerField = 8;

int pointerCount = event.getPointerCount();
Expand Down