Test touch for Android windows added by platform views (#55068)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user