From cbb88109494ffc7916f6639c20ce05c0cec941a9 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 07 四月 2021 15:07:45 +0800 Subject: [PATCH] 3.9.1bug修复 --- BuWanVideo/src/com/weikou/beibeivideo/util/ad/SplashAdUtil.java | 113 ++++++++++++++++++++++++-------------------------------- 1 files changed, 49 insertions(+), 64 deletions(-) diff --git a/BuWanVideo/src/com/weikou/beibeivideo/util/ad/SplashAdUtil.java b/BuWanVideo/src/com/weikou/beibeivideo/util/ad/SplashAdUtil.java index d927a90..191ce66 100644 --- a/BuWanVideo/src/com/weikou/beibeivideo/util/ad/SplashAdUtil.java +++ b/BuWanVideo/src/com/weikou/beibeivideo/util/ad/SplashAdUtil.java @@ -1,6 +1,9 @@ package com.weikou.beibeivideo.util.ad; import android.app.Activity; +import android.content.Context; +import android.os.SystemClock; +import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; @@ -14,11 +17,14 @@ import com.qq.e.ads.splash.SplashADListener; import com.qq.e.comm.util.AdError; import com.weikou.beibeivideo.entity.ad.AdTypeVO; +import com.weikou.beibeivideo.entity.ad.SplashAdLoadInfo; import com.weikou.beibeivideo.util.BeibeiConstant; import com.weikou.beibeivideo.util.DimenUtils; import com.weikou.beibeivideo.util.downutil.StringUtils; public class SplashAdUtil { + + private static final String TAG = "SplashAdUtil"; /** * 鍔犺浇寮�灞忓箍鍛� @@ -26,32 +32,33 @@ * @param adType * @param context * @param skip - * @param vg_ad * @param tv_time * @param splashAdListener */ - public static void loadAD(AdUtil.AD_TYPE adType, Activity context, final View skip, ViewGroup vg_ad, final TextView tv_time, final SplashAdListener splashAdListener) { - if (adType==null) { + public static void loadAD(String pid, AdUtil.AD_TYPE adType, Context context, final View skip, final TextView tv_time, final SplashAdListener splashAdListener) { + if (adType == null) { splashAdListener.close(); return; } - if (AdUtil.AD_TYPE.csj==adType) { - loadCSJ(context, skip, vg_ad, splashAdListener); - } else if (AdUtil.AD_TYPE.gdt==adType) { - loadGDT(context, skip, vg_ad, tv_time, splashAdListener); + if (AdUtil.AD_TYPE.csj == adType) { + loadCSJ(pid, context, skip, splashAdListener); + } else if (AdUtil.AD_TYPE.gdt == adType) { + loadGDT(pid, context, skip, tv_time, splashAdListener); } else { splashAdListener.close(); } } - private static void loadGDT(Activity context, final View skip, ViewGroup vg_ad, final TextView tv_time, final SplashAdListener splashAdListener) { + private static SplashAD gdtSplashAD; + + private static void loadGDT(String code, Context context, final View skip, final TextView tv_time, final SplashAdListener splashAdListener) { String channel = ManifestDataUtil.getAppMetaData(context, "UMENG_CHANNEL"); - String code = BeibeiConstant.GDT_SPLASH_POSITION_ID; - if ("vivo".equalsIgnoreCase(channel)) { - code = BeibeiConstant.GDT_SPLASH_VIVO_POSITION_ID; - } - new SplashAD(context, skip, code, new SplashADListener() { + if (StringUtils.isNullOrEmpty(code)) + code = BeibeiConstant.GDT_SPLASH_POSITION_ID; + if (skip != null) + skip.setVisibility(View.VISIBLE); + gdtSplashAD = new SplashAD(context, skip, code, new SplashADListener() { @Override public void onADDismissed() { splashAdListener.close(); @@ -59,18 +66,20 @@ @Override public void onNoAD(AdError adError) { + Log.i(TAG, "GDT:onNoAD-" + adError.getErrorMsg()); splashAdListener.noAd(); } @Override public void onADPresent() { - skip.post(new Runnable() { - @Override - public void run() { - skip.setVisibility(View.VISIBLE); - } - }); + if (skip != null) + skip.post(new Runnable() { + @Override + public void run() { + skip.setVisibility(View.VISIBLE); + } + }); } @Override @@ -80,12 +89,13 @@ @Override public void onADTick(final long l) { - tv_time.post(new Runnable() { - @Override - public void run() { - tv_time.setText(l / 1000 + ""); - } - }); + if (tv_time != null) + tv_time.post(new Runnable() { + @Override + public void run() { + tv_time.setText(l / 1000 + ""); + } + }); } @Override @@ -95,15 +105,11 @@ @Override public void onADLoaded(long l) { - System.out.println(""); - skip.post(new Runnable() { - @Override - public void run() { - skip.setVisibility(View.VISIBLE); - } - }); + Log.i(TAG, "GDT:onADLoaded-" + l); + splashAdListener.onAdLoad(new SplashAdLoadInfo(gdtSplashAD, System.currentTimeMillis() + (l - SystemClock.elapsedRealtime()))); } - }, 0).fetchAndShowIn(vg_ad); + }, 0); + gdtSplashAD.fetchAdOnly(); } @@ -112,11 +118,11 @@ * * @param context * @param skip - * @param vg_ad * @param splashAdListener */ - private static void loadCSJ(Activity context, final View skip, final ViewGroup vg_ad, final SplashAdListener splashAdListener) { - skip.setVisibility(View.GONE); + private static void loadCSJ(String code, Context context, final View skip, final SplashAdListener splashAdListener) { + if (skip != null) + skip.setVisibility(View.GONE); TTAdManager ttAdManager = TTAdManagerHolder.get(); TTAdNative mTTAdNative = ttAdManager.createAdNative(context.getApplicationContext()); //绌垮北鐢插箍鍛� @@ -126,11 +132,8 @@ width = 720; if (height == 0) height = 1080; - String channel = ManifestDataUtil.getAppMetaData(context, "UMENG_CHANNEL"); - String code = CSJConstant.SPLASH_AD; - if ("vivo".equalsIgnoreCase(channel)) { - code = CSJConstant.SPLASH_AD_VIVO; - } + if (StringUtils.isNullOrEmpty(code)) + code = CSJConstant.SPLASH_AD; AdSlot adSlot = new AdSlot.Builder() .setCodeId(code) @@ -155,37 +158,19 @@ splashAdListener.noAd(); return; } - View view = ad.getSplashView(); - vg_ad.removeAllViews(); - //鎶奡plashView 娣诲姞鍒癡iewGroup涓� - vg_ad.addView(view); - //璁剧疆SplashView鐨勪氦浜掔洃鍚櫒 - ad.setSplashInteractionListener(new TTSplashAd.AdInteractionListener() { - @Override - public void onAdClicked(View view, int type) { - } - @Override - public void onAdShow(View view, int type) { - } + splashAdListener.onAdLoad(new SplashAdLoadInfo(System.currentTimeMillis() + 1000 * 60 * 30L, ad)); - @Override - public void onAdSkip() { - splashAdListener.close(); - } - - @Override - public void onAdTimeOver() { - splashAdListener.close(); - } - }); } - }); + }, 4000); } public interface SplashAdListener { + + public void onAdLoad(SplashAdLoadInfo adLoadInfo); + public void close(); public void noAd(); -- Gitblit v1.8.0