Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
唐文
/
AiyoZhuaWaWa
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a5fb389d
authored
Dec 08, 2017
by
chengfengpiaopiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
原生WebView替換為TBS騰訊WebView
parent
f7b87623
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
87 additions
and
73 deletions
.gitignore
.idea/misc.xml
.idea/modules.xml
app/src/main/java/com/maile/jingcai/view/activity/MainActivity.java
app/src/main/java/com/maile/jingcai/view/fragment/SimpleCardFragment.java
app/src/main/java/com/maile/jingcai/view/iview/IWebView.java
app/src/main/res/layout/fr_simple_card.xml
build.gradle
.gitignore
View file @
a5fb389d
...
...
@@ -7,3 +7,4 @@
/build
/captures
.externalNativeBuild
build.gradle
.idea/misc.xml
View file @
a5fb389d
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"EntryPointsManager"
>
<entry_points
version=
"2.0"
/>
</component>
<component
name=
"NullableNotNullManager"
>
<option
name=
"myDefaultNullable"
value=
"android.support.annotation.Nullable"
/>
<option
name=
"myDefaultNotNull"
value=
"android.support.annotation.NonNull"
/>
...
...
@@ -24,7 +27,7 @@
</value>
</option>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
8"
default
=
"true"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
7"
default=
"true"
assert-keyword=
"true"
jdk-15
=
"true"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
</component>
<component
name=
"ProjectType"
>
...
...
.idea/modules.xml
View file @
a5fb389d
...
...
@@ -3,7 +3,8 @@
<component
name=
"ProjectModuleManager"
>
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/DuoBaoJingCai.iml"
filepath=
"$PROJECT_DIR$/DuoBaoJingCai.iml"
/>
<module
fileurl=
"file://G:\Product\Android\DuoBaoJingCai\DuoBaoJingCai2.iml"
filepath=
"G:\Product\Android\DuoBaoJingCai\DuoBaoJingCai2.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/DuoBaoJingCai2.iml"
filepath=
"$PROJECT_DIR$/DuoBaoJingCai2.iml"
/>
<module
fileurl=
"file://G:/Product/Android/DuoBaoJingCai/DuoBaoJingCai2.iml"
filepath=
"G:/Product/Android/DuoBaoJingCai/DuoBaoJingCai2.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/app/app.iml"
filepath=
"$PROJECT_DIR$/app/app.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/multi-image-selector/multi-image-selector.iml"
filepath=
"$PROJECT_DIR$/multi-image-selector/multi-image-selector.iml"
/>
</modules>
...
...
app/src/main/java/com/maile/jingcai/view/activity/MainActivity.java
View file @
a5fb389d
...
...
@@ -103,7 +103,7 @@ public class MainActivity extends FragmentActivity implements IWebView ,Activity
private
CommonTabLayout
mTabLayout_2
;
private
long
exitTime
;
private
WebView
mWebView
;
private
com
.
tencent
.
smtt
.
sdk
.
WebView
mWebView
;
private
String
mWebURL
;
//h5.7peng.cn 大厅
//http://api.7peng.cn/shop 商城
...
...
@@ -221,6 +221,30 @@ public class MainActivity extends FragmentActivity implements IWebView ,Activity
}
@Override
public
void
editUserImage
(
com
.
tencent
.
smtt
.
sdk
.
WebView
webView
,
String
webURL
,
String
uid
)
{
this
.
mWebView
=
webView
;
this
.
mWebURL
=
webURL
;
this
.
uid
=
uid
;
mToastBar
.
showErrorBar
(
"正在拉起库"
);
/**
* 直接拉起相册库--》去除dialog
*/
if
(!
NetUtils
.
isNetworkOK
(
this
))
{
mToastBar
.
showErrorBar
(
R
.
string
.
network_not_ok
);
}
else
{
Intent
intent
;
//19版本
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
)
{
Intent
intentHead
=
new
Intent
(
MainActivity
.
this
,
ImageCropHeadActivity
.
class
);
startActivityForResult
(
intentHead
,
IMAGE_HEAD
);
}
else
{
intent
=
CameraUtil
.
cropImageUri
();
startActivityForResult
(
intent
,
CameraUtil
.
SELECT_A_PICTURE
);
}
}
}
private
class
MyPagerAdapter
extends
FragmentPagerAdapter
{
...
...
@@ -389,29 +413,6 @@ public class MainActivity extends FragmentActivity implements IWebView ,Activity
}});
}
@Override
public
void
editUserImage
(
WebView
webView
,
String
webURL
,
String
uid
)
{
this
.
mWebView
=
webView
;
this
.
mWebURL
=
webURL
;
this
.
uid
=
uid
;
mToastBar
.
showErrorBar
(
"正在拉起库"
);
/**
* 直接拉起相册库--》去除dialog
*/
if
(!
NetUtils
.
isNetworkOK
(
this
))
{
mToastBar
.
showErrorBar
(
R
.
string
.
network_not_ok
);
}
else
{
Intent
intent
;
//19版本
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
)
{
Intent
intentHead
=
new
Intent
(
MainActivity
.
this
,
ImageCropHeadActivity
.
class
);
startActivityForResult
(
intentHead
,
IMAGE_HEAD
);
}
else
{
intent
=
CameraUtil
.
cropImageUri
();
startActivityForResult
(
intent
,
CameraUtil
.
SELECT_A_PICTURE
);
}
}
}
private
PermissionUtils
.
PermissionGrant
mPermissionGrant
=
new
PermissionUtils
.
PermissionGrant
()
{
@Override
...
...
app/src/main/java/com/maile/jingcai/view/fragment/SimpleCardFragment.java
View file @
a5fb389d
...
...
@@ -25,8 +25,8 @@ import android.webkit.JavascriptInterface;
import
android.webkit.JsResult
;
import
android.webkit.WebChromeClient
;
import
android.webkit.WebSettings
;
import
android.webkit
.WebView
;
import
android.webkit
.WebViewClient
;
import
com.tencent.smtt.sdk
.WebView
;
import
com.tencent.smtt.sdk
.WebViewClient
;
import
android.widget.ProgressBar
;
import
android.widget.RelativeLayout
;
import
android.widget.Toast
;
...
...
@@ -66,7 +66,7 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
@InjectView
(
R
.
id
.
webView_progress
)
ProgressBar
mWebViewProgress
;
@InjectView
(
R
.
id
.
webView
)
WebView
mWebView
;
com
.
tencent
.
smtt
.
sdk
.
WebView
mWebView
;
@InjectView
(
R
.
id
.
rl_loading_layout
)
RelativeLayout
mLoading
;
...
...
@@ -123,7 +123,7 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
mLoading
.
setVisibility
(
View
.
VISIBLE
);
mWebView
.
setVisibility
(
View
.
VISIBLE
);
WebSettings
webSettings
=
mWebView
.
getSettings
();
com
.
tencent
.
smtt
.
sdk
.
WebSettings
webSettings
=
mWebView
.
getSettings
();
webSettings
.
setSavePassword
(
false
);
webSettings
.
setSaveFormData
(
false
);
webSettings
.
setJavaScriptEnabled
(
true
);
...
...
@@ -146,9 +146,9 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
WebView
.
setWebContentsDebuggingEnabled
(
true
);
}
if
(
Build
.
VERSION
.
SDK_INT
>
Build
.
VERSION_CODES
.
KITKAT
)
{
CookieManager
.
getInstance
().
setAcceptThirdPartyCookies
(
mWebView
,
true
);
}
//
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
//
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true);
//
}
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
JELLY_BEAN
)
{
...
...
@@ -216,31 +216,31 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
Log
.
i
(
"ggg"
,
"onPageFinished: "
+
"ggg"
);
}
});
mWebView
.
setWebChromeClient
(
new
WebChromeClient
()
{
@Override
public
void
onProgressChanged
(
WebView
view
,
int
newProgress
)
{
if
(
newProgress
==
100
&&
null
!=
mWebViewProgress
)
{
// 网页加载完成
mWebViewProgress
.
setVisibility
(
View
.
GONE
);
}
else
{
// 加载中
if
(
view
!=
null
&&
view
.
getUrl
()
!=
null
&&
!
view
.
getUrl
().
contains
(
":blank"
))
{
if
(
null
!=
mWebViewProgress
)
{
mWebViewProgress
.
setVisibility
(
View
.
VISIBLE
);
mWebViewProgress
.
setProgress
(
newProgress
);
}
}
}
}
@Override
public
boolean
onJsAlert
(
WebView
view
,
String
url
,
String
message
,
JsResult
result
)
{
Log
.
i
(
"tangwen"
,
"<WebViewActivity> onJsAlert"
);
return
super
.
onJsAlert
(
view
,
url
,
message
,
result
);
}
});
//
mWebView.setWebChromeClient(new WebChromeClient() {
//
//
@Override
//
public void onProgressChanged(WebView view, int newProgress) {
//
//
if (newProgress == 100 && null != mWebViewProgress) {
//
// 网页加载完成
//
mWebViewProgress.setVisibility(View.GONE);
//
} else {
//
// 加载中
//
if (view != null && view.getUrl() != null && !view.getUrl().contains(":blank")) {
//
if (null != mWebViewProgress) {
//
mWebViewProgress.setVisibility(View.VISIBLE);
//
mWebViewProgress.setProgress(newProgress);
//
}
//
}
//
}
//
}
//
//
@Override
//
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
//
Log.i("tangwen", "<WebViewActivity> onJsAlert");
//
return super.onJsAlert(view, url, message, result);
//
}
//
});
}
// 调起支付宝并跳转到指定页面
private
void
startAlipayActivity
(
String
url
)
{
...
...
@@ -319,13 +319,14 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
*/
public
boolean
tryWebViewGoBack
()
{
Log
.
d
(
"tangwen"
,
"tryWebViewGoBack: currentURL = "
+
currentURL
);
if
(
TextUtils
.
isEmpty
(
currentURL
)
&&
currentURL
.
equals
(
Constant
.
SHOP_HOME
)
||
currentURL
.
equals
(
Constant
.
PERSONALE_HOME
)
||
currentURL
.
equals
(
Constant
.
GAME_HOME
)||
currentURL
.
equals
(
"http://h5.mailejifen.com/site/index"
)||
currentURL
.
equals
(
"https://h5.mailejifen.com/site/index"
)
){
return
false
;
if
(
currentURL
!=
null
&&
!
TextUtils
.
isEmpty
(
currentURL
)){
if
(
currentURL
.
equals
(
Constant
.
SHOP_HOME
)
||
currentURL
.
equals
(
Constant
.
PERSONALE_HOME
)
||
currentURL
.
equals
(
Constant
.
GAME_HOME
)||
currentURL
.
equals
(
"http://h5.mailejifen.com/site/index"
)||
currentURL
.
equals
(
"https://h5.mailejifen.com/site/index"
)){
return
false
;
}
}
if
(
mWebView
.
canGoBack
())
{
mWebView
.
goBack
();
...
...
app/src/main/java/com/maile/jingcai/view/iview/IWebView.java
View file @
a5fb389d
package
com
.
maile
.
jingcai
.
view
.
iview
;
import
android.webkit.WebView
;
import
com.tencent.smtt.sdk.WebView
;
/**
* Created by chengfeng-piaopiao on 2017/11/22.
*/
...
...
@@ -13,5 +13,5 @@ public interface IWebView {
* @param webURL 当前H5页面的URL
* @return 头像是否修改成功
*/
void
editUserImage
(
WebView
webView
,
String
webURL
,
String
uid
);
void
editUserImage
(
WebView
webView
,
String
webURL
,
String
uid
);
}
app/src/main/res/layout/fr_simple_card.xml
View file @
a5fb389d
...
...
@@ -14,12 +14,19 @@
android:layout_height=
"wrap_content"
android:progress=
"50"
android:visibility=
"gone"
/>
<WebView
<!--<WebView-->
<!--android:id="@+id/webView"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:visibility="visible">-->
<!---->
<!--</WebView>-->
<com.tencent.smtt.sdk.WebView
android:id=
"@+id/webView"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:visibility=
"visible"
>
</
WebView>
android:visibility=
"visible"
></com.tencent.smtt.sdk.
WebView>
</LinearLayout>
<include
layout=
"@layout/layout_loading"
...
...
build.gradle
View file @
a5fb389d
...
...
@@ -25,9 +25,9 @@ task clean(type: Delete) {
ext
{
//版本
compileSdkVersion
=
2
5
buildToolsVersion
=
"2
5.0.1
"
//23.0.3
targetSdkVersion
=
2
5
compileSdkVersion
=
2
3
buildToolsVersion
=
"2
3.0.3
"
//23.0.3
targetSdkVersion
=
2
3
//项目依赖
ButterKnife
=
"6.1.0"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment