Skip to content

Commit ec18bef

Browse files
afohrmandsn5ft
authored andcommitted
Delete shifting mode in favor of label visibility mode.
PiperOrigin-RevId: 182431135
1 parent f909ab4 commit ec18bef

File tree

8 files changed

+183
-321
lines changed

8 files changed

+183
-321
lines changed

lib/java/android/support/design/bottomnavigation/LabelVisibilityMode.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@
2929
* LabelVisibilityMode#LABEL_VISIBILITY_LABELED} sets the label to always show, and {@link
3030
* LabelVisibilityMode#LABEL_VISIBILITY_UNLABELED} sets the label to never show.
3131
*
32-
* <p>Setting the label visibility mode to {@link LabelVisibilityMode#LABEL_VISIBILITY_LEGACY} sets
33-
* the label to behave as it used to with {@link ShiftingMode}.
32+
* <p>Setting the label visibility mode to {@link LabelVisibilityMode#LABEL_VISIBILITY_AUTO} sets
33+
* the label to behave as "labeled" when there are 3 items or less, or "selected" when there are 4
34+
* items or more.
3435
*/
3536
@IntDef({
36-
LabelVisibilityMode.LABEL_VISIBILITY_LEGACY,
37+
LabelVisibilityMode.LABEL_VISIBILITY_AUTO,
3738
LabelVisibilityMode.LABEL_VISIBILITY_SELECTED,
3839
LabelVisibilityMode.LABEL_VISIBILITY_LABELED,
3940
LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED
4041
})
4142
@Retention(RetentionPolicy.SOURCE)
4243
public @interface LabelVisibilityMode {
4344
/**
44-
* Label is shown when {@link ShiftingMode} is enabled, or hidden when it is not.
45-
*
46-
* @deprecated Use an explicit {@link LabelVisibilityMode}s instead.
45+
* Label behaves as "labeled" when there are 3 items or less, or "selected" when there are 4 items
46+
* or more.
4747
*/
48-
@Deprecated int LABEL_VISIBILITY_LEGACY = -1;
48+
int LABEL_VISIBILITY_AUTO = -1;
4949

5050
/** Label is shown on the selected navigation item. */
5151
int LABEL_VISIBILITY_SELECTED = 0;

lib/java/android/support/design/bottomnavigation/ShiftingMode.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

lib/java/android/support/design/internal/BottomNavigationItemView.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public class BottomNavigationItemView extends FrameLayout implements MenuView.It
5555
private float scaleUpFactor;
5656
private float scaleDownFactor;
5757

58-
private boolean shiftingMode;
5958
private int labelVisibilityMode;
59+
private boolean isShifting;
6060

6161
private ImageView icon;
6262
private final TextView smallLabel;
@@ -111,9 +111,9 @@ public int getItemPosition() {
111111
return itemPosition;
112112
}
113113

114-
public void setShiftingMode(boolean enabled) {
115-
if (shiftingMode != enabled) {
116-
shiftingMode = enabled;
114+
public void setShifting(boolean shifting) {
115+
if (isShifting != shifting) {
116+
isShifting = shifting;
117117

118118
boolean initialized = itemData != null;
119119
if (initialized) {
@@ -125,14 +125,14 @@ public void setShiftingMode(boolean enabled) {
125125
public void setLabelVisibilityMode(@LabelVisibilityMode int mode) {
126126
if (labelVisibilityMode != mode) {
127127
labelVisibilityMode = mode;
128-
128+
129129
boolean initialized = itemData != null;
130130
if (initialized) {
131131
setChecked(itemData.isChecked());
132132
}
133133
}
134134
}
135-
135+
136136
@Override
137137
public MenuItemImpl getItemData() {
138138
return itemData;
@@ -157,8 +157,8 @@ public void setChecked(boolean checked) {
157157
smallLabel.setPivotY(smallLabel.getBaseline());
158158

159159
switch (labelVisibilityMode) {
160-
case LabelVisibilityMode.LABEL_VISIBILITY_LEGACY:
161-
if (shiftingMode) {
160+
case LabelVisibilityMode.LABEL_VISIBILITY_AUTO:
161+
if (isShifting) {
162162
if (checked) {
163163
setViewLayoutParams(icon, defaultMargin, Gravity.CENTER_HORIZONTAL | Gravity.TOP);
164164
setViewValues(largeLabel, 1f, 1f, VISIBLE);

lib/java/android/support/design/internal/BottomNavigationMenuView.java

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import android.support.annotation.RestrictTo;
2626
import android.support.annotation.StyleRes;
2727
import android.support.design.bottomnavigation.LabelVisibilityMode;
28-
import android.support.design.bottomnavigation.ShiftingMode;
2928
import android.support.transition.AutoTransition;
3029
import android.support.transition.TransitionManager;
3130
import android.support.transition.TransitionSet;
@@ -59,7 +58,6 @@ public class BottomNavigationMenuView extends ViewGroup implements MenuView {
5958
private final OnClickListener onClickListener;
6059
private final Pools.Pool<BottomNavigationItemView> itemPool = new Pools.SynchronizedPool<>(5);
6160

62-
private int shiftingModeFlag = ShiftingMode.SHIFTING_MODE_AUTO;
6361
private boolean itemHorizontalTranslation;
6462
@LabelVisibilityMode private int labelVisibilityMode;
6563

@@ -130,7 +128,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
130128

131129
final int heightSpec = MeasureSpec.makeMeasureSpec(itemHeight, MeasureSpec.EXACTLY);
132130

133-
if (isShifting(shiftingModeFlag, visibleCount) && itemHorizontalTranslation) {
131+
if (isShifting(labelVisibilityMode, visibleCount) && itemHorizontalTranslation) {
134132
final View activeChild = getChildAt(selectedItemPosition);
135133
int activeItemWidth = activeItemMinWidth;
136134
if (activeChild.getVisibility() != View.GONE) {
@@ -351,43 +349,14 @@ public int getItemBackgroundRes() {
351349
return itemBackgroundRes;
352350
}
353351

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-
383352
/**
384353
* Sets the navigation items' label visibility mode.
385354
*
386355
* <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.
388357
*
389358
* @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
391360
* LabelVisibilityMode#LABEL_VISIBILITY_SELECTED}, {@link
392361
* LabelVisibilityMode#LABEL_VISIBILITY_LABELED}, or {@link
393362
* LabelVisibilityMode#LABEL_VISIBILITY_UNLABELED}
@@ -407,19 +376,21 @@ public int getLabelVisibilityMode() {
407376
}
408377

409378
/**
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.
411381
*
412-
* @param itemHorizontalTranslation whether the menu items horizontally translate in shifting mode
382+
* @param itemHorizontalTranslation whether the menu items horizontally translate on selection
413383
* @see #getItemHorizontalTranslation()
414384
*/
415385
public void setItemHorizontalTranslation(boolean itemHorizontalTranslation) {
416386
this.itemHorizontalTranslation = itemHorizontalTranslation;
417387
}
418388

419389
/**
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.
421392
*
422-
* @return whether the menu items horizontally translate in shifting mode
393+
* @return whether the menu items horizontally translate on selection
423394
* @see #setItemHorizontalTranslation(boolean)
424395
*/
425396
public boolean getItemHorizontalTranslation() {
@@ -466,7 +437,7 @@ public void buildMenuView() {
466437
return;
467438
}
468439
buttons = new BottomNavigationItemView[menu.size()];
469-
boolean shifting = isShifting(shiftingModeFlag, menu.getVisibleItems().size());
440+
boolean shifting = isShifting(labelVisibilityMode, menu.getVisibleItems().size());
470441
for (int i = 0; i < menu.size(); i++) {
471442
presenter.setUpdateSuspended(true);
472443
menu.getItem(i).setCheckable(true);
@@ -480,7 +451,7 @@ public void buildMenuView() {
480451
child.setTextAppearanceActive(itemTextAppearanceActive);
481452
child.setTextColor(itemTextColorFromUser);
482453
child.setItemBackground(itemBackgroundRes);
483-
child.setShiftingMode(shifting);
454+
child.setShifting(shifting);
484455
child.setLabelVisibilityMode(labelVisibilityMode);
485456
child.initialize((MenuItemImpl) menu.getItem(i), 0);
486457
child.setItemPosition(i);
@@ -517,11 +488,11 @@ public void updateMenuView() {
517488
TransitionManager.beginDelayedTransition(this, set);
518489
}
519490

520-
boolean shifting = isShifting(shiftingModeFlag, menu.getVisibleItems().size());
491+
boolean shifting = isShifting(labelVisibilityMode, menu.getVisibleItems().size());
521492
for (int i = 0; i < menuSize; i++) {
522493
presenter.setUpdateSuspended(true);
523-
buttons[i].setShiftingMode(shifting);
524494
buttons[i].setLabelVisibilityMode(labelVisibilityMode);
495+
buttons[i].setShifting(shifting);
525496
buttons[i].initialize((MenuItemImpl) menu.getItem(i), 0);
526497
presenter.setUpdateSuspended(false);
527498
}
@@ -539,10 +510,10 @@ public int getSelectedItemId() {
539510
return selectedItemId;
540511
}
541512

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
544515
? childCount > 3
545-
: shiftingMode == ShiftingMode.SHIFTING_MODE_ON;
516+
: labelVisibilityMode == LabelVisibilityMode.LABEL_VISIBILITY_SELECTED;
546517
}
547518

548519
void tryRestoreSelectedItemId(int itemId) {

0 commit comments

Comments
 (0)