Java Code Examples for android.support.design.widget.CoordinatorLayout#getDependencies()

The following examples show how to use android.support.design.widget.CoordinatorLayout#getDependencies() . 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: BottomNavBarFabBehaviour.java    From JD-Test with Apache License 2.0 6 votes vote down vote up
private float[] getFabTranslationYForBottomNavigationBar(CoordinatorLayout parent,
                                                         FloatingActionButton fab) {
    float minOffset = 0;
    float viewHeight = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof BottomNavigationBar) {
            viewHeight = view.getHeight();
            minOffset = Math.min(minOffset,
                    ViewCompat.getTranslationY(view) - viewHeight);
        }
    }
    float[] returnValues = {minOffset, viewHeight};

    return returnValues;
}
 
Example 2
Source File: SkittleContainer.java    From Skittles with MIT License 6 votes vote down vote up
private float getFabTranslationYForSnackbar(CoordinatorLayout parent,
    SkittleContainer container) {
  float minOffset = 0.0F;
  List dependencies = parent.getDependencies(container);
  int i = 0;

  for (int z = dependencies.size(); i < z; ++i) {
    View view = (View) dependencies.get(i);
    if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(container, view)) {
      minOffset =
          Math.min(minOffset, ViewCompat.getTranslationY(view) - (float) view.getHeight());
    }
  }

  return minOffset;
}
 
Example 3
Source File: HeaderScrollingViewBehavior.java    From UcMainPagerDemo with Apache License 2.0 6 votes vote down vote up
@Override
protected void layoutChild(final CoordinatorLayout parent, final View child, final int layoutDirection) {
    final List<View> dependencies = parent.getDependencies(child);
    final View header = findFirstDependency(dependencies);

    if (header != null) {
        final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
        final Rect available = mTempRect1;
        available.set(parent.getPaddingLeft() + lp.leftMargin, header.getBottom() + lp.topMargin,
                parent.getWidth() - parent.getPaddingRight() - lp.rightMargin,
                parent.getHeight() + header.getBottom() - parent.getPaddingBottom() - lp.bottomMargin);

        final Rect out = mTempRect2;
        GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), available, out, layoutDirection);

        final int overlap = getOverlapPixelsForOffset(header);

        child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
        mVerticalLayoutGap = out.top - header.getBottom();
    } else {
        // If we don't have a dependency, let super handle it
        super.layoutChild(parent, child, layoutDirection);
        mVerticalLayoutGap = 0;
    }
}
 
Example 4
Source File: HeaderScrollingViewBehavior.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
@Override
protected void layoutChild(final CoordinatorLayout parent, final View child, final int layoutDirection) {
    final List<View> dependencies = parent.getDependencies(child);
    final View header = findFirstDependency(dependencies);

    if (header != null) {
        final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
        final Rect available = mTempRect1;
        available.set(parent.getPaddingLeft() + lp.leftMargin, header.getBottom() + lp.topMargin,
                parent.getWidth() - parent.getPaddingRight() - lp.rightMargin,
                parent.getHeight() + header.getBottom() - parent.getPaddingBottom() - lp.bottomMargin);

        final Rect out = mTempRect2;
        GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), available, out, layoutDirection);

        final int overlap = getOverlapPixelsForOffset(header);

        child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
        mVerticalLayoutGap = out.top - header.getBottom();
    } else {
        // If we don't have a dependency, let super handle it
        super.layoutChild(parent, child, layoutDirection);
        mVerticalLayoutGap = 0;
    }
}
 
Example 5
Source File: HeaderScrollingViewBehavior.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
@Override
protected void layoutChild(final CoordinatorLayout parent, final View child, final int layoutDirection) {
    final List<View> dependencies = parent.getDependencies(child);
    final View header = findFirstDependency(dependencies);

    if (header != null) {
        final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
        final Rect available = mTempRect1;
        available.set(parent.getPaddingLeft() + lp.leftMargin, header.getBottom() + lp.topMargin,
                parent.getWidth() - parent.getPaddingRight() - lp.rightMargin,
                parent.getHeight() + header.getBottom() - parent.getPaddingBottom() - lp.bottomMargin);

        final Rect out = mTempRect2;
        GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), available, out, layoutDirection);

        final int overlap = getOverlapPixelsForOffset(header);

        child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
        mVerticalLayoutGap = out.top - header.getBottom();
    } else {
        // If we don't have a dependency, let super handle it
        super.layoutChild(parent, child, layoutDirection);
        mVerticalLayoutGap = 0;
    }
}
 
