package com.ql.dev.customwebview.library.views;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.ql.dev.customwebview.library.R;
import com.ql.dev.customwebview.library.dialog.UploadPopup;
import com.ql.dev.customwebview.library.utils.StringUtils;
/**
* Created by Quanguanzhou on 2017/3/22 0022.
* Copyright (c) 2015, quanguanzhou83@gmail.com All Rights Reserved.
*/
public class CustomWebView extends LinearLayout {
private Context mContext;
private View rootView;
private RelativeLayout navWebView;
private LinearLayout llLeftBack;
private TextView tvLeftBack;
private LinearLayout llLeftClose;
private TextView tvLeftClose;
private LinearLayout llCenter;
private TextView tvCenter;
public LinearLayout llRight;
private TextView tvRight;
private ImageView ivRight;
private ProgressBar pbGress;
private WebView wvWebview;
private Params param;
private CustomWebView(Context mContext) {
super(mContext);
this.mContext = mContext;
}
private CustomWebView(Context mContext, AttributeSet attrs) {
super(mContext, attrs);
this.mContext = mContext;
}
private CustomWebView(Context mContext, AttributeSet attrs, int defStyleAttr) {
super(mContext, attrs, defStyleAttr);
this.mContext = mContext;
}
private void initView() {
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
rootView = (ViewGroup) layoutInflater.inflate(R.layout.custom_view_webview, this);
rootView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
navWebView = (RelativeLayout) rootView.findViewById(R.id.navWebView);
llLeftBack = (LinearLayout) rootView.findViewById(R.id.llLeftBack);
tvLeftBack = (TextView) rootView.findViewById(R.id.tvLeftBack);
llLeftClose = (LinearLayout) rootView.findViewById(R.id.llLeftClose);
tvLeftClose = (TextView) rootView.findViewById(R.id.tvLeftClose);
llCenter = (LinearLayout) rootView.findViewById(R.id.llCenter);
tvCenter = (TextView) rootView.findViewById(R.id.tvCenter);
llRight = (LinearLayout) rootView.findViewById(R.id.llRight);
tvRight = (TextView) rootView.findViewById(R.id.tvRight);
ivRight = (ImageView) rootView.findViewById(R.id.ivRight);
pbGress = (ProgressBar) rootView.findViewById(R.id.pbGress);
wvWebview = (WebView) rootView.findViewById(R.id.wvWebview);
initListener();
setPageProperty();
}
private void setPageProperty() {
if(param.navigationView){
if(!StringUtils.isEmpty(param.isRefresh)){
if(param.isRefresh.equals("0")) {
tvRight.setVisibility(GONE);
}else{
tvRight.setVisibility(VISIBLE);
tvRight.setTextColor(getResources().getColor(param.rightFontColor));
if(!StringUtils.isEmpty(param.rightValue)){
tvRight.setText(param.rightValue);
Drawable drawable = getResources().getDrawable(param.rightLeftPicResId);
tvRight.setCompoundDrawablesWithIntrinsicBounds(drawable,null,null,null);
}
}
}
if(!StringUtils.isEmpty(param.isShowBack)){
if(param.isShowBack.equals("0")) {
tvLeftBack.setVisibility(GONE);
}else{
tvLeftBack.setVisibility(VISIBLE);
Drawable drawable= getResources().getDrawable(param.backPic);
tvLeftBack.setTextColor(getResources().getColor(param.backfontColor));
tvLeftBack.setCompoundDrawablesWithIntrinsicBounds(drawable,null,null,null);
}
}
if(!StringUtils.isEmpty(param.isShowClose)){
if(param.isShowClose.equals("0")) {
tvLeftClose.setVisibility(GONE);
}else{
tvLeftClose.setVisibility(VISIBLE);
tvLeftClose.setTextColor(getResources().getColor(param.closeFontColor));
}
}
tvCenter.setTextColor(getResources().getColor(param.centerFontColor));
navWebView.setBackgroundColor(getResources().getColor(param.backColor));
llLeftBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (param.onNavigationCallbackListener != null) {
param.onNavigationCallbackListener.doLeftbackListener(wvWebview,param.activity);
}
}
});
llLeftClose.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (param.onNavigationCallbackListener != null) {
param.onNavigationCallbackListener.doLeftCloseListener(wvWebview,param.activity);
}
}
});
llRight.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (param.onNavigationCallbackListener != null) {
param.onNavigationCallbackListener.doRightCallbackListener(wvWebview,param.activity);
}
}
});
tvCenter.setText(param.centerTitle);
navWebView.setVisibility(VISIBLE);
}else{
navWebView.setVisibility(GONE);
}
}
private void initListener() {
try {
wvWebview.setWebChromeClient(new MyWebChromClient(pbGress, param.hostJsScopeClass,param.onWebViewChromListener));
//获取WebSettings对象
WebSettings settings = wvWebview.getSettings();
//设置是否启用支持javascript
settings.setJavaScriptEnabled(param.javaScriptEnabled);
settings.setDomStorageEnabled(param.domStorageEnabled);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//页面使用了HTTPs和HTTP混合的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
//设置缓存策略
settings.setCacheMode(param.cacheMode);
wvWebview.setWebViewClient(new MyWebViewClient(param.activity,param.openBySystem,param.onWebViewClientListener));
wvWebview.setOverScrollMode(param.overScrollMode);
wvWebview.loadUrl(param.url);
wvWebview.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
WebView.HitTestResult result = ((WebView) v).getHitTestResult();
if (null == result) {
return false;
}
int type = result.getType();
if(WebView.HitTestResult.IMAGE_TYPE == type){ // 长按图片弹对话框,进行保存图片
String imgurl = result.getExtra();
UploadPopup uploadPopup = doInitUploadPopup(R.id.wvWebview,imgurl);
uploadPopup.setValues(false,"",false,"","保存图
没有合适的资源?快使用搜索试试~ 我知道了~
通过对js层调用函数及回调函数的包装,支持异步回调,方法参数支持js所有已知的类型
共70个文件
xml:22个
java:18个
png:15个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 179 浏览量
2023-07-09
09:04:29
上传
评论
收藏 5.56MB ZIP 举报
温馨提示
抛弃使用高风险的WebView addJavascriptInterface方法,通过对js层调用函数及回调函数的包装,支持异步回调,方法参数支持js所有已知的类型,包括number、string、boolean、object、function。 同时还针对WebView的一些常用的方法进行了一定的封装,像返回、刷新、网页中图片保存、是否用系统浏览器进行打开
资源推荐
资源详情
资源评论
收起资源包目录
CustomWebViewBridge-master.zip (70个子文件)
CustomWebViewBridge-master
gradle.properties 977B
gradle
wrapper
gradle-wrapper.jar 53KB
gradle-wrapper.properties 202B
doc
IMG_5514.PNG 3.66MB
IMG_4845.JPG 188KB
QQ截图20181027140348.png 189KB
QQ截图20181027140310.png 35KB
IMG_4846.JPG 103KB
library
src
main
java
com
ql
dev
customwebview
library
dialog
UploadPopup.java 6KB
utils
StringUtils.java 765B
TaskExecutor.java 4KB
views
OnWebViewChromListener.java 732B
HostJsScope.java 3KB
OnNavigationCallbackListener.java 1KB
OnWebViewClientListener.java 2KB
WebViewDownload.java 2KB
GlobalHtmlInfo.java 2KB
MyWebViewClient.java 9KB
CustomWebView.java 18KB
MyWebChromClient.java 8KB
JsCallback.java 2KB
JsCallJava.java 9KB
res
animator
pop_hidden_anim.xml 332B
pop_show_anim.xml 333B
mipmap-mdpi
icon_back.png 1KB
values
dimens.xml 357B
colors.xml 301B
strings.xml 70B
styles.xml 795B
layout
navigation_webview.xml 3KB
pop_upload_header.xml 3KB
custom_view_webview.xml 757B
drawable
web_progressbar_bg.xml 646B
pop_common_bg.xml 206B
AndroidManifest.xml 168B
proguard-rules.pro 751B
build.gradle 796B
app
src
main
assets
zepto.js 97KB
index.html 4KB
error.html 0B
images
QQ图片20160912102956.png 1.31MB
java
com
ql
dev
customwebview
demo
CustomWebViewActivity.java 5KB
CustomHostJsScope.java 2KB
utils
ClipboardUtils.java 946B
MainActivity.java 2KB
res
mipmap-xxhdpi
ic_launcher_round.png 10KB
ic_launcher.png 6KB
mipmap-hdpi
ic_launcher_round.png 5KB
ic_launcher.png 3KB
drawable-v24
ic_launcher_foreground.xml 2KB
mipmap-anydpi-v26
ic_launcher.xml 272B
ic_launcher_round.xml 272B
mipmap-mdpi
ic_launcher_round.png 3KB
ic_launcher.png 2KB
mipmap-xxxhdpi
ic_launcher_round.png 15KB
ic_launcher.png 9KB
mipmap-xhdpi
ic_launcher_round.png 7KB
ic_launcher.png 4KB
values
colors.xml 265B
strings.xml 76B
styles.xml 383B
layout
activity_custom_webview.xml 245B
activity_main.xml 1KB
drawable
ic_launcher_background.xml 5KB
AndroidManifest.xml 1KB
proguard-rules.pro 751B
build.gradle 815B
LICENSE 11KB
build.gradle 734B
settings.gradle 27B
共 70 条
- 1
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6651
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功