@Test public void test_negative_inter_object_delay() { List<SpruceTimedView> resultViews = new ContinuousWeightedSort(-1, false, RadialSort.Position.TOP_LEFT, ContinuousWeightedSort.MEDIUM_WEIGHT, ContinuousWeightedSort.MEDIUM_WEIGHT) .getViewListWithTimeOffsets(mockParent, mockChildren); Assert.assertEquals(0, resultViews.get(0).getTimeOffset()); Assert.assertEquals(-1, resultViews.get(1).getTimeOffset()); Assert.assertEquals(-2, resultViews.get(2).getTimeOffset()); }
@Override public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) { final PointF comparisonPoint = getDistancePoint(parent, children); Collections.sort(children, new Comparator<View>() { @Override public int compare(View v1, View v2) { double leftHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v1)) * horizontalWeight; double rightHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v2)) * horizontalWeight; double leftVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v1)) * verticalWeight; double rightVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v2)) * verticalWeight; maxHorizontalDistance = calculateMaxDistance(leftHorizontalDistance, rightHorizontalDistance, maxHorizontalDistance); maxVerticalDistance = calculateMaxDistance(leftVerticalDistance, rightVerticalDistance, maxVerticalDistance); return 0; } }); List<SpruceTimedView> timedViews = new ArrayList<>(); long maxTimeOffset = 1; for (View view : children) { double viewHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(view)) * horizontalWeight; double viewVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(view)) * verticalWeight; double normalizedHorizontalDistance = viewHorizontalDistance / maxHorizontalDistance; double normalizedVerticalDistance = viewVerticalDistance / maxVerticalDistance; long offset = Math.round(duration * (normalizedHorizontalDistance * horizontalWeight + normalizedVerticalDistance * verticalWeight)); if (offset > maxTimeOffset) { maxTimeOffset = offset; } if (reversed) { offset = duration - (offset / 2); } timedViews.add(new SpruceTimedView(view, offset)); } return timedViews; }
ContinuousWeightedSort extends ContinuousSort { @Override public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) { final PointF comparisonPoint = getDistancePoint(parent, children); Collections.sort(children, new Comparator<View>() { @Override public int compare(View v1, View v2) { double leftHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v1)) * horizontalWeight; double rightHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v2)) * horizontalWeight; double leftVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v1)) * verticalWeight; double rightVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v2)) * verticalWeight; maxHorizontalDistance = calculateMaxDistance(leftHorizontalDistance, rightHorizontalDistance, maxHorizontalDistance); maxVerticalDistance = calculateMaxDistance(leftVerticalDistance, rightVerticalDistance, maxVerticalDistance); return 0; } }); List<SpruceTimedView> timedViews = new ArrayList<>(); long maxTimeOffset = 1; for (View view : children) { double viewHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(view)) * horizontalWeight; double viewVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(view)) * verticalWeight; double normalizedHorizontalDistance = viewHorizontalDistance / maxHorizontalDistance; double normalizedVerticalDistance = viewVerticalDistance / maxVerticalDistance; long offset = Math.round(duration * (normalizedHorizontalDistance * horizontalWeight + normalizedVerticalDistance * verticalWeight)); if (offset > maxTimeOffset) { maxTimeOffset = offset; } if (reversed) { offset = duration - (offset / 2); } timedViews.add(new SpruceTimedView(view, offset)); } return timedViews; } }
ContinuousWeightedSort extends ContinuousSort { @Override public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) { final PointF comparisonPoint = getDistancePoint(parent, children); Collections.sort(children, new Comparator<View>() { @Override public int compare(View v1, View v2) { double leftHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v1)) * horizontalWeight; double rightHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v2)) * horizontalWeight; double leftVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v1)) * verticalWeight; double rightVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v2)) * verticalWeight; maxHorizontalDistance = calculateMaxDistance(leftHorizontalDistance, rightHorizontalDistance, maxHorizontalDistance); maxVerticalDistance = calculateMaxDistance(leftVerticalDistance, rightVerticalDistance, maxVerticalDistance); return 0; } }); List<SpruceTimedView> timedViews = new ArrayList<>(); long maxTimeOffset = 1; for (View view : children) { double viewHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(view)) * horizontalWeight; double viewVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(view)) * verticalWeight; double normalizedHorizontalDistance = viewHorizontalDistance / maxHorizontalDistance; double normalizedVerticalDistance = viewVerticalDistance / maxVerticalDistance; long offset = Math.round(duration * (normalizedHorizontalDistance * horizontalWeight + normalizedVerticalDistance * verticalWeight)); if (offset > maxTimeOffset) { maxTimeOffset = offset; } if (reversed) { offset = duration - (offset / 2); } timedViews.add(new SpruceTimedView(view, offset)); } return timedViews; } ContinuousWeightedSort(long interObjectDelay, boolean reversed, Position position,
                                  @FloatRange(from = 0.0) double horizontalWeight,
                                  @FloatRange(from = 0.0) double verticalWeight); }
