|
@@ -0,0 +1,162 @@
|
|
|
+package com.edufound.ott.zijie.yuwen.mvp.presenter;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.os.Build;
|
|
|
+import android.view.View;
|
|
|
+import android.webkit.JavascriptInterface;
|
|
|
+import android.webkit.JsResult;
|
|
|
+import android.webkit.WebChromeClient;
|
|
|
+import android.webkit.WebResourceRequest;
|
|
|
+import android.webkit.WebResourceResponse;
|
|
|
+import android.webkit.WebSettings;
|
|
|
+import android.webkit.WebView;
|
|
|
+import android.webkit.WebViewClient;
|
|
|
+
|
|
|
+import com.edufound.ott.zijie.yuwen.base.BasePresenter;
|
|
|
+import com.edufound.ott.zijie.yuwen.mvp.model.MainModel;
|
|
|
+import com.edufound.ott.zijie.yuwen.mvp.view.MainView;
|
|
|
+import com.edufound.ott.zijie.yuwen.util.Logger;
|
|
|
+
|
|
|
+public class MainPersenter extends BasePresenter<MainModel, MainView> {
|
|
|
+
|
|
|
+ private String mLoadUrl;
|
|
|
+
|
|
|
+ @SuppressLint("JavascriptInterface")
|
|
|
+ public void initWeb() {
|
|
|
+ if (Build.VERSION.SDK_INT >= 19) {
|
|
|
+ getView().getWebView().getSettings().setLoadsImagesAutomatically(true);
|
|
|
+ } else {
|
|
|
+ getView().getWebView().getSettings().setLoadsImagesAutomatically(false);
|
|
|
+ }
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ getView().getWebView().getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
|
|
+ }
|
|
|
+ getView().getWebView().requestFocus(View.FOCUS_DOWN);
|
|
|
+ getView().getWebView().getSettings().setJavaScriptEnabled(true);
|
|
|
+ getView().getWebView().getSettings().setJavaScriptCanOpenWindowsAutomatically(true);//允许js弹出窗口
|
|
|
+ getView().getWebView().getSettings().setDomStorageEnabled(true);
|
|
|
+// webview.getSettings().setMediaPlaybackRequiresUserGesture(false);
|
|
|
+ getView().getWebView().getSettings().setBlockNetworkImage(false);
|
|
|
+ // webview.getSettings().set
|
|
|
+ getView().getWebView().setBackgroundColor(Color.TRANSPARENT);
|
|
|
+// webview.setBackgroundResource();
|
|
|
+ getView().getWebView().getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
|
|
|
+ getView().getWebView().getSettings().setUseWideViewPort(true);
|
|
|
+ getView().getWebView().getSettings().setLoadWithOverviewMode(true);
|
|
|
+ getView().getWebView().getSettings().setTextZoom(100);
|
|
|
+// mVideoBitmap = BitmapFactory.decodeResource(mView.getActivity().getResources(),
|
|
|
+// R.drawable.videoposterblack);
|
|
|
+ getView().getWebView().setWebChromeClient(new WebChromeClient() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
|
|
|
+
|
|
|
+ return super.onJsAlert(view, url, message, result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onShowCustomView(View view, CustomViewCallback callback) {
|
|
|
+
|
|
|
+ super.onShowCustomView(view, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onProgressChanged(WebView view, int newProgress) {
|
|
|
+
|
|
|
+ if (newProgress >= 100) {
|
|
|
+ }
|
|
|
+ super.onProgressChanged(view, newProgress);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Bitmap getDefaultVideoPoster() {
|
|
|
+// return mVideoBitmap;
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ getView().getWebView().setWebViewClient(new WebViewClient() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
|
+// webview.removeAllViews();
|
|
|
+ view.loadUrl(url);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
|
|
+ super.onReceivedError(view, errorCode, description, failingUrl);
|
|
|
+ view.loadUrl("");
|
|
|
+// showDisConnNeWorkWindow();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
|
|
|
+ super.onReceivedHttpError(view, request, errorResponse);
|
|
|
+// int statusCode = 0;
|
|
|
+// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+// statusCode = errorResponse.getStatusCode();
|
|
|
+// }
|
|
|
+// System.out.println("onReceivedHttpError code = " + statusCode);
|
|
|
+// if (404 == statusCode) {
|
|
|
+// view.loadUrl("about:blank");// 避免出现默认的错误界面
|
|
|
+// showDisConnNeWorkWindow();
|
|
|
+// }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
+ super.onPageStarted(view, url, favicon);
|
|
|
+ getView().showProgressDialog();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPageFinished(WebView view, String url) {
|
|
|
+ if (!view.getSettings().getLoadsImagesAutomatically()) {
|
|
|
+ view.getSettings().setLoadsImagesAutomatically(true);
|
|
|
+ }
|
|
|
+ getView().dismissProgressDialog();
|
|
|
+ super.onPageFinished(view, url);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ getView().getWebView().addJavascriptInterface(this, "efunboxJS");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void openWeb(Intent intent) {
|
|
|
+ getView().getWebView().loadUrl("");
|
|
|
+ mLoadUrl = model.getDefaultWebUrl();
|
|
|
+ String intent_url = intent.getStringExtra("url");
|
|
|
+ Logger.e("-----------------------------");
|
|
|
+ Logger.e("intent_url:" + intent_url);
|
|
|
+ Logger.e("-----------------------------");
|
|
|
+ if (intent_url != null && !intent_url.isEmpty()) {
|
|
|
+ mLoadUrl = intent_url;
|
|
|
+ }
|
|
|
+ mLoadUrl = mLoadUrl + model.getLoadParams(getView().getActivity());
|
|
|
+ getView().getWebView().loadUrl(mLoadUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onViewDestroy() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @SuppressLint("JavascriptInterface")
|
|
|
+ @JavascriptInterface
|
|
|
+ public void closeApp() {
|
|
|
+ model.closeApp();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|