diff --git a/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimplePlatformView.java b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimplePlatformView.java index 263ca75900..4e391e1564 100644 --- a/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimplePlatformView.java +++ b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimplePlatformView.java @@ -4,35 +4,37 @@ package io.flutter.integration.platformviews; +import android.app.AlertDialog; import android.content.Context; import android.view.MotionEvent; import android.view.View; +import android.widget.TextView; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.platform.PlatformView; public class SimplePlatformView implements PlatformView, MethodChannel.MethodCallHandler { - private final View mView; - private final MethodChannel mMethodChannel; - private final TouchPipe mTouchPipe; + private final View view; + private final MethodChannel methodChannel; + private final io.flutter.integration.platformviews.TouchPipe touchPipe; SimplePlatformView(Context context, MethodChannel methodChannel) { - mMethodChannel = methodChannel; - mView = new View(context) { + this.methodChannel = methodChannel; + view = new View(context) { @Override public boolean onTouchEvent(MotionEvent event) { return super.onTouchEvent(event); } }; - mView.setBackgroundColor(0xff0000ff); - mMethodChannel.setMethodCallHandler(this); - mTouchPipe = new TouchPipe(mMethodChannel, mView); + view.setBackgroundColor(0xff0000ff); + this.methodChannel.setMethodCallHandler(this); + touchPipe = new io.flutter.integration.platformviews.TouchPipe(this.methodChannel, view); } @Override public View getView() { - return mView; + return view; } @Override @@ -43,14 +45,28 @@ public class SimplePlatformView implements PlatformView, MethodChannel.MethodCal public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { switch(methodCall.method) { case "pipeTouchEvents": - mTouchPipe.enable(); + touchPipe.enable(); result.success(null); return; case "stopTouchEvents": - mTouchPipe.disable(); + touchPipe.disable(); result.success(null); return; + case "showAlertDialog": + showAlertDialog(result); + return; } result.notImplemented(); } + + private void showAlertDialog(MethodChannel.Result result) { + Context context = view.getContext(); + AlertDialog.Builder builder = new AlertDialog.Builder(context); + TextView textView = new TextView(context); + textView.setText("Alert!"); + builder.setView(textView); + final AlertDialog alertDialog = builder.show(); + result.success(null); + } + } diff --git a/dev/integration_tests/android_views/lib/main.dart b/dev/integration_tests/android_views/lib/main.dart index 5ff65056c1..7bfc49328f 100644 --- a/dev/integration_tests/android_views/lib/main.dart +++ b/dev/integration_tests/android_views/lib/main.dart @@ -4,11 +4,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_driver/driver_extension.dart'; + import 'motion_events_page.dart'; import 'page.dart'; +import 'wm_integrations.dart'; final List _allPages = [ const MotionEventsPage(), + const WindowManagerIntegrationsPage(), ]; void main() { @@ -20,17 +23,20 @@ class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - body: ListView.builder( - itemCount: _allPages.length, - itemBuilder: (_, int index) => ListTile( - title: Text(_allPages[index].title), - key: _allPages[index].tileKey, - onTap: () => _pushPage(context, _allPages[index]), - ), + body: ListView( + children: _allPages.map((PageWidget p) => _buildPageListTile(context, p)).toList(), ), ); } + Widget _buildPageListTile(BuildContext context, PageWidget page) { + return ListTile( + title: Text(page.title), + key: page.tileKey, + onTap: () { _pushPage(context, page); }, + ); + } + void _pushPage(BuildContext context, PageWidget page) { Navigator.of(context).push(MaterialPageRoute( builder: (_) => Scaffold( diff --git a/dev/integration_tests/android_views/lib/wm_integrations.dart b/dev/integration_tests/android_views/lib/wm_integrations.dart new file mode 100644 index 0000000000..3faea1392e --- /dev/null +++ b/dev/integration_tests/android_views/lib/wm_integrations.dart @@ -0,0 +1,104 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; + +import 'page.dart'; + +class WindowManagerIntegrationsPage extends PageWidget { + const WindowManagerIntegrationsPage() + : super('Window Manager Integrations Tests', const ValueKey('WmIntegrationsListTile')); + + @override + Widget build(BuildContext context) => WindowManagerBody(); + +} + +class WindowManagerBody extends StatefulWidget { + @override + State createState() => WindowManagerBodyState(); +} + +enum _LastTestStatus { + pending, + success, + error +} + +class WindowManagerBodyState extends State { + + MethodChannel viewChannel; + _LastTestStatus lastTestStatus = _LastTestStatus.pending; + String lastError; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Window Manager Integrations'), + ), + body: Column( + children: [ + SizedBox( + height: 300, + child: AndroidView( + viewType: 'simple_view', + onPlatformViewCreated: onPlatformViewCreated, + ), + ), + if (lastTestStatus != _LastTestStatus.pending) _statusWidget(), + if (viewChannel != null) RaisedButton( + key: const ValueKey('ShowAlertDialog'), + child: const Text('SHOW ALERT DIALOG'), + onPressed: onShowAlertDialogPressed, + ), + ], + ), + ); + } + + Widget _statusWidget() { + assert(lastTestStatus != _LastTestStatus.pending); + final String message = lastTestStatus == _LastTestStatus.success ? 'Success' : lastError; + return Container( + color: lastTestStatus == _LastTestStatus.success ? Colors.green : Colors.red, + child: Text( + message, + key: const ValueKey('Status'), + style: TextStyle( + color: lastTestStatus == _LastTestStatus.error ? Colors.yellow : null, + ), + ), + ); + } + + Future onShowAlertDialogPressed() async { + if (lastTestStatus != _LastTestStatus.pending) { + setState(() { + lastTestStatus = _LastTestStatus.pending; + }); + } + try { + await viewChannel.invokeMethod('showAlertDialog'); + setState(() { + lastTestStatus = _LastTestStatus.success; + }); + } catch(e) { + setState(() { + lastTestStatus = _LastTestStatus.error; + lastError = '$e'; + }); + } + } + + void onPlatformViewCreated(int id) { + setState(() { + viewChannel = MethodChannel('simple_view/$id'); + }); + } +} diff --git a/dev/integration_tests/android_views/test_driver/main_test.dart b/dev/integration_tests/android_views/test_driver/main_test.dart index e12b07fef3..d4aea33f2d 100644 --- a/dev/integration_tests/android_views/test_driver/main_test.dart +++ b/dev/integration_tests/android_views/test_driver/main_test.dart @@ -17,16 +17,29 @@ Future main() async { driver.close(); }); - group('MotionEvents tests ', () { - test('recomposition', () async { - final SerializableFinder motionEventsListTile = - find.byValueKey('MotionEventsListTile'); - await driver.tap(motionEventsListTile); - await driver.waitFor(find.byValueKey('PlatformView')); - final String errorMessage = await driver.requestData('run test'); - expect(errorMessage, ''); - }, - // TODO(amirh): enable this test https://github.com/flutter/flutter/issues/54022 - skip: true); - }); + test('MotionEvent recomposition', () async { + final SerializableFinder motionEventsListTile = + find.byValueKey('MotionEventsListTile'); + await driver.tap(motionEventsListTile); + await driver.waitFor(find.byValueKey('PlatformView')); + final String errorMessage = await driver.requestData('run test'); + expect(errorMessage, ''); + }, + // TODO(amirh): enable this test https://github.com/flutter/flutter/issues/54022 + skip: true); + + 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'); + }, + // TODO(amirh): enable this test when https://github.com/flutter/flutter/issues/34248 is fixed. + skip: true, + ); }