Search in sources :

Example 21 with WebSettings

use of android.webkit.WebSettings in project Meltdown by phubbard.

the class ItemDisplayActivity method onOptionsItemSelected.

public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
        case R.id.itemSave:
            app.markItemSaved(rss_item.id);
            nextItem();
            return true;
        case R.id.itemAddOneWeek:
            oneWeek();
            return true;
        case R.id.itemPost:
            postItem();
            return true;
        case R.id.itemZoomFar:
            WebView wv = (WebView) findViewById(R.id.itemWebView);
            WebSettings webSettings = wv.getSettings();
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
            return true;
    }
    return false;
}
Also used : WebSettings(android.webkit.WebSettings) WebView(android.webkit.WebView)

Example 22 with WebSettings

use of android.webkit.WebSettings in project K6nele by Kaljurand.

the class FormDemoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView webview = new WebView(this);
    setContentView(webview);
    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // addJavascriptInterface has security issues below API 17
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        webview.addJavascriptInterface(new WebAppInterface(this), "Android");
    }
    webview.loadUrl(getString(R.string.fileFormDemo));
}
Also used : WebSettings(android.webkit.WebSettings) WebView(android.webkit.WebView)

Example 23 with WebSettings

use of android.webkit.WebSettings in project PocketHub by pockethub.

the class RepositoryReadmeFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    webview = (WebView) view;
    final Repository repo = getParcelableExtra(Intents.EXTRA_REPOSITORY);
    WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);
    webview.addJavascriptInterface(this, "Readme");
    ServiceGenerator.createService(getActivity(), RepositoryContentService.class).getReadmeHtml(repo.owner().login(), repo.name(), null).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).as(AutoDisposeUtils.bindToLifecycle(this)).subscribe(response -> {
        String baseUrl = String.format("https://github.com/%s/%s/raw/%s/", repo.owner().login(), repo.name(), "master");
        String data = PAGE_START + response.body() + PAGE_END;
        webview.loadDataWithBaseURL(baseUrl, data, "text/html", "UTF-8", null);
    });
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) WebSettings(android.webkit.WebSettings) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService)

Example 24 with WebSettings

use of android.webkit.WebSettings in project instructure-android by instructure.

the class AddSubmissionFragment method setupWebview.

private void setupWebview() {
    // Give it a default.
    webView.loadUrl("");
    // Start off by hiding webview box.
    webView.setVisibility(View.GONE);
    // Fit to width.
    // Configure the webview
    WebSettings settings = webView.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    // Open all urls with our webview.
    webView.setWebViewClient(new WebViewClient() {

        // Once a page has loaded, stop the spinner.
        @Override
        public void onPageFinished(WebView view, final String finishedURL) {
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    String url = finishedURL;
                    scrollView.scrollTo(0, urlEntryContainer.getTop());
                    // This handles that case.
                    if (url.equals("about:blank")) {
                        return;
                    } else // Do my best to not interrupt their typing.
                    if (urlSubmission.getText().toString().endsWith("/")) {
                        if (!url.endsWith("/")) {
                            url = url + "/";
                        }
                    } else {
                        if (url.endsWith("/")) {
                            url = url.substring(0, url.length() - 1);
                        }
                    }
                    // the webview redirects and eventually returns some html that then is put into the urlSubmission editText
                    if (Patterns.WEB_URL.matcher(url).matches()) {
                        urlSubmission.setText(url);
                        urlSubmission.setSelection(urlSubmission.getText().length());
                    }
                }
            });
        }
    });
}
Also used : WebSettings(android.webkit.WebSettings) CanvasWebView(com.instructure.pandautils.views.CanvasWebView) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 25 with WebSettings

use of android.webkit.WebSettings in project RxTools by vondear.

the class ActivityWebView method initData.

private void initData() {
    // 设置加载进度最大值
    pbWebBase.setMax(100);
    // webPath = getIntent().getStringExtra("URL");
    // 加载的URL
    webPath = RxConstants.URL_BAIDU_SEARCH;
    if (webPath.equals("")) {
        webPath = "http://www.baidu.com";
    }
    WebSettings webSettings = webBase.getSettings();
    if (Build.VERSION.SDK_INT >= 19) {
        // 加载缓存否则网络
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    }
    if (Build.VERSION.SDK_INT >= 19) {
        // 图片自动缩放 打开
        webSettings.setLoadsImagesAutomatically(true);
    } else {
        // 图片自动缩放 关闭
        webSettings.setLoadsImagesAutomatically(false);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // 软件解码
        webBase.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    // 硬件解码
    webBase.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    // webSettings.setAllowContentAccess(true);
    // webSettings.setAllowFileAccessFromFileURLs(true);
    // webSettings.setAppCacheEnabled(true);
    /*     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }*/
    // setMediaPlaybackRequiresUserGesture(boolean require) //是否需要用户手势来播放Media,默认true
    // 设置支持javascript脚本
    webSettings.setJavaScriptEnabled(true);
    // webSettings.setPluginState(WebSettings.PluginState.ON);
    // 设置可以支持缩放
    webSettings.setSupportZoom(true);
    // 设置出现缩放工具 是否使用WebView内置的缩放组件,由浮动在窗口上的缩放控制和手势缩放控制组成,默认false
    webSettings.setBuiltInZoomControls(true);
    // 隐藏缩放工具
    webSettings.setDisplayZoomControls(false);
    // 扩大比例的缩放
    webSettings.setUseWideViewPort(true);
    // 自适应屏幕
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    webSettings.setLoadWithOverviewMode(true);
    // 
    webSettings.setDatabaseEnabled(true);
    // 保存密码
    webSettings.setSavePassword(true);
    // 是否开启本地DOM存储  鉴于它的安全特性(任何人都能读取到它,尽管有相应的限制,将敏感数据存储在这里依然不是明智之举),Android 默认是关闭该功能的。
    webSettings.setDomStorageEnabled(true);
    webBase.setSaveEnabled(true);
    webBase.setKeepScreenOn(true);
    // 设置setWebChromeClient对象
    webBase.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            mRxTextAutoZoom.setText(title);
        }

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            // TODO Auto-generated method stub
            pbWebBase.setProgress(newProgress);
            super.onProgressChanged(view, newProgress);
        }
    });
    // 设置此方法可在WebView中打开链接,反之用浏览器打开
    webBase.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (!webBase.getSettings().getLoadsImagesAutomatically()) {
                webBase.getSettings().setLoadsImagesAutomatically(true);
            }
            pbWebBase.setVisibility(View.GONE);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            pbWebBase.setVisibility(View.VISIBLE);
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("http:") || url.startsWith("https:")) {
                view.loadUrl(url);
                return false;
            }
            // Otherwise allow the OS to handle things like tel, mailto, etc.
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return true;
        }
    });
    webBase.setDownloadListener(new DownloadListener() {

        @Override
        public void onDownloadStart(String paramAnonymousString1, String paramAnonymousString2, String paramAnonymousString3, String paramAnonymousString4, long paramAnonymousLong) {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            intent.setData(Uri.parse(paramAnonymousString1));
            startActivity(intent);
        }
    });
    webBase.loadUrl(webPath);
    Log.v("帮助类完整连接", webPath);
// webBase.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,webBase.getHeight()));
}
Also used : Bitmap(android.graphics.Bitmap) DownloadListener(android.webkit.DownloadListener) WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) Intent(android.content.Intent) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebSettings (android.webkit.WebSettings)211 WebView (android.webkit.WebView)108 WebViewClient (android.webkit.WebViewClient)75 SuppressLint (android.annotation.SuppressLint)50 WebChromeClient (android.webkit.WebChromeClient)47 View (android.view.View)38 Intent (android.content.Intent)30 Bitmap (android.graphics.Bitmap)21 WebResourceRequest (android.webkit.WebResourceRequest)15 KeyEvent (android.view.KeyEvent)11 JsResult (android.webkit.JsResult)11 LinearLayout (android.widget.LinearLayout)11 WebResourceError (android.webkit.WebResourceError)10 CookieManager (android.webkit.CookieManager)9 TextView (android.widget.TextView)9 SslError (android.net.http.SslError)8 SslErrorHandler (android.webkit.SslErrorHandler)8 WebResourceResponse (android.webkit.WebResourceResponse)8 ProgressDialog (android.app.ProgressDialog)7 Toolbar (android.support.v7.widget.Toolbar)7