.gitignore | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
.idea/workspace.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/libs/tbs_sdk_thirdapp_v4.3.0.1020_43633_sharewithdownload_withoutGame_obfs_20190111_105200.jar | 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/res/layout/item_video_detail_ad.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
BuWanVideo/src/com/weikou/beibeivideo/ui/ad/VideoDetailVideoAdFragment.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
.gitignore
New file @@ -0,0 +1,41 @@ # Built application files *.apk *.ap_ # Files for the ART/Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ out/ # Gradle files .gradle/ build/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Log Files *.log # Android Studio Navigation editor temp files .navigation/ # Android Studio captures folder captures/ # Intellij *.iml *.iws.idea/ .idea/ # Keystore files *.jks .idea/workspace.xml
@@ -104,8 +104,8 @@ <file pinned="false" current-in-tab="false"> <entry file="file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/media/VideoDetailActivity.java"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="274"> <caret line="519" column="59" selection-start-line="519" selection-start-column="40" selection-end-line="519" selection-end-column="59" /> <state relative-caret-position="226"> <caret line="102" column="26" selection-start-line="102" selection-start-column="12" selection-end-line="102" selection-end-column="38" /> <folding> <element signature="e#16029#16030#0" expanded="true" /> <element signature="e#16069#16070#0" expanded="true" /> @@ -121,6 +121,24 @@ </entry> </file> <file pinned="false" current-in-tab="false"> <entry file="file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/VideoDetailVideoAdFragment.java"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="792"> <caret line="36" column="27" lean-forward="true" selection-start-line="36" selection-start-column="27" selection-end-line="36" selection-end-column="27" /> </state> </provider> </entry> </file> <file pinned="false" current-in-tab="true"> <entry file="file://$PROJECT_DIR$/.gitignore"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="224"> <caret line="18" column="6" lean-forward="true" selection-start-line="18" selection-start-column="6" selection-end-line="18" selection-end-column="6" /> </state> </provider> </entry> </file> <file pinned="false" current-in-tab="false"> <entry file="file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/media/VideoDetailFragment.java"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="396"> @@ -129,11 +147,11 @@ </provider> </entry> </file> <file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="false"> <entry file="file://$PROJECT_DIR$/BuWanVideo/res/layout/video_detail_fragment.xml"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="198"> <caret line="24" lean-forward="true" selection-start-line="24" selection-end-line="24" /> <state relative-caret-position="242"> <caret line="35" column="55" lean-forward="true" selection-start-line="35" selection-start-column="55" selection-end-line="35" selection-end-column="55" /> </state> </provider> <provider editor-type-id="android-designer2" /> @@ -249,8 +267,8 @@ <option value="$PROJECT_DIR$/BuWanVideo/build.gradle" /> <option value="$PROJECT_DIR$/BuWanVideo/res/layout/video_detail_activity.xml" /> <option value="$PROJECT_DIR$/BuWanVideo/res/layout/item_video_detail_ad.xml" /> <option value="$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/VideoDetailVideoAdFragment.java" /> <option value="$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/media/VideoDetailActivity.java" /> <option value="$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/VideoDetailVideoAdFragment.java" /> </list> </option> </component> @@ -276,16 +294,6 @@ <item name="AndroidBuWanVideoProject" type="b2602c69:ProjectViewProjectNode" /> <item name="AndroidBuWanVideoProject" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" /> </path> <path> <item name="AndroidBuWanVideoProject" type="b2602c69:ProjectViewProjectNode" /> <item name="AndroidBuWanVideoProject" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" /> <item name="BuWanVideo" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" /> </path> <path> <item name="AndroidBuWanVideoProject" type="b2602c69:ProjectViewProjectNode" /> <item name="AndroidBuWanVideoProject" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" /> <item name="library-mine" type="8a07ba80:GradleTreeStructureProvider$GradleModuleDirectoryNode" /> </path> </expand> <select /> </subPane> @@ -309,7 +317,7 @@ <property name="android.project.structure.proportion" value="0.15" /> <property name="android.sdk.path" value="F:/Android/android-sdk" /> <property name="device.picker.selection" value="220c8e92" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/BuWanVideo/res/drawable-xhdpi" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="project.structure.last.edited" value="Dependencies" /> <property name="project.structure.proportion" value="0.17" /> <property name="project.structure.side.proportion" value="0.3819797" /> @@ -326,11 +334,11 @@ <recent name="com.weikou.beibeivideo.util" /> </key> <key name="CopyFile.RECENT_KEYS"> <recent name="D:\workspace\Android\buwan\AndroidBuWanVideoProject" /> <recent name="D:\workspace\Android\buwan\AndroidBuWanVideoProject\BuWanVideo\res\drawable-xhdpi" /> <recent name="D:\workspace\Android\buwan\AndroidBuWanVideoProject\BuWanVideo\libs" /> <recent name="D:\workspace\Android\buwan\AndroidBuWanVideoProject\BuWanVideo\res\layout" /> <recent name="D:\workspace\Android\buwan\AndroidBuWanVideoProject\BuWanVideo\res\drawable-hdpi" /> <recent name="D:\workspace\Android\buwan\AndroidBuWanVideoProject\BuWanVideo\res\drawable-ldpi" /> </key> </component> <component name="RunDashboard"> @@ -476,7 +484,7 @@ <frame x="1912" y="-8" width="1936" height="1056" extended-state="6" /> <editor active="true" /> <layout> <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.18656716" /> <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.1913646" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" /> <window_info id="Favorites" order="2" side_tool="true" /> <window_info id="Build Variants" order="3" side_tool="true" /> @@ -578,19 +586,19 @@ </line-breakpoint> <line-breakpoint enabled="true" type="java-line"> <url>file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/VideoDetailVideoAdFragment.java</url> <line>176</line> <line>173</line> <properties /> <option name="timeStamp" value="189" /> </line-breakpoint> <line-breakpoint enabled="true" type="java-line"> <url>file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/VideoDetailVideoAdFragment.java</url> <line>97</line> <line>94</line> <properties /> <option name="timeStamp" value="190" /> </line-breakpoint> <line-breakpoint enabled="true" type="java-line"> <url>file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/VideoDetailVideoAdFragment.java</url> <line>104</line> <line>101</line> <properties /> <option name="timeStamp" value="191" /> </line-breakpoint> @@ -647,13 +655,6 @@ </expressions> </component> <component name="editorHistoryManager"> <entry file="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/recyclerview-v7/27.1.1/ad225a74247e675db0b05ea4f8b17202acbb7f9d/recyclerview-v7-27.1.1-sources.jar!/android/support/v7/widget/RecyclerView.java"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="284"> <caret line="1618" column="16" selection-start-line="1618" selection-start-column="16" selection-end-line="1618" selection-end-column="16" /> </state> </provider> </entry> <entry file="file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/category/StarDetailFragment.java"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="44"> @@ -1059,33 +1060,25 @@ </state> </provider> </entry> <entry file="file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/VideoDetailVideoAdFragment.java"> <entry file="file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/media/VideoDetailFragment.java"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="111"> <caret line="94" column="36" lean-forward="true" selection-start-line="94" selection-start-column="36" selection-end-line="94" selection-end-column="36" /> <folding> <element signature="imports" expanded="true" /> <element signature="e#3692#3693#0" expanded="true" /> <element signature="e#793#794#0" expanded="true" /> <element signature="e#852#853#0" expanded="true" /> <element signature="e#6761#7048#0" expanded="true" /> <element signature="e#7047#7048#0" expanded="true" /> <element signature="e#6250#6251#0" expanded="true" /> <element signature="e#6351#6352#0" expanded="true" /> <element signature="e#6450#6451#0" expanded="true" /> <element signature="e#6547#6548#0" expanded="true" /> <element signature="e#6663#6664#0" expanded="true" /> <element signature="e#6758#6759#0" expanded="true" /> <element signature="e#12190#12539#0" expanded="true" /> <element signature="e#12538#12539#0" expanded="true" /> </folding> <state relative-caret-position="396"> <caret line="63" column="59" lean-forward="true" selection-start-line="63" selection-start-column="59" selection-end-line="63" selection-end-column="59" /> </state> </provider> </entry> <entry file="file://$PROJECT_DIR$/BuWanVideo/res/layout/video_detail_fragment.xml"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="242"> <caret line="35" column="55" lean-forward="true" selection-start-line="35" selection-start-column="55" selection-end-line="35" selection-end-column="55" /> </state> </provider> <provider editor-type-id="android-designer2" /> </entry> <entry file="file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/media/VideoDetailActivity.java"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="274"> <caret line="519" column="59" selection-start-line="519" selection-start-column="40" selection-end-line="519" selection-end-column="59" /> <state relative-caret-position="226"> <caret line="102" column="26" selection-start-line="102" selection-start-column="12" selection-end-line="102" selection-end-column="38" /> <folding> <element signature="e#16029#16030#0" expanded="true" /> <element signature="e#16069#16070#0" expanded="true" /> @@ -1099,20 +1092,19 @@ </state> </provider> </entry> <entry file="file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/media/VideoDetailFragment.java"> <entry file="file://$PROJECT_DIR$/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/VideoDetailVideoAdFragment.java"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="396"> <caret line="63" column="59" lean-forward="true" selection-start-line="63" selection-start-column="59" selection-end-line="63" selection-end-column="59" /> <state relative-caret-position="792"> <caret line="36" column="27" lean-forward="true" selection-start-line="36" selection-start-column="27" selection-end-line="36" selection-end-column="27" /> </state> </provider> </entry> <entry file="file://$PROJECT_DIR$/BuWanVideo/res/layout/video_detail_fragment.xml"> <entry file="file://$PROJECT_DIR$/.gitignore"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="198"> <caret line="24" lean-forward="true" selection-start-line="24" selection-end-line="24" /> <state relative-caret-position="224"> <caret line="18" column="6" lean-forward="true" selection-start-line="18" selection-start-column="6" selection-end-line="18" selection-end-column="6" /> </state> </provider> <provider editor-type-id="android-designer2" /> </entry> </component> <component name="masterDetails"> BuWanVideo/libs/tbs_sdk_thirdapp_v4.3.0.1020_43633_sharewithdownload_withoutGame_obfs_20190111_105200.jarBinary files differ
BuWanVideo/res/layout/item_video_detail_ad.xml
New file @@ -0,0 +1,194 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center"> <com.qq.e.ads.nativ.widget.NativeAdContainer android:id="@+id/native_ad_container" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:id="@+id/video_btns_container" android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginTop="6dp" android:orientation="horizontal" android:visibility="gone"> <CheckBox android:id="@+id/btn_mute" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="静音" android:textSize="14sp" /> <Button android:id="@+id/btn_play" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="6dp" android:layout_weight="1" android:text="播放" android:textColor="#080" android:textSize="14sp" /> <Button android:id="@+id/btn_pause" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="6dp" android:layout_weight="1" android:text="暂停" android:textColor="#00f" android:textSize="14sp" /> <Button android:id="@+id/btn_stop" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="6dp" android:layout_weight="1" android:text="停止" android:textColor="#f00" android:textSize="14sp" /> </LinearLayout> <FrameLayout android:id="@+id/custom_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true"> <!-- 原生广告的视频组件 --> <com.qq.e.ads.nativ.MediaView android:id="@+id/gdt_media_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#000" /> <!-- 原生广告的大图 --> <ImageView android:id="@+id/img_poster" android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="fitXY" /> <ProgressBar android:id="@+id/pb_progress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:visibility="gone"> </ProgressBar> <TextView android:id="@+id/tv_skip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:layout_margin="3dp" android:background="@drawable/shape_splash_ad" android:clickable="false" android:paddingLeft="8dp" android:paddingTop="2dp" android:paddingRight="8dp" android:paddingBottom="2dp" android:text="" android:textColor="@color/white" android:textSize="14sp" android:visibility="gone"> </TextView> </FrameLayout> <RelativeLayout android:id="@+id/ad_info_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="10dp" android:visibility="gone"> <!-- 原生广告的小图 --> <ImageView android:id="@+id/img_logo" android:layout_width="64dp" android:layout_height="64dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="10dp" android:layout_marginRight="10dp" android:layout_marginBottom="10dp" /> <!-- 原生广告的点击按钮 --> <Button android:id="@+id/btn_download" android:layout_width="60dp" android:layout_height="30dp" android:layout_alignTop="@id/img_logo" android:layout_alignParentRight="true" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="#80000000" android:textColor="@android:color/white" android:textSize="14sp" /> <Button android:id="@+id/btn_cta" android:layout_width="60dp" android:layout_height="30dp" android:layout_alignTop="@id/img_logo" android:layout_alignParentRight="true" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:layout_marginRight="10dp" android:background="#80000000" android:textColor="@android:color/white" android:textSize="14sp" android:visibility="invisible" /> <!-- 原生广告的标题 --> <TextView android:id="@+id/text_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/img_logo" android:layout_marginLeft="6dp" android:layout_toLeftOf="@id/btn_download" android:layout_toRightOf="@id/img_logo" android:ellipsize="end" android:singleLine="true" android:textColor="#e0000000" /> <!-- 原生广告的描述 --> <TextView android:id="@+id/text_desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/text_title" android:layout_alignBottom="@id/img_logo" android:layout_marginLeft="6dp" android:layout_marginRight="6dp" android:layout_toLeftOf="@id/btn_download" android:layout_toRightOf="@id/img_logo" android:ellipsize="end" android:maxLines="2" android:textColor="#a0000000" /> </RelativeLayout> </LinearLayout> </com.qq.e.ads.nativ.widget.NativeAdContainer> </LinearLayout> BuWanVideo/src/com/weikou/beibeivideo/ui/ad/VideoDetailVideoAdFragment.java
New file @@ -0,0 +1,429 @@ package com.weikou.beibeivideo.ui.ad; import android.content.Context; import android.graphics.Bitmap; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.animation.GlideAnimation; import com.bumptech.glide.request.target.SimpleTarget; import com.qq.e.ads.cfg.VideoOption; import com.qq.e.ads.nativ.MediaView; import com.qq.e.ads.nativ.NativeADEventListener; import com.qq.e.ads.nativ.NativeADMediaListener; import com.qq.e.ads.nativ.NativeADUnifiedListener; import com.qq.e.ads.nativ.NativeUnifiedAD; import com.qq.e.ads.nativ.NativeUnifiedADData; import com.qq.e.ads.nativ.VideoPreloadListener; import com.qq.e.ads.nativ.widget.NativeAdContainer; import com.qq.e.comm.constants.AdPatternType; import com.qq.e.comm.util.AdError; import com.yeshi.buwanshequ.R; import java.util.ArrayList; import java.util.Calendar; import java.util.List; public class VideoDetailVideoAdFragment extends Fragment implements View.OnClickListener { private MediaView mediaView; private NativeAdContainer mContainer; private NativeUnifiedADData mAdData; private TextView tv_skip; private ProgressBar pb_progress; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); } private ImageView iv_logo, img_poster; private TextView text_title; private TextView text_desc; private Button mCTAButton, mDownloadButton; private void initView(View root) { mediaView = root.findViewById(R.id.gdt_media_view); mContainer = root.findViewById(R.id.native_ad_container); iv_logo = root.findViewById(R.id.img_logo); img_poster = root.findViewById(R.id.img_poster); text_title = root.findViewById(R.id.text_title); text_desc = root.findViewById(R.id.text_desc); mCTAButton = root.findViewById(R.id.btn_cta); mDownloadButton = root.findViewById(R.id.btn_download); tv_skip = root.findViewById(R.id.tv_skip); pb_progress = root.findViewById(R.id.pb_progress); } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = LayoutInflater.from(getContext()).inflate(R.layout.item_video_detail_ad, null); initView(root); // loadVideoAD(); tv_skip.setOnClickListener(this); return root; } private Runnable timer = null; private synchronized void autoTimer(final View view) { if (timer == null) { timer = new Runnable() { @Override public void run() { if (remainTime - (mAdData.getVideoCurrentPosition() / 1000) > 0) { tv_skip.setText((remainTime - (mAdData.getVideoCurrentPosition() / 1000)) + "s后可跳过"); tv_skip.setClickable(false); } else { tv_skip.setText("跳过"); tv_skip.setClickable(true); } autoTimer(view); } }; view.postDelayed(timer, 1000); } else { view.removeCallbacks(timer); view.postDelayed(timer, 1000); } } int remainTime = 0; public void loadVideoAD(final IVideoAdListener videoAdListener) { tv_skip.setVisibility(View.GONE); if (mAdData != null) mAdData.destroy(); NativeUnifiedAD mAdManager = new NativeUnifiedAD(getContext(), "5061928359494942", new NativeADUnifiedListener() { @Override public void onNoAD(AdError adError) { System.out.println(adError); } @Override public void onADLoaded(List<NativeUnifiedADData> list) { System.out.println(list); final NativeUnifiedADData ad = list.get(0); //填充内容 mAdData = ad; renderAdUi(ad); List<View> clickableViews = new ArrayList<>(); clickableViews.add(mDownloadButton); ad.bindAdToView(getContext(), mContainer, null, clickableViews); if (ad.getAdPatternType() == AdPatternType.NATIVE_VIDEO) { final String TAG = "NativeUnifiedADData"; // 如果是视频广告,可以调用preloadVideo预加载视频素材 ad.preloadVideo(new VideoPreloadListener() { @Override public void onVideoCached() { Log.d(TAG, "onVideoCached"); //展示广告 VideoOption videoOption = getVideoOption(); ad.bindMediaView(mediaView, videoOption, new NativeADMediaListener() { @Override public void onVideoInit() { Log.d(TAG, "onVideoInit: "); pb_progress.setVisibility(View.VISIBLE); } @Override public void onVideoLoading() { Log.d(TAG, "onVideoLoading: "); } @Override public void onVideoReady() { Log.d(TAG, "onVideoReady"); img_poster.setVisibility(View.GONE); pb_progress.setVisibility(View.GONE); } @Override public void onVideoLoaded(int videoDuration) { Log.d(TAG, "onVideoLoaded: "); } @Override public void onVideoStart() { Log.d(TAG, "onVideoStart"); if (ad.getVideoDuration() / 1000 > 10) remainTime = 10; else remainTime = ad.getVideoDuration() / 1000; videoAdListener.startPlay(); autoTimer(img_poster); img_poster.post(new Runnable() { @Override public void run() { tv_skip.setVisibility(View.VISIBLE); } }); } @Override public void onVideoPause() { Log.d(TAG, "onVideoPause: "); } @Override public void onVideoResume() { Log.d(TAG, "onVideoResume: "); } @Override public void onVideoCompleted() { Log.d(TAG, "onVideoCompleted: "); tv_skip.setVisibility(View.GONE); if (videoAdListener != null) { videoAdListener.finishPlay(); } } @Override public void onVideoError(AdError error) { Log.d(TAG, "onVideoError: "); if (videoAdListener != null) { videoAdListener.finishPlay(); } } @Override public void onVideoStop() { Log.d(TAG, "onVideoStop"); } @Override public void onVideoClicked() { Log.d(TAG, "onVideoClicked"); } }); ad.setNativeAdEventListener(new NativeADEventListener() { @Override public void onADExposed() { Log.d(TAG, "onADExposed"); } @Override public void onADClicked() { Log.d(TAG, "onADClicked"); } @Override public void onADError(AdError adError) { Log.d(TAG, "onADError"); } @Override public void onADStatusChanged() { Log.d(TAG, "onADStatusChanged"); updateAdAction(mDownloadButton, ad); } }); updateAdAction(mDownloadButton, ad); List<View> CTAViews = new ArrayList<>(); CTAViews.add(mCTAButton); ad.bindCTAViews(CTAViews); String ctaText = ad.getCTAText(); //获取组件文案 if (!TextUtils.isEmpty(ctaText)) { //如果拉取广告包含CTA组件,则渲染该组件 //当广告中有营销组件时,隐藏下载按钮,仅为demo示例所用,开发者可自行决定mDownloadButton按钮是否显示 mCTAButton.setText(ctaText); mCTAButton.setVisibility(View.VISIBLE); mDownloadButton.setVisibility(View.INVISIBLE); } ad.startVideo(); } @Override public void onVideoCacheFailed(int errorNo, String msg) { Log.d(TAG, "onVideoCacheFailed:" + msg); } }); } } }); mAdManager.setVastClassName("com.qq.e.union.demo.adapter.vast.unified.ImaNativeDataAdapter"); mAdManager.setVideoPlayPolicy(getVideoPlayPolicy(getContext())); mAdManager.setVideoADContainerRender(VideoOption.VideoADContainerRender.SDK); mAdManager.loadData(1); tv_skip.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mAdData != null) mAdData.stopVideo(); if (videoAdListener != null) videoAdListener.finishPlay(); tv_skip.setVisibility(View.GONE); } }); } public static void updateAdAction(Button button, NativeUnifiedADData ad) { if (!ad.isAppAd()) { button.setText("浏览"); return; } switch (ad.getAppStatus()) { case 0: button.setText("下载"); break; case 1: button.setText("启动"); break; case 2: button.setText("更新"); break; case 4: button.setText(ad.getProgress() + "%"); break; case 8: button.setText("安装"); break; case 16: button.setText("下载失败,重新下载"); break; default: button.setText("浏览"); break; } } private void renderAdUi(final NativeUnifiedADData ad) { int patternType = ad.getAdPatternType(); if (patternType == AdPatternType.NATIVE_VIDEO) { Glide.with(getContext()).load(ad.getIconUrl()).into(iv_logo); Glide.with(getContext()).load(ad.getImgUrl()) .asBitmap().into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { if (img_poster.getVisibility() == View.VISIBLE) { img_poster.setImageBitmap(resource); } } }); text_title.setText(ad.getTitle()); text_desc.setText(ad.getDesc()); } } @Nullable public static VideoOption getVideoOption() { VideoOption.Builder builder = new VideoOption.Builder(); builder.setAutoPlayPolicy(VideoOption.AutoPlayPolicy.NEVER); builder.setAutoPlayMuted(true); builder.setDetailPageMuted(false); builder.setNeedCoverImage(true); builder.setNeedProgressBar(false); builder.setEnableDetailPage(true); builder.setEnableUserControl(false); return builder.build(); } public static int getVideoPlayPolicy(Context context) { if (1 > 0) return VideoOption.VideoPlayPolicy.MANUAL; VideoOption option = getVideoOption(); if (option == null) { return VideoOption.VideoPlayPolicy.AUTO; } int autoPlayPolicy = option.getAutoPlayPolicy(); if (autoPlayPolicy == VideoOption.AutoPlayPolicy.ALWAYS) { return VideoOption.VideoPlayPolicy.AUTO; } else if (autoPlayPolicy == VideoOption.AutoPlayPolicy.WIFI) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetworkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return wifiNetworkInfo != null && wifiNetworkInfo.isConnected() ? VideoOption.VideoPlayPolicy.AUTO : VideoOption.VideoPlayPolicy.MANUAL; } else if (autoPlayPolicy == VideoOption.AutoPlayPolicy.NEVER) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); int hour = calendar.get(Calendar.HOUR_OF_DAY); // 简单的播放策略示例,虽然VideoOption设置了从不自动播放,SDK不会主动触发自动播放 // 但晚上10点以后,开发者自行调用了startVideoPlay进行了视频播放 // 这在用户看来仍然是"自动播放"的,因为用户没有进行任何操作,视频就开始播放了 return hour >= 22 ? VideoOption.VideoPlayPolicy.AUTO : VideoOption.VideoPlayPolicy.MANUAL; } return VideoOption.VideoPlayPolicy.UNKNOWN; } @Override public void onResume() { super.onResume(); if (mAdData != null) { // 必须要在Activity.onResume()时通知到广告数据,以便重置广告恢复状态 mAdData.resume(); } } @Override public void onDestroy() { super.onDestroy(); if (mAdData != null) { // 必须要在Actiivty.destroy()时通知到广告数据,以便释放内存 mAdData.destroy(); } } @Override public void onClick(View v) { switch (v.getId()) { case R.id.tv_skip: break; } } public interface IVideoAdListener { //结束播放 public void finishPlay(); //开始播放 public void startPlay(); } }