| | |
| | | import android.app.Activity; |
| | | import android.app.Dialog; |
| | | import android.content.Context; |
| | | import android.content.DialogInterface; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.widget.FrameLayout; |
| | |
| | | import com.qq.e.ads.nativ.NativeExpressADView; |
| | | import com.qq.e.comm.util.AdError; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.entity.ad.AdTypeVO; |
| | | import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager.IAdEventListener; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | this.setCancelable(false); |
| | | } |
| | | |
| | | |
| | | public static class Builder { |
| | | private Activity context; |
| | | private String positiveButtonText; |
| | | private String negativeButtonText; |
| | | private OnClickListener positiveButtonClickListener; |
| | | private OnClickListener negativeButtonClickListener; |
| | | ExpressAdManager expressAdManager; |
| | | |
| | | public Builder(Activity context) { |
| | | this.context = context; |
| | | expressAdManager = new ExpressAdManager(AdUtil.getAdType(context, AdUtil.POSITION_EXIT_APP), context); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | private FrameLayout fl_advertisement; |
| | | |
| | | private ExpressAdContainer expressAdContainer; |
| | | |
| | | public ExitDialog create() { |
| | | LayoutInflater inflater = (LayoutInflater) context |
| | | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| | |
| | | final ExitDialog dialog = new ExitDialog(context, R.style.Dialog); |
| | | View layout = inflater.inflate(R.layout.item_exit, null); |
| | | fl_advertisement = layout.findViewById(R.id.fl_advertisement); |
| | | nativeAd(); |
| | | dialog.addContentView(layout, new FrameLayout.LayoutParams( |
| | | FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)); |
| | | // set the confirm button |
| | |
| | | params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT; |
| | | dialog.getWindow().setAttributes(params); |
| | | dialog.setCanceledOnTouchOutside(false); |
| | | dialog.setOnDismissListener(new OnDismissListener() { |
| | | @Override |
| | | public void onDismiss(DialogInterface dialog) { |
| | | fl_advertisement.removeAllViews(); |
| | | } |
| | | }); |
| | | return dialog; |
| | | } |
| | | |
| | |
| | | private NativeExpressAD nativeExpressAD; |
| | | |
| | | // 1.加载广告,先设置加载上下文环境和条件 |
| | | private void nativeAd() { |
| | | fl_advertisement.removeAllViews(); |
| | | nativeExpressAD = new NativeExpressAD(context, new ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT), |
| | | BeibeiConstant.GDT_EXIT_DIALOG, new NativeExpressAD.NativeExpressADListener() { |
| | | private void loadAd(boolean show) { |
| | | |
| | | expressAdManager.loadAppExitAd(new ExpressAdManager.IAdLoadListener() { |
| | | @Override |
| | | public void onADLoaded(final List<NativeExpressADView> list) { |
| | | fl_advertisement.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (null != list && list.size() > 0) { |
| | | NativeExpressADView adView = list.get(0); |
| | | adView.render(); |
| | | FrameLayout parent = (FrameLayout) adView.getParent(); |
| | | if (parent != null) { |
| | | parent.removeAllViews(); |
| | | public void onSuccess(List<ExpressAdContainer> adList) { |
| | | if (adList != null && adList.size() > 0) { |
| | | |
| | | ExpressAdManager.renderAd(context, adList.get(0), new ExpressAdManager.IAdRenderListener() { |
| | | @Override |
| | | public void onRenderSuccess(List<ExpressAdContainer> adList) { |
| | | expressAdContainer = adList.get(0); |
| | | if (show) { |
| | | ExpressAdManager.bindCloseListener(context, expressAdContainer, new IAdEventListener() { |
| | | @Override |
| | | public void closeAd(ExpressAdContainer ad) { |
| | | fl_advertisement.removeAllViews(); |
| | | } |
| | | }); |
| | | ExpressAdManager.fillAd(expressAdContainer, fl_advertisement); |
| | | } |
| | | fl_advertisement.addView(adView); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | @Override |
| | | public void onRenderFail(List<ExpressAdContainer> adList) { |
| | | |
| | | } |
| | | }, null); |
| | | |
| | | } |
| | | |
| | | } |
| | | }); |
| | | |
| | | @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 onADOpenOverlay(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADCloseOverlay(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onNoAD(AdError adError) { |
| | | } |
| | | }); // 传入Activity |
| | | // 注意:如果您在联盟平台上新建原生模板广告位时,选择了支持视频,那么可以进行个性化设置(可选) |
| | | nativeExpressAD.setVideoOption(new VideoOption.Builder() |
| | | .setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // WIFI 环境下可以自动播放视频 |
| | | .setAutoPlayMuted(true) // 自动播放时为静音 |
| | | .build()); // |
| | | nativeExpressAD.loadAD(2); |
| | | public void showAd() { |
| | | loadAd(true); |
| | | } |
| | | |
| | | public void refreshAd() { |
| | | nativeAd(); |
| | | loadAd(false); |
| | | } |
| | | |
| | | } |