| | |
| | | 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; |
| | | |
| | | import com.bytedance.sdk.openadsdk.AdSlot; |
| | | import com.bytedance.sdk.openadsdk.TTAdConstant; |
| | | import com.bytedance.sdk.openadsdk.TTAdManager; |
| | | import com.bytedance.sdk.openadsdk.TTAdNative; |
| | | import com.bytedance.sdk.openadsdk.TTSplashAd; |
| | |
| | | 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"; |
| | | |
| | | /** |
| | | * 加载开屏广告 |
| | |
| | | * @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, code, new SplashADListener() { |
| | | @Override |
| | | public void onADDismissed() { |
| | | splashAdListener.close(); |
| | |
| | | |
| | | @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 |
| | | public void onADClicked() { |
| | | System.out.println(""); |
| | | splashAdListener.onAdClick(); |
| | | |
| | | } |
| | | |
| | | @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 |
| | |
| | | |
| | | @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); |
| | | }, 3500); |
| | | |
| | | gdtSplashAD.fetchAdOnly(); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @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); |
| | | TTAdManager ttAdManager = TTAdManagerHolder.get(); |
| | | private static void loadCSJ(String code, Context context, final View skip, final SplashAdListener splashAdListener) { |
| | | if (skip != null) |
| | | skip.setVisibility(View.GONE); |
| | | TTAdManager ttAdManager = null; |
| | | |
| | | try { |
| | | ttAdManager = TTAdManagerHolder.get(); |
| | | } catch (Exception e) { |
| | | } |
| | | if (ttAdManager == null) { |
| | | splashAdListener.noAd(); |
| | | return; |
| | | } |
| | | TTAdNative mTTAdNative = ttAdManager.createAdNative(context.getApplicationContext()); |
| | | //穿山甲广告 |
| | | int width = DimenUtils.getScreenWidth(context.getApplicationContext()); |
| | |
| | | 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) |
| | |
| | | splashAdListener.noAd(); |
| | | return; |
| | | } |
| | | View view = ad.getSplashView(); |
| | | vg_ad.removeAllViews(); |
| | | //把SplashView 添加到ViewGroup中 |
| | | 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 onAdClick(); |
| | | |
| | | public void close(); |
| | | |
| | | public void noAd(); |