|
@@ -1,10 +1,11 @@
|
|
package com.topsoft.jianyu;
|
|
package com.topsoft.jianyu;
|
|
|
|
|
|
-import android.content.Context;
|
|
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
|
+
|
|
import android.support.annotation.Nullable;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
+import android.view.KeyEvent;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
import android.webkit.ValueCallback;
|
|
import android.webkit.ValueCallback;
|
|
@@ -13,12 +14,16 @@ import android.webkit.WebSettings;
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebViewClient;
|
|
import android.webkit.WebViewClient;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
|
|
+import android.widget.ProgressBar;
|
|
|
|
|
|
import com.topsoft.jianyu.util.AppUtil;
|
|
import com.topsoft.jianyu.util.AppUtil;
|
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
+import static android.view.View.GONE;
|
|
|
|
+import static android.view.View.VISIBLE;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Created by wangkaiyue on 2018/2/1.
|
|
* Created by wangkaiyue on 2018/2/1.
|
|
*/
|
|
*/
|
|
@@ -26,29 +31,39 @@ import java.util.Map;
|
|
public class ExternalWebPage extends AppCompatActivity{
|
|
public class ExternalWebPage extends AppCompatActivity{
|
|
|
|
|
|
private WebView wv;
|
|
private WebView wv;
|
|
- private Context ctx;
|
|
|
|
|
|
+ private ProgressBar mProgressBar;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.external_web);
|
|
setContentView(R.layout.external_web);
|
|
AppUtil.setAndroidNativeLightStatusBar(this,false,true);
|
|
AppUtil.setAndroidNativeLightStatusBar(this,false,true);
|
|
- ctx=this;
|
|
|
|
|
|
+ mProgressBar = findViewById(R.id.progressBar);
|
|
|
|
+
|
|
|
|
+
|
|
String url=getIntent().getStringExtra("url");
|
|
String url=getIntent().getStringExtra("url");
|
|
initWebview(url);
|
|
initWebview(url);
|
|
findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
|
|
findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
@Override
|
|
public void onClick(View v) {
|
|
public void onClick(View v) {
|
|
- finish();
|
|
|
|
|
|
+ if(wv.canGoBack()){
|
|
|
|
+ wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
|
|
|
|
+ wv.goBack();
|
|
|
|
+ }else{
|
|
|
|
+ finish();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+ private int lastProgress=0;
|
|
protected void initWebview(String url) {
|
|
protected void initWebview(String url) {
|
|
LinearLayout mLayout = (LinearLayout) findViewById(R.id.webview);
|
|
LinearLayout mLayout = (LinearLayout) findViewById(R.id.webview);
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
wv = new WebView(this);
|
|
wv = new WebView(this);
|
|
wv.setLayoutParams(params);
|
|
wv.setLayoutParams(params);
|
|
|
|
+
|
|
mLayout.addView(wv);
|
|
mLayout.addView(wv);
|
|
|
|
+
|
|
wv.setWebViewClient(new WebViewClient() {
|
|
wv.setWebViewClient(new WebViewClient() {
|
|
});
|
|
});
|
|
wv.setWebChromeClient(new WebChromeClient() {
|
|
wv.setWebChromeClient(new WebChromeClient() {
|
|
@@ -57,6 +72,23 @@ public class ExternalWebPage extends AppCompatActivity{
|
|
super.onShowFileChooser(webView, filePathCallback, fileChooserParams);
|
|
super.onShowFileChooser(webView, filePathCallback, fileChooserParams);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onProgressChanged(WebView view,final int newProgress) {
|
|
|
|
+ super.onProgressChanged(view, newProgress);
|
|
|
|
+ if (newProgress == 100) {
|
|
|
|
+ for(;lastProgress<100;lastProgress++){
|
|
|
|
+ mProgressBar.setProgress(newProgress);
|
|
|
|
+ }
|
|
|
|
+ mProgressBar.setVisibility(GONE);
|
|
|
|
+ lastProgress=0;
|
|
|
|
+ } else {
|
|
|
|
+ mProgressBar.setVisibility(VISIBLE);
|
|
|
|
+ for(;lastProgress<newProgress;lastProgress++){
|
|
|
|
+ mProgressBar.setProgress(newProgress);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
|
|
WebSettings webSettings = wv.getSettings();
|
|
WebSettings webSettings = wv.getSettings();
|
|
@@ -73,10 +105,25 @@ public class ExternalWebPage extends AppCompatActivity{
|
|
//可以访问文件
|
|
//可以访问文件
|
|
webSettings.setAllowFileAccess(true);
|
|
webSettings.setAllowFileAccess(true);
|
|
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
|
|
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
|
|
|
|
+ //设置放大缩小
|
|
|
|
+ webSettings.setSupportZoom(true);
|
|
|
|
+ webSettings.setBuiltInZoomControls(true);
|
|
|
|
+ webSettings.setDisplayZoomControls(false);//隐藏缩放工具
|
|
|
|
|
|
Map<String, String> map = new HashMap<String, String>();
|
|
Map<String, String> map = new HashMap<String, String>();
|
|
map.put("User-Agent", "Android");
|
|
map.put("User-Agent", "Android");
|
|
wv.loadUrl(url, map);
|
|
wv.loadUrl(url, map);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_BACK && wv.canGoBack()) {
|
|
|
|
+ wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
|
|
|
|
+ wv.goBack();
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return super.onKeyDown(keyCode, event);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|