admin
2022-04-29 67bdeebb4dc381a2f46f31e3027ebcc3243a8aeb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.demo.library_flutter.nativeview;
 
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
 
import com.bytedance.sdk.dp.DPSdk;
import com.bytedance.sdk.dp.DPWidgetDrawParams;
import com.bytedance.sdk.dp.IDPNewsListener;
import com.bytedance.sdk.dp.IDPWidget;
import com.demo.library_flutter.R;
import com.idlefish.flutterboost.FlutterBoost;
import com.qq.e.ads.nativ.NativeExpressAD;
import com.qq.e.ads.nativ.NativeExpressADView;
 
import java.util.Map;
 
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.platform.PlatformView;
 
class DrawVideoNativeView implements PlatformView {
    private static String TAG = "DrawVideoNativeView";
    private Map<String, Object> params;
    private MethodChannel methodChannel;
    private Context mContext;
    private FragmentManager mFragmentManager;
    private View contentView;
 
 
    public DrawVideoNativeView(int viewId, Context context, Map<String, Object> params, BinaryMessenger binaryMessenger) {
        this.params = params;
        this.mContext = context;
        methodChannel = new MethodChannel(binaryMessenger, "ad-draw-video-view-" + viewId);
        methodChannel.setMethodCallHandler(new MethodChannel.MethodCallHandler() {
            @Override
            public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
                if ("refresh".equalsIgnoreCase(call.method)) {
                    //刷新
 
                }
            }
        });
 
    }
 
    @Override
    public View getView() {
 
        if (contentView == null) {
            contentView = LayoutInflater.from(mContext).inflate(R.layout.fragment_draw_video, null);
            if (mFragmentManager == null) {
                FragmentActivity fragmentActivity = (FragmentActivity) FlutterBoost.instance().currentActivity();
                mFragmentManager = fragmentActivity.getSupportFragmentManager();
            }
            initVideo();
        }
        return contentView;
    }
 
    private void initVideo() {
        IDPWidget mIDPWidget = DPSdk.factory().createDraw(DPWidgetDrawParams.obtain().hideClose(true, null)
                .drawContentType(DPWidgetDrawParams.DRAW_CONTENT_TYPE_ALL)
                .enableRefresh(true)
                .customCategory("风景")
                .listener(new IDPNewsListener() {
                    @Override
                    public void onDPRefreshFinish() {
                        log("onDPRefreshFinish");
                    }
 
                    @Override
                    public void onDPNewsItemClick(Map<String, Object> map) {
                        log("onDPNewsItemClick");
                    }
 
                    @Override
                    public void onDPVideoPlay(Map<String, Object> map) {
                        log("onDPVideoPlay");
                    }
 
                    @Override
                    public void onDPVideoPause(Map<String, Object> map) {
                        log("onDPVideoPause");
                    }
 
                    @Override
                    public void onDPVideoContinue(Map<String, Object> map) {
                        log("onDPVideoContinue");
                    }
 
                    @Override
                    public void onDPVideoOver(Map<String, Object> map) {
                        log("onDPVideoOver");
//                        DPEventCollectUtil.playDrawVideo(getContext(), null, "dy", "home", false);
                    }
 
                    @Override
                    public void onDPVideoCompletion(Map<String, Object> map) {
                        log("onDPVideoCompletion");
                        super.onDPVideoCompletion(map);
//                        DPEventCollectUtil.playDrawVideo(getContext(), null, "dy", "home", true);
                    }
 
                    @Override
                    public void onDPNewsDetailEnter(Map<String, Object> map) {
                        log("onDPNewsDetailEnter");
                    }
 
                    @Override
                    public void onDPNewsDetailExit(Map<String, Object> map) {
                        log("onDPNewsDetailExit");
                    }
 
 
                }));
 
        Fragment fragment = mIDPWidget.getFragment();
        if (fragment != null) {
            mFragmentManager.beginTransaction().replace(R.id.fl_container_draw_video, fragment).commitAllowingStateLoss();
        }
    }
 
    private static void log(String msg) {
        Log.d(TAG, String.valueOf(msg));
    }
 
    @Override
    public void dispose() {
 
    }
}