Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a0379f45
Unverified
Commit
a0379f45
authored
Apr 18, 2020
by
Amir Hardon
Committed by
GitHub
Apr 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test touch for Android windows added by platform views (#55068)
parent
3e2293ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
215 additions
and
18 deletions
+215
-18
SimplePlatformView.java
.../flutter/integration/androidviews/SimplePlatformView.java
+24
-1
wm_integrations.dart
dev/integration_tests/android_views/lib/wm_integrations.dart
+158
-5
main_test.dart
...ntegration_tests/android_views/test_driver/main_test.dart
+33
-12
No files found.
dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimplePlatformView.java
View file @
a0379f45
...
...
@@ -6,8 +6,13 @@ package io.flutter.integration.platformviews;
import
android.app.AlertDialog
;
import
android.content.Context
;
import
android.graphics.PixelFormat
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.WindowManager
;
import
android.widget.Button
;
import
android.widget.TextView
;
import
io.flutter.plugin.common.MethodCall
;
...
...
@@ -24,7 +29,7 @@ public class SimplePlatformView implements PlatformView, MethodChannel.MethodCal
view
=
new
View
(
context
)
{
@Override
public
boolean
onTouchEvent
(
MotionEvent
event
)
{
return
super
.
onTouchEvent
(
event
)
;
return
true
;
}
};
view
.
setBackgroundColor
(
0xff0000ff
);
...
...
@@ -55,6 +60,10 @@ public class SimplePlatformView implements PlatformView, MethodChannel.MethodCal
case
"showAndHideAlertDialog"
:
showAndHideAlertDialog
(
result
);
return
;
case
"addWindowAndWaitForClick"
:
addWindow
(
result
);
return
;
}
result
.
notImplemented
();
}
...
...
@@ -75,4 +84,18 @@ public class SimplePlatformView implements PlatformView, MethodChannel.MethodCal
},
1000
);
}
private
void
addWindow
(
final
MethodChannel
.
Result
result
)
{
Context
context
=
view
.
getContext
();
final
Button
button
=
new
Button
(
context
);
button
.
setText
(
"This view is added as a window"
);
final
WindowManager
windowManager
=
(
WindowManager
)
context
.
getSystemService
(
Context
.
WINDOW_SERVICE
);
WindowManager
.
LayoutParams
layoutParams
=
new
WindowManager
.
LayoutParams
(
WindowManager
.
LayoutParams
.
TYPE_APPLICATION_OVERLAY
,
0
,
PixelFormat
.
OPAQUE
);
layoutParams
.
gravity
=
Gravity
.
FILL
;
windowManager
.
addView
(
button
,
layoutParams
);
button
.
setOnClickListener
(
v
->
{
windowManager
.
removeView
(
button
);
result
.
success
(
null
);
});
}
}
dev/integration_tests/android_views/lib/wm_integrations.dart
View file @
a0379f45
...
...
@@ -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
,
),
];
}
dev/integration_tests/android_views/test_driver/main_test.dart
View file @
a0379f45
...
...
@@ -30,17 +30,38 @@ Future<void> main() async {
await
driver
.
tap
(
backButton
);
});
test
(
'AlertDialog from platform view context'
,
()
async
{
final
SerializableFinder
wmListTile
=
find
.
byValueKey
(
'WmIntegrationsListTile'
);
await
driver
.
tap
(
wmListTile
);
final
SerializableFinder
showAlertDialog
=
find
.
byValueKey
(
'ShowAlertDialog'
);
await
driver
.
waitFor
(
showAlertDialog
);
await
driver
.
tap
(
showAlertDialog
);
final
String
status
=
await
driver
.
getText
(
find
.
byValueKey
(
'Status'
));
expect
(
status
,
'Success'
);
await
driver
.
waitFor
(
find
.
pageBack
());
await
driver
.
tap
(
find
.
pageBack
());
group
(
'WindowManager'
,
()
{
setUpAll
(()
async
{
final
SerializableFinder
wmListTile
=
find
.
byValueKey
(
'WmIntegrationsListTile'
);
await
driver
.
tap
(
wmListTile
);
});
tearDownAll
(()
async
{
await
driver
.
waitFor
(
find
.
pageBack
());
await
driver
.
tap
(
find
.
pageBack
());
});
test
(
'AlertDialog from platform view context'
,
()
async
{
final
SerializableFinder
showAlertDialog
=
find
.
byValueKey
(
'ShowAlertDialog'
);
await
driver
.
waitFor
(
showAlertDialog
);
await
driver
.
tap
(
showAlertDialog
);
final
String
status
=
await
driver
.
getText
(
find
.
byValueKey
(
'Status'
));
expect
(
status
,
'Success'
);
});
test
(
'Child windows can handle touches'
,
()
async
{
final
SerializableFinder
addWindow
=
find
.
byValueKey
(
'AddWindow'
);
await
driver
.
waitFor
(
addWindow
);
await
driver
.
tap
(
addWindow
);
final
SerializableFinder
tapWindow
=
find
.
byValueKey
(
'TapWindow'
);
await
driver
.
tap
(
tapWindow
);
final
String
windowClickCount
=
await
driver
.
getText
(
find
.
byValueKey
(
'WindowClickCount'
));
expect
(
windowClickCount
,
'Click count: 1'
);
},
// TODO(amirh): enable this after fixing https://github.com/flutter/flutter/issues/55066
skip:
true
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment