From 399ac289f80b7a40aa4210341db6b447cacdcf14 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 09 八月 2022 17:42:33 +0800 Subject: [PATCH] 广告升级,隐私政策整改 --- app/src/main/java/com/tejia/lijin/app/util/ad/ExpressAdManager.java | 262 +++++++++++++++++++--------------------------------- 1 files changed, 97 insertions(+), 165 deletions(-) diff --git a/app/src/main/java/com/tejia/lijin/app/util/ad/ExpressAdManager.java b/app/src/main/java/com/tejia/lijin/app/util/ad/ExpressAdManager.java index 8e567d1..344e2dd 100644 --- a/app/src/main/java/com/tejia/lijin/app/util/ad/ExpressAdManager.java +++ b/app/src/main/java/com/tejia/lijin/app/util/ad/ExpressAdManager.java @@ -12,11 +12,10 @@ import com.bytedance.sdk.openadsdk.TTAdManager; import com.bytedance.sdk.openadsdk.TTAdNative; import com.bytedance.sdk.openadsdk.TTNativeExpressAd; +import com.qq.e.ads.cfg.VideoOption; +import com.qq.e.ads.nativ.ADSize; +import com.qq.e.ads.nativ.NativeExpressAD; import com.qq.e.ads.nativ.NativeExpressADView; -import com.qq.e.ads.nativ.express2.AdEventListener; -import com.qq.e.ads.nativ.express2.NativeExpressAD2; -import com.qq.e.ads.nativ.express2.NativeExpressADData2; -import com.qq.e.ads.nativ.express2.VideoOption2; import com.qq.e.comm.util.AdError; import com.wpc.library.util.common.DimenUtils; @@ -60,23 +59,17 @@ */ public void loadAd(int widthDP, int heightDP, String pid, int count, final IAdLoadListener adLoadListener) { if (sourceType == AdUtil.AD_TYPE.gdt2) { - loadGDT2(pid, widthDP, heightDP, count, new IGDTAdLoadListener() { + loadGDT(pid, widthDP, heightDP, count, new IGDTAdLoadListener() { @Override public void onSuccess(List<NativeExpressADView> adList) { - - } - - @Override - public void onSuccess2(List<NativeExpressADData2> adList) { List<ExpressAdContainer> adContainerList = new ArrayList<>(); if (adList != null) - for (NativeExpressADData2 ad : adList) { - adContainerList.add(new ExpressAdContainer(ad)); + for (NativeExpressADView adView : adList) { + adContainerList.add(new ExpressAdContainer(adView)); } adLoadListener.onSuccess(adContainerList); } }, mContext); - } else if (sourceType == AdUtil.AD_TYPE.csj) { loadCSJ(pid, widthDP, heightDP, count, new ICSJAdLoadListener() { @Override @@ -110,45 +103,6 @@ } /** - * 2.0鐗堟湰骞跨偣閫氬師鐢� - * - * @param positionId - * @param widthDP - * @param heightDP - * @param count - * @param adLoadListener - * @param context - */ - private void loadGDT2(String positionId, int widthDP, int heightDP, int count, final IGDTAdLoadListener adLoadListener, Context context) { - - Log.i(TAG, String.format("loadGDT2:positionId-%s widthDP-%s heightDP-%s", positionId, widthDP, heightDP)); - - NativeExpressAD2 nativeExpressAD2 = new NativeExpressAD2(context, positionId, new NativeExpressAD2.AdLoadListener() { - @Override - public void onLoadSuccess(List<NativeExpressADData2> list) { - if (adLoadListener != null) - adLoadListener.onSuccess2(list); - } - - @Override - public void onNoAD(AdError adError) { - if (adLoadListener != null) - adLoadListener.onSuccess2(null); - } - }); - - nativeExpressAD2.setAdSize(widthDP, heightDP); - VideoOption2.Builder builder = new VideoOption2.Builder(); - builder.setAutoPlayPolicy(VideoOption2.AutoPlayPolicy.WIFI) // WIFI 鐜涓嬪彲浠ヨ嚜鍔ㄦ挱鏀捐棰� - .setAutoPlayMuted(true) // 鑷姩鎾斁鏃朵负闈欓煶 - .setDetailPageMuted(false) // 瑙嗛璇︽儏椤垫挱鏀炬椂涓嶉潤闊� - .setMaxVideoDuration(0) // 璁剧疆杩斿洖瑙嗛骞垮憡鐨勬渶澶ц棰戞椂闀匡紙闂尯闂达紝鍙崟鐙缃級锛屽崟浣�:绉掞紝榛樿涓� 0 浠h〃鏃犻檺鍒讹紝鍚堟硶杈撳叆涓猴細5<=maxVideoDuration<=60. 姝よ缃細褰卞搷骞垮憡濉厖锛岃璋ㄦ厧璁剧疆 - .setMinVideoDuration(0); // 璁剧疆杩斿洖瑙嗛骞垮憡鐨勬渶灏忚棰戞椂闀匡紙闂尯闂达紝鍙崟鐙缃級锛屽崟浣�:绉掞紝榛樿涓� 0 浠h〃鏃犻檺鍒讹紝 姝よ缃細褰卞搷骞垮憡濉厖锛岃璋ㄦ厧璁剧疆 - nativeExpressAD2.setVideoOption2(builder.build()); - nativeExpressAD2.loadAd(count); - } - - /** * 绌垮北鐢插箍鍛� * * @param codeId @@ -178,6 +132,69 @@ }); } + /** + * 鍔犺浇骞跨偣閫氬箍鍛� + * + * @param positionId + * @param count + * @param adLoadListener + * @param context + */ + private void loadGDT(String positionId, int widthDP, int heightDP, int count, final IGDTAdLoadListener adLoadListener, Context context) { + + + NativeExpressAD nativeExpressAD = new NativeExpressAD(context, new ADSize(widthDP, ADSize.AUTO_HEIGHT), + positionId, new NativeExpressAD.NativeExpressADListener() { + + @Override + public void onADLoaded(List<NativeExpressADView> list) { + if (adLoadListener != null) + adLoadListener.onSuccess(list); + } + + @Override + public void onRenderFail(NativeExpressADView nativeExpressADView) { + + } + + @Override + public void onRenderSuccess(NativeExpressADView nativeExpressADView) { + + } + + @Override + public void onADExposure(NativeExpressADView nativeExpressADView) { + + } + + @Override + public void onADClicked(NativeExpressADView nativeExpressADView) { + + } + + @Override + public void onADClosed(NativeExpressADView nativeExpressADView) { + + } + + @Override + public void onADLeftApplication(NativeExpressADView nativeExpressADView) { + + } + + @Override + public void onNoAD(AdError adError) { + if (adLoadListener != null) + adLoadListener.onSuccess(null); + } + }); // 浼犲叆Activity + nativeExpressAD.setVideoOption(new VideoOption.Builder() + .setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // WIFI 鐜涓嬪彲浠ヨ嚜鍔ㄦ挱鏀捐棰� + .setAutoPlayMuted(true) // 鑷姩鎾斁鏃朵负闈欓煶 + .build()); // + nativeExpressAD.loadAD(count); + } + /** * 娓叉煋妯℃澘鍜屽~鍏呭箍鍛� @@ -193,45 +210,16 @@ fl_ad.setVisibility(View.GONE); } else { fl_ad.setVisibility(View.VISIBLE); - if (ad.getGdt2() != null) { - if (fl_ad.getChildCount() > 0 && fl_ad.getChildAt(0) == ad.getGdt2().getAdView()) { + if (ad.getGdt() != null) { + if (fl_ad.getChildCount() > 0 && fl_ad.getChildAt(0) == ad.getGdt()) { return; } fl_ad.removeAllViews(); - - ad.getGdt2().setAdEventListener(new AdEventListener() { - @Override - public void onClick() { - - } - - @Override - public void onExposed() { - - } - - @Override - public void onRenderSuccess() { - if (ad.getGdt2().getAdView().getParent() != null) { - ((ViewGroup) ad.getGdt2().getAdView().getParent()).removeAllViews(); - } - fl_ad.addView(ad.getGdt2().getAdView()); - } - - @Override - public void onRenderFail() { - - } - - @Override - public void onAdClosed() { - if (adEventListener != null) { - adEventListener.closeAd(ad); - } - } - }); - ad.getGdt2().render(); - + ad.getGdt().render(); + if (ad.getGdt().getParent() != null) { + ((ViewGroup) ad.getGdt().getParent()).removeAllViews(); + } + fl_ad.addView(ad.getGdt()); } else if (ad.getCsj() != null) { if (fl_ad.getChildCount() > 0 && fl_ad.getChildAt(0) == ad.getCsj().getExpressAdView()) { return; @@ -253,6 +241,7 @@ } } + @Override public void onCancel() { @@ -269,7 +258,6 @@ } - /** * 娓叉煋骞垮憡 * @@ -284,43 +272,14 @@ return; } - if (ad.getGdt2() != null) { - ad.getGdt2().setAdEventListener(new AdEventListener() { - @Override - public void onClick() { - - } - - @Override - public void onExposed() { - - } - - @Override - public void onRenderSuccess() { - List<ExpressAdContainer> list = new ArrayList<>(); - list.add(ad); - if (adRenderListener != null) - adRenderListener.onRenderSuccess(list); - } - - @Override - public void onRenderFail() { - List<ExpressAdContainer> list = new ArrayList<>(); - list.add(ad); - if (adRenderListener != null) - adRenderListener.onRenderFail(list); - } - - @Override - public void onAdClosed() { - if (adEventListener != null) - adEventListener.closeAd(ad); - } - }); - ad.getGdt2().render(); - + if (ad.getGdt() != null) { + ad.getGdt().render(); + List<ExpressAdContainer> list = new ArrayList<>(); + list.add(ad); + if (adRenderListener != null) + adRenderListener.onRenderSuccess(list); } else if (ad.getCsj() != null) { + Log.i(TAG, "骞垮憡鏇濆厜:csj"); ad.getCsj().setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() { @Override public void onAdClicked(View view, int i) { @@ -365,6 +324,7 @@ } } + @Override public void onCancel() { @@ -377,7 +337,6 @@ } - /** * 涓哄箍鍛婄粦瀹氬叧闂簨浠� * @@ -391,35 +350,9 @@ return; } - if (ad.getGdt2() != null) { - ad.getGdt2().setAdEventListener(new AdEventListener() { - @Override - public void onClick() { - - } - - @Override - public void onExposed() { - - } - - @Override - public void onRenderSuccess() { - - } - - @Override - public void onRenderFail() { - } - - @Override - public void onAdClosed() { - if (adEventListener != null) - adEventListener.closeAd(ad); - } - }); - - } else if (ad.getCsj() != null) { + if (ad.getGdt() != null) { + return; + } else if (ad.getCsj() != null) { ad.getCsj().setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() { @Override public void onAdClicked(View view, int i) { @@ -456,16 +389,19 @@ } } + @Override public void onCancel() { } + }); } } + /** @@ -483,17 +419,16 @@ fl_ad.setVisibility(View.GONE); } else { fl_ad.setVisibility(View.VISIBLE); - if (ad.getGdt2() != null) { - if (fl_ad.getChildCount() > 0 && fl_ad.getChildAt(0) == ad.getGdt2().getAdView()) { + if (ad.getGdt() != null) { + if (fl_ad.getChildCount() > 0 && fl_ad.getChildAt(0) == ad.getGdt()) { return; } - if (ad.getGdt2().getAdView().getParent() != null) { - ((ViewGroup) ad.getGdt2().getAdView().getParent()).removeAllViews(); + if (ad.getGdt().getParent() != null) { + ((ViewGroup) ad.getGdt().getParent()).removeAllViews(); } fl_ad.removeAllViews(); - fl_ad.addView(ad.getGdt2().getAdView()); - - } else if (ad.getCsj() != null) { + fl_ad.addView(ad.getGdt()); + }else if (ad.getCsj() != null) { if (fl_ad.getChildCount() > 0 && fl_ad.getChildAt(0) == ad.getCsj().getExpressAdView()) { return; } @@ -519,11 +454,8 @@ } - interface IGDTAdLoadListener { public void onSuccess(List<NativeExpressADView> adList); - - public void onSuccess2(List<NativeExpressADData2> adList); } interface ICSJAdLoadListener { -- Gitblit v1.8.0