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

The following examples show how to use android.webkit.WebView#getScrollY() . 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: ViewUtils.java    From MVPAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
/**
 * Convert view to an image.  Can be used to make animations smoother.
 *
 * @param context           The current Context or Activity that this method is called from
 * @param viewToBeConverted View to convert to a Bitmap
 * @return Bitmap object that can be put in an ImageView.  Will look like the converted viewToBeConverted.
 */
public static Bitmap viewToImage(Context context, WebView viewToBeConverted) {
    int extraSpace = 2000; //because getContentHeight doesn't always return the full screen height.
    int height = viewToBeConverted.getContentHeight() + extraSpace;

    Bitmap viewBitmap = Bitmap.createBitmap(viewToBeConverted.getWidth(), height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(viewBitmap);
    viewToBeConverted.draw(canvas);

    //If the view is scrolled, cut off the top part that is off the screen.
    try {
        int scrollY = viewToBeConverted.getScrollY();
        if (scrollY > 0) {
            viewBitmap = Bitmap.createBitmap(viewBitmap, 0, scrollY, viewToBeConverted.getWidth(), height - scrollY);
        }
    } catch (Exception ex) {
        Log.e("PercolateAndroidUtils", "Could not remove top part of the webview image.  ex=" + ex);
    }

    return viewBitmap;
}
 
Example 2
Source File: ViewUtils.java    From RxAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
/**
 * Convert view to an image.  Can be used to make animations smoother.
 *
 * @param context           The current Context or Activity that this method is called from
 * @param viewToBeConverted View to convert to a Bitmap
 * @return Bitmap object that can be put in an ImageView.  Will look like the converted viewToBeConverted.
 */
public static Bitmap viewToImage(Context context, WebView viewToBeConverted) {
    int extraSpace = 2000; //because getContentHeight doesn't always return the full screen height.
    int height = viewToBeConverted.getContentHeight() + extraSpace;

    Bitmap viewBitmap = Bitmap.createBitmap(viewToBeConverted.getWidth(), height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(viewBitmap);
    viewToBeConverted.draw(canvas);

    //If the view is scrolled, cut off the top part that is off the screen.
    try {
        int scrollY = viewToBeConverted.getScrollY();
        if (scrollY > 0) {
            viewBitmap = Bitmap.createBitmap(viewBitmap, 0, scrollY, viewToBeConverted.getWidth(), height - scrollY);
        }
    } catch (Exception ex) {
        Log.e("PercolateAndroidUtils", "Could not remove top part of the webview image.  ex=" + ex);
    }

    return viewBitmap;
}
 
Example 3
Source File: ViewUtils.java    From caffeine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Convert view to an image.  Can be used to make animations smoother.
 *
 * @param context           The current Context or Activity that this method is called from.
 * @param viewToBeConverted View to convert to a Bitmap.
 * @return Bitmap object that can be put in an ImageView.  Will look like the converted viewToBeConverted.
 */
public static Bitmap viewToImage(Context context, WebView viewToBeConverted) {
    int extraSpace = 2000; //because getContentHeight doesn't always return the full screen height.
    int height = viewToBeConverted.getContentHeight() + extraSpace;

    Bitmap viewBitmap = Bitmap.createBitmap(viewToBeConverted.getWidth(), height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(viewBitmap);
    viewToBeConverted.draw(canvas);

    //If the view is scrolled, cut off the top part that is off the screen.
    try {
        int scrollY = viewToBeConverted.getScrollY();
        if (scrollY > 0) {
            viewBitmap = Bitmap.createBitmap(viewBitmap, 0, scrollY, viewToBeConverted.getWidth(), height - scrollY);
        }
    } catch (Exception ex) {
        Log.e("Caffeine", "Could not remove top part of the webview image.  ex=" + ex);
    }

    return viewBitmap;
}
 
Example 4
Source File: NestedTouchScrollingLayout.java    From NestedTouchScrollingLayout with MIT License 5 votes vote down vote up
/**
 * 规避 contentHeight 异步变化
 * @return
 */
private boolean canWebViewScrollUp(WebView webView) {
    if (mWebViewContentHeight == 0) {
        mWebViewContentHeight = (int) (webView.getContentHeight() * webView.getScale());
    }
    final int offset = webView.getScrollY();
    final int range = mWebViewContentHeight - webView.getHeight();
    if (range == 0) {
        return false;
    }
    return offset > 2;
}
 
Example 5
Source File: NestedTouchScrollingLayout.java    From NestedTouchScrollingLayout with MIT License 5 votes vote down vote up
/**
 * 规避 contentHeight 异步变化
 * @return
 */
private boolean canWebViewScrollDown(WebView webView) {
    if (mWebViewContentHeight == 0) {
        mWebViewContentHeight = (int) (webView.getContentHeight() * webView.getScale());
    }
    final int offset = webView.getScrollY();
    final int range = mWebViewContentHeight - webView.getHeight();
    if (range == 0) {
        return false;
    }
    return offset < range - 2;
}
 
Example 6
Source File: HeaderScrollHelper.java    From RichWebList with Apache License 2.0 5 votes vote down vote up
private boolean isWebViewTop(WebView scrollView) {
    if (scrollView != null) {
        int scrollViewY = scrollView.getScrollY();
        return scrollViewY <= 0;
    }
    return false;
}
 
Example 7
Source File: ScrollableHelper.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
private static boolean isWebViewTop(WebView scrollView) {
    if (scrollView != null) {
        int scrollViewY = scrollView.getScrollY();
        return scrollViewY <= 0;
    }
    return false;
}
 
Example 8
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 9
Source File: ScrollableHelper.java    From ScrollableLayout with Apache License 2.0 5 votes vote down vote up
private static boolean isWebViewTop(WebView scrollView) {
    if (scrollView != null) {
        int scrollViewY = scrollView.getScrollY();
        return scrollViewY <= 0;
    }
    return false;
}
 
Example 10
Source File: ScrollableHelper.java    From ScrollableLayout with MIT License 5 votes vote down vote up
private static boolean isWebViewTop(WebView scrollView){
    if(scrollView != null) {
        int scrollViewY = scrollView.getScrollY();
        return scrollViewY <= 0;
    }
    return false;
}
 
Example 11
Source File: ScrollingUtil.java    From AgentWebX5 with Apache License 2.0 4 votes vote down vote up
public static boolean isWebViewToBottom(WebView webview, int mTouchSlop) {
    return webview != null && ((webview.getContentHeight() * webview.getScale() - (webview.getHeight() + webview.getScrollY())) <= 2 * mTouchSlop);
}
 
Example 12
Source File: ScrollingUtil.java    From TwinklingRefreshLayout with Apache License 2.0 4 votes vote down vote up
public static boolean isWebViewToBottom(WebView webview, int mTouchSlop) {
    return webview != null && ((webview.getContentHeight() * webview.getScale() - (webview.getHeight() + webview.getScrollY())) <= 2 * mTouchSlop);
}
 
Example 13
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 14
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());
}