Search in sources :

Example 41 with WebView

use of android.webkit.WebView in project AgentWeb by Justson.

the class DefaultWebCreator method createGroupWithWeb.

private ViewGroup createGroupWithWeb() {
    Activity mActivity = this.mActivity;
    FrameLayout mFrameLayout = new FrameLayout(mActivity);
    WebView mWebView = null;
    if (this.mWebView != null) {
        mWebView = this.mWebView;
        AgentWebConfig.WEBVIEW_TYPE = AgentWebConfig.WEBVIEW_CUSTOM_TYPE;
    } else if (AgentWebConfig.isKikatOrBelowKikat) {
        mWebView = new AgentWebView(mActivity.getApplicationContext());
        AgentWebConfig.WEBVIEW_TYPE = AgentWebConfig.WEBVIEW_AGENTWEB_SAFE_TYPE;
    } else {
        mWebView = new WebView(mActivity.getApplicationContext());
        AgentWebConfig.WEBVIEW_TYPE = AgentWebConfig.WEBVIEW_DEFAULT_TYPE;
    }
    FrameLayout.LayoutParams mLayoutParams = new FrameLayout.LayoutParams(-1, -1);
    mFrameLayout.addView(this.mWebView = mWebView, mLayoutParams);
    LogUtils.i("Info", "    webView:" + (this.mWebView instanceof AgentWebView));
    if (isNeedDefaultProgress) {
        FrameLayout.LayoutParams lp = null;
        WebProgress mWebProgress = new WebProgress(mActivity);
        if (height_dp > 0)
            lp = new FrameLayout.LayoutParams(-2, AgentWebUtils.dp2px(mActivity, height_dp));
        else
            lp = mWebProgress.offerLayoutParams();
        if (color != -1)
            mWebProgress.setColor(color);
        lp.gravity = Gravity.TOP;
        mFrameLayout.addView((View) (this.mBaseProgressSpec = mWebProgress), lp);
    } else if (!isNeedDefaultProgress && progressView != null) {
        //            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(-2, -2);
        mFrameLayout.addView((View) (this.mBaseProgressSpec = (BaseProgressSpec) progressView), progressView.offerLayoutParams());
    }
    return mFrameLayout;
}
Also used : FrameLayout(android.widget.FrameLayout) Activity(android.app.Activity) WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView)

Example 42 with WebView

use of android.webkit.WebView in project AgentWeb by Justson.

the class AgentWebView method trySetWebDebuggEnabled.

/**
     * Android 4.4 KitKat 使用Chrome DevTools 远程调试WebView
     * WebView.setWebContentsDebuggingEnabled(true);
     * http://blog.csdn.net/t12x3456/article/details/14225235
     */
@TargetApi(19)
protected void trySetWebDebuggEnabled() {
    if (LogUtils.isDebug() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        try {
            Class<?> clazz = WebView.class;
            Method method = clazz.getMethod("setWebContentsDebuggingEnabled", boolean.class);
            method.invoke(null, true);
        } catch (Throwable e) {
            if (LogUtils.isDebug()) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Method(java.lang.reflect.Method) WebView(android.webkit.WebView) TargetApi(android.annotation.TargetApi)

Example 43 with WebView

use of android.webkit.WebView 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 44 with WebView

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

the class WebViewFragment method onCreateView.

/**
     * Called to instantiate the view. Creates and returns the WebView.
     */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (mWebView != null) {
        mWebView.destroy();
    }
    mWebView = new WebView(getContext());
    mIsWebViewAvailable = true;
    return mWebView;
}
Also used : WebView(android.webkit.WebView)

Example 45 with WebView

use of android.webkit.WebView 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)

Aggregations

WebView (android.webkit.WebView)594 WebViewClient (android.webkit.WebViewClient)214 View (android.view.View)176 WebSettings (android.webkit.WebSettings)103 Intent (android.content.Intent)87 SuppressLint (android.annotation.SuppressLint)79 WebChromeClient (android.webkit.WebChromeClient)77 TextView (android.widget.TextView)61 Bitmap (android.graphics.Bitmap)55 LinearLayout (android.widget.LinearLayout)39 DialogInterface (android.content.DialogInterface)36 ImageView (android.widget.ImageView)35 WebResourceRequest (android.webkit.WebResourceRequest)32 Uri (android.net.Uri)31 Test (org.junit.Test)27 Bundle (android.os.Bundle)26 AlertDialog (android.app.AlertDialog)24 Activity (android.app.Activity)22 Handler (android.os.Handler)20 IOException (java.io.IOException)20