use of android.webkit.WebResourceRequest in project weex-example by KalicyZhou.
the class WXWebView method initWebView.
private void initWebView(WebView wv) {
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(true);
settings.setUseWideViewPort(true);
settings.setDomStorageEnabled(true);
settings.setSupportZoom(false);
settings.setBuiltInZoomControls(false);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
WXLogUtils.v("tag", "onPageOverride " + url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
WXLogUtils.v("tag", "onPageStarted " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageStart(url);
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
WXLogUtils.v("tag", "onPageFinished " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
}
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (mOnErrorListener != null) {
//mOnErrorListener.onError("error", "page error code:" + error.getErrorCode() + ", desc:" + error.getDescription() + ", url:" + request.getUrl());
mOnErrorListener.onError("error", "page error");
}
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "http error");
}
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "ssl error");
}
}
});
wv.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
showWebView(newProgress == 100);
showProgressBar(newProgress != 100);
WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (mOnPageListener != null) {
mOnPageListener.onReceivedTitle(view.getTitle());
}
}
});
}
use of android.webkit.WebResourceRequest in project instructure-android by instructure.
the class OAuthWebLogin method createWebView.
private WebView createWebView() {
web = new WebView(this);
clearCookies();
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setBuiltInZoomControls(true);
web.getSettings().setUseWideViewPort(true);
web.getSettings().setSavePassword(false);
web.getSettings().setSaveFormData(false);
web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
web.getSettings().setAppCacheEnabled(false);
web.getSettings().setUserAgentString(CanvasAPI.getCandroidUserAgent("candroid", OAuthWebLogin.this));
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains(successURL)) {
String oAuthRequest = url.substring(url.indexOf(successURL) + successURL.length());
OAuthAPI.getToken(client_id, client_secret, oAuthRequest, getToken);
} else if (url.contains(errorURL)) {
clearCookies();
view.loadUrl(authenticationURL);
} else {
view.loadUrl(url);
}
// then it is not handled by default action
return true;
}
public void onPageFinished(WebView view, String url) {
setProgressBarIndeterminateVisibility(false);
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
if (url.contains("idp.sfcollege.edu/idp/santafe")) {
specialCase = true;
String oAuthRequest = url.substring(url.indexOf("hash=") + "hash=".length());
OAuthAPI.getToken(client_id, client_secret, oAuthRequest, getToken);
}
}
return super.shouldInterceptRequest(view, url);
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Uri uriUrl = request.getUrl();
String url = uriUrl.toString();
Utils.d("url: " + url);
if (url.contains("idp.sfcollege.edu/idp/santafe")) {
specialCase = true;
String oAuthRequest = url.substring(url.indexOf("hash=") + "hash=".length());
OAuthAPI.getToken(client_id, client_secret, oAuthRequest, getToken);
}
}
return super.shouldInterceptRequest(view, request);
}
@Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
httpAuthHandler = handler;
showAuthenticationDialog();
}
});
return web;
}
use of android.webkit.WebResourceRequest in project summer-android by cn-cerc.
the class FrmScanProduct method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frm_scan_product);
instance = this;
Intent intent = getIntent();
imgBack = (ImageView) findViewById(R.id.imgBack);
imgBack.setOnClickListener(this);
lblTitle = (TextView) findViewById(R.id.lblTitle);
lblTitle.setText(intent.getStringExtra("title"));
this.homeUrl = intent.getStringExtra("homeUrl");
this.returnUrl = intent.getStringExtra("returnUrl");
this.appendUrl = intent.getStringExtra("appendUrl");
this.modifyUrl = intent.getStringExtra("modifyUrl");
this.deleteUrl = intent.getStringExtra("deleteUrl");
this.viewUrl = intent.getStringExtra("viewUrl");
chkIsSpare = (CheckBox) findViewById(R.id.chkIsSpare);
edtBarcode = (EditText) findViewById(R.id.edtBarcode);
btnSave = (Button) findViewById(R.id.btnSave);
btnSave.setOnClickListener(this);
adapter = new ListViewAdapter(this, R.layout.activity_list_scan_product, dataSet, this);
lstView = (ListView) findViewById(R.id.lstView);
lstView.setAdapter(adapter);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
// 返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器
view.loadUrl(url);
return true;
}
});
// 启用支持javascript
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
// 打开指定的网页
webView.loadUrl(MyApp.getFormUrl(homeUrl));
// 关闭软键盘
edtBarcode.setInputType(InputType.TYPE_NULL);
edtBarcode.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
saveBarcode();
}
return false;
}
});
// 自动归位焦点
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
Message msg = new Message();
msg.what = MSG_TIMER;
handler.sendMessage(msg);
}
}, 1000, 200);
}
use of android.webkit.WebResourceRequest in project incubator-weex by apache.
the class WXWebView method initWebView.
private void initWebView(WebView wv) {
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(true);
settings.setUseWideViewPort(true);
settings.setDomStorageEnabled(true);
settings.setSupportZoom(false);
settings.setBuiltInZoomControls(false);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
WXLogUtils.v("tag", "onPageOverride " + url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
WXLogUtils.v("tag", "onPageStarted " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageStart(url);
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
WXLogUtils.v("tag", "onPageFinished " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
}
if (mOnMessageListener != null) {
evaluateJS("javascript:(window.postMessage = function(message, targetOrigin) {" + "if (message == null || !targetOrigin) return;" + (DOWNGRADE_JS_INTERFACE ? "prompt('" + BRIDGE_NAME + "://postMessage?message=' + JSON.stringify(message) + '&targetOrigin=' + targetOrigin)" : BRIDGE_NAME + ".postMessage(JSON.stringify(message), targetOrigin);") + "})");
}
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (mOnErrorListener != null) {
// mOnErrorListener.onError("error", "page error code:" + error.getErrorCode() + ", desc:" + error.getDescription() + ", url:" + request.getUrl());
mOnErrorListener.onError("error", "page error");
}
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "http error");
}
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "ssl error");
}
}
});
wv.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
showWebView(newProgress == 100);
showProgressBar(newProgress != 100);
WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (mOnPageListener != null) {
mOnPageListener.onReceivedTitle(view.getTitle());
}
}
@Override
public boolean onJsPrompt(WebView view, String url, String text, String defaultValue, JsPromptResult result) {
Uri uri = Uri.parse(text);
String scheme = uri.getScheme();
if (TextUtils.equals(scheme, BRIDGE_NAME)) {
if (TextUtils.equals(uri.getAuthority(), "postMessage")) {
String message = uri.getQueryParameter("message");
String targetOrigin = uri.getQueryParameter("targetOrigin");
onMessage(message, targetOrigin);
result.confirm("success");
} else {
result.confirm("fail");
}
return true;
}
return super.onJsPrompt(view, url, text, defaultValue, result);
}
});
if (!DOWNGRADE_JS_INTERFACE) {
wv.addJavascriptInterface(new Object() {
@JavascriptInterface
public void postMessage(String message, String targetOrigin) {
onMessage(message, targetOrigin);
}
}, BRIDGE_NAME);
}
}
use of android.webkit.WebResourceRequest in project edx-app-android by edx.
the class WebViewActivity method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
super.setToolbarAsActionBar();
final ProgressBar progress = (ProgressBar) findViewById(R.id.loading_indicator);
progress.setVisibility(View.GONE);
webView = (WebView) findViewById(R.id.webView);
final URLInterceptorWebViewClient client = new URLInterceptorWebViewClient(this, webView);
client.setPageStatusListener(new URLInterceptorWebViewClient.IPageStatusListener() {
@Override
public void onPageStarted() {
progress.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished() {
progress.setVisibility(View.GONE);
}
@Override
public void onPageLoadError(WebView view, int errorCode, String description, String failingUrl) {
progress.setVisibility(View.GONE);
}
@Override
public void onPageLoadError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse, boolean isMainRequestFailure) {
if (isMainRequestFailure) {
progress.setVisibility(View.GONE);
}
}
@Override
public void onPagePartiallyLoaded() {
progress.setVisibility(View.GONE);
}
});
webView.loadUrl(getIntent().getStringExtra(ARG_URL));
final String title = getIntent().getStringExtra(ARG_TITLE);
if (!TextUtils.isEmpty(title)) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(title);
}
}
Aggregations