25
25
import android .support .annotation .RestrictTo ;
26
26
import android .support .annotation .StyleRes ;
27
27
import android .support .design .bottomnavigation .LabelVisibilityMode ;
28
- import android .support .design .bottomnavigation .ShiftingMode ;
29
28
import android .support .transition .AutoTransition ;
30
29
import android .support .transition .TransitionManager ;
31
30
import android .support .transition .TransitionSet ;
@@ -59,7 +58,6 @@ public class BottomNavigationMenuView extends ViewGroup implements MenuView {
59
58
private final OnClickListener onClickListener ;
60
59
private final Pools .Pool <BottomNavigationItemView > itemPool = new Pools .SynchronizedPool <>(5 );
61
60
62
- private int shiftingModeFlag = ShiftingMode .SHIFTING_MODE_AUTO ;
63
61
private boolean itemHorizontalTranslation ;
64
62
@ LabelVisibilityMode private int labelVisibilityMode ;
65
63
@@ -130,7 +128,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
130
128
131
129
final int heightSpec = MeasureSpec .makeMeasureSpec (itemHeight , MeasureSpec .EXACTLY );
132
130
133
- if (isShifting (shiftingModeFlag , visibleCount ) && itemHorizontalTranslation ) {
131
+ if (isShifting (labelVisibilityMode , visibleCount ) && itemHorizontalTranslation ) {
134
132
final View activeChild = getChildAt (selectedItemPosition );
135
133
int activeItemWidth = activeItemMinWidth ;
136
134
if (activeChild .getVisibility () != View .GONE ) {
@@ -351,43 +349,14 @@ public int getItemBackgroundRes() {
351
349
return itemBackgroundRes ;
352
350
}
353
351
354
- /**
355
- * Sets shifting mode override flag for menu view. If this flag is set to {@link
356
- * ShiftingMode#SHIFTING_MODE_OFF}, this menu will not have shifting behavior even if it has more
357
- * than 3 children. If this flag is set to {@link ShiftingMode#SHIFTING_MODE_ON}, this menu will
358
- * have shifting behavior for any number of children. If this flag is set to {@link
359
- * ShiftingMode#SHIFTING_MODE_AUTO} this menu will have shifting behavior only if it has 3 or more
360
- * children.
361
- *
362
- * @param shiftingMode one of {@link ShiftingMode#SHIFTING_MODE_OFF}, {@link
363
- * ShiftingMode#SHIFTING_MODE_ON}, or {@link ShiftingMode#SHIFTING_MODE_AUTO}
364
- * @deprecated use {@link #setLabelVisibilityMode(int)} instead
365
- */
366
- @ Deprecated
367
- public void setShiftingMode (@ ShiftingMode int shiftingMode ) {
368
- shiftingModeFlag = shiftingMode ;
369
- }
370
-
371
- /**
372
- * Gets the status of shifting mode override flag for this menu view.
373
- *
374
- * @return Shifting mode flag for this menu view (default {@link ShiftingMode#SHIFTING_MODE_AUTO})
375
- * @deprecated use {@link #getLabelVisibilityMode()} instead
376
- */
377
- @ Deprecated
378
- @ ShiftingMode
379
- public int getShiftingMode () {
380
- return shiftingModeFlag ;
381
- }
382
-
383
352
/**
384
353
* Sets the navigation items' label visibility mode.
385
354
*
386
355
* <p>The label is either always shown, never shown, or only shown when activated. Also supports
387
- * legacy mode, which uses {@link ShiftingMode} to decide whether the label should be shown .
356
+ * "auto" mode, which uses the item count to determine whether to show or hide the label .
388
357
*
389
358
* @param labelVisibilityMode mode which decides whether or not the label should be shown. Can be
390
- * one of {@link LabelVisibilityMode#LABEL_VISIBILITY_LEGACY }, {@link
359
+ * one of {@link LabelVisibilityMode#LABEL_VISIBILITY_AUTO }, {@link
391
360
* LabelVisibilityMode#LABEL_VISIBILITY_SELECTED}, {@link
392
361
* LabelVisibilityMode#LABEL_VISIBILITY_LABELED}, or {@link
393
362
* LabelVisibilityMode#LABEL_VISIBILITY_UNLABELED}
@@ -407,19 +376,21 @@ public int getLabelVisibilityMode() {
407
376
}
408
377
409
378
/**
410
- * Sets whether the menu items horizontally translate in shifting mode.
379
+ * Sets whether the menu items horizontally translate on selection when the combined item widths
380
+ * fill the screen.
411
381
*
412
- * @param itemHorizontalTranslation whether the menu items horizontally translate in shifting mode
382
+ * @param itemHorizontalTranslation whether the menu items horizontally translate on selection
413
383
* @see #getItemHorizontalTranslation()
414
384
*/
415
385
public void setItemHorizontalTranslation (boolean itemHorizontalTranslation ) {
416
386
this .itemHorizontalTranslation = itemHorizontalTranslation ;
417
387
}
418
388
419
389
/**
420
- * Returns whether the menu items horizontally translate in shifting mode.
390
+ * Returns whether the menu items horizontally translate on selection when the combined item
391
+ * widths fill the screen.
421
392
*
422
- * @return whether the menu items horizontally translate in shifting mode
393
+ * @return whether the menu items horizontally translate on selection
423
394
* @see #setItemHorizontalTranslation(boolean)
424
395
*/
425
396
public boolean getItemHorizontalTranslation () {
@@ -466,7 +437,7 @@ public void buildMenuView() {
466
437
return ;
467
438
}
468
439
buttons = new BottomNavigationItemView [menu .size ()];
469
- boolean shifting = isShifting (shiftingModeFlag , menu .getVisibleItems ().size ());
440
+ boolean shifting = isShifting (labelVisibilityMode , menu .getVisibleItems ().size ());
470
441
for (int i = 0 ; i < menu .size (); i ++) {
471
442
presenter .setUpdateSuspended (true );
472
443
menu .getItem (i ).setCheckable (true );
@@ -480,7 +451,7 @@ public void buildMenuView() {
480
451
child .setTextAppearanceActive (itemTextAppearanceActive );
481
452
child .setTextColor (itemTextColorFromUser );
482
453
child .setItemBackground (itemBackgroundRes );
483
- child .setShiftingMode (shifting );
454
+ child .setShifting (shifting );
484
455
child .setLabelVisibilityMode (labelVisibilityMode );
485
456
child .initialize ((MenuItemImpl ) menu .getItem (i ), 0 );
486
457
child .setItemPosition (i );
@@ -517,11 +488,11 @@ public void updateMenuView() {
517
488
TransitionManager .beginDelayedTransition (this , set );
518
489
}
519
490
520
- boolean shifting = isShifting (shiftingModeFlag , menu .getVisibleItems ().size ());
491
+ boolean shifting = isShifting (labelVisibilityMode , menu .getVisibleItems ().size ());
521
492
for (int i = 0 ; i < menuSize ; i ++) {
522
493
presenter .setUpdateSuspended (true );
523
- buttons [i ].setShiftingMode (shifting );
524
494
buttons [i ].setLabelVisibilityMode (labelVisibilityMode );
495
+ buttons [i ].setShifting (shifting );
525
496
buttons [i ].initialize ((MenuItemImpl ) menu .getItem (i ), 0 );
526
497
presenter .setUpdateSuspended (false );
527
498
}
@@ -539,10 +510,10 @@ public int getSelectedItemId() {
539
510
return selectedItemId ;
540
511
}
541
512
542
- private boolean isShifting (@ ShiftingMode int shiftingMode , int childCount ) {
543
- return shiftingMode == ShiftingMode . SHIFTING_MODE_AUTO
513
+ private boolean isShifting (@ LabelVisibilityMode int labelVisibilityMode , int childCount ) {
514
+ return labelVisibilityMode == LabelVisibilityMode . LABEL_VISIBILITY_AUTO
544
515
? childCount > 3
545
- : shiftingMode == ShiftingMode . SHIFTING_MODE_ON ;
516
+ : labelVisibilityMode == LabelVisibilityMode . LABEL_VISIBILITY_SELECTED ;
546
517
}
547
518
548
519
void tryRestoreSelectedItemId (int itemId ) {
0 commit comments