Example 6
Source File: HeaderScrollingViewBehavior.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
@Override
protected void layoutChild(final CoordinatorLayout parent, final View child, final int layoutDirection) {
    final List<View> dependencies = parent.getDependencies(child);
    final View header = findFirstDependency(dependencies);

    if (header != null) {
        final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
        final Rect available = mTempRect1;
        available.set(parent.getPaddingLeft() + lp.leftMargin, header.getBottom() + lp.topMargin,
                parent.getWidth() - parent.getPaddingRight() - lp.rightMargin,
                parent.getHeight() + header.getBottom() - parent.getPaddingBottom() - lp.bottomMargin);

        final Rect out = mTempRect2;
        GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), available, out, layoutDirection);

        final int overlap = getOverlapPixelsForOffset(header);

        child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
        mVerticalLayoutGap = out.top - header.getBottom();
    } else {
        // If we don't have a dependency, let super handle it
        super.layoutChild(parent, child, layoutDirection);
        mVerticalLayoutGap = 0;
    }
}
 
Example 7
Source File: FabSpeedDialBehaviour.java    From fab-speed-dial with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onLayoutChild(CoordinatorLayout parent, FabSpeedDial child, int layoutDirection) {
    // First, lets make sure that the visibility of the FAB is consistent
    final List<View> dependencies = parent.getDependencies(child);
    for (int i = 0, count = dependencies.size(); i < count; i++) {
        final View dependency = dependencies.get(i);
        if (dependency instanceof AppBarLayout
                && updateFabVisibility(parent, (AppBarLayout) dependency, child)) {
            break;
        }
    }
    // Now let the CoordinatorLayout lay out the FAB
    parent.onLayoutChild(child, layoutDirection);
    return true;
}
 
Example 8
Source File: FABSnackbarBehavior.java    From FABsMenu with Apache License 2.0 5 votes vote down vote up
/**
 * Find the {@code translation Y} value for any child Snackbar components.
 *
 * @return 0.0F if there are no Snackbar components found, otherwise returns the min offset that
 * the FAB component should be animated.
 */
private float getFabTranslationYForSnackbar(CoordinatorLayout parent, View fab) {
    float minOffset = 0.0F;
    final List<View> dependencies = parent.getDependencies(fab);

    for (View view : dependencies) {
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) {
            minOffset = Math.min(minOffset, view.getTranslationY() - (float) view.getHeight());
        }
    }

    return minOffset;
}
 
Example 9
Source File: FabSpeedDialBehaviour.java    From fab-speed-dial with Apache License 2.0 5 votes vote down vote up
private float getFabTranslationYForSnackbar(CoordinatorLayout parent,
                                            FabSpeedDial fab) {
    float minOffset = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) {
            minOffset = Math.min(minOffset,
                    ViewCompat.getTranslationY(view) - view.getHeight());
        }
    }

    return minOffset;
}
 
Example 10
Source File: RotateBehavior.java    From CustomBehavior with Apache License 2.0 5 votes vote down vote up
private float getFabTranslationYForSnackbar(CoordinatorLayout parent,
                                            FloatingActionButton fab) {
    float minOffset = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) {
            minOffset = Math.min(minOffset,
                    ViewCompat.getTranslationY(view) - view.getHeight());
        }
    }

    return minOffset;
}
 
Example 11
Source File: ShrinkBehavior.java    From CustomBehavior with Apache License 2.0 5 votes vote down vote up
private float getFabTranslationYForSnackbar(CoordinatorLayout parent,
                                            FloatingActionButton fab) {
    float minOffset = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) {
            minOffset = Math.min(minOffset,
                    ViewCompat.getTranslationY(view) - view.getHeight());
        }
    }

    return minOffset;
}
 
Example 12
Source File: BottomButton.java    From citrus with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param parent
 * @param bb
 * @return
 */
private float getFabTranslationYForSnackbar(CoordinatorLayout parent, BottomButton bb) {
    float minOffset = 0.0F;
    List dependencies = parent.getDependencies(bb);
    int i = 0;

    for (int z = dependencies.size(); i < z; ++i) {
        View view = (View) dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(bb, view)) {
            minOffset = Math.min(minOffset, ViewCompat.getTranslationY(view) - (float) view.getHeight());
        }
    }

    return minOffset;
}
 
