Migrate Android views e2e to the new embedding (#61205)
This commit is contained in:
parent
eadc35f62b
commit
158256b5a7
@ -25,5 +25,10 @@ found in the LICENSE file. -->
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
@ -9,10 +9,14 @@ import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import io.flutter.app.FlutterActivity;
|
||||
import io.flutter.embedding.android.FlutterActivity;
|
||||
import io.flutter.embedding.engine.dart.DartExecutor;
|
||||
import io.flutter.embedding.engine.FlutterEngine;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||
@ -27,18 +31,29 @@ public class MainActivity extends FlutterActivity implements MethodChannel.Metho
|
||||
// This is null when not waiting for the Android permission request;
|
||||
private MethodChannel.Result permissionResult;
|
||||
|
||||
private View getFlutterView() {
|
||||
// TODO(egarciad): Set an unique ID in FlutterView, so it's easier to look it up.
|
||||
ViewGroup root = (ViewGroup)findViewById(android.R.id.content);
|
||||
return ((ViewGroup)root.getChildAt(0)).getChildAt(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
GeneratedPluginRegistrant.registerWith(this);
|
||||
getFlutterView().getPluginRegistry()
|
||||
.registrarFor("io.flutter.integration.platform_views").platformViewRegistry()
|
||||
.registerViewFactory("simple_view", new SimpleViewFactory(getFlutterView()));
|
||||
mMethodChannel = new MethodChannel(this.getFlutterView(), "android_views_integration");
|
||||
mMethodChannel.setMethodCallHandler(this);
|
||||
mFlutterViewTouchPipe = new TouchPipe(mMethodChannel, getFlutterView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureFlutterEngine(FlutterEngine flutterEngine) {
|
||||
DartExecutor executor = flutterEngine.getDartExecutor();
|
||||
flutterEngine
|
||||
.getPlatformViewsController()
|
||||
.getRegistry()
|
||||
.registerViewFactory("simple_view", new SimpleViewFactory(executor));
|
||||
mMethodChannel = new MethodChannel(executor, "android_views_integration");
|
||||
mMethodChannel.setMethodCallHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
|
||||
switch(methodCall.method) {
|
||||
|
@ -20,19 +20,21 @@ import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.platform.PlatformView;
|
||||
|
||||
public class SimplePlatformView implements PlatformView, MethodChannel.MethodCallHandler {
|
||||
private final View view;
|
||||
private final TextView view;
|
||||
private final MethodChannel methodChannel;
|
||||
private final io.flutter.integration.platformviews.TouchPipe touchPipe;
|
||||
|
||||
SimplePlatformView(Context context, MethodChannel methodChannel) {
|
||||
this.methodChannel = methodChannel;
|
||||
view = new View(context) {
|
||||
view = new TextView(context) {
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
view.setTextSize(72);
|
||||
view.setBackgroundColor(0xff0000ff);
|
||||
view.setText("Hello from Android view");
|
||||
this.methodChannel.setMethodCallHandler(this);
|
||||
touchPipe = new io.flutter.integration.platformviews.TouchPipe(this.methodChannel, view);
|
||||
}
|
||||
|
@ -6,22 +6,22 @@ package io.flutter.integration.platformviews;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.embedding.engine.dart.DartExecutor;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.platform.PlatformView;
|
||||
import io.flutter.plugin.platform.PlatformViewFactory;
|
||||
|
||||
public class SimpleViewFactory extends PlatformViewFactory {
|
||||
final BinaryMessenger messenger;
|
||||
final DartExecutor executor;
|
||||
|
||||
public SimpleViewFactory(BinaryMessenger messenger) {
|
||||
public SimpleViewFactory(DartExecutor executor) {
|
||||
super(null);
|
||||
this.messenger = messenger;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformView create(Context context, int id, Object params) {
|
||||
MethodChannel methodChannel = new MethodChannel(messenger, "simple_view/" + id);
|
||||
MethodChannel methodChannel = new MethodChannel(executor, "simple_view/" + id);
|
||||
return new SimplePlatformView(context, methodChannel);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
// Android MotionEvent actions for which a pointer index is encoded in the
|
||||
// unmasked action code.
|
||||
@ -14,7 +13,7 @@ const List<int> kPointerActions = <int>[
|
||||
6, // POINTER_UP
|
||||
];
|
||||
|
||||
const double kDoubleErrorMargin = precisionErrorTolerance;
|
||||
const double kDoubleErrorMargin = 1e-4;
|
||||
|
||||
String diffMotionEvents(
|
||||
Map<String, dynamic> originalEvent,
|
||||
|
Loading…
x
Reference in New Issue
Block a user