|
|
@@ -0,0 +1,329 @@
|
|
|
+package com.sheep.gamegroup.view.activity;
|
|
|
+
|
|
|
+import android.os.Bundle;
|
|
|
+import android.support.annotation.Nullable;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.FrameLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
+import com.jasmine.cantaloupe.engine.SplashEngine;
|
|
|
+import com.jasmine.cantaloupe.ui.widget.AdFrameLayout;
|
|
|
+import com.lygame.wrapper.ad.LySplashAdBuilder;
|
|
|
+import com.lygame.wrapper.interfaces.*;
|
|
|
+import com.lygame.wrapper.sdk.LySdk;
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.tencent.klevin.KleinManager;
|
|
|
+import com.tencent.klevin.base.callback.KleinResponseCallback;
|
|
|
+import com.tencent.klevin.base.view.BaseActivity;
|
|
|
+import com.tencent.klevin.util.AdUtils;
|
|
|
+
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
+
|
|
|
+import static com.tencent.klevin.base.okhttp.ErrorCode.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: ZEKI https://github.com/ZYF99
|
|
|
+ * @Date: 2021/6/1 3:56 下午
|
|
|
+ */
|
|
|
+public class DataGoAct extends BaseActivity {
|
|
|
+
|
|
|
+
|
|
|
+ FrameLayout zk_root;
|
|
|
+ AdFrameLayout flSplashYT;
|
|
|
+ TextView yt_splash_skip_view;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle bundle) {
|
|
|
+ super.onCreate(bundle);
|
|
|
+ setContentView(R.layout.act_data_go);
|
|
|
+ zk_root = findViewById(R.id.zk_root);
|
|
|
+ flSplashYT = findViewById(R.id.fv_splash_yt);
|
|
|
+ yt_splash_skip_view = findViewById(R.id.splash_skip_view);
|
|
|
+ findViewById(R.id.btn_yky_splash).setOnClickListener(v -> {
|
|
|
+ launchYKYSplash();
|
|
|
+ });
|
|
|
+ findViewById(R.id.btn_yt_splash).setOnClickListener(v -> {
|
|
|
+ launchYTSplash();
|
|
|
+ });
|
|
|
+ findViewById(R.id.btn_zk_splash).setOnClickListener(v -> {
|
|
|
+ launchZKSplash();
|
|
|
+ });
|
|
|
+ findViewById(R.id.btn_yky_courage).setOnClickListener(v -> {
|
|
|
+ showYKYCourage();
|
|
|
+ });
|
|
|
+ findViewById(R.id.btn_zk_courage).setOnClickListener(v -> {
|
|
|
+ showZKCourage();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //展示游可盈广告
|
|
|
+ private void launchYKYSplash() {
|
|
|
+ String data = "{\"placements\":[{\"pos_id\":" + 30112 + ",\"ad_count\":1}]}";
|
|
|
+ //"{\"placements\":[{\"pos_id\":" + posId + ",\"ad_count\":1}]}";
|
|
|
+ KleinManager.getInstance().prepareAD(
|
|
|
+ getApplicationContext(),
|
|
|
+ data,
|
|
|
+ 5000,
|
|
|
+ true,
|
|
|
+ new KleinResponseCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int i) {
|
|
|
+ G.showToast("游可盈-onSuccess" + i);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int i) {
|
|
|
+ //拉取广告错误或超时,直接跳过
|
|
|
+ G.showToast("游可盈-onFail" + i);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onEvent(int i) {
|
|
|
+ switch (i) {
|
|
|
+ case KLSplashAdEvent_AdShowSucc:
|
|
|
+ G.showToast("游可盈-广告展示成功");
|
|
|
+ break;
|
|
|
+ case KLSplashAdEvent_AdTap:
|
|
|
+ G.showToast("游可盈-点击广告");
|
|
|
+ break;
|
|
|
+ case KLSplashAdEvent_AdPlayCompletion:
|
|
|
+ case KLSplashAdEvent_AdShowFinish:
|
|
|
+ case KLSplashAdEvent_AdSkip:
|
|
|
+ G.showToast("游可盈-跳过广告");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ //展示优投开屏广告(新增boolean state:false----定值) 重要 mForceGoMain跳转主页 请参照此方法调用,否则可能导致广告展示链路断开 导致收益下降!!!
|
|
|
+ private void launchYTSplash() {
|
|
|
+ if (flSplashYT != null)
|
|
|
+ flSplashYT.setVisibility(View.VISIBLE);
|
|
|
+ new SplashEngine(DataGoAct.this, false, new SplashEngine.SplashAdCallBack() {
|
|
|
+ @Override
|
|
|
+ public void onSplashClick() {
|
|
|
+ G.showToast("优投-点击广告");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSplashDismissed() {
|
|
|
+ G.showToast("优投-广告消失");
|
|
|
+ if (flSplashYT != null)
|
|
|
+ flSplashYT.setVisibility(View.INVISIBLE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSplashError(String err, boolean isTimeout) {
|
|
|
+ G.showToast("优投-开屏广告" + err);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSplashShow() {
|
|
|
+ yt_splash_skip_view.setVisibility(View.VISIBLE);
|
|
|
+ G.showToast("优投-广告展示成功");
|
|
|
+ //mHasLoaded = true;
|
|
|
+ //mHandler.removeCallbacksAndMessages(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSplashPresent() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSplashLoad() {
|
|
|
+ G.showToast("优投-广告加载");
|
|
|
+ }
|
|
|
+
|
|
|
+ }).launchSplash(flSplashYT, 5 * 1000);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //掌酷广告控制器
|
|
|
+ private AtomicReference<ISplashAdController> splashControllerRef = new AtomicReference<>();
|
|
|
+
|
|
|
+ //展示掌酷广告
|
|
|
+ private void launchZKSplash() {
|
|
|
+ LySdk.loadSplashAd(this, new LySplashAdBuilder(zk_root, "52916"), new ISplashAdLoadCallback() {
|
|
|
+ @Override
|
|
|
+ public void onFailed(int i, String s) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLoaded(ISplashAdController iSplashAdController) {
|
|
|
+ splashControllerRef.set(iSplashAdController);
|
|
|
+ ISplashAdController controller;
|
|
|
+ if ((controller = splashControllerRef.getAndSet(null)) != null) {
|
|
|
+ if (zk_root != null)
|
|
|
+ zk_root.setVisibility(View.VISIBLE);
|
|
|
+ controller.show(new ISplashAdCallback() {
|
|
|
+ @Override
|
|
|
+ public void onLoadFail(int i, String s) {
|
|
|
+ zk_root.setVisibility(View.INVISIBLE);
|
|
|
+ G.showToast("掌酷-开屏广告加载onFail" + i + " " + s);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdClick() {
|
|
|
+ zk_root.setVisibility(View.INVISIBLE);
|
|
|
+ G.showToast("掌酷-开屏广告点击");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdShow() {
|
|
|
+ G.showToast("掌酷-开屏广告展示成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdSkip() {
|
|
|
+ zk_root.setVisibility(View.INVISIBLE);
|
|
|
+ G.showToast("掌酷-开屏广告跳过");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdTimeOver() {
|
|
|
+ //zk_root.setVisibility(View.INVISIBLE);
|
|
|
+ G.showToast("掌酷-开屏广告倒计时完成");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ Toast.makeText(DataGoAct.this, "掌酷广告未加载", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //展示游可盈激励视频
|
|
|
+ private void showYKYCourage() {
|
|
|
+ preAd(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ //预加载激励视频
|
|
|
+ private void preAd(boolean shouldShow) {
|
|
|
+ int posId = 30113;
|
|
|
+ int duration = 0;
|
|
|
+ //String data = "{\"placements\":[{\"pos_id\":" + posId + ",\"ad_count\":" + releaseTask.getTask().getVideo_num() + "}],\"ad_reward_trigger\":1, \"ad_reward_duration\":" + duration + ", \"ad_reward_automute\":1}";
|
|
|
+ String data = "{\"placements\":[{\"pos_id\":" + posId + ",\"ad_count\":1}],\"ad_reward_trigger\":1, \"ad_reward_duration\":" + duration + ", \"ad_reward_automute\":1}";
|
|
|
+
|
|
|
+ KleinManager.getInstance().loadEncourageAD(SheepApp.getInstance().getApplicationContext(), data, new KleinResponseCallback() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int i) {
|
|
|
+ handleSuccess(i, shouldShow);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int i) {
|
|
|
+ G.showToast("游可盈激励视频加载onFail" + i);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onEvent(int i) {
|
|
|
+ handleEvent(i);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //播放激励视频
|
|
|
+ private void showAd() {
|
|
|
+ KleinManager.getInstance().showAD(DataGoAct.this, AdUtils.TYPE_AD_REWARD,
|
|
|
+ new KleinResponseCallback() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int i) {
|
|
|
+ handleSuccess(i, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int i) {
|
|
|
+ G.showToast("游可盈激励视频onFail" + i);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onEvent(int i) {
|
|
|
+ handleEvent(i);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleSuccess(int i, boolean shouldShow) {
|
|
|
+ if (i == KLSplashAdEvent_CreativeDownloadSuccess) {
|
|
|
+ if (shouldShow) showAd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleEvent(int i) {
|
|
|
+ switch (i) {
|
|
|
+ case KLSplashAdEvent_MeetTheRewardConditions:
|
|
|
+ //满足领奖条件,去领奖
|
|
|
+ G.showToast("游可盈激励视频触发奖励(未真正获取)");
|
|
|
+ break;
|
|
|
+ case KLSplashAdEvent_AdPlayCompletion:
|
|
|
+ //一个视频播放结束
|
|
|
+ G.showToast("游可盈激励视频播放结束");
|
|
|
+ break;
|
|
|
+ case KLSplashAdEvent_AdSkip:
|
|
|
+ //用户点击关闭了界面
|
|
|
+ G.showToast("游可盈激励视频关闭");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private AtomicReference<IRewardVideoController> videoControllerRef = new AtomicReference<>();
|
|
|
+
|
|
|
+ //展示掌酷激励视频
|
|
|
+ private void showZKCourage() {
|
|
|
+ int adId = 52917;
|
|
|
+
|
|
|
+ LySdk.loadRewardVideo(DataGoAct.this, String.valueOf(adId), new IRewardVideoLoadCallback() {
|
|
|
+ @Override
|
|
|
+ public void onFailed(int i, String s) {
|
|
|
+ G.showToast("掌酷激励视频onFailed" + i + " " + s);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLoaded(IRewardVideoController iRewardVideoController) {
|
|
|
+ videoControllerRef.set(iRewardVideoController);
|
|
|
+ IRewardVideoController controller;
|
|
|
+ if ((controller = videoControllerRef.getAndSet(null)) != null) {
|
|
|
+ controller.show(new IRewardVideoPlayCallback() {
|
|
|
+ @Override
|
|
|
+ public void onAdShow() {
|
|
|
+ G.showToast("掌酷激励视频展示成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onInterTriggered() {
|
|
|
+ G.showToast("掌酷激励视频点击");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdClose() {
|
|
|
+ G.showToast("掌酷激励视频关闭");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onVideoComplete() {
|
|
|
+ G.showToast("掌酷激励视频播放完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRewarded() {
|
|
|
+ G.showToast("掌酷激励视频触发奖励(未真正获取)");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ Toast.makeText(DataGoAct.this, "广告未加载成功", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|