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

The following examples show how to use android.webkit.WebView#getMeasuredHeight() . 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: WebViewCapture.java    From ViewCapture with Apache License 2.0 5 votes vote down vote up
@SuppressLint("WrongCall")
private Bitmap captureWebView2(@NonNull final WebView view) {
    openCache(view);
    int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(measureSpec, measureSpec);
    if (view.getMeasuredWidth() <= 0 || view.getMeasuredHeight() <= 0) {
        return null;
    }
    Bitmap bm;
    try {
        bm = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    } catch (OutOfMemoryError e) {
        System.gc();
        try {
            bm = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.RGB_565);
        } catch (OutOfMemoryError ee) {
            closeCache(view);
            return captureWebView3(view);
        }
    }
    Canvas bigCanvas = new Canvas(bm);
    Paint paint = new Paint();
    int iHeight = bm.getHeight();
    bigCanvas.drawBitmap(bm, 0, iHeight, paint);
    view.draw(bigCanvas);
    closeCache(view);
    return bm;
}
 
Example 2
Source File: ShareUtil.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a picture out of {@link WebView}'s whole content
 *
 * @param webView The WebView to get contents from
 * @return A {@link Bitmap} or null
 */
@Nullable
public static Bitmap getBitmapFromWebView(final WebView webView) {
    try {
        //Measure WebView's content
        int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        webView.measure(widthMeasureSpec, heightMeasureSpec);
        webView.layout(0, 0, webView.getMeasuredWidth(), webView.getMeasuredHeight());

        //Build drawing cache and store its size
        webView.buildDrawingCache();
        int measuredWidth = webView.getMeasuredWidth();
        int measuredHeight = webView.getMeasuredHeight();

        //Creates the bitmap and draw WebView's content on in
        Bitmap bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawBitmap(bitmap, 0, bitmap.getHeight(), new Paint());

        webView.draw(canvas);
        webView.destroyDrawingCache();

        return bitmap;
    } catch (Exception | OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 3
Source File: MDRootLayout.java    From talk-android with MIT License 5 votes vote down vote up
private void invalidateDividersForWebView(WebView view, final boolean setForTop, boolean setForBottom, boolean hasButtons) {
    if (setForTop) {
        mDrawTopDivider = mTitleBar != null &&
                mTitleBar.getVisibility() != View.GONE &&
                //Not scrolled to the top.
                view.getScrollY() + view.getPaddingTop() > 0;
    }
    if (setForBottom) {
        //noinspection deprecation
        mDrawBottomDivider = hasButtons &&
                view.getScrollY() + view.getMeasuredHeight() - view.getPaddingBottom() < view.getContentHeight() * view.getScale();
    }
}
 
Example 4
Source File: ShareUtil.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
/**
 * Create a picture out of {@link WebView}'s whole content
 *
 * @param webView The WebView to get contents from
 * @return A {@link Bitmap} or null
 */
@Nullable
public static Bitmap getBitmapFromWebView(final WebView webView) {
    try {
        //Measure WebView's content
        int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        webView.measure(widthMeasureSpec, heightMeasureSpec);
        webView.layout(0, 0, webView.getMeasuredWidth(), webView.getMeasuredHeight());

        //Build drawing cache and store its size
        webView.buildDrawingCache();
        int measuredWidth = webView.getMeasuredWidth();
        int measuredHeight = webView.getMeasuredHeight();

        //Creates the bitmap and draw WebView's content on in
        Bitmap bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawBitmap(bitmap, 0, bitmap.getHeight(), new Paint());

        webView.draw(canvas);
        webView.destroyDrawingCache();

        return bitmap;
    } catch (Exception | OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 5
Source File: ShareUtil.java    From Stringlate with MIT License 5 votes vote down vote up
/**
 * Create a picture out of {@link WebView}'s whole content
 *
 * @param webView The WebView to get contents from
 * @return A {@link Bitmap} or null
 */
@Nullable
public static Bitmap getBitmapFromWebView(WebView webView) {
    try {
        //Measure WebView's content
        int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        webView.measure(widthMeasureSpec, heightMeasureSpec);
        webView.layout(0, 0, webView.getMeasuredWidth(), webView.getMeasuredHeight());

        //Build drawing cache and store its size
        webView.buildDrawingCache();
        int measuredWidth = webView.getMeasuredWidth();
        int measuredHeight = webView.getMeasuredHeight();

        //Creates the bitmap and draw WebView's content on in
        Bitmap bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawBitmap(bitmap, 0, bitmap.getHeight(), new Paint());

        webView.draw(canvas);
        webView.destroyDrawingCache();

        return bitmap;
    } catch (Exception | OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 6
Source File: MDRootLayout.java    From talk-android with MIT License 4 votes vote down vote up
private static boolean canWebViewScroll(WebView view) {
    //noinspection deprecation
    return view.getMeasuredHeight() < view.getContentHeight() * view.getScale();
}
 
Example 7
Source File: BGAScrollingUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isWebViewToBottom(WebView webView) {
    return webView != null && webView.getContentHeight() * webView.getScale() == (webView.getScrollY() + webView.getMeasuredHeight());
}
 
Example 8
Source File: ScrollingUtil.java    From Pas with Apache License 2.0 4 votes vote down vote up
public static boolean isWebViewToBottom(WebView webView) {
    return webView != null && webView.getContentHeight() * webView.getScale() == (webView.getScrollY() + webView.getMeasuredHeight());
}