Java Code Examples for android.support.design.widget.CoordinatorLayout#Behavior

The following examples show how to use android.support.design.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: BottomNavigationBehavior.java    From BottomBar with Apache License 2.0 6 votes vote down vote up
static <V extends View> BottomNavigationBehavior<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 BottomNavigationBehavior) {
        // noinspection unchecked
        return (BottomNavigationBehavior<V>) behavior;
    }

    throw new IllegalArgumentException("The view is not associated with BottomNavigationBehavior");
}
 
Example 2
Source File: RefreshHeader.java    From SpringHeader with Apache License 2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    ViewGroup.LayoutParams lp = getLayoutParams();
    if (lp instanceof CoordinatorLayout.LayoutParams) {
        CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) lp).getBehavior();
        if (behavior instanceof SpringHeaderBehavior) {
            mBehavior = (SpringHeaderBehavior) behavior;
            mBehavior.setSpringHeaderCallback(this);
        }
    }
}
 
Example 3
Source File: ScrollingAppBarLayoutBehavior.java    From react-native-bottom-sheet-behavior with MIT License 5 votes vote down vote up
public static <V extends View> ScrollingAppBarLayoutBehavior 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 ScrollingAppBarLayoutBehavior)) {
        throw new IllegalArgumentException("The view is not associated with " +
                "MergedAppBarLayoutBehavior");
    }
    return (ScrollingAppBarLayoutBehavior) behavior;
}
 
Example 4
Source File: TranslateUpDownBehavior.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
public static TranslateUpDownBehavior form(View view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (params == null || !(params instanceof CoordinatorLayout.LayoutParams)) {
        throw new IllegalArgumentException("parent must be CoordinatorLayout");
    }
    CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) params).getBehavior();
    if (!(behavior instanceof TranslateUpDownBehavior)) {
        throw new IllegalArgumentException("the behavior must be TranslateUpDownBehavior");
    }
    return (TranslateUpDownBehavior) behavior;
}
 
Example 5
Source File: TutsPlusBottomSheetDialogFragment.java    From AndroidDemoProjects with Apache License 2.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.fragment_bottom_sheet, 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);
    }
}
 
Example 6
Source File: NavigationTabBarBehavior.java    From NavigationTabBar with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
public static NavigationTabBarBehavior from(NavigationTabBar view) {
    final ViewGroup.LayoutParams params = view.getLayoutParams();
    if (!(params instanceof CoordinatorLayout.LayoutParams))
        throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");

    final CoordinatorLayout.Behavior behavior =
            ((CoordinatorLayout.LayoutParams) params).getBehavior();
    if (!(behavior instanceof NavigationTabBarBehavior))
        throw new IllegalArgumentException(
                "The view is not associated with NavigationTabBarBehavior");

    return (NavigationTabBarBehavior) behavior;
}
 
Example 7
Source File: MergedAppBarLayoutBehavior.java    From react-native-bottom-sheet-behavior with MIT License 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 8
Source File: GoogleMapsBottomSheetBehavior.java    From Google-Maps-BottomSheet with The Unlicense 5 votes vote down vote up
/**
 * A utility function to get the {@link GoogleMapsBottomSheetBehavior} associated with the {@code view}.
 *
 * @param view The {@link View} with {@link GoogleMapsBottomSheetBehavior}.
 * @return The {@link GoogleMapsBottomSheetBehavior} associated with the {@code view}.
 */
@SuppressWarnings("unchecked")
public static <V extends View> GoogleMapsBottomSheetBehavior<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 GoogleMapsBottomSheetBehavior)) {
        throw new IllegalArgumentException(
                "The view is not associated with GoogleMapsBottomSheetBehavior");
    }
    return (GoogleMapsBottomSheetBehavior<V>) behavior;
}
 
Example 9
Source File: AnchorSheetBehavior.java    From AnchorSheetBehavior with Apache License 2.0 5 votes vote down vote up
/**
 * A utility function to get the {@link AnchorSheetBehavior} associated with the {@code view}.
 *
 * @param view The {@link View} with {@link AnchorSheetBehavior}.
 * @return The {@link AnchorSheetBehavior} associated with the {@code view}.
 */
