use of com.aurelhubert.ahbottomnavigation.AHBottomNavigationAdapter in project ahbottomnavigation by aurelhubert.
the class DemoActivity method updateBottomNavigationItems.
/**
* Add or remove items of the bottom navigation
*/
public void updateBottomNavigationItems(boolean addItems) {
if (useMenuResource) {
if (addItems) {
navigationAdapter = new AHBottomNavigationAdapter(this, R.menu.bottom_navigation_menu_5);
navigationAdapter.setupWithBottomNavigation(bottomNavigation, tabColors);
bottomNavigation.setNotification("1", 3);
} else {
navigationAdapter = new AHBottomNavigationAdapter(this, R.menu.bottom_navigation_menu_3);
navigationAdapter.setupWithBottomNavigation(bottomNavigation, tabColors);
}
} else {
if (addItems) {
AHBottomNavigationItem item4 = new AHBottomNavigationItem(getString(R.string.tab_4), ContextCompat.getDrawable(this, R.drawable.ic_maps_local_bar), ContextCompat.getColor(this, R.color.color_tab_4));
AHBottomNavigationItem item5 = new AHBottomNavigationItem(getString(R.string.tab_5), ContextCompat.getDrawable(this, R.drawable.ic_maps_place), ContextCompat.getColor(this, R.color.color_tab_5));
bottomNavigation.addItem(item4);
bottomNavigation.addItem(item5);
bottomNavigation.setNotification("1", 3);
} else {
bottomNavigation.removeAllItems();
bottomNavigation.addItems(bottomNavigationItems);
}
}
}
use of com.aurelhubert.ahbottomnavigation.AHBottomNavigationAdapter in project ahbottomnavigation by aurelhubert.
the class DemoActivity method initUI.
/**
* Init UI
*/
private void initUI() {
bottomNavigation = (AHBottomNavigation) findViewById(R.id.bottom_navigation);
viewPager = (AHBottomNavigationViewPager) findViewById(R.id.view_pager);
floatingActionButton = (FloatingActionButton) findViewById(R.id.floating_action_button);
if (useMenuResource) {
tabColors = getApplicationContext().getResources().getIntArray(R.array.tab_colors);
navigationAdapter = new AHBottomNavigationAdapter(this, R.menu.bottom_navigation_menu_3);
navigationAdapter.setupWithBottomNavigation(bottomNavigation, tabColors);
} else {
AHBottomNavigationItem item1 = new AHBottomNavigationItem(R.string.tab_1, R.drawable.ic_apps_black_24dp, R.color.color_tab_1);
AHBottomNavigationItem item2 = new AHBottomNavigationItem(R.string.tab_2, R.drawable.ic_maps_local_bar, R.color.color_tab_2);
AHBottomNavigationItem item3 = new AHBottomNavigationItem(R.string.tab_3, R.drawable.ic_maps_local_restaurant, R.color.color_tab_3);
bottomNavigationItems.add(item1);
bottomNavigationItems.add(item2);
bottomNavigationItems.add(item3);
bottomNavigation.addItems(bottomNavigationItems);
}
bottomNavigation.manageFloatingActionButtonBehavior(floatingActionButton);
bottomNavigation.setTranslucentNavigationEnabled(true);
bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
@Override
public boolean onTabSelected(int position, boolean wasSelected) {
if (currentFragment == null) {
currentFragment = adapter.getCurrentFragment();
}
if (wasSelected) {
currentFragment.refresh();
return true;
}
if (currentFragment != null) {
currentFragment.willBeHidden();
}
viewPager.setCurrentItem(position, false);
currentFragment = adapter.getCurrentFragment();
currentFragment.willBeDisplayed();
if (position == 1) {
bottomNavigation.setNotification("", 1);
floatingActionButton.setVisibility(View.VISIBLE);
floatingActionButton.setAlpha(0f);
floatingActionButton.setScaleX(0f);
floatingActionButton.setScaleY(0f);
floatingActionButton.animate().alpha(1).scaleX(1).scaleY(1).setDuration(300).setInterpolator(new OvershootInterpolator()).setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
floatingActionButton.animate().setInterpolator(new LinearOutSlowInInterpolator()).start();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
}).start();
} else {
if (floatingActionButton.getVisibility() == View.VISIBLE) {
floatingActionButton.animate().alpha(0).scaleX(0).scaleY(0).setDuration(300).setInterpolator(new LinearOutSlowInInterpolator()).setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
floatingActionButton.setVisibility(View.GONE);
}
@Override
public void onAnimationCancel(Animator animation) {
floatingActionButton.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animator animation) {
}
}).start();
}
}
return true;
}
});
/*
bottomNavigation.setOnNavigationPositionListener(new AHBottomNavigation.OnNavigationPositionListener() {
@Override public void onPositionChange(int y) {
Log.d("DemoActivity", "BottomNavigation Position: " + y);
}
});
*/
viewPager.setOffscreenPageLimit(4);
adapter = new DemoViewPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
currentFragment = adapter.getCurrentFragment();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Setting custom colors for notification
AHNotification notification = new AHNotification.Builder().setText(":)").setBackgroundColor(ContextCompat.getColor(DemoActivity.this, R.color.color_notification_back)).setTextColor(ContextCompat.getColor(DemoActivity.this, R.color.color_notification_text)).build();
bottomNavigation.setNotification(notification, 1);
Snackbar.make(bottomNavigation, "Snackbar with bottom navigation", Snackbar.LENGTH_SHORT).show();
}
}, 3000);
//bottomNavigation.setDefaultBackgroundResource(R.drawable.bottom_navigation_background);
}
Aggregations