static float getScrollX(View view) { return view.getScrollX(); }
public int getScrollX() { View view = mView.get(); if (view == null) { return 0; } return view.getScrollX(); } public void setScrollX(int value) {
private void captureValues(TransitionValues transitionValues) { transitionValues.values.put(PROPNAME_SCROLL_X, transitionValues.view.getScrollX()); transitionValues.values.put(PROPNAME_SCROLL_Y, transitionValues.view.getScrollY()); }
public void setScrollY(int value) { View view = mView.get(); if (view != null) { view.scrollTo(view.getScrollX(), value); } }
public static boolean isTransformedTouchPointInView(@NonNull View group,@NonNull View child, float x, float y,PointF outLocalPoint) { if (child.getVisibility() != View.VISIBLE) { return false; } final float[] point = new float[2]; point[0] = x; point[1] = y; // transformPointToViewLocal(group, child, point); point[0] += group.getScrollX() - child.getLeft(); point[1] += group.getScrollY() - child.getTop(); // final boolean isInView = pointInView(child, point[0], point[1], 0); final boolean isInView = point[0] >= 0 && point[1] >= 0 && point[0] < (child.getWidth()) && point[1] < ((child.getHeight())); if (isInView && outLocalPoint != null) { outLocalPoint.set(point[0]-x, point[1]-y); } return isInView; }
public static boolean isTransformedTouchPointInView(@NonNull View group,@NonNull View child, float x, float y,PointF outLocalPoint) { if (child.getVisibility() != View.VISIBLE) { return false; } final float[] point = new float[2]; point[0] = x; point[1] = y; // transformPointToViewLocal(group, child, point); point[0] += group.getScrollX() - child.getLeft(); point[1] += group.getScrollY() - child.getTop(); // final boolean isInView = pointInView(child, point[0], point[1], 0); final boolean isInView = point[0] >= 0 && point[1] >= 0 && point[0] < (child.getWidth()) && point[1] < ((child.getHeight())); if (isInView && outLocalPoint != null) { outLocalPoint.set(point[0]-x, point[1]-y); } return isInView; }
private void transformPointToViewLocal(int[] point, View child) { ViewParent viewParent = child.getParent(); while (viewParent instanceof View) { View view = (View) viewParent; point[0] += view.getScrollX() - child.getLeft(); point[1] += view.getScrollY() - child.getTop(); if (view instanceof DrawerLayout) { break; } child = view; viewParent = child.getParent(); } }
private static JSONObject getDimensionOfView(View view) { JSONObject dimension = new JSONObject(); try { dimension.put(DIMENSION_TOP_KEY, view.getTop()); dimension.put(DIMENSION_LEFT_KEY, view.getLeft()); dimension.put(DIMENSION_WIDTH_KEY, view.getWidth()); dimension.put(DIMENSION_HEIGHT_KEY, view.getHeight()); dimension.put(DIMENSION_SCROLL_X_KEY, view.getScrollX()); dimension.put(DIMENSION_SCROLL_Y_KEY, view.getScrollY()); dimension.put(DIMENSION_VISIBILITY_KEY, view.getVisibility()); } catch (JSONException e) { Log.e(TAG, "Failed to create JSONObject for dimension.", e); } return dimension; }
private static void getLocation(View target, int[] position) { position[0] += target.getLeft(); position[1] += target.getTop(); ViewParent viewParent = target.getParent(); while (viewParent instanceof View) { final View view = (View) viewParent; if (view.getId() == android.R.id.content) return; position[0] -= view.getScrollX(); position[1] -= view.getScrollY(); position[0] += view.getLeft(); position[1] += view.getTop(); viewParent = view.getParent(); } position[0] = (int) (position[0] + 0.5f); position[1] = (int) (position[1] + 0.5f); }
/** * Create bitmap from specified View with specified with * * @param view source for bitmap * @param parentWidth result bitmap width * @return bitmap from specified view */ protected Bitmap measureViewAndGetBitmap(View view, int parentWidth) { int specW = View.MeasureSpec.makeMeasureSpec(parentWidth, View.MeasureSpec.EXACTLY); int specH = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); view.measure(specW, specH); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); Bitmap b = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); c.translate(-view.getScrollX(), -view.getScrollY()); view.draw(c); return b; }
private static void getLocation(View target, int[] position) { position[0] += target.getLeft(); position[1] += target.getTop(); ViewParent viewParent = target.getParent(); while (viewParent instanceof View) { final View view = (View) viewParent; if (view.getId() == android.R.id.content) return; position[0] -= view.getScrollX(); position[1] -= view.getScrollY(); position[0] += view.getLeft(); position[1] += view.getTop(); viewParent = view.getParent(); } position[0] = (int) (position[0] + 0.5f); position[1] = (int) (position[1] + 0.5f); }
private boolean canScrollUp(View view, float x, float y) { if (view instanceof ViewGroup) { ViewGroup vg = (ViewGroup) view; for (int i = 0; i < vg.getChildCount(); i++) { View child = vg.getChildAt(i); int childLeft = child.getLeft() - view.getScrollX(); int childTop = child.getTop() - view.getScrollY(); int childRight = child.getRight() - view.getScrollX(); int childBottom = child.getBottom() - view.getScrollY(); boolean intersects = x > childLeft && x < childRight && y > childTop && y < childBottom; if (intersects && canScrollUp(child, x - childLeft, y - childTop)) { return true; } } } return view.canScrollVertically(-1); }
public S hasScrollX(int scroll) { isNotNull(); int actualScroll = actual.getScrollX(); assertThat(actualScroll) // .overridingErrorMessage("Expected x scroll <%s> but was <%s>", scroll, actualScroll) // .isEqualTo(scroll); return myself; }
/** * Tests scrollability within child views of v given a delta of dx. * * @param v View to test for horizontal scrollability * @param checkV Whether the view v passed should itself be checked for scrollability (true), * or just its children (false). * @param dx Delta scrolled in pixels * @param x X coordinate of the active touch point * @param y Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. */ protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { if (v instanceof ViewGroup) { final ViewGroup group = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int count = group.getChildCount(); // Count backwards - let topmost views consume scroll distance first. for (int i = count - 1; i >= 0; i--) { final View child = group.getChildAt(i); if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && ViewCompat.canScrollHorizontally(v, -dx); }
if (v instanceof ViewGroup) { final ViewGroup group = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int count = group.getChildCount();
private static void transformMatrixToPager(Matrix matrix, View view, ViewPager pager) { if (view.getParent() instanceof View) { View parent = (View) view.getParent(); if (parent != pager) { transformMatrixToPager(matrix, parent, pager); } matrix.preTranslate(-parent.getScrollX(), -parent.getScrollY()); } matrix.preTranslate(view.getLeft(), view.getTop()); matrix.preConcat(view.getMatrix()); }
@Test public void shouldGetScrollXAndY() { assertEquals(0, view.getScrollX()); assertEquals(0, view.getScrollY()); }
@Test public void setScrolls_canBeAskedFor() throws Exception { view.setScrollX(234); view.setScrollY(544); assertThat(view.getScrollX()).isEqualTo(234); assertThat(view.getScrollY()).isEqualTo(544); }
@Test public void scrollBy_shouldStoreTheScrolledCoordinates() throws Exception { view.scrollTo(4, 5); view.scrollBy(10, 20); assertThat(shadowOf(view).scrollToCoordinates).isEqualTo(new Point(14, 25)); assertThat(view.getScrollX()).isEqualTo(14); assertThat(view.getScrollY()).isEqualTo(25); }
@Test public void shouldScrollTo() throws Exception { view.scrollTo(7, 6); assertEquals(7, view.getScrollX()); assertEquals(6, view.getScrollY()); }