@SuppressWarnings("unchecked")
public static <V extends View> AnchorSheetBehavior<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 AnchorSheetBehavior)) {
        throw new IllegalArgumentException("The view is not associated with AnchorSheetBehavior");
    }
    return (AnchorSheetBehavior<V>) behavior;
}
 
Example 10
Source File: RNBottomSheetBehavior.java    From react-native-bottom-sheet-behavior with MIT License 5 votes vote down vote up
/**
 * A utility function to get the {@link RNBottomSheetBehavior} associated with the {@code view}.
 *
 * @param view The {@link View} with {@link RNBottomSheetBehavior}.
 * @return The {@link RNBottomSheetBehavior} associated with the {@code view}.
 */
@SuppressWarnings("unchecked")
public static <V extends View> RNBottomSheetBehavior<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 RNBottomSheetBehavior)) {
    throw new IllegalArgumentException(
        "The view is not associated with RNBottomSheetBehavior");
  }
  return (RNBottomSheetBehavior<V>) behavior;
}
 
Example 11
Source File: BottomNavigationBehavior.java    From NanoIconPack with Apache License 2.0 5 votes vote down vote up
public static <V extends View> BottomNavigationBehavior<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 BottomNavigationBehavior)) {
        throw new IllegalArgumentException(
                "The view is not associated with BottomNavigationBehavior");
    }
    return (BottomNavigationBehavior<V>) behavior;
}
 
Example 12
Source File: CommonBehavior.java    From Aurora with Apache License 2.0 5 votes vote down vote up
public static CommonBehavior from(View 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 CommonBehavior)) {
        throw new IllegalArgumentException("The view's behavior isn't an instance of CommonBehavior. " +
                "Try to check the [app:layout_behavior]");
    }
    return (CommonBehavior) behavior;
}
 
Example 13
Source File: BottomSheetBehaviorV2.java    From paper-launcher with MIT License 5 votes vote down vote up
/**
 * A utility function to get the {@link BottomSheetBehaviorV2} associated with the {@code view}.
 *
 * @param view The {@link View} with {@link BottomSheetBehaviorV2}.
 * @return The {@link BottomSheetBehaviorV2} associated with the {@code view}.
 */
@SuppressWarnings("unchecked")
public static <V extends View> BottomSheetBehaviorV2<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 BottomSheetBehaviorV2)) {
        throw new IllegalArgumentException(
                "The view is not associated with BottomSheetBehavior");
    }
    return (BottomSheetBehaviorV2<V>) behavior;
}
 
Example 14
Source File: ViewPagerBottomSheetBehavior.java    From FabulousFilter with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <V extends View> ViewPagerBottomSheetBehavior<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 ViewPagerBottomSheetBehavior)) {
        throw new IllegalArgumentException(
                "The view is not associated with ViewPagerBottomSheetBehavior");
    }
    return (ViewPagerBottomSheetBehavior<V>) behavior;
}
 
Example 15
Source File: ViewUtils.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
public static int getOverlayTop(@NonNull final View view) {
    final ViewGroup.LayoutParams params = view.getLayoutParams();
    if (params instanceof CoordinatorLayout.LayoutParams) {
        final CoordinatorLayout.Behavior<?> behavior = ((CoordinatorLayout.LayoutParams) params)
                .getBehavior();
        if (behavior instanceof AppBarLayout.ScrollingViewBehavior) {
            return ((AppBarLayout.ScrollingViewBehavior) behavior).getOverlayTop();
        }
    }
    return 0;
}
 
Example 16
Source File: BlurZoomCoordinatorLayout.java    From BlurZoomGallery with MIT License 5 votes vote down vote up
private void setUpDurationAndInterpolator() {
    try {
        if(duration == -1 && interpolator == null) {
            return;
        }

        CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).getBehavior();

        Class appBarLayoutBehaviorClass = Class.forName("android.support.design.widget.AppBarLayout$Behavior");
        Field animatorField = appBarLayoutBehaviorClass.getDeclaredField("mAnimator");
        animatorField.setAccessible(true);

        Object oldAnimator = animatorField.get(behavior);

        Class valueAnimatorCompatClass = Class.forName("android.support.design.widget.ValueAnimatorCompat");
        if(duration != -1) {
            Method setDurationMethod = valueAnimatorCompatClass.getMethod("setDuration", int.class);
            setDurationMethod.invoke(oldAnimator, duration);
        }
        if(interpolator != null) {
            Method setInterpolatorMethod = valueAnimatorCompatClass.getMethod("setInterpolator", Interpolator.class);
            setInterpolatorMethod.invoke(oldAnimator, interpolator);
        }
    }
    catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example 17
