| | |
| | | * 信息流广告管理 |
| | | */ |
| | | 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); |
| | |
| | | * @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) { |
| | |
| | | |
| | | } |
| | | }, 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) { |
| | |
| | | } |
| | | }, 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) { |
| | |
| | | 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; |
| | | } |
| | | //获取屏幕的宽 |
| | |
| | | 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; |
| | | } |
| | | //获取屏幕的宽 |
| | |
| | | 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; |
| | | } |
| | | //获取屏幕的宽 |
| | |
| | | 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) |
| | |
| | | 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; |
| | | } |
| | | //获取屏幕的宽 |
| | |
| | | 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; |
| | | } |
| | | //获取屏幕的宽 |
| | |
| | | |
| | | //加载大图 |
| | | 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) |
| | |
| | | |
| | | |
| | | /** |
| | | * 加载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 |