admin
2020-09-10 a62905c725c5ffd88f29dfac644591cde18751e1
BuWanVideo/src/com/weikou/beibeivideo/util/ad/ExpressAdManager.java
@@ -32,22 +32,20 @@
 * 信息流广告管理
 */
public class ExpressAdManager {
    public final static int SOURCE_GDT = 1;//广点通
    public final static int SOURCE_GDT2 = 11;//广点通2.0
    public final static int SOURCE_CSJ = 2;//穿山甲
    final static String TAG = "ExpressAdManager";
    int sourceType = SOURCE_GDT;
    AdUtil.AD_TYPE sourceType = AdUtil.AD_TYPE.gdt;
    private TTAdNative mTTAdNative;
    private Context mContext;
    public ExpressAdManager(int adSource, Context context) {
    public ExpressAdManager(AdUtil.AD_TYPE adSource, Context context) {
        sourceType = adSource;
        this.mContext = context;
        if (sourceType == SOURCE_CSJ) {
        if (sourceType == AdUtil.AD_TYPE.csj) {
            TTAdManager ttAdManager = TTAdManagerHolder.get();
            mTTAdNative = ttAdManager.createAdNative(context);
//            TTAdManagerHolder.get().requestPermissionIfNecessary(context);
@@ -66,7 +64,7 @@
     * @param adLoadListener
     */
    public void loadAd(int widthDP, int heightDP, String pid, int count, final IAdLoadListener adLoadListener) {
        if (sourceType == SOURCE_GDT) {
        if (sourceType == AdUtil.AD_TYPE.gdt) {
            loadGDT(pid, widthDP, heightDP, count, new IGDTAdLoadListener() {
                @Override
                public void onSuccess(List<NativeExpressADView> adList) {
@@ -83,7 +81,7 @@
                }
            }, mContext);
        } else if (sourceType == SOURCE_GDT2) {
        } else if (sourceType == AdUtil.AD_TYPE.gdt2) {
            loadGDT2(pid, widthDP, heightDP, count, new IGDTAdLoadListener() {
                @Override
                public void onSuccess(List<NativeExpressADView> adList) {
@@ -101,7 +99,7 @@
                }
            }, mContext);
        } else if (sourceType == SOURCE_CSJ) {
        } else if (sourceType == AdUtil.AD_TYPE.csj) {
            loadCSJ(pid, widthDP, heightDP, count, new ICSJAdLoadListener() {
                @Override
                public void onSuccess(List<TTNativeExpressAd> adList) {
@@ -130,12 +128,12 @@
        int width = deviceWidth - 6;
        int height = (int) (width * 0.8);
        String pid = null;
        if (sourceType == SOURCE_CSJ) {
        if (sourceType == AdUtil.AD_TYPE.csj) {
            pid = CSJConstant.RECOMMEND_BIG_IMG_AD;
            height = (int) (width * 0.56);
        } else if (sourceType == SOURCE_GDT) {
        } else if (sourceType == AdUtil.AD_TYPE.gdt) {
            pid = BeibeiConstant.GDT_RECOMMAND_NATIVE;
        } else if (sourceType == SOURCE_GDT2) {
        } else if (sourceType == AdUtil.AD_TYPE.gdt2) {
            pid = GDTConstant.PID_HOME_RECOMMEND_BIG_IMG;
        }
        //获取屏幕的宽
@@ -152,9 +150,9 @@
    public void loadRecommendSmallAd(final IAdLoadListener adLoadListener) {
        //加载大图
        String pid = null;
        if (sourceType == SOURCE_CSJ) {
        if (sourceType == AdUtil.AD_TYPE.csj) {
            pid = "945375047";
        } else if (sourceType == SOURCE_GDT) {
        } else if (sourceType == AdUtil.AD_TYPE.gdt) {
            pid = BeibeiConstant.GDT_RECOMMAND_MIN_NATIVE;
        }
        //获取屏幕的宽
@@ -174,9 +172,9 @@
    public void loadVideoDetailPlayerBottomAd(final IAdLoadListener adLoadListener) {
        //加载大图
        String pid = null;
        if (sourceType == SOURCE_CSJ) {
        if (sourceType == AdUtil.AD_TYPE.csj) {
            pid = "945375047";
        } else if (sourceType == SOURCE_GDT2) {
        } else if (sourceType == AdUtil.AD_TYPE.gdt2) {
            pid = GDTConstant.PID_2_VIDEO_DETAIL_PLAY_EXPRESS1;
        }
        //获取屏幕的宽
@@ -196,9 +194,9 @@
    public void loadVideoDetailRelativeVideoBottomAd(final IAdLoadListener adLoadListener) {
        //加载大图
        String pid = null;
        if (sourceType == SOURCE_CSJ) {
        if (sourceType == AdUtil.AD_TYPE.csj) {
            pid = "945375047";
        } else if (sourceType == SOURCE_GDT2) {
        } else if (sourceType == AdUtil.AD_TYPE.gdt2) {
            pid = GDTConstant.PID_2_VIDEO_DETAIL_PLAY_EXPRESS2;
        }
        if (mContext == null)
@@ -220,9 +218,9 @@
    public void loadRecommendCategorySmallAd(final IAdLoadListener adLoadListener) {
        //加载大图
        String pid = null;
        if (sourceType == SOURCE_CSJ) {
        if (sourceType == AdUtil.AD_TYPE.csj) {
            pid = "945375047";
        } else if (sourceType == SOURCE_GDT) {
        } else if (sourceType == AdUtil.AD_TYPE.gdt) {
            pid = BeibeiConstant.GDT_RECOMMEND_CATEGORY_MIN_NATIVE;
        }
        //获取屏幕的宽
@@ -242,9 +240,9 @@
    public void loadSearchResultSmallAd(int count, final IAdLoadListener adLoadListener) {
        //加载大图
        String pid = null;
        if (sourceType == SOURCE_CSJ) {
        if (sourceType == AdUtil.AD_TYPE.csj) {
            pid = "945379581";
        } else if (sourceType == SOURCE_GDT) {
        } else if (sourceType == AdUtil.AD_TYPE.gdt) {
            pid = BeibeiConstant.GDT_SEARCH_RESULT_MIN_NATIVE;
        }
        //获取屏幕的宽
@@ -267,9 +265,9 @@
        //加载大图
        String pid = null;
        if (sourceType == SOURCE_CSJ) {
        if (sourceType == AdUtil.AD_TYPE.csj) {
            pid = "945406595";
        } else if (sourceType == SOURCE_GDT2) {
        } else if (sourceType == AdUtil.AD_TYPE.gdt2) {
            if (columns == 3)
                pid = GDTConstant.PID_2_VIDEO_LIST_SMALL_AD_COLUMN3;
            else if (columns == 2)
@@ -294,6 +292,29 @@
    /**
     * 加载APP退出广告
     *
     * @param adLoadListener
     */
    public void loadAppExitAd(final IAdLoadListener adLoadListener) {
        //加载大图
        String pid = null;
        if (sourceType == AdUtil.AD_TYPE.csj) {
            pid = CSJConstant.APP_EXIT;
        } else if (sourceType == AdUtil.AD_TYPE.gdt) {
            pid = BeibeiConstant.GDT_EXIT_DIALOG;
        }
        //获取屏幕的宽
        int deviceWidth = DimenUtils.getScreenWidth(mContext);
        deviceWidth = DimenUtils.px2dip(mContext, deviceWidth);
        int width = deviceWidth * 3 / 4;
        int height = (int) (width / 1.78f);
        loadAd(width, height, pid, 1, adLoadListener);
    }
    /**
     * 加载广点通广告
     *
     * @param positionId