@@ -43,7 +43,7 @@ public void testCenterArrangement_shouldShiftStart() {
43
43
new float [] {20F , 60F , 90F , 110F , 125F , 135F }
44
44
};
45
45
KeylineState state =
46
- new KeylineState .Builder (40F )
46
+ new KeylineState .Builder (40F , 140 )
47
47
.addKeyline (5F , getKeylineMaskPercentage (10F , 40F ), 10F )
48
48
.addKeyline (20F , getKeylineMaskPercentage (20F , 40F ), 20F )
49
49
.addKeylineRange (50F , 0F , 40F , 2 , true )
@@ -72,7 +72,7 @@ public void testCenterArrangement_shouldCreateIntermediaryStates() {
72
72
new float [] {20F , 60F , 90F , 110F , 125F , 135F }
73
73
};
74
74
KeylineState state =
75
- new KeylineState .Builder (40F )
75
+ new KeylineState .Builder (40F , 140 )
76
76
.addKeyline (5F , getKeylineMaskPercentage (10F , 40F ), 10F )
77
77
.addKeyline (20F , getKeylineMaskPercentage (20F , 40F ), 20F )
78
78
.addKeylineRange (50F , 0F , 40F , 2 , true )
@@ -103,7 +103,7 @@ public void testCenterArrangement_shouldShiftEnd() {
103
103
};
104
104
105
105
KeylineState state =
106
- new KeylineState .Builder (40F )
106
+ new KeylineState .Builder (40F , 140 )
107
107
.addKeyline (5F , getKeylineMaskPercentage (10F , 40F ), 10F )
108
108
.addKeyline (20F , getKeylineMaskPercentage (20F , 40F ), 20F )
109
109
.addKeylineRange (50F , 0F , 40F , 2 , true )
@@ -126,7 +126,7 @@ public void testCenterArrangement_shouldShiftEnd() {
126
126
@ Test
127
127
public void testCenterArrangement_shouldNotShift () {
128
128
KeylineState state =
129
- new KeylineState .Builder (40F )
129
+ new KeylineState .Builder (40F , 140 )
130
130
.addKeyline (5F , getKeylineMaskPercentage (10F , 40F ), 10F )
131
131
.addKeyline (20F , getKeylineMaskPercentage (20F , 40F ), 20F )
132
132
.addKeylineRange (50F , 0F , 40F , 2 , true )
@@ -144,7 +144,7 @@ public void testCenterArrangement_shouldNotShift() {
144
144
@ Test
145
145
public void testStartArrangement_shouldShiftStart () {
146
146
KeylineState state =
147
- new KeylineState .Builder (40F )
147
+ new KeylineState .Builder (40F , 70 )
148
148
.addKeyline (20F , 0F , 40F , true )
149
149
.addKeyline (50F , getKeylineMaskPercentage (20F , 40F ), 20F )
150
150
.addKeyline (65F , getKeylineMaskPercentage (10F , 40F ), 10F )
@@ -169,7 +169,7 @@ public void testStartArrangement_shouldShiftEnd() {
169
169
};
170
170
171
171
KeylineState state =
172
- new KeylineState .Builder (40F )
172
+ new KeylineState .Builder (40F , 70 )
173
173
.addKeyline (20F , 0F , 40F , true )
174
174
.addKeyline (50F , getKeylineMaskPercentage (20F , 40F ), 20F )
175
175
.addKeyline (65F , getKeylineMaskPercentage (10F , 40F ), 10F )
@@ -191,16 +191,17 @@ public void testStartArrangement_shouldShiftEnd() {
191
191
public void testStartArrangementWithOutOfBoundsKeylines_shouldShiftStart () {
192
192
float [][] startStepsLocOffsets =
193
193
new float [][] {
194
- new float [] {-10F , 10F , 40F , 70F , 85F },
195
- new float [] {-10F , 20F , 50F , 70F , 85F }
194
+ new float [] {-10F , 10F , 40F , 70F , 90F },
195
+ new float [] {-10F , 20F , 50F , 70F , 90F }
196
196
};
197
197
198
198
KeylineState state =
199
- new KeylineState .Builder (40F )
200
- .addKeylineRange (-10F , getKeylineMaskPercentage (20F , 40F ), 20F , 2 )
199
+ new KeylineState .Builder (40F , 90 )
200
+ .addAnchorKeyline (-10F , getKeylineMaskPercentage (20F , 40F ), 20F )
201
+ .addKeyline (10F , getKeylineMaskPercentage (20F , 40F ), 20F , false )
201
202
.addKeyline (40F , 0F , 40F , true )
202
203
.addKeyline (70F , getKeylineMaskPercentage (20F , 40F ), 20F )
203
- .addKeyline (85F , getKeylineMaskPercentage (10F , 40F ), 10F )
204
+ .addKeyline (90F , getKeylineMaskPercentage (20F , 40F ), 20F )
204
205
.build ();
205
206
KeylineStateList stateList = KeylineStateList .from (createCarouselWithWidth (90 ), state );
206
207
@@ -220,17 +221,21 @@ public void testStartArrangementWithOutOfBoundsKeylines_shouldShiftStart() {
220
221
public void testStartArrangementWithOutOfBoundsKeyline_shouldShiftEnd () {
221
222
float [][] endStepsLocOffsets =
222
223
new float [][] {
223
- new float [] {-10F , 10F , 40F , 70F , 90F , 110F , 125F },
224
- new float [] {-10F , 10F , 30F , 60F , 90F , 110F , 125F },
225
- new float [] {-10F , 10F , 30F , 50F , 80F , 110F , 125F },
224
+ // keyline sizes are as follows: {20, 20, 20, 20, 40, 20, 20}
225
+ new float [] {-50F , -30F , -10F , 10F , 40F , 70F , 90F },
226
+ // keyline sizes are as follows: {20, 20, 20, 20, 20, 40, 20}
227
+ new float [] {-50F , -30F , -10F , 10F , 30F , 60F , 90F },
228
+ // keyline sizes are as follows: {20, 20, 20, 20, 20, 20, 40}
229
+ new float [] {-50F , -30F , -10F , 10F , 30F , 50F , 80F },
226
230
};
227
231
228
232
KeylineState state =
229
- new KeylineState .Builder (40F )
230
- .addKeylineRange (-10F , getKeylineMaskPercentage (20F , 40F ), 20F , 2 )
233
+ new KeylineState .Builder (40F , 100F )
234
+ .addAnchorKeyline (-10F , getKeylineMaskPercentage (20F , 40F ), 20F )
235
+ .addKeyline (10F , getKeylineMaskPercentage (20F , 40F ), 20F , false )
231
236
.addKeyline (40F , 0F , 40F , true )
232
237
.addKeylineRange (70F , getKeylineMaskPercentage (20F , 40F ), 20F , 3 )
233
- .addKeyline (125F , getKeylineMaskPercentage (10F , 40F ), 10F )
238
+ .addKeyline (130F , getKeylineMaskPercentage (20F , 40F ), 20F )
234
239
.build ();
235
240
KeylineStateList stateList = KeylineStateList .from (createCarouselWithWidth (100 ), state );
236
241
@@ -239,7 +244,8 @@ public void testStartArrangementWithOutOfBoundsKeyline_shouldShiftEnd() {
239
244
float maxScroll = 5 * 40F ;
240
245
241
246
for (int j = 0 ; j < scrollSteps .length ; j ++) {
242
- KeylineState s = stateList .getShiftedState (maxScroll - scrollSteps [j ], minScroll , maxScroll );
247
+ KeylineState s =
248
+ stateList .getShiftedState (maxScroll - scrollSteps [j ], minScroll , maxScroll , true );
243
249
for (int i = 0 ; i < s .getKeylines ().size (); i ++) {
244
250
assertThat (s .getKeylines ().get (i ).locOffset ).isEqualTo (endStepsLocOffsets [j ][i ]);
245
251
}
@@ -255,7 +261,7 @@ public void testEndArrangement_shouldShiftStart() {
255
261
new float [] {20F , 50F , 65F }
256
262
};
257
263
KeylineState state =
258
- new KeylineState .Builder (40F )
264
+ new KeylineState .Builder (40F , 70 )
259
265
.addKeyline (5F , getKeylineMaskPercentage (10F , 40F ), 10F )
260
266
.addKeyline (20F , getKeylineMaskPercentage (20F , 40F ), 20F )
261
267
.addKeyline (50F , 0F , 40F , true )
@@ -276,7 +282,7 @@ public void testEndArrangement_shouldShiftStart() {
276
282
@ Test
277
283
public void testEndArrangement_shouldNotShiftEnd () {
278
284
KeylineState state =
279
- new KeylineState .Builder (40F )
285
+ new KeylineState .Builder (40F , 70 )
280
286
.addKeyline (5F , getKeylineMaskPercentage (10F , 40F ), 10F )
281
287
.addKeyline (20F , getKeylineMaskPercentage (20F , 40F ), 20F )
282
288
.addKeyline (50F , 0F , 40F , true )
@@ -290,14 +296,14 @@ public void testEndArrangement_shouldNotShiftEnd() {
290
296
}
291
297
292
298
@ Test
293
- public void testFullScreenArrangementWithOutOfBoundsKeylines_nothingShifts () {
299
+ public void testFullScreenArrangementWithAnchorKeylines_nothingShifts () {
294
300
float [] locOffsets = new float [] {-5F , 20F , 45F };
295
301
296
302
KeylineState state =
297
- new KeylineState .Builder (40F )
298
- .addKeyline (-5F , getKeylineMaskPercentage (210F , 40F ), 10F )
303
+ new KeylineState .Builder (40F , 40 )
304
+ .addAnchorKeyline (-5F , getKeylineMaskPercentage (210F , 40F ), 10F )
299
305
.addKeyline (20F , 0F , 40F , true )
300
- .addKeyline (45F , getKeylineMaskPercentage (10F , 40F ), 10F )
306
+ .addAnchorKeyline (45F , getKeylineMaskPercentage (10F , 40F ), 10F )
301
307
.build ();
302
308
KeylineStateList stateList = KeylineStateList .from (createCarouselWithWidth (40 ), state );
303
309
@@ -312,7 +318,7 @@ public void testFullScreenArrangementWithOutOfBoundsKeylines_nothingShifts() {
312
318
@ Test
313
319
public void testMultipleFocalItems_shiftsFocalRange () {
314
320
KeylineState state =
315
- new KeylineState .Builder (100F )
321
+ new KeylineState .Builder (100F , 500 )
316
322
.addKeyline (25F , .5F , 50F )
317
323
.addKeylineRange (100F , 0F , 100F , 4 , true )
318
324
.addKeyline (475F , .5F , 50F )
@@ -326,7 +332,7 @@ public void testMultipleFocalItems_shiftsFocalRange() {
326
332
@ Test
327
333
public void testKeylineStateForPosition () {
328
334
KeylineState state =
329
- new KeylineState .Builder (100F )
335
+ new KeylineState .Builder (100F , 500 )
330
336
.addKeyline (25F , .5F , 50F )
331
337
.addKeylineRange (100F , 0F , 100F , 4 , true )
332
338
.addKeyline (475F , .5F , 50F )
@@ -354,7 +360,7 @@ public void testKeylineStateForPosition() {
354
360
@ Test
355
361
public void testKeylineStateForPositionRTL () {
356
362
KeylineState state =
357
- new KeylineState .Builder (100F )
363
+ new KeylineState .Builder (100F , 500 )
358
364
.addKeyline (25F , .5F , 50F )
359
365
.addKeylineRange (100F , 0F , 100F , 4 , true )
360
366
.addKeyline (475F , .5F , 50F )
@@ -383,7 +389,7 @@ public void testKeylineStateForPositionRTL() {
383
389
@ Test
384
390
public void testKeylineStateForPositionVertical () {
385
391
KeylineState state =
386
- new KeylineState .Builder (100F )
392
+ new KeylineState .Builder (100F , 500 )
387
393
.addKeyline (25F , .5F , 50F )
388
394
.addKeylineRange (100F , 0F , 100F , 4 , true )
389
395
.addKeyline (475F , .5F , 50F )
@@ -408,4 +414,70 @@ public void testKeylineStateForPositionVertical() {
408
414
}
409
415
assertThat (latestKeylineLoc ).isEqualTo (stateList .getEndState ().getFirstFocalKeyline ().loc );
410
416
}
417
+
418
+ @ Test
419
+ public void testCutoffEndKeylines_changeEndKeylineLocOffsets () {
420
+ float [][] endStepsLocOffsets =
421
+ new float [][] {
422
+ // keyline sizes are as follows: {large, large, cutoff-large}
423
+ new float [] {-5F , 20F , 60F , 100F , 125F },
424
+ // keyline sizes are as follows: {cutoff-large, large, large}
425
+ new float [] {-25F , 0F , 40F , 80F , 105F },
426
+ };
427
+
428
+ // Carousel size is 100, with 2 larges and a cutoff large
429
+ KeylineState state =
430
+ new KeylineState .Builder (40F , 100 )
431
+ .addAnchorKeyline (-5F , getKeylineMaskPercentage (10F , 40F ), 10F )
432
+ .addKeyline (20F , 0F , 40F , /* isFocal= */ true )
433
+ .addKeyline (60F , 0F , 40F , /* isFocal= */ true )
434
+ .addKeyline (100F , 0F , 40F , /* isFocal= */ true )
435
+ .addAnchorKeyline (125F , getKeylineMaskPercentage (10F , 40F ), 10F )
436
+ .build ();
437
+ KeylineStateList stateList = KeylineStateList .from (createCarouselWithWidth (100 ), state );
438
+
439
+ float [] scrollSteps = new float [] {40F , 0F };
440
+ float minScroll = 0F ;
441
+ float maxScroll = 5 * 80F ;
442
+
443
+ for (int j = 0 ; j < scrollSteps .length ; j ++) {
444
+ KeylineState s = stateList .getShiftedState (maxScroll - scrollSteps [j ], minScroll , maxScroll );
445
+ for (int i = 0 ; i < s .getKeylines ().size (); i ++) {
446
+ assertThat (s .getKeylines ().get (i ).locOffset ).isEqualTo (endStepsLocOffsets [j ][i ]);
447
+ }
448
+ }
449
+ }
450
+
451
+ @ Test
452
+ public void testCutoffStartKeylines_doesNotChangeEndKeylineLocOffsets () {
453
+ float [][] endStepsLocOffsets =
454
+ new float [][] {
455
+ // keyline sizes are as follows: {cutoff-large, large, large}
456
+ new float [] {-25F , 0F , 40F , 80F , 105F },
457
+ // keyline sizes are as follows: {cutoff-large, large, large}
458
+ new float [] {-25F , 0F , 40F , 80F , 105F },
459
+ };
460
+
461
+ // Carousel size is 100, with cutoff large and 2 larges
462
+ KeylineState state =
463
+ new KeylineState .Builder (40F , 100 )
464
+ .addAnchorKeyline (-25F , getKeylineMaskPercentage (10F , 40F ), 10F )
465
+ .addKeyline (0F , 0F , 40F , /* isFocal= */ true )
466
+ .addKeyline (40F , 0F , 40F , /* isFocal= */ true )
467
+ .addKeyline (80F , 0F , 40F , /* isFocal= */ true )
468
+ .addAnchorKeyline (105F , getKeylineMaskPercentage (10F , 40F ), 10F )
469
+ .build ();
470
+ KeylineStateList stateList = KeylineStateList .from (createCarouselWithWidth (100 ), state );
471
+
472
+ float [] scrollSteps = new float [] {40F , 0F };
473
+ float minScroll = 0F ;
474
+ float maxScroll = 5 * 80F ;
475
+
476
+ for (int j = 0 ; j < scrollSteps .length ; j ++) {
477
+ KeylineState s = stateList .getShiftedState (maxScroll - scrollSteps [j ], minScroll , maxScroll );
478
+ for (int i = 0 ; i < s .getKeylines ().size (); i ++) {
479
+ assertThat (s .getKeylines ().get (i ).locOffset ).isEqualTo (endStepsLocOffsets [j ][i ]);
480
+ }
481
+ }
482
+ }
411
483
}
0 commit comments