Java Code Examples for androidx.recyclerview.widget.OrientationHelper#getDecoratedStart()
The following examples show how to use
androidx.recyclerview.widget.OrientationHelper#getDecoratedStart() .
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: CarouselSnapHelper.java From CarouselView with MIT License | 6 votes |
private View findFirstView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) { if (layoutManager == null) return null; int childCount = layoutManager.getChildCount(); if (childCount == 0) return null; int absClosest = Integer.MAX_VALUE; View closestView = null; int start = helper.getStartAfterPadding(); for (int i=0; i < childCount; i++) { View child = layoutManager.getChildAt(i); int childStart = helper.getDecoratedStart(child); int absDistanceToStart = Math.abs(childStart - start); if (absDistanceToStart < absClosest) { absClosest = absDistanceToStart; closestView = child; } } return closestView; }
Example 2
Source File: StartSnapHelper.java From litho with Apache License 2.0 | 6 votes |
/** @return the first View whose start is before the start of this recycler view */ @Nullable private static View findFirstViewBeforeStart( LayoutManager layoutManager, OrientationHelper helper) { int childCount = layoutManager.getChildCount(); if (childCount == 0) { return null; } View closestChild = null; final int start = helper.getStartAfterPadding(); int absClosest = Integer.MAX_VALUE; for (int i = 0; i < childCount; i++) { final View child = layoutManager.getChildAt(i); int childStart = helper.getDecoratedStart(child); int absDistance = Math.abs(childStart - start); if (childStart < start && absDistance < absClosest) { absClosest = absDistance; closestChild = child; } } return closestChild; }
Example 3
Source File: GravityDelegate.java From GetApk with MIT License | 5 votes |
private int distanceToStart(View targetView, OrientationHelper helper, boolean fromEnd) { if (isRtlHorizontal && !fromEnd) { return distanceToEnd(targetView, helper, true); } return helper.getDecoratedStart(targetView) - helper.getStartAfterPadding(); }
Example 4
Source File: StartSnapHelper.java From litho with Apache License 2.0 | 5 votes |
private int distanceToStart( @NonNull RecyclerView.LayoutManager layoutManager, @NonNull View targetView, OrientationHelper helper) { final int childStart = helper.getDecoratedStart(targetView); final int containerStart = helper.getStartAfterPadding(); return childStart - containerStart; }
Example 5
Source File: StartSnapHelper.java From litho with Apache License 2.0 | 5 votes |
/** * Return the child view that is currently closest to the start of this parent. * * @param layoutManager The {@link LayoutManager} associated with the attached {@link * RecyclerView}. * @param helper The relevant {@link OrientationHelper} for the attached {@link RecyclerView}. * @return the child view that is currently closest to the start of this parent. */ @Nullable private static View findViewClosestToStart( LayoutManager layoutManager, OrientationHelper helper) { int childCount = layoutManager.getChildCount(); if (childCount == 0) { return null; } View closestChild = null; final int start = helper.getStartAfterPadding(); int absClosest = Integer.MAX_VALUE; for (int i = 0; i < childCount; i++) { final View child = layoutManager.getChildAt(i); int childStart = helper.getDecoratedStart(child); int absDistance = Math.abs(childStart - start); /** if child start is closer than previous closest, set it as closest * */ if (absDistance < absClosest) { absClosest = absDistance; closestChild = child; } } return closestChild; }
Example 6
Source File: RecyclerViewPositionHelper.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
View findOneVisibleChild(int fromIndex, int toIndex, boolean completelyVisible, boolean acceptPartiallyVisible) { OrientationHelper helper; if (layoutManager.canScrollVertically()) { helper = OrientationHelper.createVerticalHelper(layoutManager); } else { helper = OrientationHelper.createHorizontalHelper(layoutManager); } final int start = helper.getStartAfterPadding(); final int end = helper.getEndAfterPadding(); final int next = toIndex > fromIndex ? 1 : -1; View partiallyVisible = null; for (int i = fromIndex; i != toIndex; i += next) { final View child = layoutManager.getChildAt(i); final int childStart = helper.getDecoratedStart(child); final int childEnd = helper.getDecoratedEnd(child); if (childStart < end && childEnd > start) { if (completelyVisible) { if (childStart >= start && childEnd <= end) { return child; } else if (acceptPartiallyVisible && partiallyVisible == null) { partiallyVisible = child; } } else { return child; } } } return partiallyVisible; }
Example 7
Source File: GravitySnapHelper.java From GravitySnapHelper with Apache License 2.0 | 5 votes |
private int getDistanceToStart(View targetView, @NonNull OrientationHelper helper) { int distance; // If we don't care about padding, just snap to the start of the view if (!snapToPadding) { int childStart = helper.getDecoratedStart(targetView); if (childStart >= helper.getStartAfterPadding() / 2) { distance = childStart - helper.getStartAfterPadding(); } else { distance = childStart; } } else { distance = helper.getDecoratedStart(targetView) - helper.getStartAfterPadding(); } return distance; }
Example 8
Source File: RecyclerViewPositionHelper.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
View findOneVisibleChild(int fromIndex, int toIndex, boolean completelyVisible, boolean acceptPartiallyVisible) { OrientationHelper helper; if (layoutManager.canScrollVertically()) { helper = OrientationHelper.createVerticalHelper(layoutManager); } else { helper = OrientationHelper.createHorizontalHelper(layoutManager); } final int start = helper.getStartAfterPadding(); final int end = helper.getEndAfterPadding(); final int next = toIndex > fromIndex ? 1 : -1; View partiallyVisible = null; for (int i = fromIndex; i != toIndex; i += next) { final View child = layoutManager.getChildAt(i); final int childStart = helper.getDecoratedStart(child); final int childEnd = helper.getDecoratedEnd(child); if (childStart < end && childEnd > start) { if (completelyVisible) { if (childStart >= start && childEnd <= end) { return child; } else if (acceptPartiallyVisible && partiallyVisible == null) { partiallyVisible = child; } } else { return child; } } } return partiallyVisible; }
Example 9
Source File: RecyclerViewPositionHelper.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
private View findOneVisibleChild(int fromIndex, int toIndex, boolean completelyVisible, boolean acceptPartiallyVisible) { OrientationHelper helper; if (layoutManager.canScrollVertically()) { helper = OrientationHelper.createVerticalHelper(layoutManager); } else { helper = OrientationHelper.createHorizontalHelper(layoutManager); } final int start = helper.getStartAfterPadding(); final int end = helper.getEndAfterPadding(); final int next = toIndex > fromIndex ? 1 : -1; View partiallyVisible = null; for (int i = fromIndex; i != toIndex; i += next) { final View child = layoutManager.getChildAt(i); final int childStart = helper.getDecoratedStart(child); final int childEnd = helper.getDecoratedEnd(child); if (childStart < end && childEnd > start) { if (completelyVisible) { if (childStart >= start && childEnd <= end) { return child; } else if (acceptPartiallyVisible && partiallyVisible == null) { partiallyVisible = child; } } else { return child; } } } return partiallyVisible; }
Example 10
Source File: RecyclerViewPositionHelper.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
View findOneVisibleChild(int fromIndex, int toIndex, boolean completelyVisible, boolean acceptPartiallyVisible) { OrientationHelper helper; if (linearLayoutManager.canScrollVertically()) { helper = OrientationHelper.createVerticalHelper(linearLayoutManager); } else { helper = OrientationHelper.createHorizontalHelper(linearLayoutManager); } final int start = helper.getStartAfterPadding(); final int end = helper.getEndAfterPadding(); final int next = toIndex > fromIndex ? 1 : -1; View partiallyVisible = null; for (int i = fromIndex; i != toIndex; i += next) { final View child = linearLayoutManager.getChildAt(i); final int childStart = helper.getDecoratedStart(child); final int childEnd = helper.getDecoratedEnd(child); if (childStart < end && childEnd > start) { if (completelyVisible) { if (childStart >= start && childEnd <= end) { return child; } else if (acceptPartiallyVisible && partiallyVisible == null) { partiallyVisible = child; } } else { return child; } } } return partiallyVisible; }
Example 11
Source File: GravitySnapHelper.java From MaterialDateTimePicker with Apache License 2.0 | 5 votes |
private int distanceToStart(View targetView, OrientationHelper helper, boolean fromEnd) { if (isRtlHorizontal && !fromEnd) { return distanceToEnd(targetView, helper, true); } return helper.getDecoratedStart(targetView) - helper.getStartAfterPadding(); }
Example 12
Source File: GravitySnapHelper.java From MaterialDateTimePicker with Apache License 2.0 | 5 votes |
private View findEndView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) { if (layoutManager instanceof LinearLayoutManager) { int lastChild = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition(); if (lastChild == RecyclerView.NO_POSITION) { return null; } View child = layoutManager.findViewByPosition(lastChild); float visibleWidth; if (isRtlHorizontal) { visibleWidth = (float) helper.getDecoratedEnd(child) / helper.getDecoratedMeasurement(child); } else { visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child)) / helper.getDecoratedMeasurement(child); } // If we're at the start of the list, we shouldn't snap // to avoid having the first item not completely visible. boolean startOfList = ((LinearLayoutManager) layoutManager) .findFirstCompletelyVisibleItemPosition() == 0; if (visibleWidth > 0.5f && !startOfList) { return child; } else if (startOfList) { return null; } else { // If the child wasn't returned, we need to return the previous view return layoutManager.findViewByPosition(lastChild - 1); } } return null; }
Example 13
Source File: CarouselSnapHelper.java From CarouselView with MIT License | 4 votes |
private int distanceStart(View targetView, OrientationHelper helper) { int childStart = helper.getDecoratedStart(targetView); int containerStart = helper.getStartAfterPadding(); return childStart - containerStart; }
Example 14
Source File: GravityDelegate.java From GetApk with MIT License | 4 votes |
/** * Returns the first view that we should snap to. * * @param layoutManager the recyclerview's layout manager * @param helper orientation helper to calculate view sizes * @return the first view in the LayoutManager to snap to */ private View findStartView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) { if (layoutManager instanceof LinearLayoutManager) { int firstChild = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition(); int offset = 1; if (layoutManager instanceof GridLayoutManager) { offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1; } if (firstChild == RecyclerView.NO_POSITION) { return null; } View child = layoutManager.findViewByPosition(firstChild); float visibleWidth; // We should return the child if it's visible width // is greater than 0.5 of it's total width. // In a RTL configuration, we need to check the start point and in LTR the end point if (isRtlHorizontal) { visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child)) / helper.getDecoratedMeasurement(child); } else { visibleWidth = (float) helper.getDecoratedEnd(child) / helper.getDecoratedMeasurement(child); } // If we're at the end of the list, we shouldn't snap // to avoid having the last item not completely visible. boolean endOfList = ((LinearLayoutManager) layoutManager) .findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1; if (visibleWidth > 0.5f && !endOfList) { return child; } else if (snapLastItem && endOfList) { return child; } else if (endOfList) { return null; } else { // If the child wasn't returned, we need to return // the next view close to the start. return layoutManager.findViewByPosition(firstChild + offset); } } return null; }
Example 15
Source File: GravityDelegate.java From GetApk with MIT License | 4 votes |
private View findEndView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) { if (layoutManager instanceof LinearLayoutManager) { int lastChild = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition(); int offset = 1; if (layoutManager instanceof GridLayoutManager) { offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1; } if (lastChild == RecyclerView.NO_POSITION) { return null; } View child = layoutManager.findViewByPosition(lastChild); float visibleWidth; if (isRtlHorizontal) { visibleWidth = (float) helper.getDecoratedEnd(child) / helper.getDecoratedMeasurement(child); } else { visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child)) / helper.getDecoratedMeasurement(child); } // If we're at the start of the list, we shouldn't snap // to avoid having the first item not completely visible. boolean startOfList = ((LinearLayoutManager) layoutManager) .findFirstCompletelyVisibleItemPosition() == 0; if (visibleWidth > 0.5f && !startOfList) { return child; } else if (snapLastItem && startOfList) { return child; } else if (startOfList) { return null; } else { // If the child wasn't returned, we need to return the previous view return layoutManager.findViewByPosition(lastChild - offset); } } return null; }
Example 16
Source File: SnapToStartHelper.java From aptoide-client-v8 with GNU General Public License v3.0 | 4 votes |
private int distanceToStart(View targetView, OrientationHelper helper) { return helper.getDecoratedStart(targetView) - helper.getStartAfterPadding(); }
Example 17
Source File: GravitySnapHelper.java From MaterialDateTimePicker with Apache License 2.0 | 4 votes |
/** * Returns the first view that we should snap to. * * @param layoutManager the recyclerview's layout manager * @param helper orientation helper to calculate view sizes * @return the first view in the LayoutManager to snap to */ private View findStartView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) { if (layoutManager instanceof LinearLayoutManager) { int firstChild = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition(); if (firstChild == RecyclerView.NO_POSITION) { return null; } View child = layoutManager.findViewByPosition(firstChild); float visibleWidth; // We should return the child if it's visible width // is greater than 0.5 of it's total width. // In a RTL configuration, we need to check the start point and in LTR the end point if (isRtlHorizontal) { visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child)) / helper.getDecoratedMeasurement(child); } else { visibleWidth = (float) helper.getDecoratedEnd(child) / helper.getDecoratedMeasurement(child); } // If we're at the end of the list, we shouldn't snap // to avoid having the last item not completely visible. boolean endOfList = ((LinearLayoutManager) layoutManager) .findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1; if (visibleWidth > 0.5f && !endOfList) { return child; } else if (endOfList) { return null; } else { // If the child wasn't returned, we need to return // the next view close to the start. return layoutManager.findViewByPosition(firstChild + 1); } } return null; }