Java Code Examples for androidx.coordinatorlayout.widget.CoordinatorLayout#getChildAt()

The following examples show how to use androidx.coordinatorlayout.widget.CoordinatorLayout#getChildAt() . 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: BackdropBottomSheetBehavior.java    From CustomBottomSheetBehavior with Apache License 2.0 6 votes vote down vote up
/**
 * Look into the CoordiantorLayout for the {@link BottomSheetBehaviorGoogleMapsLike}
 * @param coordinatorLayout with app:layout_behavior= {@link BottomSheetBehaviorGoogleMapsLike}
 */
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {

    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);

        if (child instanceof NestedScrollView) {

            try {
                BottomSheetBehaviorGoogleMapsLike temp = BottomSheetBehaviorGoogleMapsLike.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            }
            catch (IllegalArgumentException e){}
        }
    }
}
 
Example 2
Source File: ScrollAwareFABBehavior.java    From CustomBottomSheetBehavior with Apache License 2.0 6 votes vote down vote up
/**
     * Define one of the point in where the FAB should be hide when it reaches that point.
     * @param coordinatorLayout container of BottomSheet and AppBarLayout
     */
    private void setOffsetValue(CoordinatorLayout coordinatorLayout) {

        for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
            View child = coordinatorLayout.getChildAt(i);

            if (child instanceof MergedAppBarLayout) {
                offset = child.getY()+child.getHeight();
                break;
            }

//            if (child instanceof AppBarLayout) {
//
//                if (child.getTag() != null &&
//                        child.getTag().toString().contentEquals("modal-appbar") ) {
//                    offset = child.getY()+child.getHeight();
//                    break;
//                }
//            }
        }
    }
 
Example 3
Source File: ScrollAwareFABBehavior.java    From CustomBottomSheetBehavior with Apache License 2.0 6 votes vote down vote up
/**
 * Look into the CoordiantorLayout for the {@link BottomSheetBehaviorGoogleMapsLike}
 * @param coordinatorLayout with app:layout_behavior= {@link BottomSheetBehaviorGoogleMapsLike}
 */
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {

    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);

        if (child instanceof NestedScrollView) {

            try {
                BottomSheetBehaviorGoogleMapsLike temp = BottomSheetBehaviorGoogleMapsLike.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            }
            catch (IllegalArgumentException e){}
        }
    }
}
 
Example 4
Source File: MergedAppBarLayoutBehavior.java    From CustomBottomSheetBehavior with Apache License 2.0 6 votes vote down vote up
/**
 * Look into the CoordiantorLayout for the {@link BottomSheetBehaviorGoogleMapsLike}
 * @param coordinatorLayout with app:layout_behavior= {@link BottomSheetBehaviorGoogleMapsLike}
 */
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {

    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);

        if (child instanceof NestedScrollView) {

            try {
                BottomSheetBehaviorGoogleMapsLike temp = BottomSheetBehaviorGoogleMapsLike.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            }
            catch (IllegalArgumentException e){}
        }
    }
}
 
Example 5
Source File: ScrollingAppBarLayoutBehavior.java    From CustomBottomSheetBehavior with Apache License 2.0 6 votes vote down vote up
/**
 * Look into the CoordiantorLayout for the {@link BottomSheetBehaviorGoogleMapsLike}
 * @param coordinatorLayout with app:layout_behavior= {@link BottomSheetBehaviorGoogleMapsLike}
 */
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {

    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);

        if (child instanceof NestedScrollView) {

            try {
                BottomSheetBehaviorGoogleMapsLike temp = BottomSheetBehaviorGoogleMapsLike.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            }
            catch (IllegalArgumentException e){}
        }
    }
}
 
Example 6
Source File: AppBarLayout.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Nullable
private View findFirstScrollingChild(@NonNull CoordinatorLayout parent) {
  for (int i = 0, z = parent.getChildCount(); i < z; i++) {
    final View child = parent.getChildAt(i);
    if (child instanceof NestedScrollingChild
        || child instanceof ListView
        || child instanceof ScrollView) {
      return child;
    }
  }
  return null;
}
 
Example 7
Source File: BottomSheetBehavior.java    From bottomsheetrecycler with Apache License 2.0 4 votes vote down vote up
private void updateImportantForAccessibility(boolean expanded) {
    if (viewRef == null) {
        return;
    }

    ViewParent viewParent = viewRef.get().getParent();
    if (!(viewParent instanceof CoordinatorLayout)) {
        return;
    }

    CoordinatorLayout parent = (CoordinatorLayout) viewParent;
    final int childCount = parent.getChildCount();
    if ((VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) && expanded) {
        if (importantForAccessibilityMap == null) {
            importantForAccessibilityMap = new HashMap<>(childCount);
        } else {
            // The important for accessibility values of the child views have been saved already.
            return;
        }
    }

    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        if (child == viewRef.get()) {
            continue;
        }

        if (!expanded) {
            if (importantForAccessibilityMap != null
                    && importantForAccessibilityMap.containsKey(child)) {
                // Restores the original important for accessibility value of the child view.
                ViewCompat.setImportantForAccessibility(child, importantForAccessibilityMap.get(child));
            }
        } else {
            // Saves the important for accessibility value of the child view.
            if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
                importantForAccessibilityMap.put(child, child.getImportantForAccessibility());
            }

            ViewCompat.setImportantForAccessibility(
                    child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
        }
    }

    if (!expanded) {
        importantForAccessibilityMap = null;
    }
}
 
