@@ -101,14 +101,13 @@ public class BottomNavigationView extends FrameLayout {
101
101
102
102
private static final int MENU_PRESENTER_ID = 1 ;
103
103
104
- private final MenuBuilder mMenu ;
105
- private final BottomNavigationMenuView mMenuView ;
106
- private final BottomNavigationPresenter mPresenter = new BottomNavigationPresenter ();
107
- private MenuInflater mMenuInflater ;
108
-
109
- private OnNavigationItemSelectedListener mSelectedListener ;
110
- private OnNavigationItemReselectedListener mReselectedListener ;
104
+ private final MenuBuilder menu ;
105
+ private final BottomNavigationMenuView menuView ;
106
+ private final BottomNavigationPresenter presenter = new BottomNavigationPresenter ();
107
+ private MenuInflater menuInflater ;
111
108
109
+ private OnNavigationItemSelectedListener selectedListener ;
110
+ private OnNavigationItemReselectedListener reselectedListener ;
112
111
113
112
public BottomNavigationView (Context context ) {
114
113
this (context , null );
@@ -124,20 +123,20 @@ public BottomNavigationView(Context context, AttributeSet attrs, int defStyleAtt
124
123
ThemeEnforcement .checkAppCompatTheme (context );
125
124
126
125
// Create the menu
127
- mMenu = new BottomNavigationMenu (context );
126
+ this . menu = new BottomNavigationMenu (context );
128
127
129
- mMenuView = new BottomNavigationMenuView (context );
128
+ menuView = new BottomNavigationMenuView (context );
130
129
FrameLayout .LayoutParams params =
131
130
new FrameLayout .LayoutParams (
132
131
ViewGroup .LayoutParams .WRAP_CONTENT , ViewGroup .LayoutParams .WRAP_CONTENT );
133
132
params .gravity = Gravity .CENTER ;
134
- mMenuView .setLayoutParams (params );
133
+ menuView .setLayoutParams (params );
135
134
136
- mPresenter .setBottomNavigationMenuView (mMenuView );
137
- mPresenter .setId (MENU_PRESENTER_ID );
138
- mMenuView .setPresenter (mPresenter );
139
- mMenu . addMenuPresenter (mPresenter );
140
- mPresenter .initForMenu (getContext (), mMenu );
135
+ presenter .setBottomNavigationMenuView (menuView );
136
+ presenter .setId (MENU_PRESENTER_ID );
137
+ menuView .setPresenter (presenter );
138
+ this . menu . addMenuPresenter (presenter );
139
+ presenter .initForMenu (getContext (), this . menu );
141
140
142
141
// Custom attributes
143
142
TintTypedArray a =
@@ -149,15 +148,15 @@ public BottomNavigationView(Context context, AttributeSet attrs, int defStyleAtt
149
148
R .style .Widget_Design_BottomNavigationView );
150
149
151
150
if (a .hasValue (R .styleable .BottomNavigationView_itemIconTint )) {
152
- mMenuView .setIconTintList (a .getColorStateList (R .styleable .BottomNavigationView_itemIconTint ));
151
+ menuView .setIconTintList (a .getColorStateList (R .styleable .BottomNavigationView_itemIconTint ));
153
152
} else {
154
- mMenuView .setIconTintList (createDefaultColorStateList (android .R .attr .textColorSecondary ));
153
+ menuView .setIconTintList (createDefaultColorStateList (android .R .attr .textColorSecondary ));
155
154
}
156
155
if (a .hasValue (R .styleable .BottomNavigationView_itemTextColor )) {
157
- mMenuView .setItemTextColor (
156
+ menuView .setItemTextColor (
158
157
a .getColorStateList (R .styleable .BottomNavigationView_itemTextColor ));
159
158
} else {
160
- mMenuView .setItemTextColor (createDefaultColorStateList (android .R .attr .textColorSecondary ));
159
+ menuView .setItemTextColor (createDefaultColorStateList (android .R .attr .textColorSecondary ));
161
160
}
162
161
if (a .hasValue (R .styleable .BottomNavigationView_elevation )) {
163
162
ViewCompat .setElevation (
@@ -167,7 +166,7 @@ public BottomNavigationView(Context context, AttributeSet attrs, int defStyleAtt
167
166
@ ShiftingMode
168
167
int shiftingMode =
169
168
a .getInt (R .styleable .BottomNavigationView_shiftingMode , ShiftingMode .SHIFTING_MODE_AUTO );
170
- mMenuView .setShiftingMode (shiftingMode );
169
+ menuView .setShiftingMode (shiftingMode );
171
170
}
172
171
173
172
setLabelVisibilityMode (
@@ -178,27 +177,27 @@ public BottomNavigationView(Context context, AttributeSet attrs, int defStyleAtt
178
177
a .getBoolean (R .styleable .BottomNavigationView_itemHorizontalTranslation , true ));
179
178
180
179
int itemBackground = a .getResourceId (R .styleable .BottomNavigationView_itemBackground , 0 );
181
- mMenuView .setItemBackgroundRes (itemBackground );
180
+ menuView .setItemBackgroundRes (itemBackground );
182
181
183
182
if (a .hasValue (R .styleable .BottomNavigationView_menu )) {
184
183
inflateMenu (a .getResourceId (R .styleable .BottomNavigationView_menu , 0 ));
185
184
}
186
185
a .recycle ();
187
186
188
- addView (mMenuView , params );
187
+ addView (menuView , params );
189
188
if (Build .VERSION .SDK_INT < 21 ) {
190
189
addCompatibilityTopDivider (context );
191
190
}
192
191
193
- mMenu .setCallback (
192
+ this . menu .setCallback (
194
193
new MenuBuilder .Callback () {
195
194
@ Override
196
195
public boolean onMenuItemSelected (MenuBuilder menu , MenuItem item ) {
197
- if (mReselectedListener != null && item .getItemId () == getSelectedItemId ()) {
198
- mReselectedListener .onNavigationItemReselected (item );
196
+ if (reselectedListener != null && item .getItemId () == getSelectedItemId ()) {
197
+ reselectedListener .onNavigationItemReselected (item );
199
198
return true ; // item is already selected
200
199
}
201
- return mSelectedListener != null && !mSelectedListener .onNavigationItemSelected (item );
200
+ return selectedListener != null && !selectedListener .onNavigationItemSelected (item );
202
201
}
203
202
204
203
@ Override
@@ -216,7 +215,7 @@ public void onMenuModeChange(MenuBuilder menu) {}
216
215
*/
217
216
public void setOnNavigationItemSelectedListener (
218
217
@ Nullable OnNavigationItemSelectedListener listener ) {
219
- mSelectedListener = listener ;
218
+ selectedListener = listener ;
220
219
}
221
220
222
221
/**
@@ -228,13 +227,13 @@ public void setOnNavigationItemSelectedListener(
228
227
*/
229
228
public void setOnNavigationItemReselectedListener (
230
229
@ Nullable OnNavigationItemReselectedListener listener ) {
231
- mReselectedListener = listener ;
230
+ reselectedListener = listener ;
232
231
}
233
232
234
233
/** Returns the {@link Menu} instance associated with this bottom navigation bar. */
235
234
@ NonNull
236
235
public Menu getMenu () {
237
- return mMenu ;
236
+ return menu ;
238
237
}
239
238
240
239
/**
@@ -245,10 +244,10 @@ public Menu getMenu() {
245
244
* @param resId ID of a menu resource to inflate
246
245
*/
247
246
public void inflateMenu (int resId ) {
248
- mPresenter .setUpdateSuspended (true );
249
- getMenuInflater ().inflate (resId , mMenu );
250
- mPresenter .setUpdateSuspended (false );
251
- mPresenter .updateMenuView (true );
247
+ presenter .setUpdateSuspended (true );
248
+ getMenuInflater ().inflate (resId , menu );
249
+ presenter .setUpdateSuspended (false );
250
+ presenter .updateMenuView (true );
252
251
}
253
252
254
253
/** @return The maximum number of items that can be shown in BottomNavigationView. */
@@ -264,7 +263,7 @@ public int getMaxItemCount() {
264
263
*/
265
264
@ Nullable
266
265
public ColorStateList getItemIconTintList () {
267
- return mMenuView .getIconTintList ();
266
+ return menuView .getIconTintList ();
268
267
}
269
268
270
269
/**
@@ -274,7 +273,7 @@ public ColorStateList getItemIconTintList() {
274
273
* @attr ref R.styleable#BottomNavigationView_itemIconTint
275
274
*/
276
275
public void setItemIconTintList (@ Nullable ColorStateList tint ) {
277
- mMenuView .setIconTintList (tint );
276
+ menuView .setIconTintList (tint );
278
277
}
279
278
280
279
/**
@@ -287,7 +286,7 @@ public void setItemIconTintList(@Nullable ColorStateList tint) {
287
286
*/
288
287
@ Nullable
289
288
public ColorStateList getItemTextColor () {
290
- return mMenuView .getItemTextColor ();
289
+ return menuView .getItemTextColor ();
291
290
}
292
291
293
292
/**
@@ -298,7 +297,7 @@ public ColorStateList getItemTextColor() {
298
297
* @attr ref R.styleable#BottomNavigationView_itemTextColor
299
298
*/
300
299
public void setItemTextColor (@ Nullable ColorStateList textColor ) {
301
- mMenuView .setItemTextColor (textColor );
300
+ menuView .setItemTextColor (textColor );
302
301
}
303
302
304
303
/**
@@ -309,7 +308,7 @@ public void setItemTextColor(@Nullable ColorStateList textColor) {
309
308
*/
310
309
@ DrawableRes
311
310
public int getItemBackgroundResource () {
312
- return mMenuView .getItemBackgroundRes ();
311
+ return menuView .getItemBackgroundRes ();
313
312
}
314
313
315
314
/**
@@ -319,7 +318,7 @@ public int getItemBackgroundResource() {
319
318
* @attr ref R.styleable#BottomNavigationView_itemBackground
320
319
*/
321
320
public void setItemBackgroundResource (@ DrawableRes int resId ) {
322
- mMenuView .setItemBackgroundRes (resId );
321
+ menuView .setItemBackgroundRes (resId );
323
322
}
324
323
325
324
/**
@@ -329,7 +328,7 @@ public void setItemBackgroundResource(@DrawableRes int resId) {
329
328
*/
330
329
@ IdRes
331
330
public int getSelectedItemId () {
332
- return mMenuView .getSelectedItemId ();
331
+ return menuView .getSelectedItemId ();
333
332
}
334
333
335
334
/**
@@ -339,9 +338,9 @@ public int getSelectedItemId() {
339
338
* @see #getSelectedItemId()
340
339
*/
341
340
public void setSelectedItemId (@ IdRes int itemId ) {
342
- MenuItem item = mMenu .findItem (itemId );
341
+ MenuItem item = menu .findItem (itemId );
343
342
if (item != null ) {
344
- if (!mMenu .performItemAction (item , mPresenter , 0 )) {
343
+ if (!menu .performItemAction (item , presenter , 0 )) {
345
344
item .setChecked (true );
346
345
}
347
346
}
@@ -357,7 +356,7 @@ public void setSelectedItemId(@IdRes int itemId) {
357
356
@ Deprecated
358
357
@ ShiftingMode
359
358
public int getShiftingMode () {
360
- return mMenuView .getShiftingMode ();
359
+ return menuView .getShiftingMode ();
361
360
}
362
361
363
362
/**
@@ -380,9 +379,9 @@ public int getShiftingMode() {
380
379
*/
381
380
@ Deprecated
382
381
public void setShiftingMode (@ ShiftingMode int shiftingMode ) {
383
- if (mMenuView .getShiftingMode () != shiftingMode ) {
384
- mMenuView .setShiftingMode (shiftingMode );
385
- mPresenter .updateMenuView (false /* cleared */ );
382
+ if (menuView .getShiftingMode () != shiftingMode ) {
383
+ menuView .setShiftingMode (shiftingMode );
384
+ presenter .updateMenuView (false /* cleared */ );
386
385
}
387
386
}
388
387
@@ -401,9 +400,9 @@ public void setShiftingMode(@ShiftingMode int shiftingMode) {
401
400
* @see #getLabelVisibilityMode()
402
401
*/
403
402
public void setLabelVisibilityMode (@ LabelVisibilityMode int labelVisibilityMode ) {
404
- if (mMenuView .getLabelVisibilityMode () != labelVisibilityMode ) {
405
- mMenuView .setLabelVisibilityMode (labelVisibilityMode );
406
- mPresenter .updateMenuView (false );
403
+ if (menuView .getLabelVisibilityMode () != labelVisibilityMode ) {
404
+ menuView .setLabelVisibilityMode (labelVisibilityMode );
405
+ presenter .updateMenuView (false );
407
406
}
408
407
}
409
408
@@ -433,7 +432,7 @@ public void setLabelVisibilityModeResource(@IntegerRes int labelVisibilityModeId
433
432
*/
434
433
@ LabelVisibilityMode
435
434
public int getLabelVisibilityMode () {
436
- return mMenuView .getLabelVisibilityMode ();
435
+ return menuView .getLabelVisibilityMode ();
437
436
}
438
437
439
438
/**
@@ -443,9 +442,9 @@ public int getLabelVisibilityMode() {
443
442
* @see #getItemHorizontalTranslation()
444
443
*/
445
444
public void setItemHorizontalTranslation (boolean itemHorizontalTranslation ) {
446
- if (mMenuView .getItemHorizontalTranslation () != itemHorizontalTranslation ) {
447
- mMenuView .setItemHorizontalTranslation (itemHorizontalTranslation );
448
- mPresenter .updateMenuView (false );
445
+ if (menuView .getItemHorizontalTranslation () != itemHorizontalTranslation ) {
446
+ menuView .setItemHorizontalTranslation (itemHorizontalTranslation );
447
+ presenter .updateMenuView (false );
449
448
}
450
449
}
451
450
@@ -466,7 +465,7 @@ public void setItemHorizontalTranslation(@BoolRes int itemHorizontalTranslation)
466
465
* @see #setItemHorizontalTranslation(boolean)
467
466
*/
468
467
public boolean getItemHorizontalTranslation () {
469
- return mMenuView .getItemHorizontalTranslation ();
468
+ return menuView .getItemHorizontalTranslation ();
470
469
}
471
470
472
471
/** Listener for handling selection events on bottom navigation items. */
@@ -507,10 +506,10 @@ private void addCompatibilityTopDivider(Context context) {
507
506
}
508
507
509
508
private MenuInflater getMenuInflater () {
510
- if (mMenuInflater == null ) {
511
- mMenuInflater = new SupportMenuInflater (getContext ());
509
+ if (menuInflater == null ) {
510
+ menuInflater = new SupportMenuInflater (getContext ());
512
511
}
513
- return mMenuInflater ;
512
+ return menuInflater ;
514
513
}
515
514
516
515
private ColorStateList createDefaultColorStateList (int baseColorThemeAttr ) {
@@ -538,7 +537,7 @@ protected Parcelable onSaveInstanceState() {
538
537
Parcelable superState = super .onSaveInstanceState ();
539
538
SavedState savedState = new SavedState (superState );
540
539
savedState .menuPresenterState = new Bundle ();
541
- mMenu .savePresenterStates (savedState .menuPresenterState );
540
+ menu .savePresenterStates (savedState .menuPresenterState );
542
541
return savedState ;
543
542
}
544
543
@@ -550,7 +549,7 @@ protected void onRestoreInstanceState(Parcelable state) {
550
549
}
551
550
SavedState savedState = (SavedState ) state ;
552
551
super .onRestoreInstanceState (savedState .getSuperState ());
553
- mMenu .restorePresenterStates (savedState .menuPresenterState );
552
+ menu .restorePresenterStates (savedState .menuPresenterState );
554
553
}
555
554
556
555
static class SavedState extends AbsSavedState {
0 commit comments