| | |
| | | import com.weikou.beibeivideo.util.DimenUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * 信息流广告管理 |
| | | */ |
| | | public class ExpressAdManager { |
| | | public final static String POSITION_RECOMMEND = "recommend"; |
| | | public final static String POSITION_SEARCH = "search"; |
| | | public final static String POSITION_SEARCH_RESULT = "search_result"; |
| | | public final static String POSITION_VIDEO_DETAIL_PLAYER_BOTTOM = "video_detail_player_bottom"; |
| | | public final static String POSITION_EXIT = "exit"; |
| | | |
| | | |
| | | final static String TAG = "ExpressAdManager"; |
| | |
| | | |
| | | private TTAdNative mTTAdNative; |
| | | private Context mContext; |
| | | private static Set<String> closedAdPositions = new HashSet<>();// 是否已经关闭广告 |
| | | private String positionName; |
| | | |
| | | |
| | | public ExpressAdManager(AdUtil.AD_TYPE adSource, Context context) { |
| | | public ExpressAdManager(AdUtil.AD_TYPE adSource, String positionName, Context context) { |
| | | sourceType = adSource; |
| | | this.mContext = context; |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | this.positionName = positionName; |
| | | } |
| | | |
| | | |
| | |
| | | * @param adLoadListener |
| | | */ |
| | | public void loadAd(int widthDP, int heightDP, String pid, int count, final IAdLoadListener adLoadListener) { |
| | | if (closedAdPositions.contains(positionName)) { |
| | | // 广告已经关闭 |
| | | return; |
| | | } |
| | | if (sourceType == AdUtil.AD_TYPE.gdt || sourceType == AdUtil.AD_TYPE.gdt2) { |
| | | loadGDT(pid, widthDP, heightDP, count, new IGDTAdLoadListener() { |
| | | @Override |
| | |
| | | * @param adLoadListener |
| | | */ |
| | | public void loadVideoDetailPlayerBottomAd(final IAdLoadListener adLoadListener) { |
| | | if(sourceType==null){ |
| | | if (sourceType == null) { |
| | | return; |
| | | } |
| | | Log.i(TAG, "loadVideoDetailPlayerBottomAd"); |
| | |
| | | int height = (int) (widthDP / 1.78f); |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | pid = CSJConstant.VIDEO_SEARCH; |
| | | height=0; |
| | | height = 0; |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt2) { |
| | | pid = BeibeiConstant.GDT_SEARCH_NATIVE; |
| | | } else if (sourceType == AdUtil.AD_TYPE.hw) { |
| | |
| | | * @param fl_ad |
| | | * @param adEventListener |
| | | */ |
| | | public static void renderAndFillAd(Activity activity, final ExpressAdContainer ad, final FrameLayout fl_ad, final IAdEventListener adEventListener) { |
| | | public static void renderAndFillAd(Activity activity, final ExpressAdContainer ad, final FrameLayout fl_ad, String positionName, final IAdEventListener adEventListener) { |
| | | |
| | | if (ad == null) {//广告为空 |
| | | fl_ad.setVisibility(View.GONE); |
| | |
| | | if (adEventListener != null) { |
| | | adEventListener.closeAd(ad); |
| | | } |
| | | closedAdPositions.add(positionName); |
| | | } |
| | | |
| | | |
| | |
| | | if (adEventListener != null) { |
| | | adEventListener.closeAd(ad); |
| | | } |
| | | closedAdPositions.add(positionName); |
| | | } |
| | | }); |
| | | |
| | |
| | | * @param adRenderListener |
| | | * @param adEventListener |
| | | */ |
| | | public static void renderAd(Activity activity, final ExpressAdContainer ad, final IAdRenderListener adRenderListener, final IAdEventListener adEventListener) { |
| | | public static void renderAd(Activity activity, final ExpressAdContainer ad, String positionName, final IAdRenderListener adRenderListener, final IAdEventListener adEventListener) { |
| | | |
| | | if (ad == null) {//广告为空 |
| | | return; |
| | |
| | | if (adEventListener != null) { |
| | | adEventListener.closeAd(ad); |
| | | } |
| | | closedAdPositions.add(positionName); |
| | | } |
| | | |
| | | |
| | |
| | | if (adEventListener != null) { |
| | | adEventListener.closeAd(ad); |
| | | } |
| | | closedAdPositions.add(positionName); |
| | | } |
| | | }); |
| | | |