Java Code Examples for android.support.design.widget.FloatingActionButton#getY()

The following examples show how to use android.support.design.widget.FloatingActionButton#getY() . 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: DotsFragment.java    From android-material-motion with Apache License 2.0 5 votes vote down vote up
@OnClick({R.id.first, R.id.third})
public void revealSides(FloatingActionButton dot) {
  if (finished) {
    finished = false;
    lastDot = dot;
    float deltaX = topPanel.getWidth() / 2 - dot.getX() - dot.getWidth() / 2;
    float deltaY = topPanel.getHeight() / 2 - dot.getY() - dot.getHeight() / 2;
    deltaY -= topPanel.getHeight() / 2 + getResources().getDimension(R.dimen.morph_radius) / 4;
    Path arcPath = createArcPath(dot, deltaX, deltaY, -deltaX);
    ValueAnimator pathAnimator = ValueAnimator.ofFloat(0, 1);
    pathAnimator.addUpdateListener(new ArcListener(arcPath, dot));
    int dotColor = dot.getBackgroundTintList().getDefaultColor();
    topPanel.setBackgroundColor(dotColor);
    if (dotColor == color) {
      backgroundReveal().start();
    }
    pathAnimator.addListener(new AnimatorListenerAdapter() {
      @Override
      public void onAnimationEnd(Animator animation) {
        super.onAnimationEnd(animation);
        Animator animator = createRevealAnimator(dot, 0);
        finish(animator);
        animator.start();
        runCloseAnimation();
      }
    });
    AnimatorSet animatorSet = morphParent(duration(R.integer.reveal_duration));
    animatorSet.play(pathAnimator);
    addScaleAnimation(duration(R.integer.short_delay), duration(R.integer.fade_duration), animatorSet);
    animatorSet.start();
  }
}
 
Example 2
Source File: DotsFragment.java    From android-material-motion with Apache License 2.0 5 votes vote down vote up
private Animator createRevealAnimator(FloatingActionButton dot, float offsetY) {
  ViewCompat.setElevation(dot, 0);
  dot.setVisibility(View.INVISIBLE);
  lastDot = dot;
  int cx = (int) (dot.getX() + dot.getHeight() / 2);
  int cy = (int) (dot.getY() + dot.getHeight() / 2 + offsetY);
  int w = topPanel.getWidth();
  int h = topPanel.getHeight();
  final int endRadius = !isFolded ? (int) Math.hypot(w, h) : dot.getHeight() / 2;
  final int startRadius = isFolded ? (int) Math.hypot(w, h) : dot.getHeight() / 2;
  topPanel.setVisibility(View.VISIBLE);
  Animator animator = ViewAnimationUtils.createCircularReveal(topPanel, cx, cy, startRadius, endRadius);
  animator.setDuration(duration(R.integer.reveal_duration));
  return animator;
}
 
Example 3
Source File: ScrollAwareFABBehavior.java    From Nibo with MIT License 5 votes vote down vote up
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
    /**
     * Because we are not moving it, we always return false in this method.
     */

    if (offset == 0)
        setOffsetValue(parent);

    if (mBottomSheetBehaviorRef == null)
        getBottomSheetBehavior(parent);

    int DyFix = getDyBetweenChildAndDependency(child, dependency);

    if ((child.getY() + DyFix) < offset)
        child.hide();
    else if ((child.getY() + DyFix) >= offset) {

        /**
         * We are calculating every time point in Y where BottomSheet get {@link BottomSheetBehaviorGoogleMapsLike#STATE_COLLAPSED}.
         * If PeekHeight change dynamically we can reflect the behavior asap.
         */
        if (mBottomSheetBehaviorRef == null || mBottomSheetBehaviorRef.get() == null)
            getBottomSheetBehavior(parent);
        int collapsedY = dependency.getHeight() - mBottomSheetBehaviorRef.get().getPeekHeight();

        if ((child.getY() + DyFix) > collapsedY)
            child.hide();
        else
            child.show();
    }

    return false;
}
 
Example 4
Source File: ScrollAwareFABBehavior.java    From Nibo with MIT License 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 5
Source File: ScrollAwareFABBehavior.java    From react-native-bottom-sheet-behavior with MIT License 5 votes vote down vote up
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
    /**
     * Because we are not moving it, we always return false in this method.
     */

    if (offset == 0)
        setOffsetValue(parent);

    if (mBottomSheetBehaviorRef == null)
        getBottomSheetBehavior(parent);

    int DyFix = getDyBetweenChildAndDependency(child, dependency);

    if ((child.getY() + DyFix) < offset)
        child.hide();
    else if ((child.getY() + DyFix) >= offset) {

        /**
         * We are calculating every time point in Y where BottomSheet get {@link BottomSheetBehaviorGoogleMapsLike#STATE_COLLAPSED}.
         * If PeekHeight change dynamically we can reflect the behavior asap.
         */
        if (mBottomSheetBehaviorRef == null || mBottomSheetBehaviorRef.get() == null)
            getBottomSheetBehavior(parent);
        int collapsedY = dependency.getHeight() - mBottomSheetBehaviorRef.get().getPeekHeight();

        if ((child.getY() + DyFix) > collapsedY)
            child.hide();
        else
            child.show();
    }

    return false;
}
 
Example 6
Source File: ScrollAwareFABBehavior.java    From react-native-bottom-sheet-behavior with MIT License 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;
}