31 new MessageCodec<Object>() {
34 public ByteBuffer encodeMessage(@Nullable Object o) {
35 if (o instanceof String) {
36 return StringCodec.INSTANCE.encodeMessage((String) o);
43 public Object decodeMessage(@Nullable ByteBuffer byteBuffer) {
44 return StringCodec.INSTANCE.decodeMessage(byteBuffer);
49 @SuppressWarnings(
"unchecked")
53 return new TexturePlatformView(context);
56 private static class TexturePlatformView
implements PlatformView {
57 static String
TAG =
"TexturePlatformView";
59 final TextureView textureView;
61 @SuppressWarnings(
"unchecked")
62 TexturePlatformView(@NonNull final
Context context) {
63 textureView =
new TextureView(context);
64 textureView.setSurfaceTextureListener(
65 new TextureView.SurfaceTextureListener() {
67 public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
68 Log.i(TAG,
"onSurfaceTextureAvailable");
69 final Canvas canvas = textureView.lockCanvas();
70 canvas.drawColor(Color.WHITE);
72 final Paint paint = new Paint();
73 paint.setColor(Color.GREEN);
74 canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, 20, paint);
75 textureView.unlockCanvasAndPost(canvas);
76 Choreographer.getInstance()
77 .postFrameCallbackDelayed(
78 new Choreographer.FrameCallback() {
80 public void doFrame(long frameTimeNanos) {
81 textureView.invalidate();
88 public boolean onSurfaceTextureDestroyed(SurfaceTexture
surface) {
89 Log.i(
TAG,
"onSurfaceTextureDestroyed");
94 public void onSurfaceTextureSizeChanged(SurfaceTexture
surface,
int width,
int height) {
95 Log.i(
TAG,
"onSurfaceTextureSizeChanged");
99 public void onSurfaceTextureUpdated(SurfaceTexture
surface) {
100 Log.i(
TAG,
"onSurfaceTextureUpdated");
107 public View getView() {
112 public void dispose() {}