Search in sources :

Example 66 with WebSettings

use of android.webkit.WebSettings in project DMGameApp by xiaohaibin.

the class WebDetailsActivity method initWeb.

@SuppressLint("SetJavaScriptEnabled")
private void initWeb() {
    WebSettings settings = webView.getSettings();
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
    webView.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (progressBar == null) {
                return;
            }
            if (newProgress == 100) {
                progressBar.setVisibility(View.GONE);
            } else {
                if (progressBar.getVisibility() == View.GONE) {
                    progressBar.setVisibility(View.VISIBLE);
                }
                progressBar.setProgress(newProgress);
            }
        }
    });
    settings.setDefaultTextEncodingName("utf-8");
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setUseWideViewPort(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setLoadWithOverviewMode(true);
    // 隐藏缩放控件
    settings.setDisplayZoomControls(false);
    // 解决HTTPS协议下出现的mixed content问题
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setAppCachePath(getCacheDir().getPath());
    settings.setAppCacheEnabled(true);
    showWebData();
}
Also used : WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) SuppressLint(android.annotation.SuppressLint) WebViewClient(android.webkit.WebViewClient) SuppressLint(android.annotation.SuppressLint)

Example 67 with WebSettings

use of android.webkit.WebSettings in project Osmand by osmandapp.

the class ContextMenuHelper method showWiki.

private static void showWiki(final Context ctx, final SampleApplication app, final Amenity a, final String lang) {
    String preferredLang = lang;
    if (Algorithms.isEmpty(preferredLang)) {
        preferredLang = SampleApplication.LANGUAGE;
    }
    final Dialog dialog = new Dialog(ctx, R.style.AppTheme);
    final String title = Algorithms.isEmpty(lang) ? a.getName() : a.getName(lang);
    LinearLayout ll = new LinearLayout(ctx);
    ll.setOrientation(LinearLayout.VERTICAL);
    final Toolbar topBar = new Toolbar(ctx);
    topBar.setClickable(true);
    Drawable back = app.getIconsCache().getIcon(R.drawable.ic_arrow_back);
    topBar.setNavigationIcon(back);
    topBar.setNavigationContentDescription(app.getString("access_shared_string_navigate_up"));
    topBar.setTitle(title);
    topBar.setBackgroundColor(ContextCompat.getColor(ctx, R.color.osmand_orange));
    topBar.setTitleTextColor(ContextCompat.getColor(ctx, R.color.color_white));
    String lng = a.getContentLanguage("content", preferredLang, "en");
    if (Algorithms.isEmpty(lng)) {
        lng = "en";
    }
    final String langSelected = lng;
    String content = a.getDescription(langSelected);
    final Button bottomBar = new Button(ctx);
    bottomBar.setText(app.getString("read_full_article"));
    bottomBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String article = "https://" + langSelected.toLowerCase() + ".wikipedia.org/wiki/" + title.replace(' ', '_');
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(article));
            ctx.startActivity(i);
        }
    });
    MenuItem mi = topBar.getMenu().add(langSelected.toUpperCase()).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            showPopupLangMenu(ctx, topBar, app, a, dialog, langSelected);
            return true;
        }
    });
    MenuItemCompat.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_ALWAYS);
    topBar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            dialog.dismiss();
        }
    });
    final WebView wv = new WebView(ctx);
    WebSettings settings = wv.getSettings();
    settings.setDefaultTextEncodingName("utf-8");
    // Zooming does not work ok here
    settings.setBuiltInZoomControls(false);
    settings.setDisplayZoomControls(false);
    // Scale web view font size with system font size
    float scale = ctx.getResources().getConfiguration().fontScale;
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        settings.setTextZoom((int) (scale * 100f));
    } else {
        if (scale <= 0.7f) {
            settings.setTextSize(WebSettings.TextSize.SMALLEST);
        } else if (scale <= 0.85f) {
            settings.setTextSize(WebSettings.TextSize.SMALLER);
        } else if (scale <= 1.0f) {
            settings.setTextSize(WebSettings.TextSize.NORMAL);
        } else if (scale <= 1.15f) {
            settings.setTextSize(WebSettings.TextSize.LARGER);
        } else {
            settings.setTextSize(WebSettings.TextSize.LARGEST);
        }
    }
    wv.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null);
    // wv.loadUrl(OsMoService.SIGN_IN_URL + app.getSettings().OSMO_DEVICE_KEY.get());
    ScrollView scrollView = new ScrollView(ctx);
    ll.addView(topBar);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0);
    lp.weight = 1;
    ll.addView(scrollView, lp);
    ll.addView(bottomBar, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    scrollView.addView(wv);
    dialog.setContentView(ll);
    wv.setFocusable(true);
    wv.setFocusableInTouchMode(true);
    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                    if (!v.hasFocus()) {
                        v.requestFocus();
                    }
                    break;
            }
            return false;
        }
    });
    dialog.setCancelable(true);
    dialog.show();
}
Also used : Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) MenuItem(android.view.MenuItem) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) MotionEvent(android.view.MotionEvent) ScrollView(android.widget.ScrollView) Button(android.widget.Button) Dialog(android.app.Dialog) WebSettings(android.webkit.WebSettings) WebView(android.webkit.WebView) LinearLayout(android.widget.LinearLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 68 with WebSettings

use of android.webkit.WebSettings in project Now by XunMengWinter.

the class WebActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);
    ButterKnife.bind(this);
    mContext = this;
    mUrl = getIntent().getStringExtra(EXTRA_URL);
    mTitle = getIntent().getStringExtra(EXTRA_TITLE);
    picUrl = getIntent().getStringExtra(EXTRA_PIC_URL);
    summary = getIntent().getStringExtra(EXTRA_SUMMARY);
    new Thread() {

        @Override
        public void run() {
            super.run();
            // }
            try {
                Drawable drawable = Glide.with(WebActivity.this).load(picUrl).submit(120, 120).get();
                bitmap = ImageUtil.drawableToBitmap(drawable);
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }
    }.start();
    mWebView.setWebChromeClient(new ChromeClient());
    mWebView.setWebViewClient(new ViewClient());
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(new PreferencesHelper(App.getInstance()).isJSEnabled());
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setAppCachePath(Constants.WEB_CACHE_DIR);
    if (NowAppUtil.isWifiConnected())
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    else
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    mWebView.loadUrl(mUrl);
    mWebView.setOnTouchListener(this);
    setTitle(mTitle);
    mFloatingActionButton.setVisibility(View.GONE);
}
Also used : WebChromeClient(android.webkit.WebChromeClient) WebViewClient(android.webkit.WebViewClient) WebSettings(android.webkit.WebSettings) Drawable(android.graphics.drawable.Drawable) PreferencesHelper(top.wefor.now.PreferencesHelper)

