use of android.webkit.WebResourceError in project LiYuJapanese by 54wall.
the class WebViewActivity method initWebView.
private void initWebView() {
webView.setWebChromeClient(new MyWebChromeClient(this));
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
webView.loadUrl(url);
progressBar.setVisibility(View.GONE);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
}
});
webView.clearCache(true);
webView.clearHistory();
webView.getSettings().setJavaScriptEnabled(true);
webView.setHorizontalScrollBarEnabled(false);
webView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getPointerCount() > 1) {
// Multi touch detected
return true;
}
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
{
// save the x
m_downX = event.getX();
}
break;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
{
// set x so that it doesn't move
event.setLocation(m_downX, event.getY());
}
break;
}
return false;
}
});
}
use of android.webkit.WebResourceError in project MvvmNews by huanglinqing123.
the class NewsDetailActivity method initWebView.
@SuppressLint("SetJavaScriptEnabled")
private void initWebView() {
webview.getSettings().setBlockNetworkImage(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setAllowFileAccess(true);
webview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webview.getSettings().setDatabaseEnabled(true);
webview.getSettings().setAppCacheEnabled(true);
webview.getSettings().setAllowFileAccess(true);
webview.getSettings().setAppCacheMaxSize(5 * 1024 * 1024);
webview.getSettings().setPluginState(WebSettings.PluginState.ON);
webview.loadUrl(getIntent().getStringExtra("newsurl"));
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
webview.setVisibility(View.GONE);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webview.getSettings().setBlockNetworkImage(false);
}
});
}
use of android.webkit.WebResourceError in project AppCenter-SDK-Android by Microsoft.
the class MSALoginActivity method signOut.
@SuppressWarnings("unused")
public void signOut(View view) {
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
if (url.startsWith(REDIRECT_URL)) {
clearCookies();
Uri uri = Uri.parse(url);
sSharedPreferences.edit().remove(MSA_REFRESH_TOKEN_SCOPE_KEY).apply();
sSharedPreferences.edit().remove(MSA_REFRESH_TOKEN_KEY).apply();
sSharedPreferences.edit().remove(MSA_AUTH_TYPE_KEY).apply();
sSharedPreferences.edit().remove(MSA_TOKEN_KEY).apply();
String error = uri.getQueryParameter("error");
if (error != null) {
failSignOut(0, error);
} else {
signIn(null);
}
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
clearCookies();
failSignOut(errorCode, description);
}
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
clearCookies();
failSignOut(error.getErrorCode(), error.getDescription());
}
});
mWebView.loadUrl(SIGN_OUT_URL + REDIRECT_URI_PARAM + CLIENT_ID_PARAM);
}
use of android.webkit.WebResourceError in project AppCenter-SDK-Android by Microsoft.
the class MSALoginActivity method signIn.
@SuppressWarnings("unused")
public void signIn(View view) {
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
checkSignInCompletion(url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
failSignIn(errorCode, description);
}
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
failSignIn(error.getErrorCode(), error.getDescription());
}
});
boolean compactTicket = mAuthType == AuthenticationProvider.Type.MSA_COMPACT;
String responseType = compactTicket ? "token" : "code";
String[] scopes = compactTicket ? SCOPES_COMPACT : SCOPES_DELEGATE;
mWebView.loadUrl(AUTHORIZE_URL + REDIRECT_URI_PARAM + CLIENT_ID_PARAM + "&response_type=" + responseType + "&scope=" + TextUtils.join("+", scopes));
}
use of android.webkit.WebResourceError in project android-sdk by testpress.
the class WebViewUtils method initWebView.
@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" })
public void initWebView(String htmlContent, final Activity activity) {
initWebView(webView);
webView.addJavascriptInterface(new ImageHandler(activity), "ImageHandler");
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
WebViewUtils.this.onPageStarted();
hasError = false;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (!hasError) {
String javascript = getJavascript(activity);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript(javascript, null);
} else {
webView.loadUrl(javascript, null);
}
onLoadFinished();
}
}
@SuppressWarnings("deprecation")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return WebViewUtils.this.shouldOverrideUrlLoading(activity, url);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (InternetConnectivityChecker.isConnected(activity)) {
return;
}
onNetworkError();
hasError = true;
}
});
loadHtml(htmlContent);
}
Aggregations