Commit 21b5253f by gao.chao

web优化

parent fc1d4efe
...@@ -150,7 +150,7 @@ public class BaseWebActivity extends BaseActivity { ...@@ -150,7 +150,7 @@ public class BaseWebActivity extends BaseActivity {
if (TextUtils.isEmpty(url)) { if (TextUtils.isEmpty(url)) {
return; return;
} }
if (url.contains("isNeedBackButton")) { if (url.contains("isNeedBackButton=true")) {
title.setVisibility(View.VISIBLE); title.setVisibility(View.VISIBLE);
} else { } else {
title.setVisibility(View.GONE); title.setVisibility(View.GONE);
...@@ -216,7 +216,6 @@ public class BaseWebActivity extends BaseActivity { ...@@ -216,7 +216,6 @@ public class BaseWebActivity extends BaseActivity {
public void takePhoto() { public void takePhoto() {
StringBuilder fileName = new StringBuilder(); StringBuilder fileName = new StringBuilder();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileName.append(System.currentTimeMillis()).append("_upload.jpg"); fileName.append(System.currentTimeMillis()).append("_upload.jpg");
File tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString()); File tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
...@@ -257,12 +256,11 @@ public class BaseWebActivity extends BaseActivity { ...@@ -257,12 +256,11 @@ public class BaseWebActivity extends BaseActivity {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
webView.loadUrl("javascript:appCallJs.invoking;(" + method + "," + data + ")"); webView.loadUrl("javascript:appCallJs(" + method + "," + data + ")");
} }
}); });
} }
@JavascriptInterface @JavascriptInterface
public void invoking(final String method, final String data) { public void invoking(final String method, final String data) {
handler.post(new Runnable() { handler.post(new Runnable() {
...@@ -273,7 +271,12 @@ public class BaseWebActivity extends BaseActivity { ...@@ -273,7 +271,12 @@ public class BaseWebActivity extends BaseActivity {
webView.clearHistory(); webView.clearHistory();
webView.clearFormData(); webView.clearFormData();
} else if (TextUtils.equals("goCallPhone", method)) {//去打电话 } else if (TextUtils.equals("goCallPhone", method)) {//去打电话
SystemUtil.makePhoneCall(BaseWebActivity.this, data); try {
JSONObject jsonObject=new JSONObject(data);
SystemUtil.makePhoneCall(BaseWebActivity.this, jsonObject.optString("tel"));
} catch (JSONException e) {
e.printStackTrace();
}
} else if (TextUtils.equals("backPage", method)) {//返回上一页 } else if (TextUtils.equals("backPage", method)) {//返回上一页
webPageBack(); webPageBack();
} else if (TextUtils.equals("goPage", method)) {//跳转原生页面 } else if (TextUtils.equals("goPage", method)) {//跳转原生页面
...@@ -286,7 +289,8 @@ public class BaseWebActivity extends BaseActivity { ...@@ -286,7 +289,8 @@ public class BaseWebActivity extends BaseActivity {
appCallJs("setUserInfo", SpUtil.get(Key.USER_INFO, "")); appCallJs("setUserInfo", SpUtil.get(Key.USER_INFO, ""));
} else if (TextUtils.equals("sendSMS", method)) {//发送短信 } else if (TextUtils.equals("sendSMS", method)) {//发送短信
sendSMS(data); sendSMS(data);
} else if (TextUtils.equals("location", method)) {//定位 }
// else if (TextUtils.equals("location", method)) {//定位
// LocationUtils.startLocation(BaseWebActivity.this, new LocationUtils.LocationCallback() { // LocationUtils.startLocation(BaseWebActivity.this, new LocationUtils.LocationCallback() {
// @Override // @Override
// public void onFail(String msg) { // public void onFail(String msg) {
...@@ -298,7 +302,7 @@ public class BaseWebActivity extends BaseActivity { ...@@ -298,7 +302,7 @@ public class BaseWebActivity extends BaseActivity {
// appCallJs("LocationSuccess", JSON.toJSONString(bean)); // appCallJs("LocationSuccess", JSON.toJSONString(bean));
// } // }
// }); // });
} // }
} }
}); });
} }
...@@ -326,20 +330,20 @@ public class BaseWebActivity extends BaseActivity { ...@@ -326,20 +330,20 @@ public class BaseWebActivity extends BaseActivity {
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (TextUtils.equals(pageName, "MapLocation")) {//地图定位页面 // if (TextUtils.equals(pageName, "MapLocation")) {//地图定位页面
// Intent intent = new Intent(this, MapLocationActivity.class); // Intent intent = new Intent(this, MapLocationActivity.class);
// startActivityForResult(intent, RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE); // startActivityForResult(intent, RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE);
} else { // } else {
if (webListener != null) { if (webListener != null) {
webListener.goPageListener(pageName, parameter); webListener.goPageListener(pageName, parameter);
} }
} // }
} }
private void initWebView() { private void initWebView() {
WebSettings settings = webView.getSettings(); WebSettings settings = webView.getSettings();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(2); settings.setMixedContentMode(0);
} }
settings.setBlockNetworkImage(false); settings.setBlockNetworkImage(false);
...@@ -357,7 +361,7 @@ public class BaseWebActivity extends BaseActivity { ...@@ -357,7 +361,7 @@ public class BaseWebActivity extends BaseActivity {
settings.setDefaultTextEncodingName("utf-8"); settings.setDefaultTextEncodingName("utf-8");
settings.setJavaScriptEnabled(true); settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setAllowFileAccess(true); settings.setAllowFileAccess(true);
settings.setAppCacheEnabled(true); settings.setAppCacheEnabled(true);
webView.setHorizontalScrollBarEnabled(false);//水平不显示 webView.setHorizontalScrollBarEnabled(false);//水平不显示
......
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