下面列出了android.webkit.WebView#stopLoading ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void destroyWebView(WebView mWebView) {
if (mWebView != null) {
try {
ViewParent parent = mWebView.getParent();
if (parent != null) {
((ViewGroup) parent).removeView(mWebView);
}
mWebView.stopLoading();
mWebView.getSettings().setJavaScriptEnabled(false);
mWebView.clearHistory();
mWebView.clearView();
mWebView.removeAllViews();
mWebView.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
}
static final void clearWebView(WebView m) {
if (m == null) {
return;
}
if (Looper.myLooper() != Looper.getMainLooper()) {
return;
}
m.loadUrl("about:blank");
m.stopLoading();
if (m.getHandler() != null) {
m.getHandler().removeCallbacksAndMessages(null);
}
m.removeAllViews();
ViewGroup mViewGroup = null;
if ((mViewGroup = ((ViewGroup) m.getParent())) != null) {
mViewGroup.removeView(m);
}
m.setWebChromeClient(null);
m.setWebViewClient(null);
m.setTag(null);
m.clearHistory();
m.destroy();
m = null;
}
public void onPageFinished(WebView view, String url) {
try {
String path = new URL(url).getPath();
LogInfo.log("ZSM onPageFinished path = " + path);
if (path.contains("checklogin")) {
LeResponseMessage response = LeMessageManager.getInstance().dispatchMessage(new LeMessage(LeMessageIds.MSG_WEBVIEW_COOKIE_SSO_TOKEN, url));
if (LeResponseMessage.checkResponseMessageValidity(response, String.class)) {
PreferencesManager.getInstance().setSso_tk((String) response.getData());
}
view.setVisibility(4);
view.loadUrl("javascript:window.handler.show(document.body.innerText);");
view.stopLoading();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if ("Just a moment...".equals(view.getTitle())) {
wasChecked = true;
} else {
String cookie = null;
boolean success = false;
if (wasChecked) {
cookie = StringUtils.nullIfEmpty(extractCookie(url, COOKIE_CLOUDFLARE));
if (cookie != null) {
success = true;
}
}
storeCookie(chanName, cookie, url);
view.stopLoading();
for (CheckHolder checkHolder : checkHolders) {
synchronized (checkHolder) {
checkHolder.success = success;
checkHolder.ready = true;
checkHolder.notifyAll();
}
}
handleNextJavaScript();
}
}
/**
* Clear a view. Applies to ImageView, WebView, and TextView.
*
* @return self
*/
public T clear() {
if (view != null) {
if (view instanceof ImageView) {
ImageView iv = ((ImageView) view);
iv.setImageBitmap(null);
} else if (view instanceof WebView) {
WebView wv = ((WebView) view);
wv.stopLoading();
wv.clearView();
} else if (view instanceof TextView) {
TextView tv = ((TextView) view);
tv.setText("");
}
}
return self();
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
view.stopLoading();
HWUtils.logError(TAG, errorCode + "\n" + description + "\n"
+ failingUrl);
view.clearView();
showErrorPage();
super.onReceivedError(view, errorCode, description, failingUrl);
}
public void onPageFinished(WebView view, String url) {
try {
if (new URL(url).getPath().contains("callbackdata")) {
view.setVisibility(4);
view.loadUrl("javascript:window.handler.show(document.body.innerText);");
view.stopLoading();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
mCircleProgressBar.setVisibility(View.VISIBLE);
DevLog.printLog("OAUTH_ACTIVITY-onPageStarted:", "" + url);
if (url.startsWith(mIsAuthPro ? WeiboOAuthConstances.HACK_DIRECT_URL : WeiboOAuthConstances.DIRECT_URL)) {
handleRedirectUrl(url);
view.stopLoading();
return;
}
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
showProgress();
if (url.startsWith(SeniorUrl.SeniorUrl_Public)) {
view.stopLoading();
handleRedirectUrl(view, url, WebViewActivity.this);
return;
}
super.onPageStarted(view, url, favicon);
}
private boolean handleUrlLoad(WebView view, String url) {
// prevent loading content that isn't ours
if (!url.startsWith(Constants.WEBAPP_URL)) {
// stop loading
// stopping only would cause the PWA to freeze, need to reload the app as a workaround
view.stopLoading();
view.reload();
// open external URL in Browser/3rd party apps instead
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
if (intent.resolveActivity(activity.getPackageManager()) != null) {
activity.startActivity(intent);
} else {
showNoAppDialog(activity);
}
} catch (Exception e) {
showNoAppDialog(activity);
}
// return value for shouldOverrideUrlLoading
return true;
} else {
// let WebView load the page!
// activate loading animation screen
uiManager.setLoading(true);
// return value for shouldOverrideUrlLoading
return false;
}
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
showProgress();
if (url.startsWith(SeniorUrl.SeniorUrl_Public)) {
view.stopLoading();
handleRedirectUrl(view, url, GSIDWebViewActivity.this);
return;
}
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
showProgress();
if (url.startsWith(SeniorUrl.SeniorUrl_Public)) {
view.stopLoading();
handleRedirectUrl(view, url, JSWebViewActivity.this);
return;
}
super.onPageStarted(view, url, favicon);
}
public static void recycleViewGroupAndChildViews(ViewGroup viewGroup, boolean recycleBitmap) {
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
if (child instanceof WebView) {
WebView webView = (WebView) child;
webView.loadUrl("about:blank");
webView.stopLoading();
continue;
}
if (child instanceof ViewGroup) {
recycleViewGroupAndChildViews((ViewGroup) child, true);
continue;
}
if (child instanceof ImageView) {
ImageView iv = (ImageView) child;
Drawable drawable = iv.getDrawable();
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
if (recycleBitmap && bitmap != null) {
bitmap.recycle();
}
}
iv.setImageBitmap(null);
iv.setBackground(null);
continue;
}
child.setBackground(null);
}
viewGroup.setBackground(null);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
showProgress();
if (url.startsWith(SeniorUrl.SeniorUrl_Public)) {
view.stopLoading();
handleRedirectUrl(view, url, JSWebViewActivity.this);
return;
}
super.onPageStarted(view, url, favicon);
}
public static void recycleViewGroupAndChildViews(ViewGroup viewGroup, boolean recycleBitmap) {
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
if (child instanceof WebView) {
WebView webView = (WebView) child;
webView.loadUrl("about:blank");
webView.stopLoading();
continue;
}
if (child instanceof ViewGroup) {
recycleViewGroupAndChildViews((ViewGroup) child, true);
continue;
}
if (child instanceof ImageView) {
ImageView iv = (ImageView) child;
Drawable drawable = iv.getDrawable();
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
if (recycleBitmap && bitmap != null) {
bitmap.recycle();
}
}
iv.setImageBitmap(null);
iv.setBackground(null);
continue;
}
child.setBackground(null);
}
viewGroup.setBackground(null);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
showProgress();
if (url.startsWith(SeniorUrl.SeniorUrl_Public)) {
view.stopLoading();
handleRedirectUrl(view, url, WebViewActivity.this);
return;
}
super.onPageStarted(view, url, favicon);
}
@Override
public void run() {
mUrl = null;
mLoadingFinished = true;
if (mReference != null) {
WebView webView = mReference.get();
if (webView != null) {
webView.stopLoading();
}
}
}
@SuppressWarnings("deprecation")
@Override
public void onLoadResource(WebView view, String url) {
if (url.startsWith("http")) {
HitTestResult hitTestResult;
try {
hitTestResult = getHitTestResult();
if (hitTestResult == null) {
return;
}
// check that the hitTestResult matches the url
if (hitTestResult.getExtra() == null
|| !hitTestResult.getExtra().equals(url)) {
return;
}
} catch (NullPointerException e) {
return;
}
switch (hitTestResult.getType()) {
default:
break;
case HitTestResult.ANCHOR_TYPE:
case HitTestResult.IMAGE_ANCHOR_TYPE:
case HitTestResult.SRC_ANCHOR_TYPE:
case HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
loadURLInCorrectBrowser(url);
view.stopLoading();
fireAdClicked();
break;
}
}
}
/**
* 获取webview
* @return
*/
public WebView getWebView(){
WebView webView = mWebViewList.remove(0);
webView.stopLoading();
return webView;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
DevLog.printLog("JSAutoLogin onPageStarted", url);
if (url.startsWith(SeniorUrl.SeniorUrl_Public)) {
view.stopLoading();
CookieManager cookieManager = CookieManager.getInstance();
String cookie = cookieManager.getCookie(url);
String uid = "";
String uname = "";
String gsid = "";
AccountDatabaseManager manager = new AccountDatabaseManager(mContext);
if (!TextUtils.isEmpty(cookie)) {
String[] cookies = cookie.split("; ");
for (String string : cookies) {
String oneLine = Uri.decode(Uri.decode(string));
if (oneLine.contains("SUB=")) {
DevLog.printLog("GSID", "" + oneLine);
gsid = oneLine.split("SUB=")[1];
}
String uidtmp = PatternUtils.macthUID(oneLine);
if (!TextUtils.isEmpty(uidtmp)) {
uid = uidtmp;
}
uname = PatternUtils.macthUname(oneLine);
if (!TextUtils.isEmpty(uname)) {
manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.USER_NAME, uname);
manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.GSID, gsid);
BeeboApplication.getInstance().updateAccountBean();
}
}
}
Log.d("Weibo-Cookie", "after for : " + uid);
if (uid.equals(mAccountBean.getUid())) {
if (mListener != null) {
mListener.onAutoLonin(true);
}
manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.COOKIE, cookie);
BeeboApplication.getInstance().updateAccountBean();
} else if (!TextUtils.isEmpty(uid)) {
mWebView.loadUrl(url);
}
return;
}
super.onPageStarted(view, url, favicon);
}