@@ -47,22 +47,22 @@ public class BottomNavigationItemView extends FrameLayout implements MenuView.It
47
47
48
48
private static final int [] CHECKED_STATE_SET = {android .R .attr .state_checked };
49
49
50
- private final int mDefaultMargin ;
51
- private final int mShiftAmount ;
52
- private final float mScaleUpFactor ;
53
- private final float mScaleDownFactor ;
50
+ private final int defaultMargin ;
51
+ private final int shiftAmount ;
52
+ private final float scaleUpFactor ;
53
+ private final float scaleDownFactor ;
54
54
55
- private boolean mShiftingMode ;
55
+ private boolean shiftingMode ;
56
56
private int labelVisibilityMode ;
57
57
58
- private ImageView mIcon ;
59
- private final TextView mSmallLabel ;
60
- private final TextView mLargeLabel ;
61
- private int mItemPosition = INVALID_ITEM_POSITION ;
58
+ private ImageView icon ;
59
+ private final TextView smallLabel ;
60
+ private final TextView largeLabel ;
61
+ private int itemPosition = INVALID_ITEM_POSITION ;
62
62
63
- private MenuItemImpl mItemData ;
63
+ private MenuItemImpl itemData ;
64
64
65
- private ColorStateList mIconTint ;
65
+ private ColorStateList iconTint ;
66
66
67
67
public BottomNavigationItemView (@ NonNull Context context ) {
68
68
this (context , null );
@@ -78,21 +78,21 @@ public BottomNavigationItemView(Context context, AttributeSet attrs, int defStyl
78
78
int inactiveLabelSize = res .getDimensionPixelSize (R .dimen .design_bottom_navigation_text_size );
79
79
int activeLabelSize =
80
80
res .getDimensionPixelSize (R .dimen .design_bottom_navigation_active_text_size );
81
- mDefaultMargin = res .getDimensionPixelSize (R .dimen .design_bottom_navigation_margin );
82
- mShiftAmount = inactiveLabelSize - activeLabelSize ;
83
- mScaleUpFactor = 1f * activeLabelSize / inactiveLabelSize ;
84
- mScaleDownFactor = 1f * inactiveLabelSize / activeLabelSize ;
81
+ defaultMargin = res .getDimensionPixelSize (R .dimen .design_bottom_navigation_margin );
82
+ shiftAmount = inactiveLabelSize - activeLabelSize ;
83
+ scaleUpFactor = 1f * activeLabelSize / inactiveLabelSize ;
84
+ scaleDownFactor = 1f * inactiveLabelSize / activeLabelSize ;
85
85
86
86
LayoutInflater .from (context ).inflate (R .layout .design_bottom_navigation_item , this , true );
87
87
setBackgroundResource (R .drawable .design_bottom_navigation_item_background );
88
- mIcon = findViewById (R .id .icon );
89
- mSmallLabel = findViewById (R .id .smallLabel );
90
- mLargeLabel = findViewById (R .id .largeLabel );
88
+ icon = findViewById (R .id .icon );
89
+ smallLabel = findViewById (R .id .smallLabel );
90
+ largeLabel = findViewById (R .id .largeLabel );
91
91
}
92
92
93
93
@ Override
94
94
public void initialize (MenuItemImpl itemData , int menuType ) {
95
- mItemData = itemData ;
95
+ this . itemData = itemData ;
96
96
setCheckable (itemData .isCheckable ());
97
97
setChecked (itemData .isChecked ());
98
98
setEnabled (itemData .isEnabled ());
@@ -105,20 +105,20 @@ public void initialize(MenuItemImpl itemData, int menuType) {
105
105
}
106
106
107
107
public void setItemPosition (int position ) {
108
- mItemPosition = position ;
108
+ itemPosition = position ;
109
109
}
110
110
111
111
public int getItemPosition () {
112
- return mItemPosition ;
112
+ return itemPosition ;
113
113
}
114
114
115
115
public void setShiftingMode (boolean enabled ) {
116
- if (mShiftingMode != enabled ) {
117
- mShiftingMode = enabled ;
116
+ if (shiftingMode != enabled ) {
117
+ shiftingMode = enabled ;
118
118
119
- boolean initialized = mItemData != null ;
119
+ boolean initialized = itemData != null ;
120
120
if (initialized ) {
121
- setChecked (mItemData .isChecked ());
121
+ setChecked (itemData .isChecked ());
122
122
}
123
123
}
124
124
}
@@ -127,22 +127,22 @@ public void setLabelVisibilityMode(@LabelVisibilityMode int mode) {
127
127
if (labelVisibilityMode != mode ) {
128
128
labelVisibilityMode = mode ;
129
129
130
- boolean initialized = mItemData != null ;
130
+ boolean initialized = itemData != null ;
131
131
if (initialized ) {
132
- setChecked (mItemData .isChecked ());
132
+ setChecked (itemData .isChecked ());
133
133
}
134
134
}
135
135
}
136
136
137
137
@ Override
138
138
public MenuItemImpl getItemData () {
139
- return mItemData ;
139
+ return itemData ;
140
140
}
141
141
142
142
@ Override
143
143
public void setTitle (CharSequence title ) {
144
- mSmallLabel .setText (title );
145
- mLargeLabel .setText (title );
144
+ smallLabel .setText (title );
145
+ largeLabel .setText (title );
146
146
}
147
147
148
148
@ Override
@@ -152,64 +152,64 @@ public void setCheckable(boolean checkable) {
152
152
153
153
@ Override
154
154
public void setChecked (boolean checked ) {
155
- mLargeLabel .setPivotX (mLargeLabel .getWidth () / 2 );
156
- mLargeLabel .setPivotY (mLargeLabel .getBaseline ());
157
- mSmallLabel .setPivotX (mSmallLabel .getWidth () / 2 );
158
- mSmallLabel .setPivotY (mSmallLabel .getBaseline ());
155
+ largeLabel .setPivotX (largeLabel .getWidth () / 2 );
156
+ largeLabel .setPivotY (largeLabel .getBaseline ());
157
+ smallLabel .setPivotX (smallLabel .getWidth () / 2 );
158
+ smallLabel .setPivotY (smallLabel .getBaseline ());
159
159
160
160
switch (labelVisibilityMode ) {
161
161
case LabelVisibilityMode .LABEL_VISIBILITY_LEGACY :
162
- if (mShiftingMode ) {
162
+ if (shiftingMode ) {
163
163
if (checked ) {
164
- setViewLayoutParams (mIcon , mDefaultMargin , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
165
- setViewValues (mLargeLabel , 1f , 1f , VISIBLE );
164
+ setViewLayoutParams (icon , defaultMargin , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
165
+ setViewValues (largeLabel , 1f , 1f , VISIBLE );
166
166
} else {
167
- setViewLayoutParams (mIcon , mDefaultMargin , Gravity .CENTER );
168
- setViewValues (mLargeLabel , 0.5f , 0.5f , INVISIBLE );
167
+ setViewLayoutParams (icon , defaultMargin , Gravity .CENTER );
168
+ setViewValues (largeLabel , 0.5f , 0.5f , INVISIBLE );
169
169
}
170
- mSmallLabel .setVisibility (INVISIBLE );
170
+ smallLabel .setVisibility (INVISIBLE );
171
171
} else {
172
172
if (checked ) {
173
173
setViewLayoutParams (
174
- mIcon , mDefaultMargin + mShiftAmount , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
175
- setViewValues (mLargeLabel , 1f , 1f , VISIBLE );
176
- setViewValues (mSmallLabel , mScaleUpFactor , mScaleUpFactor , INVISIBLE );
174
+ icon , defaultMargin + shiftAmount , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
175
+ setViewValues (largeLabel , 1f , 1f , VISIBLE );
176
+ setViewValues (smallLabel , scaleUpFactor , scaleUpFactor , INVISIBLE );
177
177
} else {
178
- setViewLayoutParams (mIcon , mDefaultMargin , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
179
- setViewValues (mLargeLabel , mScaleDownFactor , mScaleDownFactor , INVISIBLE );
180
- setViewValues (mSmallLabel , 1f , 1f , VISIBLE );
178
+ setViewLayoutParams (icon , defaultMargin , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
179
+ setViewValues (largeLabel , scaleDownFactor , scaleDownFactor , INVISIBLE );
180
+ setViewValues (smallLabel , 1f , 1f , VISIBLE );
181
181
}
182
182
}
183
183
break ;
184
184
185
185
case LabelVisibilityMode .LABEL_VISIBILITY_SELECTED :
186
186
if (checked ) {
187
- setViewLayoutParams (mIcon , mDefaultMargin , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
188
- setViewValues (mLargeLabel , 1f , 1f , VISIBLE );
187
+ setViewLayoutParams (icon , defaultMargin , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
188
+ setViewValues (largeLabel , 1f , 1f , VISIBLE );
189
189
} else {
190
- setViewLayoutParams (mIcon , mDefaultMargin , Gravity .CENTER );
191
- setViewValues (mLargeLabel , 0.5f , 0.5f , INVISIBLE );
190
+ setViewLayoutParams (icon , defaultMargin , Gravity .CENTER );
191
+ setViewValues (largeLabel , 0.5f , 0.5f , INVISIBLE );
192
192
}
193
- mSmallLabel .setVisibility (INVISIBLE );
193
+ smallLabel .setVisibility (INVISIBLE );
194
194
break ;
195
195
196
196
case LabelVisibilityMode .LABEL_VISIBILITY_LABELED :
197
197
if (checked ) {
198
198
setViewLayoutParams (
199
- mIcon , mDefaultMargin + mShiftAmount , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
200
- setViewValues (mLargeLabel , 1f , 1f , VISIBLE );
201
- setViewValues (mSmallLabel , mScaleUpFactor , mScaleUpFactor , INVISIBLE );
199
+ icon , defaultMargin + shiftAmount , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
200
+ setViewValues (largeLabel , 1f , 1f , VISIBLE );
201
+ setViewValues (smallLabel , scaleUpFactor , scaleUpFactor , INVISIBLE );
202
202
} else {
203
- setViewLayoutParams (mIcon , mDefaultMargin , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
204
- setViewValues (mLargeLabel , mScaleDownFactor , mScaleDownFactor , INVISIBLE );
205
- setViewValues (mSmallLabel , 1f , 1f , VISIBLE );
203
+ setViewLayoutParams (icon , defaultMargin , Gravity .CENTER_HORIZONTAL | Gravity .TOP );
204
+ setViewValues (largeLabel , scaleDownFactor , scaleDownFactor , INVISIBLE );
205
+ setViewValues (smallLabel , 1f , 1f , VISIBLE );
206
206
}
207
207
break ;
208
208
209
209
case LabelVisibilityMode .LABEL_VISIBILITY_UNLABELED :
210
- setViewLayoutParams (mIcon , mDefaultMargin , Gravity .CENTER );
211
- mLargeLabel .setVisibility (GONE );
212
- mSmallLabel .setVisibility (GONE );
210
+ setViewLayoutParams (icon , defaultMargin , Gravity .CENTER );
211
+ largeLabel .setVisibility (GONE );
212
+ smallLabel .setVisibility (GONE );
213
213
break ;
214
214
215
215
default :
@@ -235,9 +235,9 @@ private void setViewValues(@NonNull View view, float scaleX, float scaleY, int v
235
235
@ Override
236
236
public void setEnabled (boolean enabled ) {
237
237
super .setEnabled (enabled );
238
- mSmallLabel .setEnabled (enabled );
239
- mLargeLabel .setEnabled (enabled );
240
- mIcon .setEnabled (enabled );
238
+ smallLabel .setEnabled (enabled );
239
+ largeLabel .setEnabled (enabled );
240
+ icon .setEnabled (enabled );
241
241
242
242
if (enabled ) {
243
243
ViewCompat .setPointerIcon (
@@ -250,7 +250,7 @@ public void setEnabled(boolean enabled) {
250
250
@ Override
251
251
public int [] onCreateDrawableState (final int extraSpace ) {
252
252
final int [] drawableState = super .onCreateDrawableState (extraSpace + 1 );
253
- if (mItemData != null && mItemData .isCheckable () && mItemData .isChecked ()) {
253
+ if (itemData != null && itemData .isCheckable () && itemData .isChecked ()) {
254
254
mergeDrawableStates (drawableState , CHECKED_STATE_SET );
255
255
}
256
256
return drawableState ;
@@ -264,9 +264,9 @@ public void setIcon(Drawable icon) {
264
264
if (icon != null ) {
265
265
Drawable .ConstantState state = icon .getConstantState ();
266
266
icon = DrawableCompat .wrap (state == null ? icon : state .newDrawable ()).mutate ();
267
- DrawableCompat .setTintList (icon , mIconTint );
267
+ DrawableCompat .setTintList (icon , iconTint );
268
268
}
269
- mIcon .setImageDrawable (icon );
269
+ this . icon .setImageDrawable (icon );
270
270
}
271
271
272
272
@ Override
@@ -280,16 +280,16 @@ public boolean showsIcon() {
280
280
}
281
281
282
282
public void setIconTintList (ColorStateList tint ) {
283
- mIconTint = tint ;
284
- if (mItemData != null ) {
283
+ iconTint = tint ;
284
+ if (itemData != null ) {
285
285
// Update the icon so that the tint takes effect
286
- setIcon (mItemData .getIcon ());
286
+ setIcon (itemData .getIcon ());
287
287
}
288
288
}
289
289
290
290
public void setTextColor (ColorStateList color ) {
291
- mSmallLabel .setTextColor (color );
292
- mLargeLabel .setTextColor (color );
291
+ smallLabel .setTextColor (color );
292
+ largeLabel .setTextColor (color );
293
293
}
294
294
295
295
public void setItemBackground (int background ) {
0 commit comments