Example 69 with WebSettings

use of android.webkit.WebSettings in project Memento-Calendar by alexstyl.

the class FacebookWebView method setup.

private void setup() {
    ((MementoApplication) getContext().getApplicationContext()).getApplicationModule().inject(this);
    clearCache(false);
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    WebSettings settings = getSettings();
    settings.setJavaScriptEnabled(true);
    addJavascriptInterface(new FacebookJavaScriptInterface(), "HTMLOUT");
    client = new FBImportClient(this);
    setWebViewClient(client);
}
Also used : WebSettings(android.webkit.WebSettings)

Example 70 with WebSettings

use of android.webkit.WebSettings in project braintree_android by braintree.

the class ThreeDSecureWebViewUnitTest method init_setsWebSettings.

@Test
public void init_setsWebSettings() {
    mThreeDSecureWebView.init(mActivity);
    WebSettings settings = mThreeDSecureWebView.getSettings();
    assertEquals(BraintreeHttpClient.getUserAgent(), settings.getUserAgentString());
    assertEquals(WebSettings.LOAD_CACHE_ELSE_NETWORK, settings.getCacheMode());
    assertTrue(settings.supportMultipleWindows());
    assertTrue(settings.getJavaScriptEnabled());
    assertTrue(settings.getBuiltInZoomControls());
    assertFalse(settings.getDisplayZoomControls());
    assertTrue(settings.getDomStorageEnabled());
    assertTrue(settings.getDatabaseEnabled());
}
Also used : WebSettings(android.webkit.WebSettings) Test(org.junit.Test)

Aggregations

WebSettings (android.webkit.WebSettings)213 WebView (android.webkit.WebView)110 WebViewClient (android.webkit.WebViewClient)77 SuppressLint (android.annotation.SuppressLint)52 WebChromeClient (android.webkit.WebChromeClient)49 View (android.view.View)38 Intent (android.content.Intent)32 Bitmap (android.graphics.Bitmap)23 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