use of android.webkit.WebViewClient in project ETSMobile-Android2 by ApplETS.
the class BiblioFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup v = (ViewGroup) inflater.inflate(R.layout.fragment_web_view, container, false);
super.onCreateView(inflater, v, savedInstanceState);
webView = (WebView) v.findViewById(R.id.webView);
final WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
loadingView.showLoadingView();
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
view.loadUrl(url);
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
// super.onPageFinished(view, url);
LoadingView.hideLoadingView(loadingView);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
view.loadUrl("file:///android_asset/webview_error_page.html");
}
});
webView.loadUrl(getActivity().getString(R.string.url_biblio));
AnalyticsHelper.getInstance(getActivity()).sendScreenEvent(getClass().getSimpleName());
return v;
}
use of android.webkit.WebViewClient in project DroidPlugin by DroidPluginTeam.
the class WebViewTestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view_test);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
});
mWebView.loadUrl("http://www.baidu.com");
}
use of android.webkit.WebViewClient in project Bolts-Android by BoltsFramework.
the class WebViewAppLinkResolver method getAppLinkFromUrlInBackground.
@Override
public Task<AppLink> getAppLinkFromUrlInBackground(final Uri url) {
final Capture<String> content = new Capture<String>();
final Capture<String> contentType = new Capture<String>();
return Task.callInBackground(new Callable<Void>() {
@Override
public Void call() throws Exception {
URL currentURL = new URL(url.toString());
URLConnection connection = null;
while (currentURL != null) {
// Fetch the content at the given URL.
connection = currentURL.openConnection();
if (connection instanceof HttpURLConnection) {
// Unfortunately, this doesn't actually follow redirects if they go from http->https,
// so we have to do that manually.
((HttpURLConnection) connection).setInstanceFollowRedirects(true);
}
connection.setRequestProperty(PREFER_HEADER, META_TAG_PREFIX);
connection.connect();
if (connection instanceof HttpURLConnection) {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
if (httpConnection.getResponseCode() >= 300 && httpConnection.getResponseCode() < 400) {
currentURL = new URL(httpConnection.getHeaderField("Location"));
httpConnection.disconnect();
} else {
currentURL = null;
}
} else {
currentURL = null;
}
}
try {
content.set(readFromConnection(connection));
contentType.set(connection.getContentType());
} finally {
if (connection instanceof HttpURLConnection) {
((HttpURLConnection) connection).disconnect();
}
}
return null;
}
}).onSuccessTask(new Continuation<Void, Task<JSONArray>>() {
@Override
public Task<JSONArray> then(Task<Void> task) throws Exception {
// Load the content in a WebView and use JavaScript to extract the meta tags.
final TaskCompletionSource<JSONArray> tcs = new TaskCompletionSource<>();
final WebView webView = new WebView(context);
webView.getSettings().setJavaScriptEnabled(true);
webView.setNetworkAvailable(false);
webView.setWebViewClient(new WebViewClient() {
private boolean loaded = false;
private void runJavaScript(WebView view) {
if (!loaded) {
// After the first resource has been loaded (which will be the pre-populated data)
// run the JavaScript meta tag extraction script
loaded = true;
view.loadUrl(TAG_EXTRACTION_JAVASCRIPT);
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
runJavaScript(view);
}
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
runJavaScript(view);
}
});
// Inject an object that will receive the JSON for the extracted JavaScript tags
webView.addJavascriptInterface(new Object() {
@JavascriptInterface
public void setValue(String value) {
try {
tcs.trySetResult(new JSONArray(value));
} catch (JSONException e) {
tcs.trySetError(e);
}
}
}, "boltsWebViewAppLinkResolverResult");
String inferredContentType = null;
if (contentType.get() != null) {
inferredContentType = contentType.get().split(";")[0];
}
webView.loadDataWithBaseURL(url.toString(), content.get(), inferredContentType, null, null);
return tcs.getTask();
}
}, Task.UI_THREAD_EXECUTOR).onSuccess(new Continuation<JSONArray, AppLink>() {
@Override
public AppLink then(Task<JSONArray> task) throws Exception {
Map<String, Object> alData = parseAlData(task.getResult());
AppLink appLink = makeAppLinkFromAlData(alData, url);
return appLink;
}
});
}
use of android.webkit.WebViewClient in project bilibili-android-client by HotBitmapGG.
the class BrowserActivity method setupWebView.
@SuppressLint("SetJavaScriptEnabled")
private void setupWebView() {
progressBar.spin();
final WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setDomStorageEnabled(true);
webSettings.setGeolocationEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
mWebView.getSettings().setBlockNetworkImage(true);
mWebView.setWebViewClient(webViewClient);
mWebView.requestFocus(View.FOCUS_DOWN);
mWebView.getSettings().setDefaultTextEncodingName("UTF-8");
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
AlertDialog.Builder b2 = new AlertDialog.Builder(BrowserActivity.this).setTitle(R.string.app_name).setMessage(message).setPositiveButton("确定", (dialog, which) -> result.confirm());
b2.setCancelable(false);
b2.create();
b2.show();
return true;
}
});
mWebView.loadUrl(url);
}
use of android.webkit.WebViewClient in project UltimateAndroid by cymcsg.
the class WebViewActivity method initWebView.
private void initWebView() {
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebChromeClient(new WebChromeClient());
WebSettings settings = mWebView.getSettings();
settings.setSavePassword(true);
settings.setSaveFormData(true);
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(false);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setDomStorageEnabled(true);
settings.setSupportMultipleWindows(false);
mWebView.loadUrl("http://developer.android.com");
}
Aggregations