Java Code Examples for androidx.coordinatorlayout.widget.CoordinatorLayout#Behavior

The following examples show how to use androidx.coordinatorlayout.widget.CoordinatorLayout#Behavior . 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: EmojiBSFragment.java    From indigenous-android with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("RestrictedApi")
@Override
public void setupDialog(Dialog dialog, int style) {
    super.setupDialog(dialog, style);
    View contentView = View.inflate(getContext(), R.layout.photoeditor_fragment_bottom_sticker_emoji_dialog, null);
    dialog.setContentView(contentView);
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
    CoordinatorLayout.Behavior behavior = params.getBehavior();

    if (behavior instanceof BottomSheetBehavior) {
        ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
    }
    ((View) contentView.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent));
    RecyclerView rvEmoji = contentView.findViewById(R.id.rvEmoji);

    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 5);
    rvEmoji.setLayoutManager(gridLayoutManager);
    EmojiAdapter emojiAdapter = new EmojiAdapter();
    rvEmoji.setAdapter(emojiAdapter);
}
 
Example 2
Source File: EmojiBSFragment.java    From PhotoEditor with MIT License 6 votes vote down vote up
@SuppressLint("RestrictedApi")
@Override
public void setupDialog(Dialog dialog, int style) {
    super.setupDialog(dialog, style);
    View contentView = View.inflate(getContext(), R.layout.fragment_bottom_sticker_emoji_dialog, null);
    dialog.setContentView(contentView);
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
    CoordinatorLayout.Behavior behavior = params.getBehavior();

    if (behavior != null && behavior instanceof BottomSheetBehavior) {
        ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
    }
    ((View) contentView.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent));
    RecyclerView rvEmoji = contentView.findViewById(R.id.rvEmoji);

    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 5);
    rvEmoji.setLayoutManager(gridLayoutManager);
    EmojiAdapter emojiAdapter = new EmojiAdapter();
    rvEmoji.setAdapter(emojiAdapter);
}
 
Example 3
Source File: StickerBSFragment.java    From PhotoEditor with MIT License 6 votes vote down vote up
@SuppressLint("RestrictedApi")
@Override
public void setupDialog(Dialog dialog, int style) {
    super.setupDialog(dialog, style);
    View contentView = View.inflate(getContext(), R.layout.fragment_bottom_sticker_emoji_dialog, null);
    dialog.setContentView(contentView);
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
    CoordinatorLayout.Behavior behavior = params.getBehavior();

    if (behavior != null && behavior instanceof BottomSheetBehavior) {
        ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
    }
    ((View) contentView.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent));
    RecyclerView rvEmoji = contentView.findViewById(R.id.rvEmoji);

    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
    rvEmoji.setLayoutManager(gridLayoutManager);
    StickerAdapter stickerAdapter = new StickerAdapter();
    rvEmoji.setAdapter(stickerAdapter);
}
 
Example 4
Source File: BottomSheetUserDialogFragment.java    From intra42 with Apache License 2.0 6 votes vote down vote up
@Override
public void setupDialog(Dialog dialog, int style) {
    super.setupDialog(dialog, style);
    View contentView = View.inflate(getContext(), R.layout.fragment_bottom_sheet_user, null);
    dialog.setContentView(contentView);

    imageViewProfile = contentView.findViewById(R.id.imageViewProfile);
    textViewName = contentView.findViewById(R.id.textViewName);

    textViewName.setText(mUser.login);

    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
    CoordinatorLayout.Behavior behavior = params.getBehavior();

    if (behavior != null && behavior instanceof BottomSheetBehavior) {
        ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
    }
}
 
Example 5
Source File: AppBarLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private boolean shouldJumpElevationState(@NonNull CoordinatorLayout parent, @NonNull T layout) {
  // We should jump the elevated state if we have a dependent scrolling view which has
  // an overlapping top (i.e. overlaps us)
  final List<View> dependencies = parent.getDependents(layout);
  for (int i = 0, size = dependencies.size(); i < size; i++) {
    final View dependency = dependencies.get(i);
    final CoordinatorLayout.LayoutParams lp =
        (CoordinatorLayout.LayoutParams) dependency.getLayoutParams();
    final CoordinatorLayout.Behavior behavior = lp.getBehavior();

    if (behavior instanceof ScrollingViewBehavior) {
      return ((ScrollingViewBehavior) behavior).getOverlayTop() != 0;
    }
  }
  return false;
}
 
