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"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</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>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -9,10 +9,14 @@ import android.content.pm.PackageManager;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import java.util.HashMap;
|
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.MethodCall;
|
||||||
import io.flutter.plugin.common.MethodChannel;
|
import io.flutter.plugin.common.MethodChannel;
|
||||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
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;
|
// This is null when not waiting for the Android permission request;
|
||||||
private MethodChannel.Result permissionResult;
|
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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(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());
|
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
|
@Override
|
||||||
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
|
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
|
||||||
switch(methodCall.method) {
|
switch(methodCall.method) {
|
||||||
|
@ -20,19 +20,21 @@ import io.flutter.plugin.common.MethodChannel;
|
|||||||
import io.flutter.plugin.platform.PlatformView;
|
import io.flutter.plugin.platform.PlatformView;
|
||||||
|
|
||||||
public class SimplePlatformView implements PlatformView, MethodChannel.MethodCallHandler {
|
public class SimplePlatformView implements PlatformView, MethodChannel.MethodCallHandler {
|
||||||
private final View view;
|
private final TextView view;
|
||||||
private final MethodChannel methodChannel;
|
private final MethodChannel methodChannel;
|
||||||
private final io.flutter.integration.platformviews.TouchPipe touchPipe;
|
private final io.flutter.integration.platformviews.TouchPipe touchPipe;
|
||||||
|
|
||||||
SimplePlatformView(Context context, MethodChannel methodChannel) {
|
SimplePlatformView(Context context, MethodChannel methodChannel) {
|
||||||
this.methodChannel = methodChannel;
|
this.methodChannel = methodChannel;
|
||||||
view = new View(context) {
|
view = new TextView(context) {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
view.setTextSize(72);
|
||||||
view.setBackgroundColor(0xff0000ff);
|
view.setBackgroundColor(0xff0000ff);
|
||||||
|
view.setText("Hello from Android view");
|
||||||
this.methodChannel.setMethodCallHandler(this);
|
this.methodChannel.setMethodCallHandler(this);
|
||||||
touchPipe = new io.flutter.integration.platformviews.TouchPipe(this.methodChannel, view);
|
touchPipe = new io.flutter.integration.platformviews.TouchPipe(this.methodChannel, view);
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,22 @@ package io.flutter.integration.platformviews;
|
|||||||
|
|
||||||
import android.content.Context;
|
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.common.MethodChannel;
|
||||||
import io.flutter.plugin.platform.PlatformView;
|
import io.flutter.plugin.platform.PlatformView;
|
||||||
import io.flutter.plugin.platform.PlatformViewFactory;
|
import io.flutter.plugin.platform.PlatformViewFactory;
|
||||||
|
|
||||||
public class SimpleViewFactory extends PlatformViewFactory {
|
public class SimpleViewFactory extends PlatformViewFactory {
|
||||||
final BinaryMessenger messenger;
|
final DartExecutor executor;
|
||||||
|
|
||||||
public SimpleViewFactory(BinaryMessenger messenger) {
|
public SimpleViewFactory(DartExecutor executor) {
|
||||||
super(null);
|
super(null);
|
||||||
this.messenger = messenger;
|
this.executor = executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformView create(Context context, int id, Object params) {
|
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);
|
return new SimplePlatformView(context, methodChannel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
|
|
||||||
// Android MotionEvent actions for which a pointer index is encoded in the
|
// Android MotionEvent actions for which a pointer index is encoded in the
|
||||||
// unmasked action code.
|
// unmasked action code.
|
||||||
@ -14,7 +13,7 @@ const List<int> kPointerActions = <int>[
|
|||||||
6, // POINTER_UP
|
6, // POINTER_UP
|
||||||
];
|
];
|
||||||
|
|
||||||
const double kDoubleErrorMargin = precisionErrorTolerance;
|
const double kDoubleErrorMargin = 1e-4;
|
||||||
|
|
||||||
String diffMotionEvents(
|
String diffMotionEvents(
|
||||||
Map<String, dynamic> originalEvent,
|
Map<String, dynamic> originalEvent,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user