|
|
@@ -1,7 +1,9 @@
|
|
|
package com.sheep.jiuyan.samllsheep.page;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
+import android.webkit.JavascriptInterface;
|
|
|
import android.webkit.WebChromeClient;
|
|
|
import android.webkit.WebResourceRequest;
|
|
|
import android.webkit.WebView;
|
|
|
@@ -11,8 +13,18 @@ import android.widget.TextView;
|
|
|
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.base.BaseActivity;
|
|
|
+import com.sheep.jiuyan.samllsheep.net.NetManager;
|
|
|
+import com.sheep.jiuyan.samllsheep.net.SheepCallback;
|
|
|
+import com.sheep.jiuyan.samllsheep.net.Url;
|
|
|
+import com.sheep.jiuyan.samllsheep.page.entry.WXAccount;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* Created by kemllor on 2018/1/2.
|
|
|
*/
|
|
|
@@ -21,6 +33,8 @@ public class WebActivity extends BaseActivity {
|
|
|
|
|
|
private WebView mWeb;
|
|
|
public final static String INTENT_URL = "url";
|
|
|
+ public final static String INTENT_TITLE = "INTENT_TITLE";
|
|
|
+ public final static String INTENT_LOAD_JS = "INTENT_LOAD_JS";//只要此INTENT有就会载入
|
|
|
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
@@ -29,6 +43,11 @@ public class WebActivity extends BaseActivity {
|
|
|
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
+ if (!getIntent().hasExtra(INTENT_URL)) {
|
|
|
+ G.showToast("网址打开失败!");
|
|
|
+ finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
mWeb = (WebView) findViewById(R.id.web);
|
|
|
mWeb.setWebChromeClient(new WebChromeClient() {
|
|
|
|
|
|
@@ -42,18 +61,56 @@ public class WebActivity extends BaseActivity {
|
|
|
}
|
|
|
});
|
|
|
TitleBarUtils.getInstance()
|
|
|
- .setTitle(this, "任务攻略")
|
|
|
+ .setTitle(this, getIntent().hasExtra(INTENT_TITLE) ?
|
|
|
+ getIntent().getStringExtra(INTENT_TITLE) : "任务攻略")
|
|
|
.setTitleFinish(this);
|
|
|
+
|
|
|
+ if (getIntent().hasExtra(INTENT_LOAD_JS)) {
|
|
|
+ mWeb.addJavascriptInterface(new PublicJavaScript(), "PublicJavaScript");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * JS调用方法
|
|
|
+ */
|
|
|
+ public class PublicJavaScript {
|
|
|
+ @JavascriptInterface
|
|
|
+ public void submit(String user, String pass, String phone) {
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("wx_open_id", SpUtils.getOpenId(WebActivity.this));
|
|
|
+ map.put("wx_1", user);
|
|
|
+ map.put("ps_1", pass);
|
|
|
+ map.put("phone", phone);
|
|
|
+ NetManager.get(Url.WXACCOUNT, map, WebActivity.this,
|
|
|
+ new SheepCallback<String>(WebActivity.this) {
|
|
|
+ @Override
|
|
|
+ public void success(String string) {
|
|
|
+ G.showToast("申请成功!");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void finish() {
|
|
|
+ WebActivity.this.finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void setTitle(String title) {
|
|
|
+ TitleBarUtils.getInstance().setTitle(WebActivity.this, title);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public void initListener() {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
- Intent intent = getIntent();
|
|
|
- String url = intent.getStringExtra("url");
|
|
|
+ String url = getIntent().getStringExtra(INTENT_URL);
|
|
|
mWeb.loadUrl(url);
|
|
|
}
|
|
|
|