Example 6
Source File: BottomSheetBehavior.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * A utility function to get the {@link BottomSheetBehavior} associated with the {@code view}.
 *
 * @param view The {@link View} with {@link BottomSheetBehavior}.
 * @return The {@link BottomSheetBehavior} associated with the {@code view}.
 */
@NonNull
@SuppressWarnings("unchecked")
public static <V extends View> BottomSheetBehavior<V> from(@NonNull V view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (!(params instanceof CoordinatorLayout.LayoutParams)) {
        throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
    }
    CoordinatorLayout.Behavior<?> behavior =
            ((CoordinatorLayout.LayoutParams) params).getBehavior();
    if (!(behavior instanceof BottomSheetBehavior)) {
        throw new IllegalArgumentException("The view is not associated with BottomSheetBehavior");
    }
    return (BottomSheetBehavior<V>) behavior;
}
 
Example 7
Source File: CustomBottomSheetDialogFragment.java    From Weather with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setupDialog(Dialog dialog, int style) {
    //super.setupDialog(dialog, style);
    View contentView = View.inflate(getContext(), R.layout.dialog_modal, null);
    dialog.setContentView(contentView);
    CoordinatorLayout.LayoutParams layoutParams =
            (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
    CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
    if (behavior != null && behavior instanceof BottomSheetBehavior) {
        ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);

    }
}
 
Example 8
Source File: TSnackbar.java    From TSnackBar with Apache License 2.0 5 votes vote down vote up
private boolean isBeingDragged() {
    final ViewGroup.LayoutParams lp = mView.getLayoutParams();

    if (lp instanceof CoordinatorLayout.LayoutParams) {
        final CoordinatorLayout.LayoutParams cllp = (CoordinatorLayout.LayoutParams) lp;
        final CoordinatorLayout.Behavior behavior = cllp.getBehavior();

        if (behavior instanceof SwipeDismissBehavior) {
            return ((SwipeDismissBehavior) behavior).getDragState()
                    != SwipeDismissBehavior.STATE_IDLE;
        }
    }
    return false;
}
 
Example 9
Source File: AppBarLayout.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void offsetChildAsNeeded(@NonNull View child, @NonNull View dependency) {
  final CoordinatorLayout.Behavior behavior =
      ((CoordinatorLayout.LayoutParams) dependency.getLayoutParams()).getBehavior();
  if (behavior instanceof BaseBehavior) {
    // Offset the child, pinning it to the bottom the header-dependency, maintaining
    // any vertical gap and overlap
    final BaseBehavior ablBehavior = (BaseBehavior) behavior;
    ViewCompat.offsetTopAndBottom(
        child,
        (dependency.getBottom() - child.getTop())
            + ablBehavior.offsetDelta
            + getVerticalLayoutGap()
            - getOverlapPixelsForOffset(dependency));
  }
}
 
Example 10
Source File: BottomSheetBehavior.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * A utility function to get the {@link BottomSheetBehavior} associated with the {@code view}.
 *
 * @param view The {@link View} with {@link BottomSheetBehavior}.
 * @return The {@link BottomSheetBehavior} associated with the {@code view}.
 */
@NonNull
@SuppressWarnings("unchecked")
public static <V extends View> BottomSheetBehavior<V> from(@NonNull V view) {
  ViewGroup.LayoutParams params = view.getLayoutParams();
  if (!(params instanceof CoordinatorLayout.LayoutParams)) {
    throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
  }
  CoordinatorLayout.Behavior<?> behavior =
      ((CoordinatorLayout.LayoutParams) params).getBehavior();
  if (!(behavior instanceof BottomSheetBehavior)) {
    throw new IllegalArgumentException("The view is not associated with BottomSheetBehavior");
  }
  return (BottomSheetBehavior<V>) behavior;
}
 