Example 8
Source File: BottomSheetBehavior.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void updateImportantForAccessibility(boolean expanded) {
  if (viewRef == null) {
    return;
  }

  ViewParent viewParent = viewRef.get().getParent();
  if (!(viewParent instanceof CoordinatorLayout)) {
    return;
  }

  CoordinatorLayout parent = (CoordinatorLayout) viewParent;
  final int childCount = parent.getChildCount();
  if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) && expanded) {
    if (importantForAccessibilityMap == null) {
      importantForAccessibilityMap = new HashMap<>(childCount);
    } else {
      // The important for accessibility values of the child views have been saved already.
      return;
    }
  }

  for (int i = 0; i < childCount; i++) {
    final View child = parent.getChildAt(i);
    if (child == viewRef.get()) {
      continue;
    }

    if (expanded) {
      // Saves the important for accessibility value of the child view.
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        importantForAccessibilityMap.put(child, child.getImportantForAccessibility());
      }
      if (updateImportantForAccessibilityOnSiblings) {
        ViewCompat.setImportantForAccessibility(
            child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
      }
    } else {
      if (updateImportantForAccessibilityOnSiblings
          && importantForAccessibilityMap != null
          && importantForAccessibilityMap.containsKey(child)) {
        // Restores the original important for accessibility value of the child view.
        ViewCompat.setImportantForAccessibility(child, importantForAccessibilityMap.get(child));
      }
    }
  }

  if (!expanded) {
    importantForAccessibilityMap = null;
  }
}
 
Example 9
Source File: FabTransformationSheetBehavior.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void updateImportantForAccessibility(@NonNull View sheet, boolean expanded) {
  ViewParent viewParent = sheet.getParent();
  if (!(viewParent instanceof CoordinatorLayout)) {
    return;
  }

  CoordinatorLayout parent = (CoordinatorLayout) viewParent;
  final int childCount = parent.getChildCount();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && expanded) {
    importantForAccessibilityMap = new HashMap<>(childCount);
  }

  for (int i = 0; i < childCount; i++) {
    final View child = parent.getChildAt(i);

    // Don't change the accessibility importance of the sheet or the scrim.
    boolean hasScrimBehavior =
        (child.getLayoutParams() instanceof CoordinatorLayout.LayoutParams)
            && (((CoordinatorLayout.LayoutParams) child.getLayoutParams()).getBehavior()
                instanceof FabTransformationScrimBehavior);
    if (child == sheet || hasScrimBehavior) {
      continue;
    }

    if (!expanded) {
      if (importantForAccessibilityMap != null
          && importantForAccessibilityMap.containsKey(child)) {
        // Restores the original important for accessibility value of the child view.
        ViewCompat.setImportantForAccessibility(child, importantForAccessibilityMap.get(child));
      }
    } else {
      // Saves the important for accessibility value of the child view.
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        importantForAccessibilityMap.put(child, child.getImportantForAccessibility());
      }

      ViewCompat.setImportantForAccessibility(
          child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
    }
  }

  if (!expanded) {
    importantForAccessibilityMap = null;
  }
}
 
Example 10
Source File: BottomSheetBehavior.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void updateImportantForAccessibility(boolean expanded) {
    if (viewRef == null) {
        return;
    }

    ViewParent viewParent = viewRef.get().getParent();
    if (!(viewParent instanceof CoordinatorLayout)) {
        return;
    }

    CoordinatorLayout parent = (CoordinatorLayout) viewParent;
    final int childCount = parent.getChildCount();
    if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) && expanded) {
        if (importantForAccessibilityMap == null) {
            importantForAccessibilityMap = new HashMap<>(childCount);
        } else {
            // The important for accessibility values of the child views have been saved already.
            return;
        }
    }

    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        if (child == viewRef.get()) {
            continue;
        }

        if (expanded) {
            // Saves the important for accessibility value of the child view.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                importantForAccessibilityMap.put(child, child.getImportantForAccessibility());
            }
            if (updateImportantForAccessibilityOnSiblings) {
                ViewCompat.setImportantForAccessibility(
                        child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
            }
        } else {
            if (updateImportantForAccessibilityOnSiblings
                    && importantForAccessibilityMap != null
                    && importantForAccessibilityMap.containsKey(child)) {
                // Restores the original important for accessibility value of the child view.
                ViewCompat.setImportantForAccessibility(child, importantForAccessibilityMap.get(child));
            }
        }
    }

    if (!expanded) {
        importantForAccessibilityMap = null;
    }
}