Example usage for android.view View getScrollY

List of usage examples for android.view View getScrollY

Introduction

In this page you can find the example usage for android.view View getScrollY.

Prototype

public final int getScrollY() 

Source Link

Document

Return the scrolled top position of this view.

Usage

From source file:Main.java

/**
 * Given a coordinate relative to the descendant, find the coordinate in a parent view's
 * coordinates./*from   w w  w  .j  av  a  2s.c  o m*/
 *
 * @param descendant The descendant to which the passed coordinate is relative.
 * @param root The root view to make the coordinates relative to.
 * @param coord The coordinate that we want mapped.
 * @param includeRootScroll Whether or not to account for the scroll of the descendant:
 *          sometimes this is relevant as in a child's coordinates within the descendant.
 * @return The factor by which this descendant is scaled relative to this DragLayer. Caution
 *         this scale factor is assumed to be equal in X and Y, and so if at any point this
 *         assumption fails, we will need to return a pair of scale factors.
 */
public static float getDescendantCoordRelativeToParent(View descendant, View root, int[] coord,
        boolean includeRootScroll) {
    ArrayList<View> ancestorChain = new ArrayList<View>();

    float[] pt = { coord[0], coord[1] };

    View v = descendant;
    while (v != root && v != null) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);

    float scale = 1.0f;
    int count = ancestorChain.size();
    for (int i = 0; i < count; i++) {
        View v0 = ancestorChain.get(i);
        // For TextViews, scroll has a meaning which relates to the text position
        // which is very strange... ignore the scroll.
        if (v0 != descendant || includeRootScroll) {
            pt[0] -= v0.getScrollX();
            pt[1] -= v0.getScrollY();
        }

        v0.getMatrix().mapPoints(pt);
        pt[0] += v0.getLeft();
        pt[1] += v0.getTop();
        scale *= v0.getScaleX();
    }

    coord[0] = (int) Math.round(pt[0]);
    coord[1] = (int) Math.round(pt[1]);
    return scale;
}

From source file:Main.java

/**
 * Maps a coordinate in the root to a descendent.
 *///w w w. j a va 2  s.  c  om
public static float mapCoordInSelfToDescendent(View descendant, View root, float[] coord,
        Matrix tmpInverseMatrix) {
    ArrayList<View> ancestorChain = new ArrayList<View>();

    float[] pt = { coord[0], coord[1] };

    View v = descendant;
    while (v != root) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);

    float scale = 1.0f;
    int count = ancestorChain.size();
    tmpInverseMatrix.set(IDENTITY_MATRIX);
    for (int i = count - 1; i >= 0; i--) {
        View ancestor = ancestorChain.get(i);
        View next = i > 0 ? ancestorChain.get(i - 1) : null;

        pt[0] += ancestor.getScrollX();
        pt[1] += ancestor.getScrollY();

        if (next != null) {
            pt[0] -= next.getLeft();
            pt[1] -= next.getTop();
            next.getMatrix().invert(tmpInverseMatrix);
            tmpInverseMatrix.mapPoints(pt);
            scale *= next.getScaleX();
        }
    }

    coord[0] = pt[0];
    coord[1] = pt[1];
    return scale;
}

From source file:Main.java

/**
 * Maps a coordinate in the root to a descendent.
 *//*www  .  j a v  a  2 s.  co m*/
public static float mapCoordInSelfToDescendent(View descendant, View root, float[] coord,
        Matrix tmpInverseMatrix) {
    ArrayList<View> ancestorChain = new ArrayList<>();

    float[] pt = { coord[0], coord[1] };

    View v = descendant;
    while (v != root) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);

    float scale = 1.0f;
    int count = ancestorChain.size();
    tmpInverseMatrix.set(IDENTITY_MATRIX);
    for (int i = count - 1; i >= 0; i--) {
        View ancestor = ancestorChain.get(i);
        View next = i > 0 ? ancestorChain.get(i - 1) : null;

        pt[0] += ancestor.getScrollX();
        pt[1] += ancestor.getScrollY();

        if (next != null) {
            pt[0] -= next.getLeft();
            pt[1] -= next.getTop();
            next.getMatrix().invert(tmpInverseMatrix);
            tmpInverseMatrix.mapPoints(pt);
            scale *= next.getScaleX();
        }
    }

    coord[0] = pt[0];
    coord[1] = pt[1];
    return scale;
}

From source file:Main.java

public static boolean canChildScrollUp(View view) {
    if (view instanceof AbsListView) {
        AbsListView absListView = (AbsListView) view;
        Log.d("debug", absListView.getChildAt(0).getTop() + "v2top");
        return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0
                || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
    }/*from ww  w .  j  av a 2 s.  c  o  m*/
    if (Build.VERSION.SDK_INT < 14) {
        return view.getScrollY() > 0;
    } else {
        return view.canScrollVertically(-1);
    }
}

From source file:Main.java

public static Drawable convertViewToDrawable(View view) {
    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(spec, spec);//from   w ww .ja  v a 2 s .c o  m
    view.layout(UPPER_LEFT_X, UPPER_LEFT_Y, view.getMeasuredWidth(), view.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    c.translate(-view.getScrollX(), -view.getScrollY());
    view.draw(c);
    view.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = view.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    view.destroyDrawingCache();
    return new BitmapDrawable(viewBmp);
}

From source file:net.soulwolf.widget.parallaxrefresh.Utils.java

static boolean canChildScrollUp(View view) {
    if (view == null) {
        return false;
    }/*w ww . ja va  2 s.c  o  m*/
    if (Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0
                    || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
        } else {
            return ViewCompat.canScrollVertically(view, -1) || view.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(view, -1);
    }
}

From source file:android.support.ViewUtils.java

public static boolean canScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0
                    || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
        } else {//w  ww  . ja  v a2 s  .c  o  m
            return ViewCompat.canScrollVertically(view, -1) || view.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(view, -1);
    }
}

From source file:com.ranger.xyg.library.tkrefreshlayout.utils.ScrollingUtil.java

public static boolean isViewToTop(View view, int mTouchSlop) {
    if (view instanceof AbsListView)
        return isAbsListViewToTop((AbsListView) view);
    if (view instanceof RecyclerView)
        return isRecyclerViewToTop((RecyclerView) view);
    return (view != null && Math.abs(view.getScrollY()) <= 2 * mTouchSlop);
}

From source file:com.wzdsqyy.commonview.ScrollUtil.java

/**
 * ???/*from  w  w w  . j av a  2 s  .c  o m*/
 */
public static boolean canChildScrollUp(View target) {
    if (target == null) {
        return false;
    }
    if (Build.VERSION.SDK_INT < 14) {
        if (target instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) target;
            return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0
                    || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
        } else {
            return ViewCompat.canScrollVertically(target, -1) || target.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(target, -1);
    }
}

From source file:com.wzdsqyy.commonview.ScrollUtil.java

/**
 * Whether it is possible for the child view of this layout to scroll down. Override this if the child view is a custom view.
 * ??//from   ww w . j a  v  a  2s  .  co  m
 */
public static boolean canChildScrollDown(View target) {
    if (Build.VERSION.SDK_INT < 14) {
        if (target instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) target;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                            || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView
                                    .getPaddingBottom());
        } else {
            return ViewCompat.canScrollVertically(target, 1) || target.getScrollY() < 0;
        }
    } else {
        return ViewCompat.canScrollVertically(target, 1);
    }
}