Example 13
Source File: FabSpeedDialBehaviour.java    From fab-speed-dial with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onLayoutChild(CoordinatorLayout parent, FabSpeedDial child, int layoutDirection) {
    // First, lets make sure that the visibility of the FAB is consistent
    final List<View> dependencies = parent.getDependencies(child);
    for (int i = 0, count = dependencies.size(); i < count; i++) {
        final View dependency = dependencies.get(i);
        if (dependency instanceof AppBarLayout
                && updateFabVisibility(parent, (AppBarLayout) dependency, child)) {
            break;
        }
    }
    // Now let the CoordinatorLayout lay out the FAB
    parent.onLayoutChild(child, layoutDirection);
    return true;
}
 
Example 14
Source File: FabSpeedDialBehaviour.java    From fab-speed-dial with Apache License 2.0 5 votes vote down vote up
private float getFabTranslationYForSnackbar(CoordinatorLayout parent,
                                            FabSpeedDial fab) {
    float minOffset = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) {
            minOffset = Math.min(minOffset,
                    ViewCompat.getTranslationY(view) - view.getHeight());
        }
    }

    return minOffset;
}
 
Example 15
Source File: ShrinkBehavior.java    From AndroidDesignWidgetsSample with Apache License 2.0 5 votes vote down vote up
private float getFabTranslationYForSnackbar(CoordinatorLayout parent,
                                            FloatingActionButton fab) {
    float minOffset = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) {
            Log.d("ddmeng", "getTranslationY " + ViewCompat.getTranslationY(view) + ", getHeight() " + view.getHeight());
            minOffset = Math.min(minOffset, ViewCompat.getTranslationY(view) - view.getHeight());
        }
    }

    return minOffset;
}
 
Example 16
Source File: FooterBehavior.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
private float getTranslationYForSnackbar(CoordinatorLayout parent, FooterLayout footerLayout) {

        float minOffset = 0;
        final List<View> dependencies = parent.getDependencies(footerLayout);
        for (int i = 0, z = dependencies.size(); i < z; i++) {
            final View view = dependencies.get(i);
            if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(footerLayout, view)) {
                minOffset = Math.min(minOffset, ViewCompat.getTranslationY(view) - view.getHeight());
            }
        }

        return minOffset;
    }
 
Example 17
Source File: FloatingActionButtonBehavior.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onDependentViewChanged(@NonNull
                                                final CoordinatorLayout parent, @NonNull
                                                final FloatingActionButton child, final View dependency) {
    log(TAG, INFO, "onDependentViewChanged: " + dependency);
    final List<View> list = parent.getDependencies(child);
    ViewGroup.MarginLayoutParams params = ((ViewGroup.MarginLayoutParams) child.getLayoutParams());
    int bottomMargin = (params.bottomMargin + params.rightMargin) - (params.topMargin + params.leftMargin);
    float t = 0;
    float t2 = 0;
    float t3 = 0;
    boolean result = false;
    for (View dep : list) {
        if (Snackbar.SnackbarLayout.class.isInstance(dep)) {
            t += dep.getTranslationY() - dep.getHeight();
            result = true;
        } else if (BottomNavigation.class.isInstance(dep)) {
            BottomNavigation navigation = (BottomNavigation) dep;
            t2 = navigation.getTranslationY() - navigation.getHeight() + bottomMargin;
            t += t2;
            result = true;

            if (navigationBarHeight > 0) {
                if (!navigation.isExpanded()) {
                    child.hide();
                } else {
                    child.show();
                }
            }
        }
    }

    if (navigationBarHeight > 0 && t2 < 0) {
        t = Math.min(t2, t + navigationBarHeight);
    }

    child.setTranslationY(t);
    return result;
}
 
Example 18
Source File: BottomNavBarFabBehaviour.java    From JD-Test with Apache License 2.0 5 votes vote down vote up
private float getFabTranslationYForSnackBar(CoordinatorLayout parent,
                                            FloatingActionButton fab) {
    float minOffset = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) {
            minOffset = Math.min(minOffset,
                    ViewCompat.getTranslationY(view) - view.getHeight());
        }
    }

    return minOffset;
}
 
Example 19
Source File: BottomVerticalScrollBehavior.java    From JD-Test with Apache License 2.0 5 votes vote down vote up
private Snackbar.SnackbarLayout getSnackBarInstance(CoordinatorLayout parent, V child) {
    final List<View> dependencies = parent.getDependencies(child);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout) {
            return (Snackbar.SnackbarLayout) view;
        }
    }
    return null;
}