mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
resolve merge conflicts of 9e1bec8 to master
Change-Id: Ia992f6a6995d30961d7a258337102da792561d5f GitOrigin-RevId=5fa3fd281ab74ca1dbc56550e830fe2ef9682da6 PiperOrigin-RevId: 141505173
This commit is contained in:
parent
4ef0f07686
commit
d6acdded21
@ -97,10 +97,6 @@ public class BottomNavigationMenuView extends ViewGroup implements MenuView {
|
||||
@Override
|
||||
public void initialize(MenuBuilder menu) {
|
||||
mMenu = menu;
|
||||
if (mMenu == null) return;
|
||||
if (mMenu.size() > mActiveButton) {
|
||||
mMenu.getItem(mActiveButton).setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -125,7 +121,7 @@ public class BottomNavigationMenuView extends ViewGroup implements MenuView {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final int maxAvailable = width / count;
|
||||
final int maxAvailable = width / (count == 0 ? 1 : count);
|
||||
final int childWidth = Math.min(maxAvailable, mActiveItemMaxWidth);
|
||||
int extra = width - childWidth * count;
|
||||
for (int i = 0; i < count; i++) {
|
||||
@ -257,6 +253,9 @@ public class BottomNavigationMenuView extends ViewGroup implements MenuView {
|
||||
}
|
||||
}
|
||||
removeAllViews();
|
||||
if (mMenu.size() == 0) {
|
||||
return;
|
||||
}
|
||||
mButtons = new BottomNavigationItemView[mMenu.size()];
|
||||
mShiftingMode = mMenu.size() > 3;
|
||||
for (int i = 0; i < mMenu.size(); i++) {
|
||||
@ -274,6 +273,8 @@ public class BottomNavigationMenuView extends ViewGroup implements MenuView {
|
||||
child.setOnClickListener(mOnClickListener);
|
||||
addView(child);
|
||||
}
|
||||
mActiveButton = Math.min(mMenu.size() - 1, mActiveButton);
|
||||
mMenu.getItem(mActiveButton).setChecked(true);
|
||||
}
|
||||
|
||||
public void updateMenuView() {
|
||||
|
||||
@ -117,7 +117,7 @@ public class BottomNavigationView extends FrameLayout {
|
||||
mPresenter.setBottomNavigationMenuView(mMenuView);
|
||||
mMenuView.setPresenter(mPresenter);
|
||||
mMenu.addMenuPresenter(mPresenter);
|
||||
|
||||
mPresenter.initForMenu(getContext(), mMenu);
|
||||
|
||||
// Custom attributes
|
||||
TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs,
|
||||
@ -188,7 +188,6 @@ public class BottomNavigationView extends FrameLayout {
|
||||
public void inflateMenu(int resId) {
|
||||
mPresenter.setUpdateSuspended(true);
|
||||
getMenuInflater().inflate(resId, mMenu);
|
||||
mPresenter.initForMenu(getContext(), mMenu);
|
||||
mPresenter.setUpdateSuspended(false);
|
||||
mPresenter.updateMenuView(true);
|
||||
}
|
||||
|
||||
@ -42,10 +42,12 @@ import android.support.annotation.ColorInt;
|
||||
import android.support.design.test.R;
|
||||
import android.support.design.testutils.TestDrawable;
|
||||
import android.support.design.testutils.TestUtilsMatchers;
|
||||
import android.support.test.annotation.UiThreadTest;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.v4.content.res.ResourcesCompat;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -77,6 +79,20 @@ public class BottomNavigationViewTest
|
||||
mMenuStringContent.put(R.id.destination_people, res.getString(R.string.navigate_people));
|
||||
}
|
||||
|
||||
@UiThreadTest
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testAddItemsWithoutMenuInflation() {
|
||||
BottomNavigationView navigation = new BottomNavigationView(mActivityTestRule.getActivity());
|
||||
mActivityTestRule.getActivity().setContentView(navigation);
|
||||
navigation.getMenu().add("Item1");
|
||||
navigation.getMenu().add("Item2");
|
||||
assertEquals(2, navigation.getMenu().size());
|
||||
navigation.getMenu().removeItem(0);
|
||||
navigation.getMenu().removeItem(0);
|
||||
assertEquals(0, navigation.getMenu().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testBasics() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user