5package dev.flutter.scenarios;
7import static io.flutter.Build.API_LEVELS;
9import android.annotation.TargetApi;
11import android.content.ContextWrapper;
16import android.view.SurfaceHolder;
19import androidx.annotation.NonNull;
20import androidx.annotation.Nullable;
22import io.flutter.plugin.common.MessageCodec;
23import io.flutter.plugin.common.StringCodec;
24import io.flutter.plugin.platform.PlatformView;
25import io.flutter.plugin.platform.PlatformViewFactory;
26import java.nio.ByteBuffer;
28@TargetApi(API_LEVELS.API_23)
30 private boolean preserveContext;
37 public ByteBuffer encodeMessage(@Nullable Object o) {
38 if (o instanceof String) {
46 public Object decodeMessage(@Nullable ByteBuffer byteBuffer) {
50 this.preserveContext = preserveContext;
53 @SuppressWarnings(
"unchecked")
57 if (preserveContext) {
58 return new SurfacePlatformView(context);
60 final Context differentContext =
new ContextWrapper(context);
61 return new SurfacePlatformView(differentContext);
65 private static class SurfacePlatformView
implements PlatformView {
66 static String
TAG =
"SurfacePlatformView";
68 final SurfaceView surfaceView;
70 @SuppressWarnings(
"unchecked")
71 SurfacePlatformView(@NonNull final Context context) {
72 surfaceView =
new SurfaceView(context);
76 new SurfaceHolder.Callback() {
78 public void surfaceCreated(SurfaceHolder holder) {
79 Log.i(TAG,
"surfaceCreated");
80 final Surface surface = holder.getSurface();
81 final Canvas canvas = surface.lockHardwareCanvas();
82 canvas.drawColor(Color.WHITE);
84 final Paint paint = new Paint();
85 paint.setColor(Color.RED);
86 canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, 20, paint);
87 surface.unlockCanvasAndPost(canvas);
91 public void surfaceChanged(
97 public void surfaceDestroyed(SurfaceHolder holder) {
98 Log.i(
TAG,
"surfaceDestroyed");
105 public View getView() {
110 public void dispose() {}
static void i(@NonNull String tag, @NonNull String message)
static final StringCodec INSTANCE
ByteBuffer encodeMessage(@Nullable String message)
String decodeMessage(@Nullable ByteBuffer message)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
void Log(const char *format,...) SK_PRINTF_LIKE(1