|
@@ -5,7 +5,9 @@ import android.content.Intent;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.BitmapFactory;
|
|
|
import android.graphics.Color;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
+import android.os.Process;
|
|
|
import android.view.View;
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
import android.webkit.JsResult;
|
|
@@ -19,13 +21,14 @@ 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.ContextUtil;
|
|
|
import com.edufound.ott.zijie.yuwen.util.Logger;
|
|
|
+import com.edufound.ott.zijie.yuwen.util.SharedPerfenceUtil;
|
|
|
|
|
|
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);
|
|
@@ -121,22 +124,28 @@ public class MainPersenter extends BasePresenter<MainModel, MainView> {
|
|
|
if (!view.getSettings().getLoadsImagesAutomatically()) {
|
|
|
view.getSettings().setLoadsImagesAutomatically(true);
|
|
|
}
|
|
|
+ if (getView() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
getView().dismissProgressDialog();
|
|
|
super.onPageFinished(view, url);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
- getView().getWebView().addJavascriptInterface(this, "efunboxJS");
|
|
|
+ getView().getWebView().addJavascriptInterface(new MainJsMethod(), "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("-----------------------------");
|
|
|
+ Uri uri = intent.getData();
|
|
|
+ String intent_url = "";
|
|
|
+ if (uri != null) {
|
|
|
+ intent_url = uri.getQueryParameter("url");
|
|
|
+ } else {
|
|
|
+ intent_url = intent.getStringExtra("url");
|
|
|
+ }
|
|
|
if (intent_url != null && !intent_url.isEmpty()) {
|
|
|
mLoadUrl = intent_url;
|
|
|
}
|
|
@@ -150,11 +159,41 @@ public class MainPersenter extends BasePresenter<MainModel, MainView> {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //--------------------------------------------------------JS方法
|
|
|
+
|
|
|
+ class MainJsMethod {
|
|
|
+ @JavascriptInterface
|
|
|
+ public void closeApp() {
|
|
|
+ android.os.Process.killProcess(Process.myPid());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 根据key设置SP参数方法
|
|
|
+ * */
|
|
|
+ @JavascriptInterface
|
|
|
+ public void setPreData(String key, String json) {
|
|
|
+ SharedPerfenceUtil.setPrefString(ContextUtil.getmApplicationContext(), key, json);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 根据key获取SP参数方法
|
|
|
+ * */
|
|
|
+ @JavascriptInterface
|
|
|
+ public String getPreData(String key) {
|
|
|
+ return SharedPerfenceUtil.getPrefString(ContextUtil.getmApplicationContext(), key, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 根据key删除SP参数
|
|
|
+ * */
|
|
|
+ @JavascriptInterface
|
|
|
+ public void delPreData(String key) {
|
|
|
+ SharedPerfenceUtil.clearRecourds(ContextUtil.getmApplicationContext(), key);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- @SuppressLint("JavascriptInterface")
|
|
|
- @JavascriptInterface
|
|
|
- public void closeApp() {
|
|
|
- model.closeApp();
|
|
|
}
|
|
|
|
|
|
}
|