Skip to content

Commit 93cde1c

Browse files
committed
webView优化
1 parent 85aa219 commit 93cde1c

39 files changed

+888
-0
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WebViewLib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

WebViewLib/build.gradle

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 26
5+
buildToolsVersion "28.0.0"
6+
7+
8+
defaultConfig {
9+
minSdkVersion 15
10+
targetSdkVersion 26
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
25+
}
26+
27+
dependencies {
28+
compile fileTree(include: ['*.jar'], dir: 'libs')
29+
compile 'com.android.support:appcompat-v7:26.1.0'
30+
compile files('libs/tbs_sdk_thirdapp_v3.6.0.1325_43613_sharewithdownload_withoutGame_obfs_20180807_151115.jar')
31+
}
32+
33+
34+
35+
/** 以下开始是将Android Library上传到jcenter的相关配置**/
36+
apply plugin: 'com.github.dcendents.android-maven'
37+
apply plugin: 'com.jfrog.bintray'
38+
39+
//项目主页
40+
def siteUrl = 'https://github.com/yangchong211/YCWebView' // project homepage
41+
//项目的版本控制地址
42+
def gitUrl = 'https://github.com/yangchong211/YCWebView.git' // project git
43+
44+
//发布到组织名称名字,必须填写
45+
group = "cn.yc"
46+
//发布到JCenter上的项目名字,必须填写
47+
def libName = "WebViewLib"
48+
// 版本号,下次更新是只需要更改版本号即可
49+
version = "1.0.0"
50+
/** 上面配置后上传至jcenter后的编译路径是这样的: compile 'cn.yc:WebViewLib:1.0.0' **/
51+
52+
//生成源文件
53+
task sourcesJar(type: Jar) {
54+
from android.sourceSets.main.java.srcDirs
55+
classifier = 'sources'
56+
}
57+
//生成文档
58+
task javadoc(type: Javadoc) {
59+
source = android.sourceSets.main.java.srcDirs
60+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
61+
options.encoding "UTF-8"
62+
options.charSet 'UTF-8'
63+
options.author true
64+
options.version true
65+
options.links "https://github.com/linglongxin24/FastDev/tree/master/mylibrary/docs/javadoc"
66+
failOnError false
67+
}
68+
69+
//文档打包成jar
70+
task javadocJar(type: Jar, dependsOn: javadoc) {
71+
classifier = 'javadoc'
72+
from javadoc.destinationDir
73+
}
74+
//拷贝javadoc文件
75+
task copyDoc(type: Copy) {
76+
from "${buildDir}/docs/"
77+
into "docs"
78+
}
79+
80+
//上传到jcenter所需要的源码文件
81+
artifacts {
82+
archives javadocJar
83+
archives sourcesJar
84+
}
85+
86+
// 配置maven库,生成POM.xml文件
87+
install {
88+
repositories.mavenInstaller {
89+
// This generates POM.xml with proper parameters
90+
pom {
91+
project {
92+
packaging 'aar'
93+
//项目描述,自由填写
94+
name 'This is webView lib'
95+
url siteUrl
96+
licenses {
97+
license {
98+
//开源协议
99+
name 'The Apache Software License, Version 2.0'
100+
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
101+
}
102+
}
103+
developers {
104+
developer {
105+
//开发者的个人信息,根据个人信息填写
106+
id 'yangchong'
107+
name 'yc'
108+
109+
}
110+
}
111+
scm {
112+
connection gitUrl
113+
developerConnection gitUrl
114+
url siteUrl
115+
}
116+
}
117+
}
118+
}
119+
}
120+
121+
//上传到jcenter
122+
Properties properties = new Properties()
123+
properties.load(project.rootProject.file('local.properties').newDataInputStream())
124+
bintray {
125+
user = properties.getProperty("bintray.user") //读取 local.properties 文件里面的 bintray.user
126+
key = properties.getProperty("bintray.apikey") //读取 local.properties 文件里面的 bintray.apikey
127+
configurations = ['archives']
128+
pkg {
129+
repo = "maven"
130+
name = libName //发布到JCenter上的项目名字,必须填写
131+
desc = 'android webView' //项目描述
132+
websiteUrl = siteUrl
133+
vcsUrl = gitUrl
134+
licenses = ["Apache-2.0"]
135+
publish = true
136+
}
137+
}
138+
139+
javadoc {
140+
options {
141+
//如果你的项目里面有中文注释的话,必须将格式设置为UTF-8,不然会出现乱码
142+
encoding "UTF-8"
143+
charSet 'UTF-8'
144+
author true
145+
version true
146+
links "http://docs.oracle.com/javase/7/docs/api"
147+
}
148+
}
149+

WebViewLib/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.ycbjie.webviewlib" >
3+
4+
5+
6+
7+
</manifest>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.ycbjie.webviewlib;
2+
3+
4+
import android.app.Application;
5+
import android.content.Context;
6+
import android.util.Log;
7+
8+
import com.tencent.smtt.sdk.QbSdk;
9+
10+
/**
11+
* <pre>
12+
* @author yangchong
13+
* blog : https://github.com/yangchong211
14+
* time : 2018/5/6
15+
* desc : WebView工具类
16+
* revise: 潇湘剑雨,持续更新,欢迎各位同行提出问题和建议
17+
* </pre>
18+
*/
19+
public class WebViewUtils {
20+
21+
22+
/**
23+
* 不能直接new,否则抛个异常
24+
*/
25+
private WebViewUtils() {
26+
throw new UnsupportedOperationException("u can't instantiate me...");
27+
}
28+
29+
30+
/**
31+
* 初始化WebView
32+
* @param context 注意,必须是全局上下文,否则报错
33+
*/
34+
public static void initWebView(Context context){
35+
if(context instanceof Application){
36+
//搜集本地tbs内核信息并上报服务器,服务器返回结果决定使用哪个内核。
37+
QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
38+
@Override
39+
public void onViewInitFinished(boolean arg0) {
40+
//x5內核初始化完成的回调,为true表示x5内核加载成功
41+
//否则表示x5内核加载失败,会自动切换到系统内核。
42+
Log.d("app", " onViewInitFinished is " + arg0);
43+
}
44+
45+
@Override
46+
public void onCoreInitFinished() {
47+
Log.d("app", " onCoreInitFinished ");
48+
}
49+
};
50+
//x5内核初始化接口
51+
QbSdk.initX5Environment(context, cb);
52+
}else {
53+
throw new UnsupportedOperationException("context must be application...");
54+
}
55+
}
56+
57+
58+
}
15.1 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">WebViewLib</string>
3+
</resources>

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

0 commit comments

Comments
 (0)