|
|
@@ -14,12 +14,16 @@ import android.support.v7.app.ActionBar;
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
+import android.view.animation.Animation;
|
|
|
+import android.view.animation.AnimationUtils;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.ProgressBar;
|
|
|
|
|
|
-import com.sheep.gamegroup.absBase.IJumpWeb;
|
|
|
import com.sheep.gamegroup.model.entity.WebParams;
|
|
|
import com.sheep.gamegroup.module.webview.util.WebResourceRequestAdapter;
|
|
|
import com.sheep.gamegroup.module.webview.util.WebResourceResponseAdapter;
|
|
|
import com.sheep.gamegroup.util.CommonUtil;
|
|
|
+import com.sheep.gamegroup.util.GlideImageLoader;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
|
import com.sheep.gamegroup.util.NetUtil;
|
|
|
@@ -64,6 +68,10 @@ public class ActWebX5 extends BaseActWeb {
|
|
|
|
|
|
@BindView(R.id.webview)
|
|
|
WebView mWebView;
|
|
|
+ @BindView(R.id.act_web_loading_pb)
|
|
|
+ ProgressBar act_web_loading_pb;
|
|
|
+ @BindView(R.id.act_web_loading_iv)
|
|
|
+ ImageView act_web_loading_iv;
|
|
|
private WebParams webParams;
|
|
|
private WebSettings webViewSettings;
|
|
|
|
|
|
@@ -75,6 +83,8 @@ public class ActWebX5 extends BaseActWeb {
|
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
+ GlideImageLoader.setImage(act_web_loading_iv, R.drawable.gif_sheep_loading);
|
|
|
+
|
|
|
Intent intent = getIntent();
|
|
|
webParams = (WebParams) intent.getSerializableExtra(WebParams.class.getSimpleName());
|
|
|
String url = webParams.getUrl();
|
|
|
@@ -253,10 +263,29 @@ public class ActWebX5 extends BaseActWeb {
|
|
|
|
|
|
@Override
|
|
|
public void onProgressChanged(WebView view, int newProgress) {
|
|
|
- if (newProgress == 100) {
|
|
|
- String action = "javascript:imgsrc('" + url + "')";
|
|
|
- runWebviewUrl(action);
|
|
|
+ LogUtil.println("ActWeb", "onProgressChanged", newProgress);
|
|
|
+ if (newProgress == 100 && ViewUtil.isVisible(act_web_loading_iv)) {
|
|
|
+ Animation animation = AnimationUtils.loadAnimation(SheepApp.getInstance(), R.anim.anim_alpha_1_0);
|
|
|
+ animation.setAnimationListener(new Animation.AnimationListener() {
|
|
|
+ @Override
|
|
|
+ public void onAnimationStart(Animation animation) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAnimationEnd(Animation animation) {
|
|
|
+ ViewUtil.setVisibility(act_web_loading_iv, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAnimationRepeat(Animation animation) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ act_web_loading_iv.startAnimation(animation);
|
|
|
}
|
|
|
+ ViewUtil.setVisibility(act_web_loading_pb, newProgress != 100);
|
|
|
+ act_web_loading_pb.setProgress(newProgress);
|
|
|
super.onProgressChanged(view, newProgress);
|
|
|
}
|
|
|
});
|
|
|
@@ -330,26 +359,21 @@ public class ActWebX5 extends BaseActWeb {
|
|
|
public void onPageFinished(WebView view, String url) {
|
|
|
LogUtil.println("ActWeb", "onPageFinished", url);
|
|
|
super.onPageFinished(view, url);
|
|
|
- imgReset();
|
|
|
loadJs();
|
|
|
}
|
|
|
});
|
|
|
webViewSettings.setJavaScriptEnabled(true);
|
|
|
+
|
|
|
if (webParams.isNeedJsInteract()) {
|
|
|
mWebView.addJavascriptInterface(new KFZSJs(this), "kfzsjs");
|
|
|
- String loadUrl = addUrl(url, webParams.getTokenKey(), SpUtils.getToken(SheepApp.getInstance()));
|
|
|
- LogUtil.println("ActWeb loadUrl = " + loadUrl);
|
|
|
- if (CommonUtil.getInstance().judgeUrlPicture(url)) {
|
|
|
- runWebviewUrl("file:///android_asset/loadImg.html");
|
|
|
- } else {
|
|
|
- webViewLoadUrl(mWebView, loadUrl);
|
|
|
+ String loadUrl = url;
|
|
|
+ if(webParams.getTokenKey() != null){
|
|
|
+ loadUrl = addUrlQuery(url, webParams.getTokenKey(), SpUtils.getToken(SheepApp.getInstance()));
|
|
|
}
|
|
|
+ LogUtil.println("ActWeb loadUrl = " + loadUrl);
|
|
|
+ webViewLoadUrl(mWebView, loadUrl);
|
|
|
} else {
|
|
|
- if (CommonUtil.getInstance().judgeUrlPicture(url)) {
|
|
|
- runWebviewUrl("file:///android_asset/loadImg.html");
|
|
|
- } else {
|
|
|
- webViewLoadUrl(mWebView, url);
|
|
|
- }
|
|
|
+ webViewLoadUrl(mWebView, url);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -439,28 +463,6 @@ public class ActWebX5 extends BaseActWeb {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void imgReset() {
|
|
|
- ViewUtil.loadJs(mWebView, "(function(){" +
|
|
|
- "var objs = document.getElementsByTagName('img'); " +
|
|
|
- "for(var i=0;i<objs.length;i++) " +
|
|
|
- "{"
|
|
|
- + "var img = objs[i]; " +
|
|
|
- " img.style.maxWidth = '100%';" +
|
|
|
- "}" +
|
|
|
- "})()");
|
|
|
- }
|
|
|
-
|
|
|
- private void runWebviewUrl(final String url) {
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- if (mWebView != null && !TextUtils.isEmpty(url)) {
|
|
|
- webViewLoadUrl(mWebView, url);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
// 注入js函数监听
|
|
|
public void loadJs() {
|
|
|
if (TextUtils.isEmpty(js))
|