Source File: LayoutInflaterCompat.java    From Neptune with Apache License 2.0 5 votes vote down vote up
private static Map<String, Constructor<CoordinatorLayout.Behavior>> getBehaviorConstructors() {
    Map<String, Constructor<CoordinatorLayout.Behavior>> constructorMap = null;
    if (sBehaviorConstructors == null) {
        sBehaviorConstructors = ReflectionUtils.on(CoordinatorLayout.class).get("sConstructors");
    }
    if (sBehaviorConstructors != null) {
        constructorMap = sBehaviorConstructors.get();
    }
    return constructorMap;
}
 
Example 18
Source File: ModalsBottomSheetDialogFragment.java    From OsmGo with MIT License 4 votes vote down vote up
@Override
@SuppressLint("RestrictedApi")
public void setupDialog(Dialog dialog, int style) {
  super.setupDialog(dialog, style);

  if (options == null) {
    return;
  }

  Window w = dialog.getWindow();

  final float scale = getResources().getDisplayMetrics().density;

  float layoutPaddingDp16 = 16.0f;
  float layoutPaddingDp12  = 12.0f;
  float layoutPaddingDp8  = 8.0f;
  int layoutPaddingPx16 = (int) (layoutPaddingDp16 * scale + 0.5f);
  int layoutPaddingPx12 = (int) (layoutPaddingDp12 * scale + 0.5f);
  int layoutPaddingPx8 = (int) (layoutPaddingDp8 * scale + 0.5f);

  CoordinatorLayout parentLayout = new CoordinatorLayout(getContext());

  LinearLayout layout = new LinearLayout(getContext());
  layout.setOrientation(LinearLayout.VERTICAL);
  layout.setPadding(layoutPaddingPx16, layoutPaddingPx16, layoutPaddingPx16, layoutPaddingPx16);

  try {
    List<Object> optionsList = options.toList();
    for (int i = 0; i < optionsList.size(); i++) {
      final int optionIndex = i;
      JSObject o = JSObject.fromJSONObject((JSONObject) optionsList.get(i));
      String styleOption = o.getString("style", "DEFAULT");
      String titleOption = o.getString("title", "");

      TextView tv = new TextView(getContext());
      tv.setTextColor(Color.parseColor("#000000"));
      tv.setPadding(layoutPaddingPx12, layoutPaddingPx12, layoutPaddingPx12, layoutPaddingPx12);
      //tv.setBackgroundColor(Color.parseColor("#80000000"));
      tv.setText(titleOption);
      tv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
          Log.d(LogUtils.getCoreTag(), "CliCKED: " + optionIndex);

          if (listener != null) {
            listener.onSelected(optionIndex);
          }
        }
      });
      layout.addView(tv);
    }

    parentLayout.addView(layout.getRootView());

    dialog.setContentView(parentLayout.getRootView());

    //dialog.getWindow().getDecorView().setBackgroundColor(Color.parseColor("#000000"));

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

    if (behavior != null && behavior instanceof BottomSheetBehavior) {
      ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
    }
  } catch (JSONException ex) {
    Log.e(LogUtils.getCoreTag(), "JSON error processing an option for showActions", ex);
  }
}
 
Example 19
Source File: DependentViewBehavior.java    From SpringHeader with Apache License 2.0 4 votes vote down vote up
private CoordinatorLayout.Behavior getBehavior(View view) {
    CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) view.getLayoutParams();
    return lp.getBehavior();
}
 
Example 20
Source File: TitleFAB.java    From FABsMenu with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public CoordinatorLayout.Behavior getBehavior() {
    return new FABSnackbarBehavior();
}