Java Code Examples for android.webkit.WebView#getParent()

The following examples show how to use android.webkit.WebView#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallActivity.java    From sealrtc-android with MIT License 6 votes vote down vote up
public void destroyWebView(WebView mWebView) {
    if (mWebView != null) {
        try {
            ViewParent parent = mWebView.getParent();
            if (parent != null) {
                ((ViewGroup) parent).removeView(mWebView);
            }
            mWebView.stopLoading();
            mWebView.getSettings().setJavaScriptEnabled(false);
            mWebView.clearHistory();
            mWebView.clearView();
            mWebView.removeAllViews();

            mWebView.destroy();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 2
Source File: AgentWebUtils.java    From AgentWeb with Apache License 2.0 6 votes vote down vote up
static final void clearWebView(WebView m) {
	if (m == null) {
		return;
	}
	if (Looper.myLooper() != Looper.getMainLooper()) {
		return;
	}
	m.loadUrl("about:blank");
	m.stopLoading();
	if (m.getHandler() != null) {
		m.getHandler().removeCallbacksAndMessages(null);
	}
	m.removeAllViews();
	ViewGroup mViewGroup = null;
	if ((mViewGroup = ((ViewGroup) m.getParent())) != null) {
		mViewGroup.removeView(m);
	}
	m.setWebChromeClient(null);
	m.setWebViewClient(null);
	m.setTag(null);
	m.clearHistory();
	m.destroy();
	m = null;
}
 
Example 3
Source File: TurbolinksView.java    From turbolinks-android with MIT License 5 votes vote down vote up
/**
 * <p>Attach the swipeRefreshLayout, which contains the shared webView, to the TurbolinksView.</p>
 *
 * @param webView              The shared webView.
 * @param screenshotsEnabled   Indicates whether screenshots are enabled for the current session.
 * @param pullToRefreshEnabled Indicates whether pull to refresh is enabled for the current session.
 * @return True if the webView has been attached to a new parent, otherwise false
 */
boolean attachWebView(WebView webView, boolean screenshotsEnabled, boolean pullToRefreshEnabled) {
    if (webView.getParent() == refreshLayout) return false;

    refreshLayout.setEnabled(pullToRefreshEnabled);

    if (webView.getParent() instanceof TurbolinksSwipeRefreshLayout) {
        TurbolinksSwipeRefreshLayout previousRefreshLayout = (TurbolinksSwipeRefreshLayout) webView.getParent();
        TurbolinksView previousTurbolinksView = (TurbolinksView) previousRefreshLayout.getParent();

        if (screenshotsEnabled) previousTurbolinksView.screenshotView();

        try {
            // This is an admittedly hacky workaround, but it buys us some time as we investigate
            // a potential bug with Chrome 64, which is currently throwing an IllegalStateException
            // when accessibility services (like Talkback or 1password) are enabled.
            // We're tracking this bug on the Chromium issue tracker:
            // https://bugs.chromium.org/p/chromium/issues/detail?id=806108
            previousRefreshLayout.removeView(webView);
        } catch (Exception e) {
            previousRefreshLayout.removeView(webView);
        }
    }

    // Set the webview background to match the container background
    if (getBackground() instanceof ColorDrawable) {
        webView.setBackgroundColor(((ColorDrawable) getBackground()).getColor());
    }

    refreshLayout.addView(webView);
    return true;
}
 
Example 4
Source File: WebViewCache.java    From tysq-android with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 存储webview
 * @param webView
 */
public void saveWebView(WebView webView){
    ViewGroup parent = (ViewGroup) webView.getParent();
    parent.removeView(webView);
    mWebViewList.add(webView);
}