nilupeng
2022-01-29 0c89bf11bcddd39b5193bb19e28399648c59a2b8
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
package com.runt.open.mvvm.ui.splash;
 
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
 
import androidx.annotation.NonNull;
import androidx.lifecycle.Observer;
 
import com.bytedance.sdk.openadsdk.TTSplashAd;
import com.runt.open.mvvm.MainActivity;
import com.runt.open.mvvm.base.activities.BaseActivity;
import com.runt.open.mvvm.databinding.ActivitySplashBinding;
 
 
/**
 * My father is Object, ites purpose of 启动页
 *
 * @purpose Created by Runt (qingingrunt2010@qq.com) on 2020-4-16.
 */
public class SplashActivity extends BaseActivity<ActivitySplashBinding,SplashViewModel> {
 
    final String TAG = "WelcomeActivity";
 
    Handler handler = new Handler(){
        boolean started = false;
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if(!started) {//确保该语句只执行一次
                started = true;
                Intent intent = new Intent(mContext, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }
    };
 
    @Override
    public void initViews() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);//全屏
        hideBottomUIMenu();
        viewModel.getSplashAd().observe(this, new Observer<TTSplashAd>() {
            @Override
            public void onChanged(TTSplashAd ttSplashAd) {
                binding.splashAdContainer.addView(ttSplashAd.getSplashView());
                //设置SplashView的交互监听器
                ttSplashAd.setSplashInteractionListener(new TTSplashAd.AdInteractionListener() {
                    @Override
                    public void onAdClicked(View view, int type) {
                        Log.d(TAG, "onAdClicked");
                    }
 
                    @Override
                    public void onAdShow(View view, int type) {
                        Log.d(TAG, "onAdShow");
                    }
 
                    @Override
                    public void onAdSkip() {
                        Log.d(TAG, "onAdSkip");
                        handler.sendMessage(new Message());
 
                    }
 
                    @Override
                    public void onAdTimeOver() {
                        Log.d(TAG, "onAdTimeOver");
                        handler.sendMessage(new Message());
                    }
                });
            }
        });
        viewModel.getTimeOut().observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {
                handler.sendMessage(new Message());
            }
        });
        viewModel.applyTdAd(mContext);;//请求广告
    }
 
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        binding.splashAdContainer.removeAllViews();
    }
}