| | |
| | | |
| | | 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; |
| | |
| | | |
| | | 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(String pid, AdUtil.AD_TYPE adType, Context context, final View skip, ViewGroup vg_ad, final TextView tv_time, final SplashAdListener splashAdListener) { |
| | | 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(pid, context, skip, vg_ad, splashAdListener); |
| | | loadCSJ(pid, context, skip, splashAdListener); |
| | | } else if (AdUtil.AD_TYPE.gdt == adType) { |
| | | loadGDT(pid, context, skip, vg_ad, tv_time, splashAdListener); |
| | | loadGDT(pid, context, skip, tv_time, splashAdListener); |
| | | } else { |
| | | splashAdListener.close(); |
| | | } |
| | |
| | | |
| | | private static SplashAD gdtSplashAD; |
| | | |
| | | private static void loadGDT(String code, Context context, final View skip, ViewGroup vg_ad, final TextView tv_time, final SplashAdListener splashAdListener) { |
| | | 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"); |
| | | if (StringUtils.isNullOrEmpty(code)) |
| | | code = BeibeiConstant.GDT_SPLASH_POSITION_ID; |
| | | gdtSplashAD = new SplashAD(context, skip, code, new SplashADListener() { |
| | | 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) { |
| | | // gdtSplashAD.preLoad(); |
| | | // System.out.println(""); |
| | | splashAdListener.onAdLoad(new SplashAdLoadInfo(gdtSplashAD, l)); |
| | | Log.i(TAG, "GDT:onADLoaded-" + l); |
| | | splashAdListener.onAdLoad(new SplashAdLoadInfo(gdtSplashAD, System.currentTimeMillis() + (l - SystemClock.elapsedRealtime()))); |
| | | } |
| | | }, 0); |
| | | }, 3500); |
| | | |
| | | gdtSplashAD.fetchAdOnly(); |
| | | } |
| | | |
| | |
| | | * |
| | | * @param context |
| | | * @param skip |
| | | * @param vg_ad |
| | | * @param splashAdListener |
| | | */ |
| | | private static void loadCSJ(String code, Context 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()); |
| | |
| | | return; |
| | | } |
| | | |
| | | splashAdListener.onAdLoad(new SplashAdLoadInfo(gdtSplashAD, System.currentTimeMillis()+1000*60*30L)); |
| | | splashAdListener.onAdLoad(new SplashAdLoadInfo(System.currentTimeMillis() + 1000 * 60 * 30L, ad)); |
| | | |
| | | } |
| | | },4000); |
| | | }, 4000); |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | public void onAdLoad(SplashAdLoadInfo adLoadInfo); |
| | | |
| | | public void onAdClick(); |
| | | |
| | | public void close(); |
| | | |
| | | public void noAd(); |