ContinuousWeightedSort extends ContinuousSort { @Override public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) { final PointF comparisonPoint = getDistancePoint(parent, children); Collections.sort(children, new Comparator<View>() { @Override public int compare(View v1, View v2) { double leftHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v1)) * horizontalWeight; double rightHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v2)) * horizontalWeight; double leftVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v1)) * verticalWeight; double rightVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v2)) * verticalWeight; maxHorizontalDistance = calculateMaxDistance(leftHorizontalDistance, rightHorizontalDistance, maxHorizontalDistance); maxVerticalDistance = calculateMaxDistance(leftVerticalDistance, rightVerticalDistance, maxVerticalDistance); return 0; } }); List<SpruceTimedView> timedViews = new ArrayList<>(); long maxTimeOffset = 1; for (View view : children) { double viewHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(view)) * horizontalWeight; double viewVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(view)) * verticalWeight; double normalizedHorizontalDistance = viewHorizontalDistance / maxHorizontalDistance; double normalizedVerticalDistance = viewVerticalDistance / maxVerticalDistance; long offset = Math.round(duration * (normalizedHorizontalDistance * horizontalWeight + normalizedVerticalDistance * verticalWeight)); if (offset > maxTimeOffset) { maxTimeOffset = offset; } if (reversed) { offset = duration - (offset / 2); } timedViews.add(new SpruceTimedView(view, offset)); } return timedViews; } ContinuousWeightedSort(long interObjectDelay, boolean reversed, Position position,
                                  @FloatRange(from = 0.0) double horizontalWeight,
                                  @FloatRange(from = 0.0) double verticalWeight); @Override List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children); @Override void sortChildren(ViewGroup parent, List<View> children); }
ContinuousWeightedSort extends ContinuousSort { @Override public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) { final PointF comparisonPoint = getDistancePoint(parent, children); Collections.sort(children, new Comparator<View>() { @Override public int compare(View v1, View v2) { double leftHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v1)) * horizontalWeight; double rightHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v2)) * horizontalWeight; double leftVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v1)) * verticalWeight; double rightVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v2)) * verticalWeight; maxHorizontalDistance = calculateMaxDistance(leftHorizontalDistance, rightHorizontalDistance, maxHorizontalDistance); maxVerticalDistance = calculateMaxDistance(leftVerticalDistance, rightVerticalDistance, maxVerticalDistance); return 0; } }); List<SpruceTimedView> timedViews = new ArrayList<>(); long maxTimeOffset = 1; for (View view : children) { double viewHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(view)) * horizontalWeight; double viewVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(view)) * verticalWeight; double normalizedHorizontalDistance = viewHorizontalDistance / maxHorizontalDistance; double normalizedVerticalDistance = viewVerticalDistance / maxVerticalDistance; long offset = Math.round(duration * (normalizedHorizontalDistance * horizontalWeight + normalizedVerticalDistance * verticalWeight)); if (offset > maxTimeOffset) { maxTimeOffset = offset; } if (reversed) { offset = duration - (offset / 2); } timedViews.add(new SpruceTimedView(view, offset)); } return timedViews; } ContinuousWeightedSort(long interObjectDelay, boolean reversed, Position position,
                                  @FloatRange(from = 0.0) double horizontalWeight,
                                  @FloatRange(from = 0.0) double verticalWeight); @Override List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children); @Override void sortChildren(ViewGroup parent, List<View> children); static final double LIGHT_WEIGHT; static final double MEDIUM_WEIGHT; static final double HEAVY_WEIGHT; }