Example 11
Source File: MergedAppBarLayoutBehavior.java    From CustomBottomSheetBehavior with Apache License 2.0 5 votes vote down vote up
public static <V extends View> MergedAppBarLayoutBehavior from(V view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (!(params instanceof CoordinatorLayout.LayoutParams)) {
        throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
    }
    CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) params)
            .getBehavior();
    if (!(behavior instanceof MergedAppBarLayoutBehavior)) {
        throw new IllegalArgumentException("The view is not associated with " +
                "MergedAppBarLayoutBehavior");
    }
    return (MergedAppBarLayoutBehavior) behavior;
}
 
Example 12
Source File: BottomSheetBehaviorGoogleMapsLike.java    From CustomBottomSheetBehavior with Apache License 2.0 5 votes vote down vote up
/**
 * A utility function to get the {@link BottomSheetBehaviorGoogleMapsLike} associated with the {@code view}.
 *
 * @param view The {@link View} with {@link BottomSheetBehaviorGoogleMapsLike}.
 * @param <V> Instance of behavior
 * @return The {@link BottomSheetBehaviorGoogleMapsLike} associated with the {@code view}.
 */
@SuppressWarnings("unchecked")
public static <V extends View> BottomSheetBehaviorGoogleMapsLike<V> from(V view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (!(params instanceof CoordinatorLayout.LayoutParams)) {
        throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
    }
    CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) params)
            .getBehavior();
    if (!(behavior instanceof BottomSheetBehaviorGoogleMapsLike)) {
        throw new IllegalArgumentException(
                "The view is not associated with BottomSheetBehaviorGoogleMapsLike");
    }
    return (BottomSheetBehaviorGoogleMapsLike<V>) behavior;
}
 
Example 13
Source File: FabScaleBehavior.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
public static <V extends View> FabScaleBehavior from(V view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (!(params instanceof CoordinatorLayout.LayoutParams)) {
        throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
    }
    CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) params).getBehavior();
    if (!(behavior instanceof FabScaleBehavior)) {
        throw new IllegalArgumentException("The view is not associated with ScaleDownShowBehavior");
    }
    return (FabScaleBehavior) behavior;
}
 
Example 14
Source File: BottomSheetBehavior.java    From bottomsheetrecycler with Apache License 2.0 5 votes vote down vote up
/**
 * A utility function to get the {@link BottomSheetBehavior} associated with the {@code view}.
 *
 * @param view The {@link View} with {@link BottomSheetBehavior}.
 * @return The {@link BottomSheetBehavior} associated with the {@code view}.
 */
@SuppressWarnings("unchecked")
public static <V extends View> BottomSheetBehavior<V> from(V view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (!(params instanceof LayoutParams)) {
        throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
    }
    CoordinatorLayout.Behavior behavior = ((LayoutParams) params).getBehavior();
    if (!(behavior instanceof BottomSheetBehavior)) {
        throw new IllegalArgumentException("The view is not associated with BottomSheetBehavior");
    }
    return (BottomSheetBehavior<V>) behavior;
}
 
Example 15
Source File: ArcMenu.java    From MaterialArcMenu with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public CoordinatorLayout.Behavior getBehavior() {
    return new MoveUpwardBehaviour();
}
 
Example 16
Source File: CoordinatorLayoutUtils.java    From react-native-navigation with MIT License 4 votes vote down vote up
public static CoordinatorLayout.LayoutParams matchParentWithBehaviour(CoordinatorLayout.Behavior behavior) {
    CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
    lp.setBehavior(behavior);
    return lp;
}
 
Example 17
Source File: FloatingActionButton.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
public CoordinatorLayout.Behavior<FloatingActionButton> getBehavior() {
  return new FloatingActionButton.Behavior();
}
 
Example 18
Source File: AppBarLayout.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
public CoordinatorLayout.Behavior<AppBarLayout> getBehavior() {
  return new AppBarLayout.Behavior();
}
 
Example 19
Source File: CustomTextView.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
public CoordinatorLayout.Behavior<TextView> getBehavior() {
    return new TestFloatingBehavior();
}
 
Example 20
Source File: CoordinatorScrollingFrameLayout.java    From AndroidFastScroll with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public CoordinatorLayout.Behavior getBehavior() {
    return new Behavior();
}