Search in sources :

Example 26 with WebSettings

use of android.webkit.WebSettings in project UltimateAndroid by cymcsg.

the class Html5Webview method init.

private void init(Context context) {
    mContext = context;
    Activity mActivity = (Activity) mContext;
    mLayout = new FrameLayout(context);
    mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity).inflate(R.layout.custom_screen, null);
    mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.main_content);
    mCustomViewContainer = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.fullscreen_custom_content);
    mLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
    // Configure the webview
    WebSettings s = getSettings();
    s.setBuiltInZoomControls(true);
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    s.setUseWideViewPort(true);
    s.setLoadWithOverviewMode(true);
    //  s.setSavePassword(true);
    s.setSaveFormData(true);
    s.setJavaScriptEnabled(true);
    mWebChromeClient = new MyWebChromeClient();
    setWebChromeClient(mWebChromeClient);
    setWebViewClient(new WebViewClient());
    setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    // enable navigator.geolocation
    // s.setGeolocationEnabled(true);
    // s.setGeolocationDatabasePath("/data/data/org.itri.html5webview/databases/");
    // enable Web Storage: localStorage, sessionStorage
    s.setDomStorageEnabled(true);
    mContentView.addView(this);
}
Also used : WebSettings(android.webkit.WebSettings) FrameLayout(android.widget.FrameLayout) Activity(android.app.Activity) WebViewClient(android.webkit.WebViewClient)

Example 27 with WebSettings

use of android.webkit.WebSettings in project weex-example by KalicyZhou.

the class WXWebView method initWebView.

private void initWebView(WebView wv) {
    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAppCacheEnabled(true);
    settings.setUseWideViewPort(true);
    settings.setDomStorageEnabled(true);
    settings.setSupportZoom(false);
    settings.setBuiltInZoomControls(false);
    wv.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            WXLogUtils.v("tag", "onPageOverride " + url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            WXLogUtils.v("tag", "onPageStarted " + url);
            if (mOnPageListener != null) {
                mOnPageListener.onPageStart(url);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            WXLogUtils.v("tag", "onPageFinished " + url);
            if (mOnPageListener != null) {
                mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
            }
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            if (mOnErrorListener != null) {
                //mOnErrorListener.onError("error", "page error code:" + error.getErrorCode() + ", desc:" + error.getDescription() + ", url:" + request.getUrl());
                mOnErrorListener.onError("error", "page error");
            }
        }

        @Override
        public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
            super.onReceivedHttpError(view, request, errorResponse);
            if (mOnErrorListener != null) {
                mOnErrorListener.onError("error", "http error");
            }
        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            super.onReceivedSslError(view, handler, error);
            if (mOnErrorListener != null) {
                mOnErrorListener.onError("error", "ssl error");
            }
        }
    });
    wv.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            showWebView(newProgress == 100);
            showProgressBar(newProgress != 100);
            WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            if (mOnPageListener != null) {
                mOnPageListener.onReceivedTitle(view.getTitle());
            }
        }
    });
}
Also used : SslErrorHandler(android.webkit.SslErrorHandler) WebResourceRequest(android.webkit.WebResourceRequest) SslError(android.net.http.SslError) Bitmap(android.graphics.Bitmap) WebResourceResponse(android.webkit.WebResourceResponse) WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebResourceError(android.webkit.WebResourceError) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 28 with WebSettings

use of android.webkit.WebSettings in project android_frameworks_base by DirtyUnicorns.

