use of android.webkit.WebViewClient in project materialistic by hidroh.
the class WebFragmentTest method testAdBlocker.
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Test
public void testAdBlocker() {
WebView webView = (WebView) activity.findViewById(R.id.web_view);
WebViewClient client = shadowOf(webView).getWebViewClient();
assertNull(client.shouldInterceptRequest(webView, "http://google.com"));
assertNull(client.shouldInterceptRequest(webView, "http://google.com"));
assertNotNull(client.shouldInterceptRequest(webView, "http://page2.g.doubleclick.net"));
assertNotNull(client.shouldInterceptRequest(webView, "http://page2.g.doubleclick.net"));
}
use of android.webkit.WebViewClient in project fitscales by paulburton.
the class OAuthDialogFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.oauth_dialog, container, false);
web = (WebView) v.findViewById(R.id.web);
btnCancel = (Button) v.findViewById(R.id.btnCancel);
web.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Object tag = view.getTag();
if (!(tag instanceof OAuthDialogFragment))
return;
if (DEBUG)
Log.d(TAG, "onPageStarted " + url);
if (url.startsWith("http://oauth.localhost/")) {
if (DEBUG)
Log.d(TAG, "Got OAuth response url");
view.setTag(null);
svc.setOAuthPageResult(url);
OAuthDialogFragment.this.responded = true;
web.post(new Runnable() {
public void run() {
OAuthDialogFragment.this.dismiss();
}
});
}
}
});
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OAuthDialogFragment.this.dismiss();
}
});
web.setTag(OAuthDialogFragment.this);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl(url);
getDialog().setTitle(getResources().getString(R.string.dialog_oauth_title));
return v;
}
use of android.webkit.WebViewClient in project PocketHub by pockethub.
the class LoginWebViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
webView.loadUrl(getIntent().getStringExtra(LoginActivity.INTENT_EXTRA_URL));
webView.setWebViewClient(new WebViewClient() {
MaterialDialog dialog = new MaterialDialog.Builder(LoginWebViewActivity.this).content(R.string.loading).progress(true, 0).build();
@Override
public void onPageStarted(android.webkit.WebView view, String url, Bitmap favicon) {
dialog.show();
}
@Override
public void onPageFinished(android.webkit.WebView view, String url) {
dialog.dismiss();
}
@Override
public boolean shouldOverrideUrlLoading(android.webkit.WebView view, String url) {
Uri uri = Uri.parse(url);
if (uri.getScheme().equals(getString(R.string.github_oauth_scheme))) {
Intent data = new Intent();
data.setData(uri);
setResult(RESULT_OK, data);
finish();
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
});
setContentView(webView);
}
use of android.webkit.WebViewClient in project robolectric by robolectric.
the class ShadowWebViewTest method shouldRecordWebViewClient.
@Test
public void shouldRecordWebViewClient() {
WebViewClient webViewClient = new WebViewClient();
assertThat(shadowWebView.getWebViewClient()).isNull();
webView.setWebViewClient(webViewClient);
assertThat(shadowWebView.getWebViewClient()).isSameAs(webViewClient);
}
use of android.webkit.WebViewClient in project MarqueeView by sfsheng0322.
the class AboutActivity method initView.
@SuppressLint("NewApi")
private void initView() {
webView = (WebView) findViewById(R.id.webView);
setTitle("关于(V" + getVersionName(this) + ")");
settings = webView.getSettings();
//如果访问的页面中有Javascript,则WebView必须设置支持Javascript
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
//支持缩放
settings.setSupportZoom(true);
//支持手势缩放
settings.setBuiltInZoomControls(true);
//是否显示缩放按钮
settings.setDisplayZoomControls(false);
// >= 19(SDK4.4)启动硬件加速,否则启动软件加速
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
//支持自动加载图片
settings.setLoadsImagesAutomatically(true);
} else {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
settings.setLoadsImagesAutomatically(false);
}
//将图片调整到适合WebView的大小
settings.setUseWideViewPort(true);
//自适应屏幕
settings.setLoadWithOverviewMode(true);
settings.setDomStorageEnabled(true);
settings.setSaveFormData(true);
settings.setSupportMultipleWindows(true);
settings.setAppCacheEnabled(true);
//优先使用缓存
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
webView.setHorizontalScrollbarOverlay(true);
webView.setHorizontalScrollBarEnabled(false);
// 取消WebView中滚动或拖动到顶部、底部时的阴影
webView.setOverScrollMode(View.OVER_SCROLL_NEVER);
// 取消滚动条白边效果
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.requestFocus();
webView.loadUrl("file:///android_asset/about.html");
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
Aggregations