Search in sources :

Example 1 with AHNotification

use of com.aurelhubert.ahbottomnavigation.notification.AHNotification 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);
}
Also used : OvershootInterpolator(android.view.animation.OvershootInterpolator) AHBottomNavigation(com.aurelhubert.ahbottomnavigation.AHBottomNavigation) LinearOutSlowInInterpolator(android.support.v4.view.animation.LinearOutSlowInInterpolator) Animator(android.animation.Animator) AHNotification(com.aurelhubert.ahbottomnavigation.notification.AHNotification) AHBottomNavigationAdapter(com.aurelhubert.ahbottomnavigation.AHBottomNavigationAdapter) AHBottomNavigationItem(com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem)

Example 2 with AHNotification

use of com.aurelhubert.ahbottomnavigation.notification.AHNotification in project ahbottomnavigation by aurelhubert.

the class AHBottomNavigation method updateNotifications.

/**
	 * Update notifications
	 */
private void updateNotifications(boolean updateStyle, int itemPosition) {
    for (int i = 0; i < views.size(); i++) {
        if (itemPosition != UPDATE_ALL_NOTIFICATIONS && itemPosition != i) {
            continue;
        }
        final AHNotification notificationItem = notifications.get(i);
        final int currentTextColor = AHNotificationHelper.getTextColor(notificationItem, notificationTextColor);
        final int currentBackgroundColor = AHNotificationHelper.getBackgroundColor(notificationItem, notificationBackgroundColor);
        TextView notification = (TextView) views.get(i).findViewById(R.id.bottom_navigation_notification);
        String currentValue = notification.getText().toString();
        boolean animate = !currentValue.equals(String.valueOf(notificationItem.getText()));
        if (updateStyle) {
            notification.setTextColor(currentTextColor);
            if (notificationTypeface != null) {
                notification.setTypeface(notificationTypeface);
            } else {
                notification.setTypeface(null, Typeface.BOLD);
            }
            if (notificationBackgroundDrawable != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    Drawable drawable = notificationBackgroundDrawable.getConstantState().newDrawable();
                    notification.setBackground(drawable);
                } else {
                    notification.setBackgroundDrawable(notificationBackgroundDrawable);
                }
            } else if (currentBackgroundColor != 0) {
                Drawable defautlDrawable = ContextCompat.getDrawable(context, R.drawable.notification_background);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    notification.setBackground(AHHelper.getTintDrawable(defautlDrawable, currentBackgroundColor, forceTint));
                } else {
                    notification.setBackgroundDrawable(AHHelper.getTintDrawable(defautlDrawable, currentBackgroundColor, forceTint));
                }
            }
        }
        if (notificationItem.isEmpty() && notification.getText().length() > 0) {
            notification.setText("");
            if (animate) {
                notification.animate().scaleX(0).scaleY(0).alpha(0).setInterpolator(new AccelerateInterpolator()).setDuration(150).start();
            }
        } else if (!notificationItem.isEmpty()) {
            notification.setText(String.valueOf(notificationItem.getText()));
            if (animate) {
                notification.setScaleX(0);
                notification.setScaleY(0);
                notification.animate().scaleX(1).scaleY(1).alpha(1).setInterpolator(new OvershootInterpolator()).setDuration(150).start();
            }
        }
    }
}
Also used : AccelerateInterpolator(android.view.animation.AccelerateInterpolator) OvershootInterpolator(android.view.animation.OvershootInterpolator) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) AHNotification(com.aurelhubert.ahbottomnavigation.notification.AHNotification) SuppressLint(android.annotation.SuppressLint)

Example 3 with AHNotification

use of com.aurelhubert.ahbottomnavigation.notification.AHNotification in project ahbottomnavigation by aurelhubert.

the class AHBottomNavigation method setNotification.

/**
     * Set fully customized Notification
     *
     * @param notification AHNotification
     * @param itemPosition int
     */
public void setNotification(AHNotification notification, int itemPosition) {
    if (itemPosition < 0 || itemPosition > items.size() - 1) {
        throw new IndexOutOfBoundsException(String.format(Locale.US, EXCEPTION_INDEX_OUT_OF_BOUNDS, itemPosition, items.size()));
    }
    if (notification == null) {
        // instead of null, use empty notification
        notification = new AHNotification();
    }
    notifications.set(itemPosition, notification);
    updateNotifications(true, itemPosition);
}
Also used : AHNotification(com.aurelhubert.ahbottomnavigation.notification.AHNotification)

Aggregations

AHNotification (com.aurelhubert.ahbottomnavigation.notification.AHNotification)3 OvershootInterpolator (android.view.animation.OvershootInterpolator)2 Animator (android.animation.Animator)1 SuppressLint (android.annotation.SuppressLint)1 Drawable (android.graphics.drawable.Drawable)1 LinearOutSlowInInterpolator (android.support.v4.view.animation.LinearOutSlowInInterpolator)1 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)1 TextView (android.widget.TextView)1 AHBottomNavigation (com.aurelhubert.ahbottomnavigation.AHBottomNavigation)1 AHBottomNavigationAdapter (com.aurelhubert.ahbottomnavigation.AHBottomNavigationAdapter)1 AHBottomNavigationItem (com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem)1