Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TextPlatformViewFactory.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package dev.flutter.scenarios;
6
7import android.content.Context;
8import android.graphics.Color;
9import android.view.View;
10import android.widget.TextView;
11import androidx.annotation.NonNull;
12import androidx.annotation.Nullable;
13import io.flutter.plugin.common.MessageCodec;
14import io.flutter.plugin.common.StringCodec;
15import io.flutter.plugin.platform.PlatformView;
16import io.flutter.plugin.platform.PlatformViewFactory;
17import java.nio.ByteBuffer;
18
19public final class TextPlatformViewFactory extends PlatformViewFactory {
21 super(
22 new MessageCodec<Object>() {
23 @Nullable
24 @Override
25 public ByteBuffer encodeMessage(@Nullable Object o) {
26 if (o instanceof String) {
27 return StringCodec.INSTANCE.encodeMessage((String) o);
28 }
29 return null;
30 }
31
32 @Nullable
33 @Override
34 public Object decodeMessage(@Nullable ByteBuffer byteBuffer) {
35 return StringCodec.INSTANCE.decodeMessage(byteBuffer);
36 }
37 });
38 }
39
40 @SuppressWarnings("unchecked")
41 @Override
42 @NonNull
43 public PlatformView create(@NonNull Context context, int id, @Nullable Object args) {
44 String params = (String) args;
45 return new TextPlatformView(context, id, params);
46 }
47
48 private static class TextPlatformView implements PlatformView {
49 final TextView textView;
50
51 @SuppressWarnings("unchecked")
52 TextPlatformView(@NonNull final Context context, int id, @Nullable String params) {
53 textView = new TextView(context);
54 textView.setTextSize(72);
55 textView.setBackgroundColor(Color.WHITE);
56 textView.setText(params);
57 }
58
59 @Override
60 @NonNull
61 public View getView() {
62 return textView;
63 }
64
65 @Override
66 public void dispose() {}
67 }
68}
PlatformView create(@NonNull Context context, int id, @Nullable Object args)
const EmbeddedViewParams * params
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args