|
24 | 24 | import android.os.Parcelable; |
25 | 25 | import android.support.annotation.DrawableRes; |
26 | 26 | import android.support.annotation.MenuRes; |
| 27 | +import android.support.annotation.NonNull; |
27 | 28 | import android.support.annotation.Nullable; |
28 | 29 | import android.support.design.widget.AppBarLayout; |
29 | 30 | import android.support.design.widget.CoordinatorLayout; |
30 | 31 | import android.support.design.widget.FloatingActionButton; |
31 | | -import android.support.design.widget.Snackbar; |
32 | | -import android.support.v4.view.ViewCompat; |
33 | 32 | import android.support.v7.view.SupportMenuInflater; |
34 | 33 | import android.support.v7.view.menu.MenuBuilder; |
35 | 34 | import android.support.v7.widget.AppCompatImageButton; |
36 | 35 | import android.support.v7.widget.LinearLayoutCompat; |
37 | 36 | import android.support.v7.widget.RecyclerView; |
38 | 37 | import android.util.AttributeSet; |
39 | | -import android.util.DisplayMetrics; |
40 | 38 | import android.util.TypedValue; |
41 | 39 | import android.view.Gravity; |
42 | 40 | import android.view.LayoutInflater; |
|
45 | 43 | import android.view.View; |
46 | 44 | import android.view.ViewGroup; |
47 | 45 | import android.view.ViewTreeObserver; |
48 | | -import android.view.animation.AccelerateDecelerateInterpolator; |
49 | 46 | import android.widget.Toast; |
50 | 47 |
|
51 | 48 | import java.util.ArrayList; |
@@ -519,81 +516,13 @@ public interface MorphListener { |
519 | 516 | // FloatingActionButton.Behavior adapted |
520 | 517 | public static class Behavior extends CoordinatorLayout.Behavior<FloatingToolbar> { |
521 | 518 |
|
522 | | - private float mTranslationY; |
523 | | - private ValueAnimator mTranslationYAnimator; |
524 | | - |
525 | | - @Override |
526 | | - public boolean layoutDependsOn(CoordinatorLayout parent, FloatingToolbar child, |
527 | | - View dependency) { |
528 | | - return dependency instanceof Snackbar.SnackbarLayout; |
529 | | - } |
530 | | - |
531 | 519 | @Override |
532 | | - public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingToolbar child, |
533 | | - View dependency) { |
534 | | - |
535 | | - if (dependency instanceof Snackbar.SnackbarLayout) { |
536 | | - updateTranslationForSnackbar(parent, child); |
537 | | - } |
538 | | - return false; |
539 | | - } |
540 | | - |
541 | | - @Override |
542 | | - public void onDependentViewRemoved(CoordinatorLayout parent, FloatingToolbar child, |
543 | | - View dependency) { |
544 | | - if (dependency instanceof Snackbar.SnackbarLayout) { |
545 | | - updateTranslationForSnackbar(parent, child); |
546 | | - } |
547 | | - } |
548 | | - |
549 | | - private void updateTranslationForSnackbar(CoordinatorLayout parent, |
550 | | - final FloatingToolbar layout) { |
551 | | - |
552 | | - final float targetTransY = getTranslationYForSnackbar(parent, layout); |
553 | | - if (mTranslationY == targetTransY) { |
554 | | - return; |
555 | | - } |
556 | | - |
557 | | - final float currentTransY = ViewCompat.getTranslationY(layout); |
558 | | - |
559 | | - if (mTranslationYAnimator != null && mTranslationYAnimator.isRunning()) { |
560 | | - mTranslationYAnimator.cancel(); |
561 | | - } |
562 | | - |
563 | | - if (layout.isShowing() |
564 | | - && Math.abs(currentTransY - targetTransY) > (layout.getHeight() * 0.667f)) { |
565 | | - if (mTranslationYAnimator == null) { |
566 | | - mTranslationYAnimator = new ValueAnimator(); |
567 | | - mTranslationYAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); |
568 | | - mTranslationYAnimator.addUpdateListener( |
569 | | - new ValueAnimator.AnimatorUpdateListener() { |
570 | | - @Override |
571 | | - public void onAnimationUpdate(ValueAnimator animator) { |
572 | | - ViewCompat.setTranslationY(layout, animator.getAnimatedFraction()); |
573 | | - } |
574 | | - }); |
575 | | - } |
576 | | - mTranslationYAnimator.setFloatValues(currentTransY, targetTransY); |
577 | | - mTranslationYAnimator.start(); |
578 | | - } else { |
579 | | - ViewCompat.setTranslationY(layout, targetTransY); |
| 520 | + public void onAttachedToLayoutParams(@NonNull CoordinatorLayout.LayoutParams lp) { |
| 521 | + if (lp.dodgeInsetEdges == Gravity.NO_GRAVITY) { |
| 522 | + // If the developer hasn't set dodgeInsetEdges, lets set it to BOTTOM so that |
| 523 | + // we dodge any Snackbars |
| 524 | + lp.dodgeInsetEdges = Gravity.BOTTOM; |
580 | 525 | } |
581 | | - |
582 | | - mTranslationY = targetTransY; |
583 | | - } |
584 | | - |
585 | | - private float getTranslationYForSnackbar(CoordinatorLayout parent, FloatingToolbar layout) { |
586 | | - float minOffset = 0; |
587 | | - final List<View> dependencies = parent.getDependencies(layout); |
588 | | - for (int i = 0, z = dependencies.size(); i < z; i++) { |
589 | | - final View view = dependencies.get(i); |
590 | | - if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(layout, view)) { |
591 | | - minOffset = Math.min(minOffset, |
592 | | - ViewCompat.getTranslationY(view) - view.getHeight()); |
593 | | - } |
594 | | - } |
595 | | - |
596 | | - return minOffset; |
597 | 526 | } |
598 | 527 | } |
599 | 528 |
|
|
0 commit comments