Commit a91cd0fa by gao.chao

web拆出

parent 68e43135
......@@ -38,14 +38,19 @@ android {
}
}
repositories{
flatDir {
dirs 'libs'
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api 'com.android.support:appcompat-v7:28.0.0'
api 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api "com.tencent.bugly:crashreport_upgrade:1.3.4"
api 'com.tencent.bugly:nativecrashreport:3.6.0.1'
// api(name:'fastDevelop-release', ext:'aar')
api project(':fastDevelop')
api project(':web')
}
......@@ -4,12 +4,14 @@ import android.app.Application;
import com.mayi.fastdevelop.base.BaseApplication;
import com.mayi.fastdevelop.comnon.Configure;
import com.mayi.fastdevelop.web.WebUtil;
public class MyApplication extends BaseApplication{
@Override
public void onCreate() {
super.onCreate();
WebUtil.initX5Webview();
initBugly("cb8018da1b",true);
Configure.APP_LOGO=R.mipmap.ic_launcher;
}
......
......@@ -9,13 +9,13 @@ import android.view.View;
import com.mayi.fastdevelop.base.BaseAPI;
import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.base.BasePresenter;
import com.mayi.fastdevelop.commonpage.WebActivity;
import com.mayi.fastdevelop.commonpage.amap.MapLocationActivity;
import com.mayi.fastdevelop.commonpage.login.LoginActivity;
import com.mayi.fastdevelop.comnon.Key;
import com.mayi.fastdevelop.comnon.RequestCode;
import com.mayi.fastdevelop.util.ToolUtils;
import com.mayi.fastdevelop.view.OnMultiClickListener;
//import com.mayi.fastdevelop.web.BaseWebActivity;
public class PageActivity extends BaseActivity {
......@@ -39,7 +39,7 @@ public class PageActivity extends BaseActivity {
public void onMultiClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("url", "https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5&username=18001874470&v=" + System.currentTimeMillis());
gotoActivity(WebActivity.class, bundle);
// gotoActivity(BaseWebActivity.class, bundle);
}
});
findViewById(R.id.b2).setOnClickListener(new OnMultiClickListener() {
......@@ -48,7 +48,7 @@ public class PageActivity extends BaseActivity {
Bundle bundle = new Bundle();
bundle.putString("url", "https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5" +
"&username=18001874470&v=" + System.currentTimeMillis() + "&isNeedBackButton=true&userAppTitle=潜客");
gotoActivity(WebActivity.class, bundle);
// gotoActivity(BaseWebActivity.class, bundle);
}
});
findViewById(R.id.b3).setOnClickListener(new OnMultiClickListener() {
......
......@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
......@@ -25,3 +25,4 @@ allprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}
......@@ -42,9 +42,5 @@ dependencies {
api 'com.alibaba:fastjson:1.2.12'
api 'com.android.support:recyclerview-v7:28.0.0'
api 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api files('libs/zixing-core-3.2.0.jar')
implementation files('libs/tbs_sdk_thirdapp_v3.6.0.1371_43624_sharewithdownload_withoutGame_obfs_20181106_121046.jar')//腾讯X5浏览器
}
......@@ -18,14 +18,13 @@
<application>
<activity android:name=".commonpage.amap.MapLocationActivity" />
<activity android:name=".commonpage.WebActivity" />
<activity android:name=".commonpage.main.MainActivity" />
<activity android:name=".commonpage.login.LoginActivity"/>
<!-- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mayi.fastdevelop"
android:authorities="${applicationId}.uri"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
......
......@@ -61,7 +61,7 @@ public abstract class BaseActivity<P extends BasePresenter, M extends BaseAPI> e
public void showLoadingDialog() {
if (dialog == null) {
dialog = LoadingDialog.init(this).show();
dialog = LoadingDialog.init(this).setCanTouchOutsideCancel(true).show();
} else {
dialog.show();
}
......
......@@ -29,10 +29,6 @@ import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.tencent.bugly.crashreport.CrashReport;
import com.tencent.smtt.sdk.CookieManager;
import com.tencent.smtt.sdk.CookieSyncManager;
import com.tencent.smtt.sdk.QbSdk;
import com.tencent.smtt.sdk.WebStorage;
import java.text.SimpleDateFormat;
import java.util.Date;
......@@ -51,7 +47,6 @@ public abstract class BaseApplication extends Application {
super.onCreate();
registerActivityListener();
initLog();
initX5Webview();
initSmartRefreshLayout();
}
......@@ -128,36 +123,6 @@ public abstract class BaseApplication extends Application {
CrashReport.initCrashReport(getApplicationContext(), key, isDebug);
}
private void initX5Webview() {
//清空所有Cookie
CookieSyncManager.createInstance(getApplicationContext());
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookies(null);
cookieManager.removeAllCookie();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.flush();
} else {
CookieSyncManager.getInstance().sync();
}
WebStorage.getInstance().deleteAllData();
//搜集本地tbs内核信息并上报服务器,服务器返回结果决定使用哪个内核。
QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
@Override
public void onViewInitFinished(boolean arg0) {
//x5內核初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核。
LogUtils.i("X5内核加载完成:" + arg0);
}
@Override
public void onCoreInitFinished() {
}
};
//x5内核初始化接口
QbSdk.initX5Environment(getApplicationContext(), cb);
}
/**
* 设置日志文件大小
*
......
......@@ -9,8 +9,6 @@ import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.comnon.Key;
import com.mayi.fastdevelop.comnon.UserManager;
import com.mayi.fastdevelop.util.SpUtil;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
/**
......@@ -23,13 +21,6 @@ public abstract class BaseStartActivity<T extends BaseActivity, T1 extends BaseA
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//清除浏览器缓存
WebView webView = new WebView(this);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.clearCache(true);
webView.clearHistory();
webView.clearFormData();
getCacheDir().delete();
mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
@Override
......
include ':app', ':fastDevelop'
include ':app', ':fastDevelop', ':web'
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
api project(':fastDevelop')
implementation files('libs/tbs_sdk_thirdapp_v3.6.0.1371_43624_sharewithdownload_withoutGame_obfs_20181106_121046.jar')//腾讯X5浏览器
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.mayi.fastdevelop.web;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.mayi.fastdevelop.web.test", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mayi.fastdevelop.web">
<application>
<activity android:name=".BaseWebActivity" />
</application>
</manifest>
\ No newline at end of file
package com.mayi.fastdevelop.commonpage;
package com.mayi.fastdevelop.web;
import android.Manifest;
import android.app.Activity;
......@@ -23,14 +24,6 @@ import android.view.View;
import android.webkit.JavascriptInterface;
import com.alibaba.fastjson.JSON;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.services.core.LatLonPoint;
import com.mayi.fastdevelop.R;
import com.mayi.fastdevelop.base.BaseAPI;
import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.base.BasePresenter;
......@@ -62,7 +55,14 @@ import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
public class WebActivity extends BaseActivity {
/**
* web基本页面
* 支持JS和Android相互调用
* 监听JS报错,上传bugly
* 支持清除缓存,拍照,相册,定位,打电话,返回上一页,跳转原生页面(待扩展),
* 开启Debug模式,给web传递用户信息,发送短信
*/
public class BaseWebActivity extends BaseActivity {
private WebView webView;
private CustomTitleBar title;
......@@ -70,6 +70,11 @@ public class WebActivity extends BaseActivity {
private ValueCallback<Uri> uploadMessage;
private ValueCallback<Uri[]> uploadMessageAboveL;
private String mCurrentPhotoPath;
private WebListener webListener;
public void setWebListener(WebListener webListener) {
this.webListener = webListener;
}
@Override
public BasePresenter getPresenterInstance() {
......@@ -189,10 +194,10 @@ public class WebActivity extends BaseActivity {
@Override
public void onClickLeft() {
//请求拍照权限
if (ActivityCompat.checkSelfPermission(WebActivity.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.checkSelfPermission(BaseWebActivity.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
takePhoto();
} else {
ActivityCompat.requestPermissions(WebActivity.this, new String[]{Manifest.permission.CAMERA}, RequestCode.REQUEST_CODE_PERMISSION_CAMERA);
ActivityCompat.requestPermissions(BaseWebActivity.this, new String[]{Manifest.permission.CAMERA}, RequestCode.REQUEST_CODE_PERMISSION_CAMERA);
}
}
......@@ -228,7 +233,7 @@ public class WebActivity extends BaseActivity {
File tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri uri = FileProvider.getUriForFile(this, "com.mayi.fastdevelop", tempFile);
Uri uri = FileProvider.getUriForFile(this, getPackageName() + ".uri", tempFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
} else {
Uri uri = Uri.fromFile(tempFile);
......@@ -270,8 +275,12 @@ public class WebActivity extends BaseActivity {
handler.post(new Runnable() {
@Override
public void run() {
if (TextUtils.equals("goCallPhone", method)) {//去打电话
SystemUtil.makePhoneCall(WebActivity.this, data);
if (TextUtils.equals("clearCache", method)) {//清除缓存
webView.clearCache(true);
webView.clearHistory();
webView.clearFormData();
} else if (TextUtils.equals("goCallPhone", method)) {//去打电话
SystemUtil.makePhoneCall(BaseWebActivity.this, data);
} else if (TextUtils.equals("backPage", method)) {//返回上一页
webPageBack();
} else if (TextUtils.equals("goPage", method)) {//跳转原生页面
......@@ -279,13 +288,13 @@ public class WebActivity extends BaseActivity {
} else if (TextUtils.equals("openDebug", method)) {//开启Debug模式
WebView.setWebContentsDebuggingEnabled(true);
} else if (TextUtils.equals("goBrowser", method)) {//跳转浏览器
SystemUtil.gotoWeb(WebActivity.this, data);
SystemUtil.gotoWeb(BaseWebActivity.this, data);
} else if (TextUtils.equals("getUserInfo", method)) {//给web传递用户信息
appCallJs("setUserInfo", SpUtil.get(Key.USER_INFO, ""));
} else if (TextUtils.equals("sendSMS", method)) {//发送短信
sendSMS(data);
} else if (TextUtils.equals("location", method)) {//发送短信
LocationUtils.startLocation(WebActivity.this, new LocationUtils.LocationCallback() {
} else if (TextUtils.equals("location", method)) {//定位
LocationUtils.startLocation(BaseWebActivity.this, new LocationUtils.LocationCallback() {
@Override
public void onFail(String msg) {
appCallJs("LocationFail", msg);
......@@ -304,7 +313,7 @@ public class WebActivity extends BaseActivity {
private void sendSMS(String data) {
try {
JSONObject jsonObject = new JSONObject(data);
SystemUtil.sendSMS(WebActivity.this, jsonObject.optString("phone")
SystemUtil.sendSMS(BaseWebActivity.this, jsonObject.optString("phone")
, jsonObject.optString("msg"));
} catch (JSONException e) {
e.printStackTrace();
......@@ -327,6 +336,10 @@ public class WebActivity extends BaseActivity {
if (TextUtils.equals(pageName, "MapLocation")) {//地图定位页面
Intent intent = new Intent(this, MapLocationActivity.class);
startActivityForResult(intent, RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE);
} else {
if (webListener != null) {
webListener.goPageListener(pageName, parameter);
}
}
}
......@@ -445,4 +458,6 @@ public class WebActivity extends BaseActivity {
asyncTask.execute();
}
}
package com.mayi.fastdevelop.web;
public interface WebListener {
public void goPageListener(String page,String parameter);//web跳转原生页面
}
package com.mayi.fastdevelop.web;
import android.content.Context;
import android.os.Build;
import com.mayi.fastdevelop.base.BaseApplication;
import com.mayi.fastdevelop.util.LogUtils;
import com.tencent.smtt.sdk.CookieManager;
import com.tencent.smtt.sdk.CookieSyncManager;
import com.tencent.smtt.sdk.QbSdk;
import com.tencent.smtt.sdk.WebStorage;
public class WebUtil {
/**
* 初始化浏览器
*/
public static void initX5Webview() {
//清空所有Cookie
CookieSyncManager.createInstance(BaseApplication.getInstance().getChildApplication().getApplicationContext());
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookies(null);
cookieManager.removeAllCookie();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.flush();
} else {
CookieSyncManager.getInstance().sync();
}
WebStorage.getInstance().deleteAllData();
//搜集本地tbs内核信息并上报服务器,服务器返回结果决定使用哪个内核。
QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
@Override
public void onViewInitFinished(boolean arg0) {
//x5內核初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核。
LogUtils.i("X5内核加载完成:" + arg0);
}
@Override
public void onCoreInitFinished() {
}
};
//x5内核初始化接口
QbSdk.initX5Environment(BaseApplication.getInstance().getChildApplication().getApplicationContext(), cb);
}
}
<resources>
<string name="app_name">web</string>
</resources>
package com.mayi.fastdevelop.web;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ 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