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
405d9feb
authored
Dec 06, 2017
by
chengfengpiaopiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
webView异常
parent
65afaca0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
55 deletions
.idea/misc.xml
app/src/main/java/com/maile/jingcai/util/preferences/IPreferencesIds.java
app/src/main/java/com/maile/jingcai/view/activity/LoginActivity.java
app/src/main/java/com/maile/jingcai/view/fragment/SimpleCardFragment.java
build.gradle
.idea/misc.xml
View file @
405d9feb
...
...
@@ -27,7 +27,7 @@
</value>
</option>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
8
"
default=
"true"
assert-keyword=
"true"
jdk-15=
"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"
>
...
...
app/src/main/java/com/maile/jingcai/util/preferences/IPreferencesIds.java
View file @
405d9feb
...
...
@@ -12,4 +12,6 @@ public class IPreferencesIds {
// KEY
public
static
final
String
TOKEN
=
"TOKEN"
;
public
static
final
String
openid_phone
=
"openid_phone"
;
public
static
final
String
FIRST_LOAD_MAIN
=
"FIRST_LOAD_MAIN"
;
}
app/src/main/java/com/maile/jingcai/view/activity/LoginActivity.java
View file @
405d9feb
...
...
@@ -213,7 +213,7 @@ public class LoginActivity extends Activity implements ILoginView {
@Override
public
void
run
()
{
Log
.
d
(
"删除LoginActivity"
,
"starting...."
);
SystemClock
.
sleep
(
2
000
);
SystemClock
.
sleep
(
1
000
);
if
(
mContext
!=
null
)
{
Log
.
d
(
"删除LoginActivity"
,
"done!"
);
((
Activity
)
mContext
).
finish
();
...
...
@@ -267,9 +267,9 @@ public class LoginActivity extends Activity implements ILoginView {
if
(
phoneLayer
.
onBackPressed
())
{
return
;
}
super
.
onBackPressed
();
myHandler
.
removeMessages
(
HANDLER_MAG_HIDE_ERRORBAR
);
myHandler
=
null
;
finish
();
}
private
void
startErrorAnim
(
boolean
isVisible
)
{
...
...
app/src/main/java/com/maile/jingcai/view/fragment/SimpleCardFragment.java
View file @
405d9feb
...
...
@@ -14,6 +14,7 @@ import android.support.annotation.RequiresApi;
import
android.support.v13.app.FragmentCompat
;
import
android.support.v4.app.Fragment
;
import
android.support.v7.app.AlertDialog
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
...
...
@@ -32,6 +33,7 @@ import android.widget.Toast;
import
com.maile.jingcai.R
;
import
com.maile.jingcai.base.BaseApplication
;
import
com.maile.jingcai.base.BaseFragment
;
import
com.maile.jingcai.base.Constant
;
import
com.maile.jingcai.module.WrapperRspEntity
;
import
com.maile.jingcai.module.api.LoginApiService
;
import
com.maile.jingcai.module.net.RetrofitManager
;
...
...
@@ -45,6 +47,8 @@ import com.maile.jingcai.view.activity.MainActivity;
import
com.maile.jingcai.view.iview.IWebView
;
import
com.umeng.analytics.MobclickAgent
;
import
org.w3c.dom.Text
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
...
...
@@ -66,14 +70,11 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
@InjectView
(
R
.
id
.
rl_loading_layout
)
RelativeLayout
mLoading
;
private
String
mTitle
;
private
String
mUrl
;
private
IWebView
mIWebView
;
private
String
currentURL
;
public
static
SimpleCardFragment
getInstance
(
String
title
,
String
mUrl
,
IWebView
mIWebView
)
{
SimpleCardFragment
sf
=
new
SimpleCardFragment
();
sf
.
mTitle
=
title
;
...
...
@@ -91,40 +92,26 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
return
view
;
}
// @Override
// public void onResume() {
// super.onResume();
// Log.i("tangwen", "onResume: " + mUrl);
// if(mUrl.equals("http://192.168.1.250:81/shop")){
// Log.i("tangwen", "onResume: " + "第二页");
// mWebView.loadUrl(mUrl);
// }
// Log.i("tangwen", "onResume: " + "其他页面");
// }
@Override
public
void
setUserVisibleHint
(
boolean
isVisibleToUser
)
{
super
.
setUserVisibleHint
(
isVisibleToUser
);
if
(
isVisibleToUser
)
{
Log
.
i
(
"tangwen"
,
"onResume: "
+
mUrl
);
if
(
mUrl
.
equals
(
"http://api.7peng.cn/shop"
)
||
mUrl
.
equals
(
"http://h5.7peng.cn/profile.html"
))
{
//Log.i("tangwen", "onResume: " + "第二页");
if
(
mUrl
.
equals
(
Constant
.
SHOP_HOME
)
||
mUrl
.
equals
(
Constant
.
PERSONALE_HOME
))
{
Log
.
i
(
"tangwen"
,
"onResume: "
+
mUrl
);
mWebView
.
loadUrl
(
mUrl
);
// PreferencesManager preferencesManager = PreferencesManager.getSharedPreference(getContext(),
// IPreferencesIds.DEFAULT_SHAREPREFERENCES_FILE,
// Context.MODE_PRIVATE);
// preferencesManager.putBoolean(IPreferencesIds.FIRST_LOAD_MAIN, false);
}
else
{
Log
.
i
(
"tangwen"
,
"onResume: "
+
mUrl
);
}
// Log.i("tangwen", "onResume: " + "其他页面");
}
}
@Override
public
void
onViewCreated
(
View
view
,
@Nullable
Bundle
savedInstanceState
)
{
super
.
onViewCreated
(
view
,
savedInstanceState
);
// loadWebView(mUrl);
}
@Override
public
void
onResume
()
{
super
.
onResume
();
}
//加载webview
...
...
@@ -187,17 +174,16 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
IPreferencesIds
.
DEFAULT_SHAREPREFERENCES_FILE
,
Context
.
MODE_PRIVATE
);
final
String
token
=
preferencesManager
.
getString
(
IPreferencesIds
.
TOKEN
,
""
);
boolean
isFirstLoadMain
=
preferencesManager
.
getBoolean
(
IPreferencesIds
.
FIRST_LOAD_MAIN
,
true
);
// if(!isFirstLoadMain && mUrl.equals(Constant.GAME_HOME)){
// return;
// }
mWebView
.
loadUrl
(
url
);
mWebView
.
addJavascriptInterface
(
new
JavaScriptInterface
(
getActivity
()),
"android"
);
//覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为,使网页用WebView打开
mWebView
.
setWebViewClient
(
new
WebViewClient
()
{
@Override
public
boolean
shouldOverrideUrlLoading
(
WebView
view
,
String
url
)
{
//返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器
/// return super.shouldOverrideUrlLoading(view, url);
// view.loadUrl(url);
// return true;
if
(
url
.
contains
(
" alipays://platformapi/startapp"
))
{
startAlipayActivity
(
url
);
// android 6.0 两种方式获取intent都可以跳转支付宝成功,7.1测试不成功
...
...
@@ -225,23 +211,8 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
if
(
mLoading
!=
null
)
{
mLoading
.
setVisibility
(
View
.
INVISIBLE
);
}
// super.onPageFinished(view, url);
// if (!mUrl.equals("http://h5.test.7peng.cn/")) {
// return;
// }
isLoading
=
true
;
Log
.
i
(
"ggg"
,
"onPageFinished: "
+
"ggg"
);
// new Handler().postDelayed(new Runnable(){
// public void run() {
// //mWebView.loadUrl("javascript:console.log('ggg'); (function(){localStorage.setItem(\"__token__\", '"+token+"');})();");
// mWebView.loadUrl("javascript:console.log('type:'+ typeof(window.h5AutoLogin));h5AutoLogin('"+token+"')");
// }
// }, 2000);
}
});
mWebView
.
setWebChromeClient
(
new
WebChromeClient
()
{
...
...
@@ -284,8 +255,6 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
}
}
class
JavaScriptInterface
{
private
Context
mContext
;
public
JavaScriptInterface
(
Context
context
){
...
...
@@ -301,6 +270,7 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
Intent
intent
=
new
Intent
(
mContext
,
LoginActivity
.
class
);
mContext
.
startActivity
(
intent
);
if
(
mContext
!=
null
)
{
Log
.
d
(
"MainActivity"
,
"退出跳转"
);
((
Activity
)
mContext
).
finish
();
}
}
...
...
@@ -314,7 +284,6 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
Log
.
d
(
"editUserHeadImage"
,
"uid: "
+
uid
);
mUid
=
uid
;
requirePermission
();
}
}
...
...
@@ -323,14 +292,30 @@ public class SimpleCardFragment extends BaseFragment implements FragmentCompat.
@Override
public
void
onDestroyView
()
{
super
.
onDestroyView
();
ButterKnife
.
reset
(
this
);
if
(
null
!=
mWebView
)
{
mWebView
.
removeAllViews
();
mWebView
.
destroy
();
mWebView
=
null
;
}
ButterKnife
.
reset
(
this
);
}
/**
* ||
currentURL.equals("http://h5.mailejifen.com/site/index")||
currentURL.equals("https://h5.mailejifen.com/site/index")
* @return
*/
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
(
mWebView
.
canGoBack
())
{
mWebView
.
goBack
();
return
true
;
...
...
build.gradle
View file @
405d9feb
...
...
@@ -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