the class CaptivePortalLoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mCm = ConnectivityManager.from(this);
    mNetwork = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);
    mCaptivePortal = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL);
    mUserAgent = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_USER_AGENT);
    mUrl = getUrl();
    if (mUrl == null) {
        // getUrl() failed to parse the url provided in the intent: bail out in a way that
        // at least provides network access.
        done(Result.WANTED_AS_IS);
        return;
    }
    if (DBG) {
        Log.d(TAG, String.format("onCreate for %s", mUrl.toString()));
    }
    // Also initializes proxy system properties.
    mCm.bindProcessToNetwork(mNetwork);
    // Proxy system properties must be initialized before setContentView is called because
    // setContentView initializes the WebView logic which in turn reads the system properties.
    setContentView(R.layout.activity_captive_portal_login);
    getActionBar().setDisplayShowHomeEnabled(false);
    // Exit app if Network disappears.
    final NetworkCapabilities networkCapabilities = mCm.getNetworkCapabilities(mNetwork);
    if (networkCapabilities == null) {
        finishAndRemoveTask();
        return;
    }
    mNetworkCallback = new NetworkCallback() {

        @Override
        public void onLost(Network lostNetwork) {
            if (mNetwork.equals(lostNetwork))
                done(Result.UNWANTED);
        }
    };
    final NetworkRequest.Builder builder = new NetworkRequest.Builder();
    for (int transportType : networkCapabilities.getTransportTypes()) {
        builder.addTransportType(transportType);
    }
    mCm.registerNetworkCallback(builder.build(), mNetworkCallback);
    final WebView myWebView = (WebView) findViewById(R.id.webview);
    myWebView.clearCache(true);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    mWebViewClient = new MyWebViewClient();
    myWebView.setWebViewClient(mWebViewClient);
    myWebView.setWebChromeClient(new MyWebChromeClient());
    // Start initial page load so WebView finishes loading proxy settings.
    // Actual load of mUrl is initiated by MyWebViewClient.
    myWebView.loadData("", "text/html", null);
}
Also used : WebSettings(android.webkit.WebSettings) Network(android.net.Network) NetworkRequest(android.net.NetworkRequest) WebView(android.webkit.WebView) NetworkCapabilities(android.net.NetworkCapabilities) NetworkCallback(android.net.ConnectivityManager.NetworkCallback)

Example 29 with WebSettings

use of android.webkit.WebSettings in project materialistic by hidroh.

the class CacheableWebView method setLoadSettings.

@SuppressLint("SetJavaScriptEnabled")
private void setLoadSettings() {
    WebSettings webSettings = getSettings();
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setJavaScriptEnabled(true);
}
Also used : WebSettings(android.webkit.WebSettings) SuppressLint(android.annotation.SuppressLint)

Example 30 with WebSettings

use of android.webkit.WebSettings in project UltimateAndroid by cymcsg.

the class Html5Webview method init.

private void init(Context context) {
    mContext = context;
    Activity mActivity = (Activity) mContext;
    mLayout = new FrameLayout(context);
    mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity).inflate(R.layout.html5_webview_custom_screen, null);
    mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.html5_webview_main_content);
    mCustomViewContainer = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.html5_webview_fullscreen_custom_content);
    mLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
    // Configure the webview
    WebSettings s = getSettings();
    s.setBuiltInZoomControls(true);
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    s.setUseWideViewPort(true);
    s.setLoadWithOverviewMode(true);
    //  s.setSavePassword(true);
    s.setSaveFormData(true);
    s.setJavaScriptEnabled(true);
    mWebChromeClient = new MyWebChromeClient();
    setWebChromeClient(mWebChromeClient);
    setWebViewClient(new WebViewClient());
    setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    // enable navigator.geolocation
    // s.setGeolocationEnabled(true);
    // s.setGeolocationDatabasePath("/data/data/org.itri.html5webview/databases/");
    // enable Web Storage: localStorage, sessionStorage
    s.setDomStorageEnabled(true);
    mContentView.addView(this);
}
Also used : WebSettings(android.webkit.WebSettings) FrameLayout(android.widget.FrameLayout) Activity(android.app.Activity) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebSettings (android.webkit.WebSettings)92 WebView (android.webkit.WebView)49 WebViewClient (android.webkit.WebViewClient)29 SuppressLint (android.annotation.SuppressLint)23 View (android.view.View)17 WebChromeClient (android.webkit.WebChromeClient)17 Intent (android.content.Intent)10 JsResult (android.webkit.JsResult)7 Bitmap (android.graphics.Bitmap)6 KeyEvent (android.view.KeyEvent)6 WebResourceRequest (android.webkit.WebResourceRequest)6 NetworkCallback (android.net.ConnectivityManager.NetworkCallback)5 Network (android.net.Network)5 NetworkCapabilities (android.net.NetworkCapabilities)5 NetworkRequest (android.net.NetworkRequest)5 Bundle (android.os.Bundle)5 RelativeLayout (android.widget.RelativeLayout)5 TextView (android.widget.TextView)5 WebResourceError (android.webkit.WebResourceError)4 Activity (android.app.Activity)3