Java Code Examples for com.google.android.material.snackbar.Snackbar#SnackbarLayout

The following examples show how to use com.google.android.material.snackbar.Snackbar#SnackbarLayout . 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: FABMenu.java    From Jockey with Apache License 2.0 6 votes vote down vote up
private float getFabTranslationYForSnackbar(CoordinatorLayout parent,
                                            FloatingActionButton fab) {
    float minOffset = 0.0F;
    List dependencies = parent.getDependencies(fab);
    int i = 0;

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

    return minOffset;
}
 
Example 2
Source File: SnackbarUtil.java    From weather with Apache License 2.0 5 votes vote down vote up
/**
 * Add view to the snackbar.
 * <p>Call it after {@link #show()}</p>
 *
 * @param layoutId The id of layout.
 * @param params   The params.
 */
public static void addView(@LayoutRes final int layoutId,
                           @NonNull final ViewGroup.LayoutParams params) {
  final View view = getView();
  if (view != null) {
    view.setPadding(0, 0, 0, 0);
    Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) view;
    View child = LayoutInflater.from(view.getContext()).inflate(layoutId, null);
    layout.addView(child, -1, params);
  }
}
 
Example 3
Source File: SnackbarBehavior.java    From CircleIndicator with Apache License 2.0 5 votes vote down vote up
private float getTranslationYForSnackbar(CoordinatorLayout parent, BaseCircleIndicator ci) {
    float minOffset = 0;
    final List<View> dependencies = parent.getDependencies(ci);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(ci, view)) {
            minOffset = Math.min(minOffset, view.getTranslationY() - view.getHeight());
        }
    }

    return minOffset;
}
 
Example 4
Source File: NotificationHelper.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void showSnackbar(@NonNull MysplashActivity activity, String content) {
    View container = activity.provideSnackbarContainer();
    if (container != null) {
        Snackbar snackbar = Snackbar.make(container, content, Snackbar.LENGTH_SHORT);

        Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbar.getView();
        snackbarLayout.setBackgroundColor(ThemeManager.getRootColor(activity));

        TextView contentTxt = snackbarLayout.findViewById(R.id.snackbar_text);
        contentTxt.setTextColor(ThemeManager.getContentColor(activity));

        snackbar.show();
    }
}
 
Example 5
Source File: AppBarBoundFabBehavior.java    From appbarsyncedfab with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton fab, View dependency) {
    //noinspection SimplifiableIfStatement
    if (dependency instanceof AppBarLayout) {
        // if the dependency is an AppBarLayout, do not allow super to react on that
        // we don't want that behavior
        return true;
    } else if (dependency instanceof Snackbar.SnackbarLayout) {
        updateFabTranslationForSnackbar(parent, fab, dependency);
        return true;
    }
    return super.onDependentViewChanged(parent, fab, dependency);
}
 
Example 6
Source File: SnackBarUtil.java    From FastLib with Apache License 2.0 5 votes vote down vote up
/**
 * 添加SnackBar视图
 * <p>在{@link #show()}之后调用</p>
 *
 * @param child  要添加的view
 * @param params 布局参数
 */
public static void addView(@NonNull final View child, @NonNull final ViewGroup.LayoutParams params) {
    final View view = getView();
    if (view != null) {
        view.setPadding(0, 0, 0, 0);
        Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) view;
        layout.addView(child, params);
    }
}
 
Example 7
Source File: EhDrawerLayout.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private float getChildTranslationYForSnackbar(CoordinatorLayout parent,
        EhDrawerLayout child) {
    float minOffset = 0;
    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 && parent.doViewsOverlap(child, view)) {
            minOffset = Math.min(minOffset,
                    ViewCompat.getTranslationY(view) - view.getHeight());
        }
    }

    return minOffset;
}
 
