Commit 3ad71d8771a222fd02dcb239be7ae3c9bef41243
Exists in
yxb_dev
and in
2 other branches
Merge branch 'developer' of http://git.shunzhi.net/taohd/parentwork into developer
Showing
3 changed files
with
83 additions
and
10 deletions
Show diff stats
app/src/main/java/com/shunzhi/parent/ui/activity/mywebview/WebViewActivity.java
... | ... | @@ -3,39 +3,75 @@ package com.shunzhi.parent.ui.activity.mywebview; |
3 | 3 | import android.content.Context; |
4 | 4 | import android.content.Intent; |
5 | 5 | import android.graphics.Bitmap; |
6 | +import android.os.Build; | |
6 | 7 | import android.os.Bundle; |
7 | 8 | import android.support.v7.app.AppCompatActivity; |
9 | +import android.util.Log; | |
8 | 10 | import android.view.View; |
9 | 11 | import android.webkit.JavascriptInterface; |
10 | 12 | import android.webkit.WebChromeClient; |
11 | 13 | import android.webkit.WebSettings; |
12 | 14 | import android.webkit.WebView; |
13 | 15 | import android.webkit.WebViewClient; |
16 | +import android.widget.LinearLayout; | |
14 | 17 | import android.widget.ProgressBar; |
18 | +import android.widget.TextView; | |
15 | 19 | |
16 | 20 | import com.share.mvpsdk.base.activity.BaseCompatActivity; |
17 | 21 | import com.share.mvpsdk.utils.AppUtils; |
18 | 22 | import com.share.mvpsdk.utils.NetworkConnectionUtils; |
19 | 23 | import com.share.mvpsdk.widgets.NestedScrollWebView; |
24 | +import com.shunzhi.parent.AppConfig; | |
20 | 25 | import com.shunzhi.parent.R; |
21 | 26 | |
22 | 27 | public class WebViewActivity extends BaseCompatActivity { |
23 | 28 | |
24 | 29 | NestedScrollWebView nesteScrollWebView; |
30 | + LinearLayout binding_success, binding_success2; | |
31 | + TextView close,tv_info,zuoye,title_web; | |
32 | + int type; | |
25 | 33 | |
26 | 34 | private ProgressBar pvWeb; |
27 | 35 | |
28 | - public static void getInstance(Context context,String url,int type) { | |
36 | + public static void getInstance(Context context, String url, int type) { | |
29 | 37 | Intent intent = new Intent(context, WebViewActivity.class); |
30 | 38 | intent.putExtra("url", url); |
31 | - intent.putExtra("type",type); | |
39 | + intent.putExtra("type", type); | |
32 | 40 | context.startActivity(intent); |
33 | 41 | } |
34 | 42 | |
35 | 43 | @Override |
36 | 44 | protected void initView(Bundle savedInstanceState) { |
37 | - nesteScrollWebView=findViewById(R.id.nesteScrollWebView); | |
38 | - pvWeb=findViewById(R.id.pb_web); | |
45 | + binding_success=findViewById(R.id.binding_success1); | |
46 | + binding_success2=findViewById(R.id.binding_success2); | |
47 | + close = findViewById(R.id.close_btn); | |
48 | + tv_info = findViewById(R.id.tv_info); | |
49 | + zuoye = findViewById(R.id.zuoye); | |
50 | + title_web = findViewById(R.id.title_web); | |
51 | + | |
52 | + nesteScrollWebView = findViewById(R.id.webView); | |
53 | + pvWeb = findViewById(R.id.pb_web); | |
54 | + type = getIntent().getIntExtra("type", 0); | |
55 | + if (type == AppConfig.BINDING_SUCCESS_HEZUO) { | |
56 | + binding_success.setVisibility(View.VISIBLE); | |
57 | + binding_success2.setVisibility(View.GONE); | |
58 | + title_web.setVisibility(View.GONE); | |
59 | + | |
60 | + } else if (type == AppConfig.BINDING_SUCCESS_NOT) { | |
61 | + binding_success.setVisibility(View.GONE); | |
62 | + binding_success2.setVisibility(View.VISIBLE); | |
63 | + title_web.setVisibility(View.GONE); | |
64 | + | |
65 | + } else if (type == AppConfig.ORDER_CENTER) { | |
66 | + binding_success.setVisibility(View.GONE); | |
67 | + binding_success2.setVisibility(View.GONE); | |
68 | + title_web.setVisibility(View.VISIBLE); | |
69 | + }else { | |
70 | + binding_success.setVisibility(View.GONE); | |
71 | + binding_success2.setVisibility(View.GONE); | |
72 | + title_web.setVisibility(View.GONE); | |
73 | + } | |
74 | + | |
39 | 75 | initWebView(); |
40 | 76 | initWebSetting(nesteScrollWebView.getSettings()); |
41 | 77 | nesteScrollWebView.loadUrl(getIntent().getStringExtra("url")); |
... | ... | @@ -43,14 +79,14 @@ public class WebViewActivity extends BaseCompatActivity { |
43 | 79 | |
44 | 80 | @Override |
45 | 81 | protected int getLayoutId() { |
46 | - return R.layout.activity_web_view; | |
82 | + return R.layout.activity_webview; | |
47 | 83 | } |
48 | 84 | |
49 | 85 | @Override |
50 | 86 | public void onBackPressedSupport() { |
51 | - if (nesteScrollWebView.canGoBack()){ | |
87 | + if (nesteScrollWebView.canGoBack()) { | |
52 | 88 | nesteScrollWebView.goBack(); |
53 | - }else { | |
89 | + } else { | |
54 | 90 | super.onBackPressedSupport(); |
55 | 91 | } |
56 | 92 | } |
... | ... | @@ -75,6 +111,20 @@ public class WebViewActivity extends BaseCompatActivity { |
75 | 111 | }); |
76 | 112 | } |
77 | 113 | } |
114 | + // 调起支付宝并跳转到指定页面 | |
115 | + private void startAlipayActivity(String url) { | |
116 | + Intent intent; | |
117 | + try { | |
118 | + intent = Intent.parseUri(url, | |
119 | + Intent.URI_INTENT_SCHEME); | |
120 | + intent.addCategory(Intent.CATEGORY_BROWSABLE); | |
121 | + intent.setComponent(null); | |
122 | + startActivity(intent); | |
123 | + finish(); | |
124 | + } catch (Exception e) { | |
125 | + e.printStackTrace(); | |
126 | + } | |
127 | + } | |
78 | 128 | |
79 | 129 | protected void initWebView() { |
80 | 130 | // 添加js交互接口类,并起别名 imagelistner |
... | ... | @@ -83,8 +133,18 @@ public class WebViewActivity extends BaseCompatActivity { |
83 | 133 | nesteScrollWebView.setWebViewClient(new WebViewClient() { |
84 | 134 | @Override |
85 | 135 | public boolean shouldOverrideUrlLoading(WebView view, String url) { |
86 | - view.loadUrl(url); | |
136 | + if (url.startsWith("http"))view.loadUrl(url); | |
137 | +// if (url.contains("platformapi/startapp")) { | |
138 | +// startAlipayActivity(url); | |
139 | +// android 6.0 两种方式获取intent都可以跳转支付宝成功,7.1测试不成功 | |
140 | +// } else if ((Build.VERSION.SDK_INT > Build.VERSION_CODES.M) | |
141 | +// && (url.contains("platformapi") && url.contains("startapp"))) { | |
142 | +// startAlipayActivity(url); | |
143 | +// } else { | |
144 | +// view.loadUrl(url); | |
145 | +// } | |
87 | 146 | return true; |
147 | + | |
88 | 148 | } |
89 | 149 | |
90 | 150 | @Override |
... | ... | @@ -178,6 +238,11 @@ public class WebViewActivity extends BaseCompatActivity { |
178 | 238 | // WebView启用JavaScript执行。默认的是false。 |
179 | 239 | settings.setJavaScriptEnabled(true); // 设置支持javascript脚本 |
180 | 240 | settings.setJavaScriptCanOpenWindowsAutomatically(true);//设置支持js脚本 |
241 | + settings.setAllowFileAccess(true);//设置可以访问文件 | |
242 | +// settings.setBuiltInZoomControls(true); | |
243 | + settings.setCacheMode(WebSettings.LOAD_NO_CACHE); | |
244 | + settings.setDomStorageEnabled(true); | |
245 | + settings.setGeolocationEnabled(true); | |
181 | 246 | if (NetworkConnectionUtils.isConnected(mContext)) { |
182 | 247 | settings.setCacheMode(WebSettings.LOAD_DEFAULT); |
183 | 248 | } else { | ... | ... |
app/src/main/res/layout/activity_webview.xml
... | ... | @@ -32,8 +32,16 @@ |
32 | 32 | |
33 | 33 | </RelativeLayout> |
34 | 34 | |
35 | + <ProgressBar | |
36 | + android:id="@+id/pb_web" | |
37 | + style="?android:attr/progressBarStyleHorizontal" | |
38 | + android:layout_width="match_parent" | |
39 | + android:layout_height="3dp" | |
40 | + android:progressDrawable="@drawable/web_progress_bar_bg" | |
41 | + android:visibility="gone"/> | |
42 | + | |
35 | 43 | <LinearLayout |
36 | - android:id="@+id/binding_success" | |
44 | + android:id="@+id/binding_success1" | |
37 | 45 | android:layout_width="match_parent" |
38 | 46 | android:layout_height="wrap_content" |
39 | 47 | android:gravity="center" | ... | ... |
mvpsdk/src/main/java/com/share/mvpsdk/utils/OkHttpExceptionUtil.java
... | ... | @@ -20,7 +20,7 @@ public class OkHttpExceptionUtil { |
20 | 20 | if (responseBody==null)return; |
21 | 21 | try { |
22 | 22 | JSONObject json = new JSONObject(responseBody.string()); |
23 | - ToastUtils.showToast(json.optString("message")); | |
23 | + ToastUtils.showToast(json.optString("message")+"json="+json); | |
24 | 24 | } catch (Exception e1) { |
25 | 25 | e1.printStackTrace(); |
26 | 26 | } | ... | ... |