Commit 8f6486daee2007f986b5cb370b51a8a47f392083
Exists in
yxb_dev
and in
2 other branches
Merge branch 'developer' into yxb_dev
# Conflicts: # app/src/main/java/com/shunzhi/parent/ui/activity/web/WebViewActivity.java
Showing
6 changed files
with
205 additions
and
88 deletions
Show diff stats
app/src/main/AndroidManifest.xml
| ... | ... | @@ -109,11 +109,11 @@ |
| 109 | 109 | android:name=".ui.activity.binding.InviteCodeActivity" |
| 110 | 110 | android:screenOrientation="portrait" /> |
| 111 | 111 | <activity |
| 112 | - android:name=".ui.activity.WebViewActivity" | |
| 112 | + android:name=".ui.activity.web.WebViewActivity" | |
| 113 | 113 | android:screenOrientation="portrait" /> |
| 114 | 114 | <activity android:name=".ui.activity.consult.ConsultTwoLevelActivity" /> |
| 115 | 115 | <activity android:name=".ui.activity.orderdetail.OrderDetailActivity" /> |
| 116 | - <activity android:name=".ui.activity.WebViewActivity"></activity> | |
| 116 | + <activity android:name=".ui.activity.web.WebViewActivity"></activity> | |
| 117 | 117 | </application> |
| 118 | 118 | |
| 119 | 119 | </manifest> |
| 120 | 120 | \ No newline at end of file | ... | ... |
app/src/main/java/com/shunzhi/parent/presenter/ceping/CePingPresenter.java
| 1 | 1 | package com.shunzhi.parent.presenter.ceping; |
| 2 | 2 | |
| 3 | -import android.util.Log; | |
| 4 | 3 | import android.view.View; |
| 5 | 4 | import android.widget.LinearLayout; |
| 6 | 5 | |
| ... | ... | @@ -11,13 +10,10 @@ import com.shunzhi.parent.R; |
| 11 | 10 | import com.shunzhi.parent.bean.ToolBean; |
| 12 | 11 | import com.shunzhi.parent.contract.ceping.CepingContract; |
| 13 | 12 | import com.shunzhi.parent.model.CePingModel; |
| 14 | -import com.shunzhi.parent.ui.activity.WebViewActivity; | |
| 13 | +import com.shunzhi.parent.ui.activity.web.WebViewActivity; | |
| 15 | 14 | import com.shunzhi.parent.util.AttrsUtils; |
| 16 | 15 | import com.shunzhi.parent.views.TextAndImgShowView; |
| 17 | 16 | |
| 18 | -import java.util.ArrayList; | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 21 | 17 | import io.reactivex.functions.Consumer; |
| 22 | 18 | |
| 23 | 19 | /** | ... | ... |
app/src/main/java/com/shunzhi/parent/ui/activity/WebViewActivity.java
| ... | ... | @@ -1,79 +0,0 @@ |
| 1 | -package com.shunzhi.parent.ui.activity; | |
| 2 | - | |
| 3 | -import android.app.Activity; | |
| 4 | -import android.content.Intent; | |
| 5 | -import android.os.Bundle; | |
| 6 | -import android.view.View; | |
| 7 | -import android.webkit.WebViewClient; | |
| 8 | -import android.widget.LinearLayout; | |
| 9 | -import android.widget.TextView; | |
| 10 | - | |
| 11 | -import com.share.mvpsdk.base.activity.BaseCompatActivity; | |
| 12 | -import com.share.mvpsdk.widgets.NestedScrollWebView; | |
| 13 | -import com.shunzhi.parent.AppConfig; | |
| 14 | -import com.shunzhi.parent.R; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * Created by Administrator on 2018/3/16 0016. | |
| 18 | - */ | |
| 19 | - | |
| 20 | -public class WebViewActivity extends BaseCompatActivity { | |
| 21 | - TextView close_btn, title_web, tv_info, zuoye; | |
| 22 | - LinearLayout binding_success, binding_success2; | |
| 23 | - NestedScrollWebView webView; | |
| 24 | - public int type; //BINDING_SUCCESS_HEZUO=1,INDING_SUCCESS_NOT=2, ORDER_CENTER=3 | |
| 25 | - | |
| 26 | - | |
| 27 | - public static void start_show(Activity activity, int type) { | |
| 28 | - Intent intent = new Intent(activity, WebViewActivity.class); | |
| 29 | - intent.putExtra("type", type); | |
| 30 | - activity.startActivity(intent); | |
| 31 | - } | |
| 32 | - | |
| 33 | - @Override | |
| 34 | - protected void initView(Bundle savedInstanceState) { | |
| 35 | - type = getIntent().getIntExtra("type", 0); | |
| 36 | - binding_success = findViewById(R.id.binding_success); | |
| 37 | - binding_success2 = findViewById(R.id.binding_success2); | |
| 38 | - close_btn = findViewById(R.id.close_btn); | |
| 39 | - title_web = findViewById(R.id.title_web); | |
| 40 | - tv_info = findViewById(R.id.tv_info); | |
| 41 | - zuoye = findViewById(R.id.zuoye); | |
| 42 | - close_btn.setOnClickListener(new View.OnClickListener() { | |
| 43 | - @Override | |
| 44 | - public void onClick(View v) { | |
| 45 | - startActivity(new Intent().setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).setClass(WebViewActivity.this, MyChildActivity.class)); | |
| 46 | - } | |
| 47 | - }); | |
| 48 | - | |
| 49 | - | |
| 50 | - webView = findViewById(R.id.webView); | |
| 51 | - webView.setWebViewClient(new WebViewClient()); | |
| 52 | - webView.loadUrl("http://blog.csdn.net/lee4755026/article/details/52161035"); | |
| 53 | - if (type == AppConfig.BINDING_SUCCESS_HEZUO) { | |
| 54 | - binding_success.setVisibility(View.VISIBLE); | |
| 55 | - binding_success2.setVisibility(View.GONE); | |
| 56 | - title_web.setVisibility(View.GONE); | |
| 57 | - } else if (type == AppConfig.BINDING_SUCCESS_NOT) { | |
| 58 | - binding_success2.setVisibility(View.VISIBLE); | |
| 59 | - binding_success.setVisibility(View.GONE); | |
| 60 | - title_web.setVisibility(View.GONE); | |
| 61 | - initInfo(); | |
| 62 | - } else if (type == AppConfig.ORDER_CENTER) { | |
| 63 | - | |
| 64 | - } | |
| 65 | - | |
| 66 | - } | |
| 67 | - | |
| 68 | - | |
| 69 | - private void initInfo() { | |
| 70 | - | |
| 71 | - | |
| 72 | - | |
| 73 | - } | |
| 74 | - | |
| 75 | - @Override | |
| 76 | - protected int getLayoutId() { | |
| 77 | - return R.layout.activity_webview; | |
| 78 | - } | |
| 79 | -} |
app/src/main/java/com/shunzhi/parent/ui/activity/binding/CheckInfoActivity.java
| ... | ... | @@ -25,7 +25,7 @@ import com.shunzhi.parent.bean.CurrentBean; |
| 25 | 25 | import com.shunzhi.parent.contract.mine.MyChildContract; |
| 26 | 26 | import com.shunzhi.parent.presenter.mine.MyChildPresenter; |
| 27 | 27 | import com.shunzhi.parent.ui.activity.MyChildActivity; |
| 28 | -import com.shunzhi.parent.ui.activity.WebViewActivity; | |
| 28 | +import com.shunzhi.parent.ui.activity.web.WebViewActivity; | |
| 29 | 29 | |
| 30 | 30 | import java.util.List; |
| 31 | 31 | ... | ... |
app/src/main/java/com/shunzhi/parent/ui/activity/web/WebViewActivity.java
0 → 100644
| ... | ... | @@ -0,0 +1,200 @@ |
| 1 | +package com.shunzhi.parent.ui.activity.web; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.graphics.Bitmap; | |
| 6 | +import android.os.Bundle; | |
| 7 | +import android.view.View; | |
| 8 | +import android.webkit.JavascriptInterface; | |
| 9 | +import android.webkit.WebChromeClient; | |
| 10 | +import android.webkit.WebSettings; | |
| 11 | +import android.webkit.WebView; | |
| 12 | +import android.webkit.WebViewClient; | |
| 13 | +import android.widget.ProgressBar; | |
| 14 | + | |
| 15 | +import com.share.mvpsdk.base.activity.BaseCompatActivity; | |
| 16 | +import com.share.mvpsdk.utils.AppUtils; | |
| 17 | +import com.share.mvpsdk.utils.NetworkConnectionUtils; | |
| 18 | +import com.share.mvpsdk.widgets.NestedScrollWebView; | |
| 19 | +import com.shunzhi.parent.R; | |
| 20 | + | |
| 21 | +public class WebViewActivity extends BaseCompatActivity { | |
| 22 | + | |
| 23 | + NestedScrollWebView nesteScrollWebView; | |
| 24 | + | |
| 25 | + private ProgressBar pvWeb; | |
| 26 | + | |
| 27 | + public static void getInstance(Context context,String url) { | |
| 28 | + Intent intent = new Intent(context, WebViewActivity.class); | |
| 29 | + intent.putExtra("url", url); | |
| 30 | + context.startActivity(intent); | |
| 31 | + } | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + protected void initView(Bundle savedInstanceState) { | |
| 35 | + nesteScrollWebView=findViewById(R.id.nesteScrollWebView); | |
| 36 | + pvWeb=findViewById(R.id.pb_web); | |
| 37 | + initWebView(); | |
| 38 | + initWebSetting(nesteScrollWebView.getSettings()); | |
| 39 | + nesteScrollWebView.loadUrl(getIntent().getStringExtra("url")); | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + protected int getLayoutId() { | |
| 44 | + return R.layout.activity_web_view; | |
| 45 | + } | |
| 46 | + | |
| 47 | + @Override | |
| 48 | + public void onBackPressedSupport() { | |
| 49 | + if (nesteScrollWebView.canGoBack()){ | |
| 50 | + nesteScrollWebView.goBack(); | |
| 51 | + }else { | |
| 52 | + super.onBackPressedSupport(); | |
| 53 | + } | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * js接口 | |
| 58 | + */ | |
| 59 | + public class SupportJavascriptInterface { | |
| 60 | + private Context context; | |
| 61 | + | |
| 62 | + public SupportJavascriptInterface(Context context) { | |
| 63 | + this.context = context; | |
| 64 | + } | |
| 65 | + | |
| 66 | + @JavascriptInterface | |
| 67 | + public void openImage(final String img) { | |
| 68 | + AppUtils.runOnUIThread(new Runnable() { | |
| 69 | + @Override | |
| 70 | + public void run() { | |
| 71 | +// gotoImageBrowse(img); | |
| 72 | + } | |
| 73 | + }); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + protected void initWebView() { | |
| 78 | + // 添加js交互接口类,并起别名 imagelistner | |
| 79 | + nesteScrollWebView.addJavascriptInterface(new SupportJavascriptInterface(this), | |
| 80 | + "imagelistner"); | |
| 81 | + nesteScrollWebView.setWebViewClient(new WebViewClient() { | |
| 82 | + @Override | |
| 83 | + public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
| 84 | + view.loadUrl(url); | |
| 85 | + return true; | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Override | |
| 89 | + public void onPageFinished(WebView view, String url) { | |
| 90 | + view.getSettings().setJavaScriptEnabled(true); | |
| 91 | + super.onPageFinished(view, url); | |
| 92 | + // html加载完成之后,添加监听图片的点击js函数 | |
| 93 | + addWebImageClickListner(view); | |
| 94 | +// toolbar.setTitle(getToolbarTitle()); | |
| 95 | + } | |
| 96 | + | |
| 97 | + @Override | |
| 98 | + public void onPageStarted(WebView view, String url, Bitmap favicon) { | |
| 99 | + view.getSettings().setJavaScriptEnabled(true); | |
| 100 | + super.onPageStarted(view, url, favicon); | |
| 101 | + } | |
| 102 | + | |
| 103 | + // 注入js函数监听 | |
| 104 | + protected void addWebImageClickListner(WebView webView) { | |
| 105 | + // 这段js函数的功能就是,遍历所有的img节点,并添加onclick函数, | |
| 106 | + // 函数的功能是在图片点击的时候调用本地java接口并传递url过去 | |
| 107 | + webView.loadUrl("javascript:(function(){" + | |
| 108 | + "var objs = document.getElementsByTagName(\"img\"); " + | |
| 109 | + "for(var i=0;i<objs.length;i++) " + | |
| 110 | + "{" | |
| 111 | + + " objs[i].onclick=function() " + | |
| 112 | + " { " | |
| 113 | + + " window.imagelistner.openImage(this.src); " + | |
| 114 | + " } " + | |
| 115 | + "}" + | |
| 116 | + "})()"); | |
| 117 | + } | |
| 118 | + }); | |
| 119 | + | |
| 120 | + nesteScrollWebView.setWebChromeClient(new WebChromeClient() { | |
| 121 | + @Override | |
| 122 | + public void onProgressChanged(WebView view, int newProgress) { | |
| 123 | + if (newProgress == 100) { | |
| 124 | + pvWeb.setVisibility(View.GONE);//加载完网页进度条消失 | |
| 125 | + } else { | |
| 126 | + pvWeb.setVisibility(View.VISIBLE);//开始加载网页时显示进度条 | |
| 127 | + pvWeb.setProgress(newProgress);//设置进度值 | |
| 128 | + } | |
| 129 | + } | |
| 130 | + }); | |
| 131 | + | |
| 132 | + nesteScrollWebView.setOnLongClickListener(new View.OnLongClickListener() { | |
| 133 | + @Override | |
| 134 | + public boolean onLongClick(View v) { | |
| 135 | + WebView.HitTestResult result = ((WebView) v).getHitTestResult(); | |
| 136 | + if (null == result) | |
| 137 | + return false; | |
| 138 | + | |
| 139 | +// mPresenter.imageLongClicked(result); | |
| 140 | +// mImgurl = result.getExtra(); | |
| 141 | + | |
| 142 | + return true; | |
| 143 | + } | |
| 144 | + }); | |
| 145 | + | |
| 146 | +// nswvDetailContent.setOnTouchListener(WebViewOnTouchListener); | |
| 147 | + } | |
| 148 | + | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * 初始化WebSetting | |
| 152 | + * | |
| 153 | + * @param settings WebSetting | |
| 154 | + */ | |
| 155 | + protected void initWebSetting(WebSettings settings) { | |
| 156 | + // 缩放至屏幕的大小 | |
| 157 | + settings.setLoadWithOverviewMode(true); | |
| 158 | + // 保存表单数据 | |
| 159 | + settings.setSaveFormData(true); | |
| 160 | + // 是否应该支持使用其屏幕缩放控件和手势缩放 | |
| 161 | + settings.setSupportZoom(true); | |
| 162 | + // //是否支持手势缩放控制 | |
| 163 | + // settings.setBuiltInZoomControls(true); | |
| 164 | + // 是否隐藏原生的缩放控件 | |
| 165 | + // settings.setDisplayZoomControls(false); | |
| 166 | + // 启动应用缓存 | |
| 167 | + settings.setAppCacheEnabled(true); | |
| 168 | + // 排版适应屏幕,只显示一列 | |
| 169 | + settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); | |
| 170 | + // settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); | |
| 171 | + // 页面加载好以后,再放开图片 | |
| 172 | + settings.setBlockNetworkImage(false); | |
| 173 | + // 使用localStorage则必须打开 | |
| 174 | + settings.setDomStorageEnabled(true); | |
| 175 | + settings.setDatabaseEnabled(true); | |
| 176 | + // WebView启用JavaScript执行。默认的是false。 | |
| 177 | + settings.setJavaScriptEnabled(true); // 设置支持javascript脚本 | |
| 178 | + settings.setJavaScriptCanOpenWindowsAutomatically(true);//设置支持js脚本 | |
| 179 | + if (NetworkConnectionUtils.isConnected(mContext)) { | |
| 180 | + settings.setCacheMode(WebSettings.LOAD_DEFAULT); | |
| 181 | + } else { | |
| 182 | + settings.setCacheMode(WebSettings.LOAD_CACHE_ONLY); | |
| 183 | + } | |
| 184 | + | |
| 185 | + // settings.setBlockNetworkImage(false); | |
| 186 | + // settings.setAppCacheEnabled(true); | |
| 187 | + // settings.setDomStorageEnabled(true); | |
| 188 | + // settings.setDatabaseEnabled(true); | |
| 189 | + // if (NetworkConnectionUtils.isConnected(mContext)) { | |
| 190 | + // settings.setCacheMode(WebSettings.LOAD_DEFAULT); | |
| 191 | + // } else { | |
| 192 | + // settings.setCacheMode(WebSettings.LOAD_CACHE_ONLY); | |
| 193 | + // } | |
| 194 | + // settings.setJavaScriptEnabled(true); | |
| 195 | + // settings.setLoadWithOverviewMode(true); | |
| 196 | + // settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); | |
| 197 | + // settings.setSupportZoom(true); | |
| 198 | + } | |
| 199 | + | |
| 200 | +} | ... | ... |
app/src/main/res/layout/activity_web_view.xml
| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | android:layout_height="match_parent" |
| 7 | 7 | android:orientation="vertical" |
| 8 | 8 | android:background="@color/bgColor" |
| 9 | - tools:context="com.shunzhi.parent.ui.activity.WebViewActivity"> | |
| 9 | + tools:context="com.shunzhi.parent.ui.activity.web.WebViewActivity"> | |
| 10 | 10 | <ProgressBar |
| 11 | 11 | android:id="@+id/pb_web" |
| 12 | 12 | style="?android:attr/progressBarStyleHorizontal" | ... | ... |