Commit aa0927d3 authored by 王雪伟's avatar 王雪伟

激励视频

parent 1cb23e3f
...@@ -21,5 +21,10 @@ ...@@ -21,5 +21,10 @@
<option name="name" value="Google" /> <option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" /> <option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
</component> </component>
</project> </project>
\ No newline at end of file
package com.ym.zxhcsdkaar; package com.ym.zxhcsdkaar;
import android.app.Activity; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
...@@ -11,11 +12,14 @@ import com.ym.zxhcsdk.HcDownLoadUtils; ...@@ -11,11 +12,14 @@ import com.ym.zxhcsdk.HcDownLoadUtils;
import com.ym.zxhcsdk.HcAdBean; import com.ym.zxhcsdk.HcAdBean;
import com.ym.zxhcsdk.PhoneUtils; import com.ym.zxhcsdk.PhoneUtils;
import com.ym.zxhcsdk.ZXHCConstant; import com.ym.zxhcsdk.ZXHCConstant;
import com.ym.zxhcsdk.ads.RewardvideoPortraitADActivity;
import com.ym.zxhcsdk.listener.FeedAdListener; import com.ym.zxhcsdk.listener.FeedAdListener;
import com.ym.zxhcsdk.listener.RewardVideoAdLoadListener;
import com.ym.zxhcsdk.listener.SplashAdListener; import com.ym.zxhcsdk.listener.SplashAdListener;
import com.ym.zxhcsdk.manager.ZXHCADManager; import com.ym.zxhcsdk.manager.ZXHCADManager;
import com.ym.zxhcsdk.manager.ZXHCAdViewManager; import com.ym.zxhcsdk.manager.ZXHCAdViewManager;
import com.ym.zxhcsdk.view.ZXHCFeedAD; import com.ym.zxhcsdk.view.ZXHCFeedAD;
import com.ym.zxhcsdk.view.ZXHCRewardVideoAD;
import com.ym.zxhcsdk.view.ZXHCSplashAD; import com.ym.zxhcsdk.view.ZXHCSplashAD;
public class MainActivity extends Activity { public class MainActivity extends Activity {
...@@ -29,7 +33,7 @@ public class MainActivity extends Activity { ...@@ -29,7 +33,7 @@ public class MainActivity extends Activity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
ZXHCADManager.getInstance().InitAd(this, "1000127", true); ZXHCADManager.getInstance().InitAd(this, "1000127", true);
Splash(); //Splash();
// ZXHCADManager.getInstance().InitAd(this, "1000298", true); // ZXHCADManager.getInstance().InitAd(this, "1000298", true);
String url = "http://sspv2test.zhangxinhuichuan.com/ssp/v1/ads?pid=2100154&type=api&ad_type=3&ad_w=480&ad_h=720&app_package=com.popcap.pvz2cthd&app_id=1000127&app_name=com.popcap.pvz2cthd&app_versionid=1005&device_geo_lat=&device_geo_lon=&device_imei=X6GNU17524105082&device_adid=d0cf1c3d5280f16b&device_mac=F0:C8:50:A1:4E:8E&device_width=1920&device_height=1132&device_imsi=460000501365163&device_carrier=&device_network=1&device_os=Android&device_os_version=24&device_density=2.0&device_ppi=2.0&device_ip=183.211.87.156&device_ua=Dalvik%2F2.1.0+%28Linux%3B+U%3B+Android+9%3B+Redmi+Note+8+Pro+MIUI%2FV10.4.9.0.PGGCNXM%29&device_type=0&is_mobile=1&device_model=FLA-AL10&device_brand=HUAWEI"; String url = "http://sspv2test.zhangxinhuichuan.com/ssp/v1/ads?pid=2100154&type=api&ad_type=3&ad_w=480&ad_h=720&app_package=com.popcap.pvz2cthd&app_id=1000127&app_name=com.popcap.pvz2cthd&app_versionid=1005&device_geo_lat=&device_geo_lon=&device_imei=X6GNU17524105082&device_adid=d0cf1c3d5280f16b&device_mac=F0:C8:50:A1:4E:8E&device_width=1920&device_height=1132&device_imsi=460000501365163&device_carrier=&device_network=1&device_os=Android&device_os_version=24&device_density=2.0&device_ppi=2.0&device_ip=183.211.87.156&device_ua=Dalvik%2F2.1.0+%28Linux%3B+U%3B+Android+9%3B+Redmi+Note+8+Pro+MIUI%2FV10.4.9.0.PGGCNXM%29&device_type=0&is_mobile=1&device_model=FLA-AL10&device_brand=HUAWEI";
String BaseUrl = "http://sspv2test.zhangxinhuichuan.com/ssp/v1/ads"; String BaseUrl = "http://sspv2test.zhangxinhuichuan.com/ssp/v1/ads";
...@@ -116,6 +120,14 @@ public class MainActivity extends Activity { ...@@ -116,6 +120,14 @@ public class MainActivity extends Activity {
} }
}); });
findViewById(R.id.RewardAd).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RewardAd();
}
});
} }
private void Splash(){ private void Splash(){
...@@ -152,4 +164,19 @@ public class MainActivity extends Activity { ...@@ -152,4 +164,19 @@ public class MainActivity extends Activity {
}, 3); }, 3);
zxhcSplashAD.fetchAdOnly(); zxhcSplashAD.fetchAdOnly();
} }
private void RewardAd(){
new ZXHCRewardVideoAD(this,"1100139").loadRewardAD(new RewardVideoAdLoadListener() {
@Override
public void OnAdLoaded() {
startActivity(new Intent(MainActivity.this, RewardvideoPortraitADActivity.class));
}
@Override
public void OnLoadError(String error) {
}
});
}
} }
\ No newline at end of file
...@@ -24,7 +24,11 @@ ...@@ -24,7 +24,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="test_DownLoad"></Button> android:text="test_DownLoad"></Button>
<Button
android:id="@+id/RewardAd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="激励视频"></Button>
<FrameLayout <FrameLayout
android:id="@+id/test_img_ad" android:id="@+id/test_img_ad"
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
...@@ -16,6 +16,7 @@ allprojects { ...@@ -16,6 +16,7 @@ allprojects {
repositories { repositories {
google() google()
jcenter() jcenter()
maven { url 'https://jitpack.io' }
} }
} }
......
...@@ -34,4 +34,7 @@ dependencies { ...@@ -34,4 +34,7 @@ dependencies {
api fileTree(include: ['*.aar'], dir: 'libs') api fileTree(include: ['*.aar'], dir: 'libs')
api 'com.android.support:design:28.0.0' api 'com.android.support:design:28.0.0'
api 'com.android.support:support-v4:28.0.0' api 'com.android.support:support-v4:28.0.0'
// implementation 'com.android.support:appcompat-v7:28.0.0'
// implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.badoo:android-weak-handler:1.2'
} }
\ No newline at end of file
...@@ -14,33 +14,28 @@ ...@@ -14,33 +14,28 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 如果有视频相关的广告且使用textureView播放,请务必添加,否则黑屏 --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 如果有视频相关的广告且使用textureView播放,请务必添加,否则黑屏 -->
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<application> <application android:theme="@android:style/Theme.Light.NoTitleBar">
<activity android:name=".ads.RewardvideoPortraitADActivity"/>
<activity <activity
android:name="com.ym.zxhcsdk.webview.HcWebActivity" android:name=".webview.HcWebActivity"
android:exported="true" android:exported="true"
android:screenOrientation="fullSensor"> android:screenOrientation="fullSensor">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<!-- <provider-->
<!-- android:name="android.support.v4.content.FileProvider"--> <provider
<!-- android:authorities="${applicationId}.fileProvider"--> android:name="android.support.v4.content.FileProvider"
<!-- android:exported="false"--> android:authorities="${applicationId}.zxhc.fileProvider"
<!-- android:grantUriPermissions="true">--> android:exported="false"
<!-- <meta-data--> android:grantUriPermissions="true">
<!-- android:name="android.support.FILE_PROVIDER_PATHS"--> <meta-data
<!-- android:resource="@xml/file_paths" />--> android:name="android.support.FILE_PROVIDER_PATHS"
<!-- </provider>--> android:resource="@xml/file_paths" />
<!-- <provider--> </provider>
<!-- android:name="android.support.v4.content.FileProvider"-->
<!-- android:authorities="${applicationId}.fileProvider"-->
<!-- android:exported="false"-->
<!-- android:grantUriPermissions="true">-->
<!-- <meta-data-->
<!-- android:name="android.support.FILE_PROVIDER_PATHS"-->
<!-- android:resource="@xml/file_paths" />-->
<!-- </provider>-->
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -151,7 +151,7 @@ public class HcDownLoadUtils { ...@@ -151,7 +151,7 @@ public class HcDownLoadUtils {
File file = new File(adBean.getDownLoadFilePath()); File file = new File(adBean.getDownLoadFilePath());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//参数1 上下文, 参数2 Provider主机地址 和配置文件中保持一致 参数3 共享的文件 //参数1 上下文, 参数2 Provider主机地址 和配置文件中保持一致 参数3 共享的文件
Uri apkUri = FileProvider.getUriForFile(activity, PhoneUtils.getInstance().getAppPackage() + ".fileProvider", file); Uri apkUri = FileProvider.getUriForFile(activity, PhoneUtils.getInstance().getAppPackage() + ".zxhc.fileProvider", file);
//添加这一句表示对目标应用临时授权该Uri所代表的文件 //添加这一句表示对目标应用临时授权该Uri所代表的文件
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(apkUri, "application/vnd.android.package-archive"); intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
......
package com.ym.zxhcsdk.ads;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.badoo.mobile.util.WeakHandler;
import com.ym.zxhcsdk.R;
import java.io.IOException;
public class RewardvideoPortraitADActivity extends Activity implements SurfaceHolder.Callback {
private MediaPlayer mPlayer = null;
private SurfaceView sfv_reward_show;
private SurfaceHolder surfaceHolder;
private FrameLayout frameView;
private TextView bottomTitle;
private TextView bottomDesc;
private ImageView bottomIcon;
private TextView bottomBtnTv;
private TextView TopTimeTv;
private ImageView TopClose;
private WeakHandler mHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rewardvideo_portrait_a_d);
mHandler = new WeakHandler();
bindViews();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
return true;
}
return super.onKeyDown(keyCode, event);
}
private void bindViews() {
sfv_reward_show = findViewById(R.id.sfv_reward_video_ad_show);
frameView = findViewById(R.id.frame_content);
bottomTitle = findViewById(R.id.reward_video_ad_title);
bottomDesc = findViewById(R.id.reward_video_ad_desc);
bottomIcon = findViewById(R.id.reward_ad_app_icon);
bottomBtnTv = findViewById(R.id.reward_video_ad_btn);
TopTimeTv = findViewById(R.id.reward_ad_time);
TopClose = findViewById(R.id.reward_ad_close);
//初始化SurfaceHolder类,SurfaceView的控制器
surfaceHolder = sfv_reward_show.getHolder();
surfaceHolder.addCallback(this);
SetAdVideo();
TopClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
private void SetAdVideo(){
TopClose.setVisibility(View.GONE);
TopTimeTv.setVisibility(View.VISIBLE);
}
@Override
protected void onResume() {
super.onResume();
if (mPlayer!=null){
if (!mPlayer.isPlaying()){
mPlayer.start();
}
}
}
@Override
protected void onPause() {
super.onPause();
if (mPlayer!=null){
if (mPlayer.isPlaying()){
mPlayer.pause();
}
}
}
@Override
protected void onDestroy() {
if (mPlayer!=null){
mPlayer.release();
mPlayer=null;
}
super.onDestroy();
}
@Override
public void surfaceCreated(@NonNull SurfaceHolder holder) {
Log.d("wxw", "surfaceCreated");
if (mPlayer!=null){
mPlayer.setDisplay(surfaceHolder);
return;
}
try {
mPlayer = new MediaPlayer();
mPlayer.setDataSource("https://zx-cdn.zhangxinhulian.com/file/2020/5/8447fa5488ee19a54d2adbe8d127693045540211.mp4");
mPlayer.setDisplay(surfaceHolder);
mPlayer.prepareAsync();
//网络流媒体的缓冲监听
mPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.d("wxw", "percent" + percent);
if (percent==100){
mp.start();
}
Log.d("wxw", "mp.getCurrentPosition() " + mp.getCurrentPosition());
}
});
//网络流媒体播放结束监听
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.d("wxw", "MediaPlayer onCompletion");
TopClose.setVisibility(View.VISIBLE);
TopTimeTv.setVisibility(View.GONE);
}
});
//设置错误信息监听
mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.d("wxw", "MediaPlayer error " + what + " extra " + extra);
TopClose.setVisibility(View.VISIBLE);
TopTimeTv.setVisibility(View.GONE);
return false;
}
});
//视频尺寸监听
mPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
// int phoneWidth = PhoneUtils.getInstance().getScreenWidth(RewardvideoPortraitADActivity.this);
// float pro = height / (float) width;
// ViewGroup.LayoutParams layoutParams = frameView.getLayoutParams();
// layoutParams.width = phoneWidth;
// layoutParams.height = (int) (phoneWidth * pro);
// frameView.setLayoutParams(layoutParams);
Log.d("wxw", "mp.getCurrentPosition() " + mp.getCurrentPosition());
}
});
//mPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
Log.d("wxw", "surfaceChanged");
}
@Override
public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
Log.d("wxw", "surfaceDestroyed");
}
private int delayTime;
CountDownTimer countDownTimer = null;
private void countDown(int time, TextView textView) {
long times = time * 1000;
//时间 倒计时 入参long类型
countDownTimer = new CountDownTimer(times, 1000) {
@Override
public void onTick(long millisUntilFinished) {
delayTime = (int) millisUntilFinished / 1000;
textView.setText(delayTime + "");
if (delayTime == 0) {
textView.setText("跳过");
}
}
@Override
public void onFinish() {
countDownTimer.cancel();
countDownTimer = null;
}
};
countDownTimer.start();
}
}
\ No newline at end of file
package com.ym.zxhcsdk.listener;
public interface RewardVideoAdLoadListener {
/// <summary>
/// 广告加载成功,可在此回调后进行广告展示
/// </summary>
void OnAdLoaded();
/// <summary>
/// 激励视频广告各种错误信息回调
/// </summary>
void OnLoadError(String error);
}
package com.ym.zxhcsdk.listener; package com.ym.zxhcsdk.listener;
public interface RewardVideoAdListener { public interface RewardVideoAdShowListener {
/// <summary>
/// 广告加载成功,可在此回调后进行广告展示
/// </summary>
void OnAdLoaded();
/// <summary>
/// 激励视频数据下载成功回调,已经下载过的视频会直接回调
/// </summary>
void OnVideoCached();
/// <summary> /// <summary>
/// 激励视频广告页面展示回调 /// 激励视频广告页面展示回调
/// </summary> /// </summary>
void OnAdShown(); void OnAdShow();
/// <summary> /// <summary>
/// 激励视频广告曝光回调 /// 激励视频广告奖励
/// </summary> /// </summary>
void OnAdExposured(); void OnRewardVerify();
/// <summary> /// <summary>
/// 激励视频广告信息点击回调 /// 激励视频广告信息点击回调
...@@ -41,6 +30,6 @@ public interface RewardVideoAdListener { ...@@ -41,6 +30,6 @@ public interface RewardVideoAdListener {
/// <summary> /// <summary>
/// 激励视频广告各种错误信息回调 /// 激励视频广告各种错误信息回调
/// </summary> /// </summary>
void OnError(String error); void OnVideoError(String error);
} }
package com.ym.zxhcsdk.view;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import com.ym.zxhcsdk.HcAdBean;
import com.ym.zxhcsdk.HttpClientUtils;
import com.ym.zxhcsdk.PhoneUtils;
import com.ym.zxhcsdk.ZXHCConstant;
import com.ym.zxhcsdk.listener.FeedAdListener;
import com.ym.zxhcsdk.listener.RewardVideoAdLoadListener;
import java.util.HashMap;
import java.util.Map;
public class ZXHCRewardVideoAD {
private Activity context;
private String codeId;
public ZXHCRewardVideoAD(Activity context, String codeId) {
this.context = context;
this.codeId = codeId;
}
private HcAdBean adBean;
public void loadRewardAD(RewardVideoAdLoadListener mlistener) {
Map<String, String> map = new HashMap<>();
map.put("pid", codeId);
map.put("type", "api");
map.put("ad_type", "3");
map.put("ad_w",PhoneUtils.getInstance().getScreenWidth(context)+"");
map.put("ad_h",PhoneUtils.getInstance().getScreenHeight(context)+"");
HttpClientUtils.get(ZXHCConstant.BASE_URL, map, new HttpClientUtils.OnRequestCallBack() {
@Override
public void onSuccess(String json) {
adBean = PhoneUtils.getInstance().jsonToObj(json);
adBean.setShowReport(false);
adBean.setClickReport(false);
adBean.setClickDpLinkSucReport(false);
adBean.setClickDpLinkfailReport(false);
context.runOnUiThread(new Runnable() {
@Override
public void run() {
if (mlistener!=null){
mlistener.OnAdLoaded();
}
}
});
if (adBean.getSrcUrls().size() > 0) {
}
}
@Override
public void onError(String errorMsg) {
context.runOnUiThread(new Runnable() {
@Override
public void run() {
if (mlistener!=null){
mlistener.OnLoadError(errorMsg);
}
//listener.OnError(errorMsg);
}
});
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true">
<SurfaceView
android:id="@+id/sfv_reward_video_ad_show"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/reward_ad_Voice"
android:layout_width="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:src="@mipmap/arrow_left" />
<View
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="0dp"/>
<TextView
android:id="@+id/reward_ad_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:textSize="20dp"
android:textColor="#000000"
android:text=""
android:layout_marginTop="20dp" />
<ImageView
android:id="@+id/reward_ad_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:src="@mipmap/feedad_close" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:background="#ffffff"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/reward_ad_app_icon"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:background="#ffff00" />
<LinearLayout
android:id="@+id/reward_ad_desc_view"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/reward_video_ad_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:text="拼多多"
android:textColor="#000000"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+id/reward_video_ad_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:text="拼拼多多拼多多拼多多拼多多拼多多多多"
android:textSize="15dp" />
</LinearLayout>
<TextView
android:id="@+id/reward_video_ad_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="@mipmap/btn"
android:gravity="center"
android:text="下载" />
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
<resources></resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment