|
|
@@ -0,0 +1,162 @@
|
|
|
+package com.sheep.gamegroup.view.activity;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.os.Build;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
+import android.webkit.WebChromeClient;
|
|
|
+import android.webkit.WebSettings;
|
|
|
+import android.webkit.WebView;
|
|
|
+import android.webkit.WebViewClient;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.kfzs.duanduan.BaseCompatActivity;
|
|
|
+import com.sheep.gamegroup.util.CommonUtil;
|
|
|
+import com.sheep.gamegroup.util.DeviceUtil;
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
+import com.zhy.http.okhttp.OkHttpUtils;
|
|
|
+import com.zhy.http.okhttp.callback.StringCallback;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.ButterKnife;
|
|
|
+import okhttp3.Call;
|
|
|
+
|
|
|
+import static com.kfzs.duanduan.bean.KFIntentKeys.EXTRA_WEBVIEW_NO_TITLE;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 闲玩
|
|
|
+ * Created by ljy on 2018/6/25.
|
|
|
+ */
|
|
|
+
|
|
|
+public class ActXinwanWeb extends BaseCompatActivity {
|
|
|
+ @BindView(R.id.webview)
|
|
|
+ WebView mWebView;
|
|
|
+ @BindView(R.id.tv_next)
|
|
|
+ TextView tv_next;
|
|
|
+
|
|
|
+ private String url_js;
|
|
|
+ private String title;
|
|
|
+ private WebSettings webViewSettings;
|
|
|
+ private Activity activity;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_guide_on_hook);
|
|
|
+ activity = this;
|
|
|
+
|
|
|
+ url_js = getIntent().getStringExtra("js_url");
|
|
|
+ title = getIntent().getStringExtra("title");
|
|
|
+// url_js = "http://10.8.210.172:8095/test.js";
|
|
|
+
|
|
|
+ ButterKnife.bind(this);
|
|
|
+ TitleBarUtils
|
|
|
+ .getInstance()
|
|
|
+ .setTitle(this, title)
|
|
|
+ .setTitleFinish(this);
|
|
|
+
|
|
|
+ webViewSettings = mWebView.getSettings();
|
|
|
+ webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ webViewSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
|
|
+ }
|
|
|
+ if (getIntent().hasExtra(EXTRA_WEBVIEW_NO_TITLE)) {//不显示标题
|
|
|
+ findViewById(R.id.appbar_act_webview).setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ tv_next.setVisibility(View.GONE);
|
|
|
+ initJsData();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initJsData() {
|
|
|
+ OkHttpUtils.get()
|
|
|
+ .url(url_js)
|
|
|
+ .build()
|
|
|
+ .execute(new StringCallback() {
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ G.showToast( R.string.service_data_error);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(String response, int id) {
|
|
|
+ js = response;
|
|
|
+ loadUrl();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ mWebView.setVisibility(View.GONE);
|
|
|
+ mWebView.removeAllViews();
|
|
|
+ mWebView.destroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadUrl() {
|
|
|
+ mWebView.setWebChromeClient(new WebChromeClient(){
|
|
|
+ @Override
|
|
|
+ public void onReceivedTitle(WebView view, String title) {
|
|
|
+ super.onReceivedTitle(view, title);
|
|
|
+ TitleBarUtils
|
|
|
+ .getInstance()
|
|
|
+ .setTitle(activity, title);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mWebView.setWebViewClient(new WebViewClient() {
|
|
|
+ @Override
|
|
|
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
|
+ try {
|
|
|
+ view.loadUrl(url);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onPageFinished(WebView view, String url) {
|
|
|
+ super.onPageFinished(view, url);
|
|
|
+ loadJs();
|
|
|
+// loadTestJs();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ webViewSettings.setJavaScriptEnabled(true);
|
|
|
+ mWebView.loadUrl(assemblyData());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBackPressed() {
|
|
|
+ if(mWebView.canGoBack()){
|
|
|
+ mWebView.goBack();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.finish();
|
|
|
+ }
|
|
|
+ // 注入js函数监听
|
|
|
+ public void loadJs() {
|
|
|
+ mWebView.loadUrl("javascript:"+getJs());
|
|
|
+ }
|
|
|
+ private String js;
|
|
|
+ private String getJs(){
|
|
|
+ return js;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装数据
|
|
|
+ * @return
|
|
|
+ * https://h5.51xianwan.com/try/try_list_plus_browser.aspx?ptype=2&deviceid=8883300242xw&appid=1010&appsign=1000&keycode=07688c3e9a783b245e59311
|
|
|
+ */
|
|
|
+ private String assemblyData(){
|
|
|
+ StringBuffer stringBuffer = new StringBuffer();
|
|
|
+ stringBuffer.append("https://h5.51xianwan.com/try/try_list_plus_browser.aspx?");
|
|
|
+ stringBuffer.append("ptype"+"");
|
|
|
+ stringBuffer.append("&deviceid"+ DeviceUtil.getDeviceId(activity));
|
|
|
+ stringBuffer.append("&appid"+"");
|
|
|
+ stringBuffer.append("&appsign"+"");
|
|
|
+ stringBuffer.append("&keycode"+CommonUtil.getInstance().encrypt2Md5("10108883300242xw2100045455"));
|
|
|
+ return stringBuffer.toString();
|
|
|
+ }
|
|
|
+}
|