Search in sources :

Example 16 with WebViewClient

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"));
}
Also used : WebView(android.webkit.WebView) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) WebViewClient(android.webkit.WebViewClient) Test(org.junit.Test) SuppressLint(android.annotation.SuppressLint)

Example 17 with WebViewClient

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;
}
Also used : Bitmap(android.graphics.Bitmap) WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 18 with WebViewClient

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);
}
Also used : Bitmap(android.graphics.Bitmap) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Intent(android.content.Intent) WebView(com.github.pockethub.android.ui.WebView) Uri(android.net.Uri) WebViewClient(android.webkit.WebViewClient)

Example 19 with WebViewClient

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);
}
Also used : WebViewClient(android.webkit.WebViewClient) Test(org.junit.Test)

Example 20 with 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;
        }
    });
}
Also used : WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient) SuppressLint(android.annotation.SuppressLint)

Aggregations

WebViewClient (android.webkit.WebViewClient)109 WebView (android.webkit.WebView)99 WebChromeClient (android.webkit.WebChromeClient)29 View (android.view.View)28 WebSettings (android.webkit.WebSettings)25 Intent (android.content.Intent)23 SuppressLint (android.annotation.SuppressLint)19 Bitmap (android.graphics.Bitmap)18 LinearLayout (android.widget.LinearLayout)9 TextView (android.widget.TextView)9 Uri (android.net.Uri)8 Bundle (android.os.Bundle)8 KeyEvent (android.view.KeyEvent)7 WebResourceRequest (android.webkit.WebResourceRequest)7 JsResult (android.webkit.JsResult)6 DialogInterface (android.content.DialogInterface)4 WebResourceError (android.webkit.WebResourceError)4 WebResourceResponse (android.webkit.WebResourceResponse)4 RelativeLayout (android.widget.RelativeLayout)4 Activity (android.app.Activity)3