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

DpLink跳转异常上报,加入跳转WebView

parent 86747623
...@@ -12,6 +12,7 @@ import android.view.View; ...@@ -12,6 +12,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import com.ym.zxhcsdk.HttpClientUtils;
import com.ym.zxhcsdk.PhoneUtils; import com.ym.zxhcsdk.PhoneUtils;
import com.ym.zxhcsdk.ZXHCConstant; import com.ym.zxhcsdk.ZXHCConstant;
import com.ym.zxhcsdk.listener.FeedAdListener; import com.ym.zxhcsdk.listener.FeedAdListener;
...@@ -25,6 +26,7 @@ import java.io.File; ...@@ -25,6 +26,7 @@ import java.io.File;
public class MainActivity extends Activity { public class MainActivity extends Activity {
ZXHCFeedAD feedAD1; ZXHCFeedAD feedAD1;
ViewGroup vp;
ZXHCSplashAD zxhcSplashAD; ZXHCSplashAD zxhcSplashAD;
@Override @Override
...@@ -32,30 +34,31 @@ public class MainActivity extends Activity { ...@@ -32,30 +34,31 @@ public class MainActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
ZXHCADManager.getInstance().InitAd(this, "1000127",false); // ZXHCADManager.getInstance().InitAd(this, "1000127", true);
ZXHCADManager.getInstance().InitAd(this, "1000127", 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";
new OaidUtils().GetOaid(MainActivity.this, new IOaidListener() { new OaidUtils().GetOaid(MainActivity.this, new IOaidListener() {
@Override @Override
public void getOaid(String oaid) { public void getOaid(String oaid) {
Log.d("wxw","oaid"+oaid); Log.d("wxw", "oaid" + oaid);
ZXHCConstant.device_oaid = oaid; ZXHCConstant.device_oaid = oaid;
} }
}); });
findViewById(R.id.test_DownLoad).setOnClickListener(new View.OnClickListener() { findViewById(R.id.test_DownLoad).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
feedAD1.destroyFeedAd(vp);
} }
}); });
findViewById(R.id.test_Feed).setOnClickListener(new View.OnClickListener() { findViewById(R.id.test_Feed).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
feedAD1 = new ZXHCFeedAD(MainActivity.this, "2100155", 1080, 720, new FeedAdListener() { feedAD1 = new ZXHCFeedAD(MainActivity.this, "2100156", 1080, 720, new FeedAdListener() {
@Override @Override
public void OnAdLoaded() { public void OnAdLoaded() {
ViewGroup vp = ZXHCAdViewManager.getInstance().newFrameLayout(MainActivity.this); vp = ZXHCAdViewManager.getInstance().newFrameLayout(MainActivity.this);
ZXHCAdViewManager.getInstance().showAdView(MainActivity.this, vp, true); ZXHCAdViewManager.getInstance().showAdView(MainActivity.this, vp, true);
feedAD1.showAd(vp); feedAD1.showAd(vp);
} }
......
...@@ -15,6 +15,17 @@ ...@@ -15,6 +15,17 @@
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<application> <application>
<activity
android:name=".webview.WebActivity"
android:exported="true"
android:screenOrientation="fullSensor"
android:theme="@android:style/Theme.Light.NoTitleBar"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<provider <provider
android:name="android.support.v4.content.FileProvider" android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileProvider" android:authorities="${applicationId}.fileProvider"
......
...@@ -14,7 +14,9 @@ public class AppInstallReceive extends BroadcastReceiver { ...@@ -14,7 +14,9 @@ public class AppInstallReceive extends BroadcastReceiver {
if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_ADDED)){ if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_ADDED)){
String packageName = intent.getData().getSchemeSpecificPart(); String packageName = intent.getData().getSchemeSpecificPart();
if (!TextUtils.isEmpty(packageName)) { if (!TextUtils.isEmpty(packageName)) {
Log.d("wxw","安装完成"+ZXHCConstant.adList.size());
for (int i =0;i<ZXHCConstant.adList.size();i++){ for (int i =0;i<ZXHCConstant.adList.size();i++){
Log.d("wxw","安装完成"+ZXHCConstant.adList.get(0).getPackage_name());
if (packageName.equals(ZXHCConstant.adList.get(i).getPackage_name())){ if (packageName.equals(ZXHCConstant.adList.get(i).getPackage_name())){
InstallFinishReport(ZXHCConstant.adList.get(i)); InstallFinishReport(ZXHCConstant.adList.get(i));
ZXHCConstant.adList.remove(i); ZXHCConstant.adList.remove(i);
...@@ -26,13 +28,13 @@ public class AppInstallReceive extends BroadcastReceiver { ...@@ -26,13 +28,13 @@ public class AppInstallReceive extends BroadcastReceiver {
if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_REMOVED)){ if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_REMOVED)){
String packageName = intent.getData().getSchemeSpecificPart(); String packageName = intent.getData().getSchemeSpecificPart();
if (!TextUtils.isEmpty(packageName)) { if (!TextUtils.isEmpty(packageName)) {
Log.d("wxw","ACTION_PACKAGE_REMOVED"+ZXHCConstant.adList.size());
} }
} }
if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_REPLACED)){ if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_REPLACED)){
String packageName = intent.getData().getSchemeSpecificPart(); String packageName = intent.getData().getSchemeSpecificPart();
if (!TextUtils.isEmpty(packageName)) { if (!TextUtils.isEmpty(packageName)) {
Log.d("wxw","ACTION_PACKAGE_REPLACED"+ZXHCConstant.adList.size());
} }
} }
// intent.getAction() // intent.getAction()
......
...@@ -45,8 +45,14 @@ public class AppliContext { ...@@ -45,8 +45,14 @@ public class AppliContext {
ZXHCConstant.is_mobile = "1"; ZXHCConstant.is_mobile = "1";
ZXHCConstant.device_model = PhoneUtils.getInstance().getModel(); ZXHCConstant.device_model = PhoneUtils.getInstance().getModel();
ZXHCConstant.device_brand = Build.BRAND; ZXHCConstant.device_brand = Build.BRAND;
ZXHCConstant.device_geo_lon = PhoneUtils.getInstance().getLocationInfo(context, 1); ZXHCConstant.device_geo_lon=PhoneUtils.getInstance().getLocationInfo(context, 1);
if (TextUtils.isEmpty(ZXHCConstant.device_geo_lon)){
ZXHCConstant.device_geo_lon="-999";
}
ZXHCConstant.device_geo_lat = PhoneUtils.getInstance().getLocationInfo(context, 2); ZXHCConstant.device_geo_lat = PhoneUtils.getInstance().getLocationInfo(context, 2);
if (TextUtils.isEmpty(ZXHCConstant.device_geo_lat)){
ZXHCConstant.device_geo_lat="-999";
}
ZXHCConstant.device_geo_city = PhoneUtils.getInstance().getLocationInfo(context, 3); ZXHCConstant.device_geo_city = PhoneUtils.getInstance().getLocationInfo(context, 3);
installedReceiver = new AppInstallReceive(); installedReceiver = new AppInstallReceive();
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
......
...@@ -76,7 +76,6 @@ public class DownLoadUtils { ...@@ -76,7 +76,6 @@ public class DownLoadUtils {
} }
request.setDestinationUri(Uri.fromFile(file)); request.setDestinationUri(Uri.fromFile(file));
String filePath = file.getAbsolutePath(); String filePath = file.getAbsolutePath();
Log.d("wxw", "filePath " + filePath);
adBean.setDownLoadFilePath(filePath); adBean.setDownLoadFilePath(filePath);
//获取DownloadManager //获取DownloadManager
if (downloadManager == null) if (downloadManager == null)
...@@ -148,9 +147,8 @@ public class DownLoadUtils { ...@@ -148,9 +147,8 @@ public class DownLoadUtils {
// 由于没有在Activity环境下启动Activity,设置下面的标签 // 由于没有在Activity环境下启动Activity,设置下面的标签
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//Android 7.0以上要使用FileProvider //Android 7.0以上要使用FileProvider
File file = new File(adBean.getDownLoadFilePath());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Log.d("wxw", "getDownLoadFilePath" + adBean.getDownLoadFilePath());
File file = new File(adBean.getDownLoadFilePath());
//参数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() + ".fileProvider", file);
//添加这一句表示对目标应用临时授权该Uri所代表的文件 //添加这一句表示对目标应用临时授权该Uri所代表的文件
......
...@@ -22,7 +22,7 @@ public class HttpClientUtils { ...@@ -22,7 +22,7 @@ public class HttpClientUtils {
public static void GetEvent(String url) { public static void GetEvent(String url) {
new Thread() { new Thread() {
public void run() { public void run() {
getRequest(url, new OnRequestCallBack() { getRequest(releactReportUrl(url), new OnRequestCallBack() {
@Override @Override
public void onSuccess(String json) { public void onSuccess(String json) {
// Log.d("wxw", "GetEvent url"+url); // Log.d("wxw", "GetEvent url"+url);
...@@ -31,8 +31,8 @@ public class HttpClientUtils { ...@@ -31,8 +31,8 @@ public class HttpClientUtils {
@Override @Override
public void onError(String errorMsg) { public void onError(String errorMsg) {
Log.d("wxw", "GetEvent url" + url); // Log.d("wxw", "GetEvent url" + url);
Log.d("wxw", "GetEvent errorMsg" + errorMsg); // Log.d("wxw", "GetEvent errorMsg" + errorMsg);
} }
}); });
} }
...@@ -65,6 +65,7 @@ public class HttpClientUtils { ...@@ -65,6 +65,7 @@ public class HttpClientUtils {
URL url = new URL(requestUrl); URL url = new URL(requestUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET"); connection.setRequestMethod("GET");
connection.setInstanceFollowRedirects(true);
connection.setConnectTimeout(50000); connection.setConnectTimeout(50000);
connection.setReadTimeout(50000); connection.setReadTimeout(50000);
// User-Agent IE9的标识 // User-Agent IE9的标识
...@@ -275,7 +276,7 @@ public class HttpClientUtils { ...@@ -275,7 +276,7 @@ public class HttpClientUtils {
void onError(String errorMsg); void onError(String errorMsg);
} }
//添加公共参数
public static String addParams(Map<String, String> request) { public static String addParams(Map<String, String> request) {
if (request == null) { if (request == null) {
request = new HashMap<>(); request = new HashMap<>();
...@@ -344,5 +345,24 @@ public class HttpClientUtils { ...@@ -344,5 +345,24 @@ public class HttpClientUtils {
str = str.substring(0, str.length() - 1); str = str.substring(0, str.length() - 1);
return str; return str;
} }
//上报参数替换
private static String releactReportUrl(String url){
url = url.replace("__RE_DOWN_X__", ZXHCConstant.downX + "");//手指按下时相对于广告位左上角的横坐标
url = url.replace("__RE_DOWN_Y__", ZXHCConstant.downY + "");//手指按下时相对于广告位左上角的纵坐标
url = url.replace("__RE_UP_X__", ZXHCConstant.upX + "");//手指抬起时相对于广告位左上角的横坐标
url = url.replace("__RE_UP_Y__", ZXHCConstant.upY + "");//手指抬起时相对于广告位左上角的纵坐标
url = url.replace("__DOWN_X__", ZXHCConstant.downRawX + "");//手指按下时相对于屏幕左上角的横坐标
url = url.replace("__DOWN_Y__", ZXHCConstant.downRawY + "");//手指按下时相对于屏幕左上角的纵坐标
url = url.replace("__UP_X__", ZXHCConstant.upRawX + "");//手指抬起时相对于屏幕左上角的横坐标
url = url.replace("__UP_Y__", ZXHCConstant.upRawY + "");//手指抬起时相对于屏幕左上角的纵坐标
url = url.replace("__UTC_TS__", System.currentTimeMillis() + "");//客户端触发时间戳,自 1970 年起的毫秒 ,13 位
url = url.replace("__UTC_TS_SECOND__", System.currentTimeMillis() / 1000 + "");//客户端触发时间戳,自 1970 年起的秒 ,10 位
url = url.replace("__WIDTH__", "-999");//实际广告位的宽,单位为像素
url = url.replace("__HEIGHT__", "-999");//实际广告位的高,单位为像素
url = url.replace("__LATITUDE__", ZXHCConstant.device_geo_lat);//地理位置信息, 纬度
url = url.replace("__LONGITUDE__", ZXHCConstant.device_geo_lon);//地理位置信息, 经度
url = url.replace("__IP__", ZXHCConstant.device_ip);
return url;
}
} }
...@@ -3,6 +3,7 @@ package com.ym.zxhcsdk; ...@@ -3,6 +3,7 @@ package com.ym.zxhcsdk;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
...@@ -712,7 +713,7 @@ public class PhoneUtils { ...@@ -712,7 +713,7 @@ public class PhoneUtils {
public String getLocationInfo(Context context, int type) { public String getLocationInfo(Context context, int type) {
//type =1 经度 2 纬度 //type =1 经度 2 纬度 3 城市
String locationProvider; String locationProvider;
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// 获取所有可用的位置提供器 // 获取所有可用的位置提供器
...@@ -776,4 +777,22 @@ public class PhoneUtils { ...@@ -776,4 +777,22 @@ public class PhoneUtils {
return ZXHCConstant.device_oaid; return ZXHCConstant.device_oaid;
} }
public boolean IsInstallApp(Context context, String pkgName){
if (pkgName== null || pkgName.isEmpty()) {
return false;
}
PackageInfo packageInfo;
try {
packageInfo = context.getPackageManager().getPackageInfo(pkgName, 0);
} catch (PackageManager.NameNotFoundException e) {
packageInfo = null;
e.printStackTrace();
}
if(packageInfo == null) {
return false;
} else {
return true;//true为安装了,false为未安装
}
}
} }
...@@ -9,7 +9,6 @@ public class ZXHCConstant { ...@@ -9,7 +9,6 @@ public class ZXHCConstant {
public static String BASE_URL = ""; public static String BASE_URL = "";
public static String app_package = ""; public static String app_package = "";
public static String app_name = ""; public static String app_name = "";
public static String app_version = ""; public static String app_version = "";
...@@ -31,25 +30,21 @@ public class ZXHCConstant { ...@@ -31,25 +30,21 @@ public class ZXHCConstant {
public static String is_mobile = ""; public static String is_mobile = "";
public static String device_model = ""; public static String device_model = "";
public static String device_brand = ""; public static String device_brand = "";
public static String device_geo_lat = ""; public static String device_geo_lat = "-999";
public static String device_geo_lon = ""; public static String device_geo_lon = "-999";
public static String device_geo_city = ""; public static String device_geo_city = "";
public static String device_oaid = ""; public static String device_oaid = "";
public static ArrayList<HcAdBean> adList = new ArrayList<>(); public static ArrayList<HcAdBean> adList = new ArrayList<>();
public static String downX = "-999";
public static String downY = "-999";
public static String downRawX = "-999";
public static String downRawY = "-999";
public static String upX = "-999";
public static String upY = "-999";
public static String upRawX = "-999";
public static String upRawY = "-999";
} }
...@@ -17,10 +17,12 @@ import android.widget.TextView; ...@@ -17,10 +17,12 @@ import android.widget.TextView;
import com.ym.zxhcsdk.DownLoadUtils; import com.ym.zxhcsdk.DownLoadUtils;
import com.ym.zxhcsdk.HcAdBean; import com.ym.zxhcsdk.HcAdBean;
import com.ym.zxhcsdk.HttpClientUtils; import com.ym.zxhcsdk.HttpClientUtils;
import com.ym.zxhcsdk.PhoneUtils;
import com.ym.zxhcsdk.R; import com.ym.zxhcsdk.R;
import com.ym.zxhcsdk.ZXHCConstant; import com.ym.zxhcsdk.ZXHCConstant;
import com.ym.zxhcsdk.listener.FeedAdListener; import com.ym.zxhcsdk.listener.FeedAdListener;
import com.ym.zxhcsdk.manager.ZXHCAdViewManager; import com.ym.zxhcsdk.manager.ZXHCAdViewManager;
import com.ym.zxhcsdk.webview.WebActivity;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -60,7 +62,7 @@ public class ZXHCFeedAD { ...@@ -60,7 +62,7 @@ public class ZXHCFeedAD {
HttpClientUtils.get(ZXHCConstant.BASE_URL, map, new HttpClientUtils.OnRequestCallBack() { HttpClientUtils.get(ZXHCConstant.BASE_URL, map, new HttpClientUtils.OnRequestCallBack() {
@Override @Override
public void onSuccess(String json) { public void onSuccess(String json) {
adBean = jsonToObj(json); adBean = jsonToObj(json);
adBean.setShowReport(false); adBean.setShowReport(false);
adBean.setClickReport(false); adBean.setClickReport(false);
adBean.setClickDpLinkSucReport(false); adBean.setClickDpLinkSucReport(false);
...@@ -95,13 +97,12 @@ public class ZXHCFeedAD { ...@@ -95,13 +97,12 @@ public class ZXHCFeedAD {
if (feedVp != null) { if (feedVp != null) {
listener.OnAdClosed(); listener.OnAdClosed();
ZXHCAdViewManager.getInstance().removeAdView(context, feedVp); ZXHCAdViewManager.getInstance().removeAdView(context, feedVp);
feedVp = null; } else {
}else { Log.d("wxw", "feedAd null");
Log.d("wxw","feedAd null");
} }
} }
private int downX = -999, downY = -999, downRawX = -999, downRawY = -999, upX = -999, upY = -999, upRawX = -999, upRawY = -999; //private int downX = -999, downY = -999, downRawX = -999, downRawY = -999, upX = -999, upY = -999, upRawX = -999, upRawY = -999;
public void showAd(ViewGroup vp) { public void showAd(ViewGroup vp) {
// feedVp = vp; // feedVp = vp;
...@@ -114,7 +115,7 @@ public class ZXHCFeedAD { ...@@ -114,7 +115,7 @@ public class ZXHCFeedAD {
TextView desc = view.findViewById(R.id.id_ad_feed_desc); TextView desc = view.findViewById(R.id.id_ad_feed_desc);
TextView title = view.findViewById(R.id.id_ad_feed_title); TextView title = view.findViewById(R.id.id_ad_feed_title);
Log.d("wxw", "adBean.getContent()"+adBean.getContent()+"adBean.getApp_name()"+adBean.getApp_name()); Log.d("wxw", "adBean.getContent()" + adBean.getContent() + "adBean.getApp_name()" + adBean.getApp_name());
desc.setText(adBean.getContent()); desc.setText(adBean.getContent());
title.setText(adBean.getTitle()); title.setText(adBean.getTitle());
ImageView feedImg = view.findViewById(R.id.id_ad_feed_img); ImageView feedImg = view.findViewById(R.id.id_ad_feed_img);
...@@ -140,21 +141,19 @@ public class ZXHCFeedAD { ...@@ -140,21 +141,19 @@ public class ZXHCFeedAD {
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) { switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
downX = (int) event.getX(); ZXHCConstant.downX = event.getX() + "";
downY = (int) event.getY(); ZXHCConstant.downY = event.getY() + "";
downRawX = (int) event.getRawX(); ZXHCConstant.downRawX = event.getRawX() + "";
downRawY = (int) event.getRawY(); ZXHCConstant.downRawY = event.getRawY() + "";
Log.e("WXW", "downX = " + downX + "; downY = " + downY + "; downRawX = " + downRawX + "; downRawY = " + downRawY);
break; break;
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
upX = (int) event.getX(); ZXHCConstant.upX = event.getX() + "";
upY = (int) event.getY(); ZXHCConstant.upY = event.getY() + "";
upRawX = (int) event.getRawX(); ZXHCConstant.upRawX = event.getRawX() + "";
upRawY = (int) event.getRawY(); ZXHCConstant.upRawY = event.getRawY() + "";
Log.e("WXW", "upX = " + upX + "; upY = " + upY + "; upRawX = " + upRawX + "; upRawY = " + upRawY);
break; break;
} }
return false; return false;
...@@ -175,7 +174,7 @@ public class ZXHCFeedAD { ...@@ -175,7 +174,7 @@ public class ZXHCFeedAD {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width = width; layoutParams.width = width;
layoutParams.height = height; layoutParams.height = height;
Log.d("wxw", "width"+width+"height"+height); Log.d("wxw", "width" + width + "height" + height);
view.setLayoutParams(layoutParams); view.setLayoutParams(layoutParams);
...@@ -189,12 +188,15 @@ public class ZXHCFeedAD { ...@@ -189,12 +188,15 @@ public class ZXHCFeedAD {
if (!TextUtils.isEmpty(adBean.getTarget_type())) { if (!TextUtils.isEmpty(adBean.getTarget_type())) {
if (adBean.getTarget_type().equals("0")) {//0:网页跳转 1:下载类应用(默认值 0) if (adBean.getTarget_type().equals("0")) {//0:网页跳转 1:下载类应用(默认值 0)
if (adBean.getDUrl() != null && adBean.getDUrl().size() > 0) { if (adBean.getDUrl() != null && adBean.getDUrl().size() > 0) {
Uri uri = Uri.parse(adBean.getDUrl().get(0)); // Uri uri = Uri.parse(adBean.getDUrl().get(0));
Intent intent = new Intent(Intent.ACTION_VIEW, uri); // Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// context.startActivity(intent);
Intent intent = new Intent(context, WebActivity.class);
intent.putExtra("url",adBean.getDUrl().get(0));
context.startActivity(intent); context.startActivity(intent);
} }
} else if (adBean.getTarget_type().equals("1")) { } else if (adBean.getTarget_type().equals("1")) {
new DownLoadUtils(context).downloadAPK(adBean); new DownLoadUtils(context).downloadAPK(adBean);
} }
} }
} else { } else {
...@@ -205,11 +207,15 @@ public class ZXHCFeedAD { ...@@ -205,11 +207,15 @@ public class ZXHCFeedAD {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); context.startActivity(intent);
} catch (Exception e) { } catch (Exception e) {
IsSuccess=false;
if (!TextUtils.isEmpty(adBean.getTarget_type())) { if (!TextUtils.isEmpty(adBean.getTarget_type())) {
if (adBean.getTarget_type().equals("0")) {//0:网页跳转 1:下载类应用(默认值 0) if (adBean.getTarget_type().equals("0")) {//0:网页跳转 1:下载类应用(默认值 0)
if (adBean.getDUrl() != null && adBean.getDUrl().size() > 0) { if (adBean.getDUrl() != null && adBean.getDUrl().size() > 0) {
Uri uri = Uri.parse(adBean.getDUrl().get(0)); // Uri uri = Uri.parse(adBean.getDUrl().get(0));
Intent intent = new Intent(Intent.ACTION_VIEW, uri); // Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// context.startActivity(intent);
Intent intent = new Intent(context, WebActivity.class);
intent.putExtra("url",adBean.getDUrl().get(0));
context.startActivity(intent); context.startActivity(intent);
} }
} else if (adBean.getTarget_type().equals("1")) { } else if (adBean.getTarget_type().equals("1")) {
...@@ -220,13 +226,17 @@ public class ZXHCFeedAD { ...@@ -220,13 +226,17 @@ public class ZXHCFeedAD {
if (IsSuccess) { if (IsSuccess) {
dpLinkSuccessReport(); dpLinkSuccessReport();
} else { } else {
dpLinkFailReport(); if (PhoneUtils.getInstance().IsInstallApp(context,adBean.getApp_name())){
dpLinkFailReport("3");
}else {
dpLinkFailReport("2");
}
} }
} }
} }
private void ClickReport() { private void ClickReport() {
if (adBean.isClickReport()){ if (adBean.isClickReport()) {
return; return;
} }
adBean.setClickReport(true); adBean.setClickReport(true);
...@@ -234,27 +244,14 @@ public class ZXHCFeedAD { ...@@ -234,27 +244,14 @@ public class ZXHCFeedAD {
if (adBean.getClickUrl().size() > 0) { if (adBean.getClickUrl().size() > 0) {
for (int i = 0; i < adBean.getClickUrl().size(); i++) { for (int i = 0; i < adBean.getClickUrl().size(); i++) {
String clickReport = adBean.getClickUrl().get(i); String clickReport = adBean.getClickUrl().get(i);
clickReport.replace("__RE_DOWN_X__", downX + "");//手指按下时相对于广告位左上角的横坐标
clickReport.replace("__RE_DOWN_Y__", downY + "");//手指按下时相对于广告位左上角的纵坐标
clickReport.replace("__RE_UP_X__", upX + "");//手指抬起时相对于广告位左上角的横坐标
clickReport.replace("__RE_UP_Y__", upY + "");//手指抬起时相对于广告位左上角的纵坐标
clickReport.replace("__DOWN_X__", downRawX + "");//手指按下时相对于屏幕左上角的横坐标
clickReport.replace("__DOWN_Y__", downRawY + "");//手指按下时相对于屏幕左上角的纵坐标
clickReport.replace("__UP_X__", upRawX + "");//手指抬起时相对于屏幕左上角的横坐标
clickReport.replace("__UP_Y__", upRawY + "");//手指抬起时相对于屏幕左上角的纵坐标
clickReport.replace("__UTC_TS__", System.currentTimeMillis() + "");//客户端触发时间戳,自 1970 年起的毫秒 ,13 位
clickReport.replace("__UTC_TS_SECOND__", System.currentTimeMillis() / 1000 + "");//客户端触发时间戳,自 1970 年起的秒 ,10 位
clickReport.replace("__WIDTH__", "-999");//实际广告位的宽,单位为像素
clickReport.replace("__HEIGHT__", "-999");//实际广告位的高,单位为像素
clickReport.replace("__LATITUDE__", "-999");//地理位置信息, 纬度
clickReport.replace("__LONGITUDE__", "-999");//地理位置信息, 经度
HttpClientUtils.GetEvent(clickReport); HttpClientUtils.GetEvent(clickReport);
} }
} }
} }
private void ShowReport() { private void ShowReport() {
if (adBean.isShowReport()){ if (adBean.isShowReport()) {
return; return;
} }
adBean.setShowReport(true); adBean.setShowReport(true);
...@@ -262,27 +259,13 @@ public class ZXHCFeedAD { ...@@ -262,27 +259,13 @@ public class ZXHCFeedAD {
if (adBean.getMonitorUrl().size() > 0) { if (adBean.getMonitorUrl().size() > 0) {
for (int i = 0; i < adBean.getMonitorUrl().size(); i++) { for (int i = 0; i < adBean.getMonitorUrl().size(); i++) {
String showReport = adBean.getMonitorUrl().get(i); String showReport = adBean.getMonitorUrl().get(i);
showReport.replace("__RE_DOWN_X__", downX + "");//手指按下时相对于广告位左上角的横坐标
showReport.replace("__RE_DOWN_Y__", downY + "");//手指按下时相对于广告位左上角的纵坐标
showReport.replace("__RE_UP_X__", upX + "");//手指抬起时相对于广告位左上角的横坐标
showReport.replace("__RE_UP_Y__", upY + "");//手指抬起时相对于广告位左上角的纵坐标
showReport.replace("__DOWN_X__", downRawX + "");//手指按下时相对于屏幕左上角的横坐标
showReport.replace("__DOWN_Y__", downRawY + "");//手指按下时相对于屏幕左上角的纵坐标
showReport.replace("__UP_X__", upRawX + "");//手指抬起时相对于屏幕左上角的横坐标
showReport.replace("__UP_Y__", upRawY + "");//手指抬起时相对于屏幕左上角的纵坐标
showReport.replace("__UTC_TS__", System.currentTimeMillis() + "");//客户端触发时间戳,自 1970 年起的毫秒 ,13 位
showReport.replace("__UTC_TS_SECOND__", System.currentTimeMillis() / 1000 + "");//客户端触发时间戳,自 1970 年起的秒 ,10 位
showReport.replace("__WIDTH__", "-999");//实际广告位的宽,单位为像素
showReport.replace("__HEIGHT__", "-999");//实际广告位的高,单位为像素
showReport.replace("__LATITUDE__", "-999");//地理位置信息, 纬度
showReport.replace("__LONGITUDE__", "-999");//地理位置信息, 经度
HttpClientUtils.GetEvent(showReport); HttpClientUtils.GetEvent(showReport);
} }
} }
} }
private void dpLinkSuccessReport() { private void dpLinkSuccessReport() {
if (adBean.isClickDpLinkSucReport()){ if (adBean.isClickDpLinkSucReport()) {
return; return;
} }
adBean.setClickDpLinkSucReport(true); adBean.setClickDpLinkSucReport(true);
...@@ -294,22 +277,22 @@ public class ZXHCFeedAD { ...@@ -294,22 +277,22 @@ public class ZXHCFeedAD {
} }
} }
private void dpLinkFailReport() { private void dpLinkFailReport(String reason) {
if (adBean.isClickDpLinkfailReport()){ if (adBean.isClickDpLinkfailReport()) {
return; return;
} }
adBean.setClickDpLinkfailReport(true); adBean.setClickDpLinkfailReport(true);
//唤醒失败上报 //唤醒失败上报
if (adBean.getDpFailmonitorUrls() != null && adBean.getDpFailmonitorUrls().size() > 0) { if (adBean.getDpFailmonitorUrls() != null && adBean.getDpFailmonitorUrls().size() > 0) {
for (int i = 0; i < adBean.getDpFailmonitorUrls().size(); i++) { for (int i = 0; i < adBean.getDpFailmonitorUrls().size(); i++) {
HttpClientUtils.GetEvent(adBean.getDpFailmonitorUrls().get(i)); String url = adBean.getDpFailmonitorUrls().get(i);
url = url.replace("__DP_REASON__", reason);//1-被拦截,2-应用未安装,3-调起异常 (vivo广告必须替换)
HttpClientUtils.GetEvent(url);
} }
} }
} }
private HcAdBean jsonToObj(String jsonString) { private HcAdBean jsonToObj(String jsonString) {
HcAdBean adBean = null; HcAdBean adBean = null;
try { try {
......
...@@ -20,10 +20,12 @@ import android.widget.TextView; ...@@ -20,10 +20,12 @@ import android.widget.TextView;
import com.ym.zxhcsdk.DownLoadUtils; import com.ym.zxhcsdk.DownLoadUtils;
import com.ym.zxhcsdk.HcAdBean; import com.ym.zxhcsdk.HcAdBean;
import com.ym.zxhcsdk.HttpClientUtils; import com.ym.zxhcsdk.HttpClientUtils;
import com.ym.zxhcsdk.PhoneUtils;
import com.ym.zxhcsdk.R; import com.ym.zxhcsdk.R;
import com.ym.zxhcsdk.ZXHCConstant; import com.ym.zxhcsdk.ZXHCConstant;
import com.ym.zxhcsdk.listener.SplashAdListener; import com.ym.zxhcsdk.listener.SplashAdListener;
import com.ym.zxhcsdk.manager.ZXHCAdViewManager; import com.ym.zxhcsdk.manager.ZXHCAdViewManager;
import com.ym.zxhcsdk.webview.WebActivity;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -95,7 +97,7 @@ public class ZXHCSplashAD { ...@@ -95,7 +97,7 @@ public class ZXHCSplashAD {
Log.d("wxw", "bitmaperrorMsg" + errorMsg); Log.d("wxw", "bitmaperrorMsg" + errorMsg);
} }
}); });
}else { } else {
listener.OnError("广告数据为0"); listener.OnError("广告数据为0");
} }
} }
...@@ -127,7 +129,7 @@ public class ZXHCSplashAD { ...@@ -127,7 +129,7 @@ public class ZXHCSplashAD {
jumpTv.setText("跳过"); jumpTv.setText("跳过");
if (delayTime <= 0) { if (delayTime <= 0) {
listener.OnAdClosed(); listener.OnAdClosed();
if (splashView!=null){ if (splashView != null) {
ZXHCAdViewManager.getInstance().removeAdView(context, splashView); ZXHCAdViewManager.getInstance().removeAdView(context, splashView);
} }
mHandler.removeMessages(SPLASH_CODE); mHandler.removeMessages(SPLASH_CODE);
...@@ -142,8 +144,8 @@ public class ZXHCSplashAD { ...@@ -142,8 +144,8 @@ public class ZXHCSplashAD {
}); });
private int downX = -999, downY = -999, downRawX = -999, downRawY = -999, upX = -999, upY = -999, upRawX = -999, upRawY = -999;
private ViewGroup splashView; private ViewGroup splashView;
public void showAd(ViewGroup vp) { public void showAd(ViewGroup vp) {
splashView = vp; splashView = vp;
context.runOnUiThread(new Runnable() { context.runOnUiThread(new Runnable() {
...@@ -172,7 +174,6 @@ public class ZXHCSplashAD { ...@@ -172,7 +174,6 @@ public class ZXHCSplashAD {
listener.OnAdClicked(); listener.OnAdClicked();
SplashAdClick(adBean); SplashAdClick(adBean);
ClickReport(adBean); ClickReport(adBean);
Log.d("WXW", "点击了");
} }
}); });
splashImg.setOnTouchListener(new View.OnTouchListener() { splashImg.setOnTouchListener(new View.OnTouchListener() {
...@@ -180,21 +181,19 @@ public class ZXHCSplashAD { ...@@ -180,21 +181,19 @@ public class ZXHCSplashAD {
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) { switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
downX = (int) event.getX(); ZXHCConstant.downX = event.getX() + "";
downY = (int) event.getY(); ZXHCConstant.downY = event.getY() + "";
downRawX = (int) event.getRawX(); ZXHCConstant.downRawX = event.getRawX() + "";
downRawY = (int) event.getRawY(); ZXHCConstant.downRawY = event.getRawY() + "";
//Log.e("WXW", "downX = " + downX + "; downY = " + downY + "; downRawX = " + downRawX + "; downRawY = " + downRawY);
break; break;
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
upX = (int) event.getX(); ZXHCConstant.upX = event.getX() + "";
upY = (int) event.getY(); ZXHCConstant.upY = event.getY() + "";
upRawX = (int) event.getRawX(); ZXHCConstant.upRawX = event.getRawX() + "";
upRawY = (int) event.getRawY(); ZXHCConstant.upRawY = event.getRawY() + "";
//Log.e("WXW", "upX = " + upX + "; upY = " + upY + "; upRawX = " + upRawX + "; upRawY = " + upRawY);
break; break;
} }
return false; return false;
...@@ -227,8 +226,11 @@ public class ZXHCSplashAD { ...@@ -227,8 +226,11 @@ public class ZXHCSplashAD {
if (!TextUtils.isEmpty(adBean.getTarget_type())) { if (!TextUtils.isEmpty(adBean.getTarget_type())) {
if (adBean.getTarget_type().equals("0")) {//0:网页跳转 1:下载类应用(默认值 0) if (adBean.getTarget_type().equals("0")) {//0:网页跳转 1:下载类应用(默认值 0)
if (adBean.getDUrl() != null && adBean.getDUrl().size() > 0) { if (adBean.getDUrl() != null && adBean.getDUrl().size() > 0) {
Uri uri = Uri.parse(adBean.getDUrl().get(0)); // Uri uri = Uri.parse(adBean.getDUrl().get(0));
Intent intent = new Intent(Intent.ACTION_VIEW, uri); // Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// context.startActivity(intent);
Intent intent = new Intent(context, WebActivity.class);
intent.putExtra("url",adBean.getDUrl().get(0));
context.startActivity(intent); context.startActivity(intent);
} }
} else if (adBean.getTarget_type().equals("1")) { } else if (adBean.getTarget_type().equals("1")) {
...@@ -247,8 +249,11 @@ public class ZXHCSplashAD { ...@@ -247,8 +249,11 @@ public class ZXHCSplashAD {
if (!TextUtils.isEmpty(adBean.getTarget_type())) { if (!TextUtils.isEmpty(adBean.getTarget_type())) {
if (adBean.getTarget_type().equals("0")) {//0:网页跳转 1:下载类应用(默认值 0) if (adBean.getTarget_type().equals("0")) {//0:网页跳转 1:下载类应用(默认值 0)
if (adBean.getDUrl() != null && adBean.getDUrl().size() > 0) { if (adBean.getDUrl() != null && adBean.getDUrl().size() > 0) {
Uri uri = Uri.parse(adBean.getDUrl().get(0)); // Uri uri = Uri.parse(adBean.getDUrl().get(0));
Intent intent = new Intent(Intent.ACTION_VIEW, uri); // Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// context.startActivity(intent);
Intent intent = new Intent(context, WebActivity.class);
intent.putExtra("url",adBean.getDUrl().get(0));
context.startActivity(intent); context.startActivity(intent);
} }
} else if (adBean.getTarget_type().equals("1")) { } else if (adBean.getTarget_type().equals("1")) {
...@@ -259,7 +264,11 @@ public class ZXHCSplashAD { ...@@ -259,7 +264,11 @@ public class ZXHCSplashAD {
if (IsSuccess) { if (IsSuccess) {
dpLinkSuccessReport(adBean); dpLinkSuccessReport(adBean);
} else { } else {
dpLinkFailReport(adBean); if (PhoneUtils.getInstance().IsInstallApp(context,adBean.getApp_name())){
dpLinkFailReport(adBean,"3");
}else {
dpLinkFailReport(adBean,"2");
}
} }
} }
} }
...@@ -274,20 +283,6 @@ public class ZXHCSplashAD { ...@@ -274,20 +283,6 @@ public class ZXHCSplashAD {
if (adBean.getMonitorUrl().size() > 0) { if (adBean.getMonitorUrl().size() > 0) {
for (int i = 0; i < adBean.getMonitorUrl().size(); i++) { for (int i = 0; i < adBean.getMonitorUrl().size(); i++) {
String showReport = adBean.getMonitorUrl().get(i); String showReport = adBean.getMonitorUrl().get(i);
showReport.replace("__RE_DOWN_X__", downX + "");//手指按下时相对于广告位左上角的横坐标
showReport.replace("__RE_DOWN_Y__", downY + "");//手指按下时相对于广告位左上角的纵坐标
showReport.replace("__RE_UP_X__", upX + "");//手指抬起时相对于广告位左上角的横坐标
showReport.replace("__RE_UP_Y__", upY + "");//手指抬起时相对于广告位左上角的纵坐标
showReport.replace("__DOWN_X__", downRawX + "");//手指按下时相对于屏幕左上角的横坐标
showReport.replace("__DOWN_Y__", downRawY + "");//手指按下时相对于屏幕左上角的纵坐标
showReport.replace("__UP_X__", upRawX + "");//手指抬起时相对于屏幕左上角的横坐标
showReport.replace("__UP_Y__", upRawY + "");//手指抬起时相对于屏幕左上角的纵坐标
showReport.replace("__UTC_TS__", System.currentTimeMillis() + "");//客户端触发时间戳,自 1970 年起的毫秒 ,13 位
showReport.replace("__UTC_TS_SECOND__", System.currentTimeMillis() / 1000 + "");//客户端触发时间戳,自 1970 年起的秒 ,10 位
showReport.replace("__WIDTH__", "-999");//实际广告位的宽,单位为像素
showReport.replace("__HEIGHT__", "-999");//实际广告位的高,单位为像素
showReport.replace("__LATITUDE__", "-999");//地理位置信息, 纬度
showReport.replace("__LONGITUDE__", "-999");//地理位置信息, 经度
HttpClientUtils.GetEvent(showReport); HttpClientUtils.GetEvent(showReport);
} }
} }
...@@ -302,20 +297,6 @@ public class ZXHCSplashAD { ...@@ -302,20 +297,6 @@ public class ZXHCSplashAD {
if (adBean.getClickUrl().size() > 0) { if (adBean.getClickUrl().size() > 0) {
for (int i = 0; i < adBean.getClickUrl().size(); i++) { for (int i = 0; i < adBean.getClickUrl().size(); i++) {
String clickReport = adBean.getClickUrl().get(i); String clickReport = adBean.getClickUrl().get(i);
clickReport.replace("__RE_DOWN_X__", downX + "");//手指按下时相对于广告位左上角的横坐标
clickReport.replace("__RE_DOWN_Y__", downY + "");//手指按下时相对于广告位左上角的纵坐标
clickReport.replace("__RE_UP_X__", upX + "");//手指抬起时相对于广告位左上角的横坐标
clickReport.replace("__RE_UP_Y__", upY + "");//手指抬起时相对于广告位左上角的纵坐标
clickReport.replace("__DOWN_X__", downRawX + "");//手指按下时相对于屏幕左上角的横坐标
clickReport.replace("__DOWN_Y__", downRawY + "");//手指按下时相对于屏幕左上角的纵坐标
clickReport.replace("__UP_X__", upRawX + "");//手指抬起时相对于屏幕左上角的横坐标
clickReport.replace("__UP_Y__", upRawY + "");//手指抬起时相对于屏幕左上角的纵坐标
clickReport.replace("__UTC_TS__", System.currentTimeMillis() + "");//客户端触发时间戳,自 1970 年起的毫秒 ,13 位
clickReport.replace("__UTC_TS_SECOND__", System.currentTimeMillis() / 1000 + "");//客户端触发时间戳,自 1970 年起的秒 ,10 位
clickReport.replace("__WIDTH__", "-999");//实际广告位的宽,单位为像素
clickReport.replace("__HEIGHT__", "-999");//实际广告位的高,单位为像素
clickReport.replace("__LATITUDE__", "-999");//地理位置信息, 纬度
clickReport.replace("__LONGITUDE__", "-999");//地理位置信息, 经度
HttpClientUtils.GetEvent(clickReport); HttpClientUtils.GetEvent(clickReport);
} }
} }
...@@ -334,7 +315,7 @@ public class ZXHCSplashAD { ...@@ -334,7 +315,7 @@ public class ZXHCSplashAD {
} }
} }
private void dpLinkFailReport(HcAdBean adBean) { private void dpLinkFailReport(HcAdBean adBean,String reason) {
if (adBean.isClickDpLinkfailReport()) { if (adBean.isClickDpLinkfailReport()) {
return; return;
} }
...@@ -342,7 +323,9 @@ public class ZXHCSplashAD { ...@@ -342,7 +323,9 @@ public class ZXHCSplashAD {
//唤醒失败上报 //唤醒失败上报
if (adBean.getDpFailmonitorUrls() != null && adBean.getDpFailmonitorUrls().size() > 0) { if (adBean.getDpFailmonitorUrls() != null && adBean.getDpFailmonitorUrls().size() > 0) {
for (int i = 0; i < adBean.getDpFailmonitorUrls().size(); i++) { for (int i = 0; i < adBean.getDpFailmonitorUrls().size(); i++) {
HttpClientUtils.GetEvent(adBean.getDpFailmonitorUrls().get(i)); String url = adBean.getDpFailmonitorUrls().get(i);
url = url.replace("__DP_REASON__", reason);//1-被拦截,2-应用未安装,3-调起异常 (vivo广告必须替换)
HttpClientUtils.GetEvent(url);
} }
} }
} }
......
package com.ym.zxhcsdk.webview;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.AttributeSet;
import android.webkit.WebView;
public class CustomWebView extends WebView {
public CustomWebView(Context context) {
super(getFixedContext(context));
}
public CustomWebView(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(getFixedContext(context), attrs, defStyleAttr);
}
public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
}
public static Context getFixedContext(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setWebContentsDebuggingEnabled(true);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return context.createConfigurationContext(new Configuration());
} else {
return context;
}
}
}
package com.ym.zxhcsdk.webview;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import com.ym.zxhcsdk.R;
public class WebActivity extends Activity {
private String url;
private String title;
private CustomWebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_web);
url = getIntent().getStringExtra("url");
title = getIntent().getStringExtra("title");
webView = findViewById(R.id.activity_webview);
initTitle();
initWebView();
webView.loadUrl(url);
}
private void initWebView() {
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
// webView.getSettings().setDefaultFontSize(56);
// webView.getSettings().setMinimumFontSize(40);//设置最小字体
// 建议禁止缓存加载,以确保在攻击发生时可快速获取最新的滑动验证组件进行对抗。
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
// 设置不使用默认浏览器,而直接使用WebView组件加载页面。
// 设置WebView组件支持加载JavaScript。
webView.getSettings().setJavaScriptEnabled(true);
// 建立JavaScript调用Java接口的桥梁。
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
// webView.loadDataWithBaseURL(null, url, "text/html", "utf-8", null);//解决乱码问题
}
private void initTitle() {
findViewById(R.id.iv_user_toolbar_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
TextView tv_title = findViewById(R.id.tv_user_toolbar_title);
// tv_title.setText(title + "");
}
@Override
protected void onResume() {
super.onResume();
if (webView != null) {
webView.loadUrl("javascript:onResume()");
}
}
@Override
protected void onPause() {
super.onPause();
if (webView != null) {
webView.loadUrl("javascript:onPause()");
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (webView != null) {
webView.destroy();
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".webview.WebActivity">
<RelativeLayout
android:id="@+id/id_rl_toolbar"
android:layout_width="match_parent"
android:layout_height="50dp">
<ImageView
android:id="@+id/iv_user_toolbar_back"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:src="@mipmap/arrow_left" />
<TextView
android:id="@+id/tv_user_toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<com.ym.zxhcsdk.webview.CustomWebView
android:id="@+id/activity_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
\ No newline at end of file
...@@ -28,22 +28,24 @@ ...@@ -28,22 +28,24 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:gravity="center_vertical" android:layout_height="wrap_content"
android:layout_height="wrap_content"> android:gravity="center_vertical">
<TextView <TextView
android:id="@+id/id_ad_feed_title" android:id="@+id/id_ad_feed_title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="aaaaaaaaa"
android:layout_weight="1" android:layout_weight="1"
android:text="aaaaaaaaa"
android:textColor="#000000" android:textColor="#000000"
android:textSize="16dp" /> android:textSize="16dp" />
<ImageView <ImageView
android:id="@+id/id_ad_feed_close" android:id="@+id/id_ad_feed_close"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:src="@mipmap/feedad_close" android:layout_height="wrap_content"
android:layout_height="wrap_content"/> android:layout_marginRight="20dp"
android:src="@mipmap/feedad_close" />
</LinearLayout> </LinearLayout>
......
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