Example usage for android.webkit WebView getParent

List of usage examples for android.webkit WebView getParent

Introduction

In this page you can find the example usage for android.webkit WebView getParent.

Prototype

public final ViewParent getParent() 

Source Link

Document

Gets the parent of this view.

Usage

From source file:com.just.agentweb.AgentWebUtils.java

static WebParentLayout getWebParentLayoutByWebView(WebView webView) {
    ViewGroup mViewGroup = null;/*w  ww  . java  2s  .  c o m*/
    if (!(webView.getParent() instanceof ViewGroup)) {
        throw new IllegalStateException("please check webcreator's create method was be called ?");
    }
    mViewGroup = (ViewGroup) webView.getParent();
    AbsAgentWebUIController mAgentWebUIController;
    while (mViewGroup != null) {

        LogUtils.i(TAG, "ViewGroup:" + mViewGroup);
        if (mViewGroup.getId() == R.id.web_parent_layout_id) {
            WebParentLayout mWebParentLayout = (WebParentLayout) mViewGroup;
            LogUtils.i(TAG, "found WebParentLayout");
            return mWebParentLayout;
        } else {
            ViewParent mViewParent = mViewGroup.getParent();
            if (mViewParent instanceof ViewGroup) {
                mViewGroup = (ViewGroup) mViewParent;
            } else {
                mViewGroup = null;
            }
        }
    }
    throw new IllegalStateException("please check webcreator's create method was be called ?");
}

From source file:com.just.agentweb.AgentWebUtils.java

static final void clearWebView(WebView m) {

    if (m == null) {
        return;/*from  www . ja v  a 2  s.co m*/
    }
    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;

}

From source file:nirwan.cordova.plugin.printer.Printer.java

private void loadContentAsBitmapIntoPrintController(String content, final Intent intent) {
    Activity ctx = cordova.getActivity();
    final WebView page = new WebView(ctx);
    final Printer self = this;

    page.setVisibility(View.INVISIBLE);
    page.getSettings().setJavaScriptEnabled(false);

    page.setWebViewClient(new WebViewClient() {
        @Override//from   w w w.  j a v  a 2 s.c  o  m
        public void onPageFinished(final WebView page, String url) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Bitmap screenshot = self.takeScreenshot(page);
                    File tmpFile = self.saveScreenshotToTmpFile(screenshot);
                    ViewGroup vg = (ViewGroup) (page.getParent());

                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tmpFile));

                    vg.removeView(page);
                }
            }, 1000);
        }
    });

    //Set base URI to the assets/www folder
    String baseURL = webView.getUrl();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/') + 1);

    ctx.addContentView(page, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    page.loadDataWithBaseURL(baseURL, content, "text/html", "UTF-8", null);
}

From source file:com.sabaibrowser.UI.java

protected void attachTabToContentView(Tab tab) {
    if ((tab == null) || (tab.getWebView() == null)) {
        return;/* ww w. j  ava2  s . c  o m*/
    }
    View container = tab.getViewContainer();
    WebView mainView = tab.getWebView();
    // Attach the WebView to the container and then attach the
    // container to the content view.
    FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper);
    ViewGroup parent = (ViewGroup) mainView.getParent();
    if (parent != wrapper) {
        if (parent != null) {
            parent.removeView(mainView);
        }
        wrapper.addView(mainView);
    }
    parent = (ViewGroup) container.getParent();
    if (parent != mContentView) {
        if (parent != null) {
            parent.removeView(container);
        }
        mContentView.addView(container, COVER_SCREEN_PARAMS);
    }
}