Test touch for Android windows added by platform views (#55068)

This commit is contained in:
Amir Hardon
2020-04-17 17:21:28 -07:00
committed by GitHub
parent 3e2293ec38
commit a0379f45d6
3 changed files with 214 additions and 17 deletions

View File

@@ -35,6 +35,8 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
MethodChannel viewChannel;
_LastTestStatus lastTestStatus = _LastTestStatus.pending;
String lastError;
int id;
int windowClickCount = 0;
@override
Widget build(BuildContext context) {
@@ -52,11 +54,32 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
),
),
if (lastTestStatus != _LastTestStatus.pending) _statusWidget(),
if (viewChannel != null) RaisedButton(
key: const ValueKey<String>('ShowAlertDialog'),
child: const Text('SHOW ALERT DIALOG'),
onPressed: onShowAlertDialogPressed,
),
if (viewChannel != null) ... <Widget>[
RaisedButton(
key: const ValueKey<String>('ShowAlertDialog'),
child: const Text('SHOW ALERT DIALOG'),
onPressed: onShowAlertDialogPressed,
),
Row(
children: <Widget>[
RaisedButton(
key: const ValueKey<String>('AddWindow'),
child: const Text('ADD WINDOW'),
onPressed: onAddWindowPressed,
),
RaisedButton(
key: const ValueKey<String>('TapWindow'),
child: const Text('TAP WINDOW'),
onPressed: onTapWindowPressed,
),
if (windowClickCount > 0)
Text(
'Click count: $windowClickCount',
key: const ValueKey<String>('WindowClickCount'),
),
],
),
],
],
),
);
@@ -96,9 +119,139 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
}
}
Future<void> onAddWindowPressed() async {
try {
await viewChannel.invokeMethod<void>('addWindowAndWaitForClick');
setState(() {
windowClickCount++;
});
} catch(e) {
setState(() {
lastTestStatus = _LastTestStatus.error;
lastError = '$e';
});
}
}
Future<void> onTapWindowPressed() async {
await Future<void>.delayed(const Duration(seconds: 1));
for (final AndroidMotionEvent event in _tapSequence) {
await SystemChannels.platform_views.invokeMethod<dynamic>(
'touch',
_motionEventasList(event, id),
);
}
}
void onPlatformViewCreated(int id) {
this.id = id;
setState(() {
viewChannel = MethodChannel('simple_view/$id');
});
}
static List<double> _pointerCoordsAsList(AndroidPointerCoords coords) {
return <double>[
coords.orientation,
coords.pressure,
coords.size,
coords.toolMajor,
coords.toolMinor,
coords.touchMajor,
coords.touchMinor,
coords.x,
coords.y,
];
}
static List<dynamic> _motionEventasList(AndroidMotionEvent event, int viewId) {
return <dynamic>[
viewId,
event.downTime,
event.eventTime,
event.action,
event.pointerCount,
event.pointerProperties.map<List<int>>((AndroidPointerProperties p) => <int> [p.id, p.toolType]).toList(),
event.pointerCoords.map<List<double>>((AndroidPointerCoords p) => _pointerCoordsAsList(p)).toList(),
event.metaState,
event.buttonState,
event.xPrecision,
event.yPrecision,
event.deviceId,
event.edgeFlags,
event.source,
event.flags,
];
}
static final List<AndroidMotionEvent> _tapSequence = <AndroidMotionEvent> [
AndroidMotionEvent(
downTime: 723657071,
pointerCount: 1,
pointerCoords: <AndroidPointerCoords> [
const AndroidPointerCoords(
orientation: 0.0,
touchMajor: 5.0,
size: 0.019607843831181526,
x: 180.0,
y: 200.0,
touchMinor: 5.0,
pressure: 1.0,
toolMajor: 5.0,
toolMinor: 5.0,
),
],
yPrecision: 1.0,
buttonState: 0,
flags: 0,
source: 4098,
deviceId: 4,
metaState: 0,
pointerProperties: <AndroidPointerProperties> [
const AndroidPointerProperties(
id: 0,
toolType: 1,
),
],
edgeFlags: 0,
eventTime: 723657071,
action: 0,
xPrecision: 1.0,
),
AndroidMotionEvent(
downTime: 723657071,
eventTime: 723657137,
action: 1,
pointerCount: 1,
pointerProperties: <AndroidPointerProperties> [
const AndroidPointerProperties(
id: 0,
toolType: 1,
),
],
pointerCoords: <AndroidPointerCoords> [
const AndroidPointerCoords(
orientation: 0.0,
touchMajor: 5.0,
size: 0.019607843831181526,
x: 180.0,
y: 200.0,
touchMinor: 5.0,
pressure: 1.0,
toolMajor: 5.0,
toolMinor: 5.0,
)
],
metaState: 0,
buttonState: 0,
xPrecision: 1.0,
yPrecision: 1.0,
deviceId: 4,
edgeFlags: 0,
source: 4098,
flags: 0,
),
];
}