@Test public void test_get_view_list_with_time_offsets_returns_correct_number_of_children() { ViewGroup mockParent = Mockito.mock(ViewGroup.class); List<View> mockChildren = new ArrayList<>(); for (int i = 0; i < 3; i++) { mockChildren.add(Mockito.mock(View.class)); } List<SpruceTimedView> resultViews = new DistancedSort(0, false).getViewListWithTimeOffsets(mockParent, mockChildren); Assert.assertEquals(mockChildren.size(), resultViews.size()); }
@Override public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) { final PointF comparisonPoint = getDistancePoint(parent, children); double lastDistance = getDistanceBetweenPoints(Utils.viewToPoint(children.get(0)), comparisonPoint); long currentTimeOffset = 0L; List<SpruceTimedView> childViews = new ArrayList<>(); for (View childView : children) { if (lastDistance != getDistanceBetweenPoints(Utils.viewToPoint(childView), comparisonPoint)) { lastDistance = getDistanceBetweenPoints(Utils.viewToPoint(childView), comparisonPoint); currentTimeOffset += interObjectDelay; } childViews.add(new SpruceTimedView(childView, currentTimeOffset)); } return childViews; }
DistancedSort extends SortFunction { @Override public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) { final PointF comparisonPoint = getDistancePoint(parent, children); double lastDistance = getDistanceBetweenPoints(Utils.viewToPoint(children.get(0)), comparisonPoint); long currentTimeOffset = 0L; List<SpruceTimedView> childViews = new ArrayList<>(); for (View childView : children) { if (lastDistance != getDistanceBetweenPoints(Utils.viewToPoint(childView), comparisonPoint)) { lastDistance = getDistanceBetweenPoints(Utils.viewToPoint(childView), comparisonPoint); currentTimeOffset += interObjectDelay; } childViews.add(new SpruceTimedView(childView, currentTimeOffset)); } return childViews; } }
DistancedSort extends SortFunction { @Override public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) { final PointF comparisonPoint = getDistancePoint(parent, children); double lastDistance = getDistanceBetweenPoints(Utils.viewToPoint(children.get(0)), comparisonPoint); long currentTimeOffset = 0L; List<SpruceTimedView> childViews = new ArrayList<>(); for (View childView : children) { if (lastDistance != getDistanceBetweenPoints(Utils.viewToPoint(childView), comparisonPoint)) { lastDistance = getDistanceBetweenPoints(Utils.viewToPoint(childView), comparisonPoint); currentTimeOffset += interObjectDelay; } childViews.add(new SpruceTimedView(childView, currentTimeOffset)); } return childViews; } DistancedSort(long interObjectDelay, boolean reversed); }
DistancedSort extends SortFunction { @Override public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) { final PointF comparisonPoint = getDistancePoint(parent, children); double lastDistance = getDistanceBetweenPoints(Utils.viewToPoint(children.get(0)), comparisonPoint); long currentTimeOffset = 0L; List<SpruceTimedView> childViews = new ArrayList<>(); for (View childView : children) { if (lastDistance != getDistanceBetweenPoints(Utils.viewToPoint(childView), comparisonPoint)) { lastDistance = getDistanceBetweenPoints(Utils.viewToPoint(childView), comparisonPoint); currentTimeOffset += interObjectDelay; } childViews.add(new SpruceTimedView(childView, currentTimeOffset)); } return childViews; } DistancedSort(long interObjectDelay, boolean reversed); @Override List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children); @Override void sortChildren(ViewGroup parent, List<View> children); PointF getDistancePoint(ViewGroup parent, List<View> children); double getDistanceBetweenPoints(PointF left, PointF right); }
DistancedSort extends SortFunction { @Override public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) { final PointF comparisonPoint = getDistancePoint(parent, children); double lastDistance = getDistanceBetweenPoints(Utils.viewToPoint(children.get(0)), comparisonPoint); long currentTimeOffset = 0L; List<SpruceTimedView> childViews = new ArrayList<>(); for (View childView : children) { if (lastDistance != getDistanceBetweenPoints(Utils.viewToPoint(childView), comparisonPoint)) { lastDistance = getDistanceBetweenPoints(Utils.viewToPoint(childView), comparisonPoint); currentTimeOffset += interObjectDelay; } childViews.add(new SpruceTimedView(childView, currentTimeOffset)); } return childViews; } DistancedSort(long interObjectDelay, boolean reversed); @Override List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children); @Override void sortChildren(ViewGroup parent, List<View> children); PointF getDistancePoint(ViewGroup parent, List<View> children); double getDistanceBetweenPoints(PointF left, PointF right);  }