Example 8
Source File: NotificationHelper.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void showActionSnackbar(String content, String action,
                                      int duration, View.OnClickListener l) {
    if (Mysplash.getInstance().getActivityCount() > 0) {
        MysplashActivity a = Mysplash.getInstance().getTopActivity();
        View container = a.provideSnackbarContainer();

        Snackbar snackbar = Snackbar
                .make(container, content, duration)
                .setAction(action, l);

        Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbar.getView();

        TextView contentTxt = (TextView) snackbarLayout.findViewById(R.id.snackbar_text);
        DisplayUtils.setTypeface(a, contentTxt);

        Button actionBtn = (Button) snackbarLayout.findViewById(R.id.snackbar_action);

        if (Mysplash.getInstance().isLightTheme()) {
            contentTxt.setTextColor(ContextCompat.getColor(a, R.color.colorTextContent_light));
            actionBtn.setTextColor(ContextCompat.getColor(a, R.color.colorTextTitle_light));
            snackbarLayout.setBackgroundResource(R.color.colorRoot_light);
        } else {
            contentTxt.setTextColor(ContextCompat.getColor(a, R.color.colorTextContent_dark));
            actionBtn.setTextColor(ContextCompat.getColor(a, R.color.colorTextTitle_dark));
            snackbarLayout.setBackgroundResource(R.color.colorRoot_dark);
        }

        snackbar.show();
    }
}
 
Example 9
Source File: FABMenu.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent,
                                      FloatingActionButton child, View dependency) {
    if (dependency instanceof Snackbar.SnackbarLayout) {
        updateFabTranslationForSnackbar(parent, child, dependency);
        return false;
    } else {
        return super.onDependentViewChanged(parent, child, dependency);
    }
}
 
Example 10
Source File: EhDrawerLayout.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, EhDrawerLayout child,
        View dependency) {
    if (dependency instanceof Snackbar.SnackbarLayout) {
        for (int i = 0, n = child.getAboveSnackViewCount(); i < n; i++) {
            View view = child.getAboveSnackViewAt(i);
            updateChildTranslationForSnackbar(parent, child, view);
        }
    }
    return false;
}
 
Example 11
Source File: BottomNavBarFabBehaviour.java    From BottomNavigation 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,
                    view.getTranslationY() - view.getHeight());
        }
    }

    return minOffset;
}
 
Example 12
Source File: SlideUpWithSnackbarBehavior.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean layoutDependsOn(@NonNull CoordinatorLayout parent,
                               @NonNull View child,
                               @NonNull View dependency)
{
  return dependency instanceof Snackbar.SnackbarLayout;
}
 
Example 13
Source File: FloatingActionMenuBehavior.java    From Maying with Apache License 2.0 4 votes vote down vote up
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionMenu child, View dependency) {
    return dependency instanceof Snackbar.SnackbarLayout;
}
 
Example 14
Source File: BehaviorBottomPadding.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {
    return (dependency instanceof Snackbar.SnackbarLayout);
}
 
Example 15
Source File: BottomVerticalScrollBehavior.java    From BottomNavigation with Apache License 2.0 4 votes vote down vote up
private void updateSnackBarPosition(CoordinatorLayout parent, V child, View dependency, float translationY) {
    if (dependency != null && dependency instanceof Snackbar.SnackbarLayout) {
        ViewCompat.animate(dependency).setInterpolator(INTERPOLATOR).setDuration(80).setStartDelay(0).translationY(translationY).start();
    }
}
 
Example 16
Source File: ObservantListBehavior.java    From HgLauncher with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {
    return dependency instanceof Snackbar.SnackbarLayout;
}
 
Example 17
Source File: MoveUpBehaviour.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency) {
    return dependency instanceof Snackbar.SnackbarLayout;
}
 
Example 18
Source File: EhDrawerLayout.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean layoutDependsOn(CoordinatorLayout parent,
        EhDrawerLayout child, View dependency) {
    // We're dependent on all SnackbarLayouts (if enabled)
    return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout;
}
 
Example 19
Source File: EhDrawerLayout.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean layoutDependsOn(CoordinatorLayout parent,
        EhDrawerLayout child, View dependency) {
    // We're dependent on all SnackbarLayouts (if enabled)
    return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout;
}
 
Example 20
Source File: FloatingActionMenuBehavior.java    From ShadowsocksRR with Apache License 2.0 4 votes vote down vote up
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionMenu child, View dependency) {
    return dependency instanceof Snackbar.SnackbarLayout;
}