Skip to content

Commit b80d9a5

Browse files
hunterstichleticiarossi
authored andcommitted
[Carousel] Fixed formatted for KeylineState and KeylineStateList
PiperOrigin-RevId: 565711087
1 parent 7151714 commit b80d9a5

File tree

2 files changed

+47
-50
lines changed

2 files changed

+47
-50
lines changed

lib/java/com/google/android/material/carousel/KeylineState.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
* <p>Keylines can be either focal or non-focal. A focal keyline is a keyline where items are
4646
* considered visible or interactable in their fullest form. This usually means where items will be
4747
* fully unmaksed and viewable. There must be at least one focal keyline in a KeylineState. The
48-
* focal keylines are important for usability and alignment. Start-aligned strategies should
49-
* place focal keylines at the beginning of the scroll container, center-aligned strategies at
50-
* the center of the scroll container, etc.
48+
* focal keylines are important for usability and alignment. Start-aligned strategies should place
49+
* focal keylines at the beginning of the scroll container, center-aligned strategies at the center
50+
* of the scroll container, etc.
5151
*/
5252
final class KeylineState {
5353

@@ -126,7 +126,7 @@ Keyline getFirstNonAnchorKeyline() {
126126
/** Returns the last non-anchor keyline. */
127127
@Nullable
128128
Keyline getLastNonAnchorKeyline() {
129-
for (int i = keylines.size()-1; i >= 0; i--) {
129+
for (int i = keylines.size() - 1; i >= 0; i--) {
130130
Keyline keyline = keylines.get(i);
131131
if (!keyline.isAnchor) {
132132
return keyline;
@@ -338,8 +338,7 @@ Builder addKeyline(
338338
}
339339
if (isAnchor) {
340340
if (isFocal) {
341-
throw new IllegalArgumentException(
342-
"Anchor keylines cannot be focal.");
341+
throw new IllegalArgumentException("Anchor keylines cannot be focal.");
343342
}
344343
if (latestAnchorKeylineIndex != NO_INDEX && latestAnchorKeylineIndex != 0) {
345344
throw new IllegalArgumentException(
@@ -421,8 +420,8 @@ Builder addKeyline(
421420
// Calculate if the item will be cut off on either side. Currently we do not support an item
422421
// cut off on both sides as we do not not support that use case. If an item is cut off on both
423422
// sides, only the end cutoff will be included in the cutoff.
424-
float keylineStart = offsetLoc - maskedItemSize/2F;
425-
float keylineEnd = offsetLoc + maskedItemSize/2F;
423+
float keylineStart = offsetLoc - maskedItemSize / 2F;
424+
float keylineEnd = offsetLoc + maskedItemSize / 2F;
426425
if (keylineEnd > availableSpace) {
427426
cutoff = Math.abs(keylineEnd - max(keylineEnd - maskedItemSize, availableSpace));
428427
} else if (keylineStart < 0) {
@@ -436,9 +435,9 @@ Builder addKeyline(
436435
* Adds an anchor keyline along the scrolling axis where an object should be masked by the given
437436
* {@code mask} and positioned at {@code offsetLoc}.
438437
*
439-
* <p>Anchor keylines are keylines that are added to increase motion of carousel items going
440-
* out of bounds of the carousel, and are 'anchored' (ie. does not shift). These keylines must
441-
* be at the start or end of all keylines.
438+
* <p>Anchor keylines are keylines that are added to increase motion of carousel items going out
439+
* of bounds of the carousel, and are 'anchored' (ie. does not shift). These keylines must be at
440+
* the start or end of all keylines.
442441
*
443442
* <p>Note that calls to {@link #addKeyline(float, float, float, boolean)} and {@link
444443
* #addKeylineRange(float, float, float, int)} are added in order. This method should be called

lib/java/com/google/android/material/carousel/KeylineStateList.java

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public KeylineState getShiftedState(
144144
* been shifted exactly according to the scroll offset.
145145
* @return a {@link KeylineState} that has been shifted according on the scroll offset.
146146
*/
147-
KeylineState getShiftedState(
147+
KeylineState getShiftedState(
148148
float scrollOffset,
149149
float minScrollOffset,
150150
float maxScrollOffset,
@@ -154,34 +154,34 @@ KeylineState getShiftedState(
154154
List<KeylineState> steps;
155155
float[] interpolationPoints;
156156
float interpolation;
157-
if (scrollOffset < startShiftOffset) {
158-
interpolation =
159-
AnimationUtils.lerp(
160-
/* outputMin= */ 1F,
161-
/* outputMax= */ 0F,
162-
/* inputMin: */ minScrollOffset,
163-
/* inputMax= */ startShiftOffset,
164-
/* value= */ scrollOffset);
165-
steps = startStateSteps;
166-
interpolationPoints = startStateStepsInterpolationPoints;
167-
} else if (scrollOffset > endShiftOffset) {
168-
interpolation =
169-
AnimationUtils.lerp(
170-
/* outputMin= */ 0F,
171-
/* outputMax= */ 1F,
172-
/* inputMin= */ endShiftOffset,
173-
/* inputMax= */ maxScrollOffset,
174-
/* value= */ scrollOffset);
175-
steps = endStateSteps;
176-
interpolationPoints = endStateStepsInterpolationPoints;
177-
} else {
178-
return defaultState;
179-
}
180-
181-
if (roundToNearestStep) {
182-
return closestStateStepFromInterpolation(steps, interpolation, interpolationPoints);
183-
}
184-
return lerp(steps, interpolation, interpolationPoints);
157+
if (scrollOffset < startShiftOffset) {
158+
interpolation =
159+
AnimationUtils.lerp(
160+
/* outputMin= */ 1F,
161+
/* outputMax= */ 0F,
162+
/* inputMin: */ minScrollOffset,
163+
/* inputMax= */ startShiftOffset,
164+
/* value= */ scrollOffset);
165+
steps = startStateSteps;
166+
interpolationPoints = startStateStepsInterpolationPoints;
167+
} else if (scrollOffset > endShiftOffset) {
168+
interpolation =
169+
AnimationUtils.lerp(
170+
/* outputMin= */ 0F,
171+
/* outputMax= */ 1F,
172+
/* inputMin= */ endShiftOffset,
173+
/* inputMax= */ maxScrollOffset,
174+
/* value= */ scrollOffset);
175+
steps = endStateSteps;
176+
interpolationPoints = endStateStepsInterpolationPoints;
177+
} else {
178+
return defaultState;
179+
}
180+
181+
if (roundToNearestStep) {
182+
return closestStateStepFromInterpolation(steps, interpolation, interpolationPoints);
183+
}
184+
return lerp(steps, interpolation, interpolationPoints);
185185
}
186186

187187
/**
@@ -213,12 +213,12 @@ private static KeylineState lerp(
213213
* @param stateSteps The steps in which to determine the 2 state steps we are in between.
214214
* @param interpolation The interpolation of the state steps we are at.
215215
* @param stateStepsInterpolationPoints The state step interpolation points; each interpolation
216-
* point corresponds to at which interpolation we are at the corresponding state step.
216+
* point corresponds to at which interpolation we are at the corresponding state step.
217217
* @return an array of the form [progress, fromIndex, toIndex] where progress represents the
218-
* progress in between the state steps at fromIndex and toIndex.
218+
* progress in between the state steps at fromIndex and toIndex.
219219
*/
220-
private static float[] getStateStepsRange(List<KeylineState> stateSteps,
221-
float interpolation, float[] stateStepsInterpolationPoints) {
220+
private static float[] getStateStepsRange(
221+
List<KeylineState> stateSteps, float interpolation, float[] stateStepsInterpolationPoints) {
222222
int numberOfSteps = stateSteps.size();
223223
// Find the step that contains `interpolation` and remap the the surrounding interpolation
224224
// points lower and upper bounds to its own 0-1 value.
@@ -365,8 +365,7 @@ private static List<KeylineState> getStateStepsStart(
365365
// If the first focal item is already at the left of the container or there are no in bounds
366366
// keylines, return a list of steps that only includes the default state (there is nowhere to
367367
// shift).
368-
if (isFirstFocalItemAtLeftOfContainer(defaultState)
369-
|| firstNonAnchorKeylineIndex == NO_INDEX) {
368+
if (isFirstFocalItemAtLeftOfContainer(defaultState) || firstNonAnchorKeylineIndex == NO_INDEX) {
370369
return steps;
371370
}
372371

@@ -438,8 +437,7 @@ private static List<KeylineState> getStateStepsStart(
438437
* last state will be the right state or the state that has the focal range at the right of the
439438
* carousel.
440439
*/
441-
private static List<KeylineState> getStateStepsEnd(
442-
Carousel carousel, KeylineState defaultState) {
440+
private static List<KeylineState> getStateStepsEnd(Carousel carousel, KeylineState defaultState) {
443441
List<KeylineState> steps = new ArrayList<>();
444442
steps.add(defaultState);
445443
int lastNonAnchorKeylineIndex = findLastNonAnchorKeylineIndex(defaultState);
@@ -643,9 +641,9 @@ Map<Integer, KeylineState> getKeylineStateForPositionMap(
643641
keylineStates.put(
644642
position,
645643
startStateSteps.get(MathUtils.clamp(startStepsIndex, 0, startStateSteps.size() - 1)));
646-
startStepsIndex++;
647-
}
644+
startStepsIndex++;
648645
}
646+
}
649647
return keylineStates;
650648
}
651649
}

0 commit comments

Comments
 (0)