|
|
@@ -0,0 +1,187 @@
|
|
|
+package org.cocos2dx.javascript.thirdSdk.ad;
|
|
|
+
|
|
|
+import android.content.pm.ActivityInfo;
|
|
|
+import android.content.res.Configuration;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.CountDownTimer;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.FrameLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
+import androidx.fragment.app.FragmentActivity;
|
|
|
+
|
|
|
+import com.anythink.core.api.ATAdConst;
|
|
|
+import com.anythink.core.api.ATAdInfo;
|
|
|
+import com.anythink.core.api.ATMediationRequestInfo;
|
|
|
+import com.anythink.core.api.AdError;
|
|
|
+import com.anythink.splashad.api.ATSplashAd;
|
|
|
+import com.anythink.splashad.api.ATSplashAdListener;
|
|
|
+import com.aries.qsllx.mz.BuildConfig;
|
|
|
+import com.aries.qsllx.mz.R;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+public class SplashAdShowActivity extends FragmentActivity implements ATSplashAdListener {
|
|
|
+
|
|
|
+ ATSplashAd splashAd;
|
|
|
+ private String unitId = "";
|
|
|
+ private FrameLayout container;
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ unitId = BuildConfig.TOPON.split(",")[5];
|
|
|
+ setContentView(R.layout.splash_ad_show);
|
|
|
+
|
|
|
+// String[] arr = BuildConfig.JL_TOPON.split(",");
|
|
|
+// unitId = arr[arr.length - 1];
|
|
|
+// String unitId = getIntent().getStringExtra("b5f8d40ea99cea");
|
|
|
+
|
|
|
+ container = findViewById(R.id.splash_ad_container);
|
|
|
+ ViewGroup.LayoutParams layoutParams = container.getLayoutParams();
|
|
|
+
|
|
|
+ Configuration cf = getResources().getConfiguration();
|
|
|
+ int ori = cf.orientation;
|
|
|
+
|
|
|
+ /**You should set size to the layout param.**/
|
|
|
+ if (ori == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
|
|
|
+ layoutParams.width = (int)(getResources().getDisplayMetrics().widthPixels * 0.9);
|
|
|
+ layoutParams.height = getResources().getDisplayMetrics().heightPixels;
|
|
|
+ } else if (ori == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
|
|
|
+ layoutParams.width = getResources().getDisplayMetrics().widthPixels;
|
|
|
+ layoutParams.height = (int) (getResources().getDisplayMetrics().heightPixels * 0.85);
|
|
|
+ } else {
|
|
|
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
|
|
|
+ layoutParams.width = getResources().getDisplayMetrics().widthPixels;
|
|
|
+ layoutParams.height = (int) (getResources().getDisplayMetrics().heightPixels * 0.85);
|
|
|
+ }
|
|
|
+
|
|
|
+ //v5.6.2新增,针对首次安装获取TopOn策略导致开屏广告加载超时,可传递各广告平台参数,直接发起请求
|
|
|
+ //请参考:https://docs.toponad.com/#/zh-cn/android/android_doc/android_sdk_splash_access?id=splash_timeout
|
|
|
+ ATMediationRequestInfo atMediationRequestInfo = null;
|
|
|
+
|
|
|
+ //Mintegral
|
|
|
+ //atMediationRequestInfo = new MintegralATRequestInfo(appid, appkey, placement_id, unitid);
|
|
|
+ //atMediationRequestInfo.setAdSourceId(mintegralTopOnAdsourceId);
|
|
|
+
|
|
|
+ //腾讯广告(Tencent Ads)
|
|
|
+ //atMediationRequestInfo = new GDTATRequestInfo(app_id, unit_id);
|
|
|
+ //atMediationRequestInfo.setAdSourceId(gdtTopOnAdsourceId);
|
|
|
+
|
|
|
+ //穿山甲(Pangle)
|
|
|
+ //atMediationRequestInfo = new TTATRequestInfo(app_id, slot_id, personalized_template);
|
|
|
+ //atMediationRequestInfo.setAdSourceId(pangleTopOnAdsourceId);
|
|
|
+
|
|
|
+ //Sigmob
|
|
|
+ //atMediationRequestInfo = new SigmobiATRequestInfo(app_id, app_key, placement_id);
|
|
|
+ //atMediationRequestInfo.setAdSourceId(sigmobTopOnAdsourceId);
|
|
|
+
|
|
|
+ //百度
|
|
|
+ //atMediationRequestInfo = new BaiduATRequestInfo(app_id, ad_place_id);
|
|
|
+ //atMediationRequestInfo.setAdSourceId(baiduTopOnAdsourceId);
|
|
|
+
|
|
|
+ //快手
|
|
|
+ //atMediationRequestInfo = new KSATRequestInfo(app_id, position_id);
|
|
|
+ //atMediationRequestInfo.setAdSourceId(kuaishouTopOnAdsourceId);
|
|
|
+
|
|
|
+ //Admob
|
|
|
+ //atMediationRequestInfo = new AdmobATRequestInfo(app_id, unit_id, orientation);
|
|
|
+ //atMediationRequestInfo.setAdSourceId(admobTopOnAdsourceId);
|
|
|
+
|
|
|
+ //atMediationRequestInfo传入后,只针对首次请求开屏的情况生效,请详细阅读上方说明
|
|
|
+ splashAd = new ATSplashAd(this, unitId, atMediationRequestInfo, this, 5000);
|
|
|
+ //splashAd = new ATSplashAd(this, TopOnPlacementId, this);
|
|
|
+
|
|
|
+ Map<String,Object> localMap = new HashMap<>();
|
|
|
+ localMap.put(ATAdConst.KEY.AD_WIDTH, layoutParams.width);
|
|
|
+ localMap.put(ATAdConst.KEY.AD_HEIGHT, layoutParams.height);
|
|
|
+ splashAd.setLocalExtra(localMap);
|
|
|
+
|
|
|
+ if (splashAd.isAdReady()) {
|
|
|
+ Log.i("===[TAG", "SplashAd is ready to show.");
|
|
|
+ splashAd.show(this, container);
|
|
|
+ } else {
|
|
|
+ Log.i("===[TAG", "SplashAd isn't ready to show, start to request.");
|
|
|
+ splashAd.loadAd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdLoaded() {
|
|
|
+ splashAd.show(this, container);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNoAdError(AdError adError) {
|
|
|
+ //注意:禁止在此回调中执行广告的加载方法进行重试,否则会引起很多无用请求且可能会导致应用卡顿
|
|
|
+ //AdError,请参考 https://docs.toponad.com/#/zh-cn/android/android_doc/android_test?id=aderror
|
|
|
+ Log.e("TAG", "onNoAdError:" + adError.getFullErrorInfo());
|
|
|
+ jumpToMainActivity();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdShow(ATAdInfo atAdInfo) {
|
|
|
+ //ATAdInfo可区分广告平台以及获取广告平台的广告位ID等
|
|
|
+ //请参考 https://docs.toponad.com/#/zh-cn/android/android_doc/android_sdk_callback_access?id=callback_info
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdClick(ATAdInfo atAdInfo) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+// public void onAdDismiss(ATAdInfo atAdInfo, IATSplashEyeAd splashEyeAd) {//v5.7.47开始,请使用此回调
|
|
|
+ public void onAdDismiss(ATAdInfo atAdInfo) {//低于v5.7.47,请使用此回调
|
|
|
+ jumpToMainActivity();
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean hasHandleJump = false;
|
|
|
+ boolean canJump;//是否可以跳转主页面,当开屏Activity处于后台时禁止跳转主页面
|
|
|
+
|
|
|
+ public void jumpToMainActivity() {
|
|
|
+
|
|
|
+ if (!canJump) {
|
|
|
+ canJump = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!hasHandleJump) {
|
|
|
+ hasHandleJump = true;
|
|
|
+ finish();
|
|
|
+ Toast.makeText(this, "start your MainActivity.", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+
|
|
|
+ if (canJump) {
|
|
|
+ jumpToMainActivity();
|
|
|
+ }
|
|
|
+
|
|
|
+ canJump = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPause() {
|
|
|
+ super.onPause();
|
|
|
+
|
|
|
+ canJump = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ if (splashAd != null) {
|
|
|
+ splashAd.onDestory();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|