Java Code Examples for com.google.android.material.floatingactionbutton.FloatingActionButton#getHeight()

The following examples show how to use com.google.android.material.floatingactionbutton.FloatingActionButton#getHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScrollAwareFABBehavior.java    From CustomBottomSheetBehavior with Apache License 2.0 5 votes vote down vote up
/**
 * In some <bold>WEIRD</bold> cases, mostly when you perform a little scroll but a fast one
 * the {@link #onDependentViewChanged(CoordinatorLayout, FloatingActionButton, View)} DOESN'T
 * reflect the real Y position of child mean the dependency get a better APROXIMATION of the real
 * Y. This was causing that FAB some times doesn't get unhidden.
 * @param child the FAB
 * @param dependency NestedScrollView instance
 * @return Dy betweens those 2 elements in Y, minus child's height/2
 */
private int getDyBetweenChildAndDependency(@NonNull FloatingActionButton child, @NonNull View dependency) {
    if (dependency.getY() == 0 || dependency.getY() < offset)
        return 0;

    if ( (dependency.getY() - child.getY()) > child.getHeight() )
        return Math.max(0, (int) ((dependency.getY() - (child.getHeight()/2)) - child.getY()) );
    else
        return 0;
}
 
Example 2
Source File: BottomNavBarFabBehaviour.java    From BottomNavigation with Apache License 2.0 5 votes vote down vote up
private void updateFabTranslationForBottomNavigationBar(CoordinatorLayout parent, FloatingActionButton fab, View dependency) {

        float snackBarTranslation = getFabTranslationYForSnackBar(parent, fab);
        float[] bottomBarParameters = getFabTranslationYForBottomNavigationBar(parent, fab);
        float bottomBarTranslation = bottomBarParameters[0];
        float bottomBarHeight = bottomBarParameters[1];

        float targetTransY;
        if (snackBarTranslation >= bottomBarTranslation) {
            // when snackBar is below BottomBar in translation present.
            targetTransY = bottomBarTranslation;
        } else {
            targetTransY = snackBarTranslation;
        }

//        if (mFabBehaviour == BottomNavigationBar.FAB_BEHAVIOUR_DISAPPEAR) {
//            if (targetTransY == 0) {
//                fab.hide();
//            } else {
//                fab.show();
//            }
//        }

        final float currentTransY = fab.getTranslationY();

        // Make sure that any current animation is cancelled
        ensureOrCancelAnimator(fab);


        if (fab.isShown()
                && Math.abs(currentTransY - targetTransY) > (fab.getHeight() * 0.667f)) {
            // If the FAB will be travelling by more than 2/3 of it's height, let's animate it instead
            mFabTranslationYAnimator.translationY(targetTransY).start();
        } else {
            // Now update the translation Y
            fab.setTranslationY(targetTransY);
        }
    }
 
Example 3
Source File: AppBarBoundFabBehavior.java    From appbarsyncedfab with Apache License 2.0 4 votes vote down vote up
private void updateFabTranslationForSnackbar(CoordinatorLayout parent,
                                             final FloatingActionButton fab, View snackbar) {

    // We want to introduce additional y-translation (with respect to what's already there),
    // by the current visible height of any snackbar
    final float targetTransYByThis = getVisibleHeightOfOverlappingSnackbar(parent, fab);

    if (snackbarFabTranslationYByThis == targetTransYByThis) {
        // We're already at (or currently animating to) the target value, return...
        return;
    }

    final float currentTransY = fab.getTranslationY();

    // Calculate difference between what we want now and what we wanted earlier
    final float stepTransYDelta = targetTransYByThis - snackbarFabTranslationYByThis;

    // ... and we're going to change the current state just by the difference
    final float targetTransY = currentTransY + stepTransYDelta;

    // Make sure that any current animation is cancelled
    if (snackbarFabTranslationYAnimator != null && snackbarFabTranslationYAnimator.isRunning()) {
        snackbarFabTranslationYAnimator.cancel();
    }

    if (fab.isShown()
            && Math.abs(currentTransY - targetTransY) > (fab.getHeight() * 0.667f)) {
        // If the FAB will be travelling by more than 2/3 of it's height, let's animate
        // it instead
        if (snackbarFabTranslationYAnimator == null) {
            snackbarFabTranslationYAnimator = ValueAnimator.ofFloat(currentTransY, targetTransY);
            snackbarFabTranslationYAnimator.setInterpolator(new FastOutSlowInInterpolator());
            snackbarFabTranslationYAnimator.addUpdateListener(
                    new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animator) {
                            fab.setTranslationY((Float) animator.getAnimatedValue());
                        }
                    }
            );
        }
        snackbarFabTranslationYAnimator.start();
    } else {
        // Now update the translation Y
        fab.setTranslationY(targetTransY);
    }

    snackbarFabTranslationYByThis = targetTransYByThis;
}