fab support for all notify types

This commit is contained in:
Vincent Breitmoser 2015-02-28 02:30:59 +01:00
parent e4d91de8d2
commit f3710b12f6

View File

@ -47,24 +47,8 @@ public class Notify {
*/ */
public static void showNotify(final Activity activity, CharSequence text, Style style) { public static void showNotify(final Activity activity, CharSequence text, Style style) {
Snackbar bar = Snackbar.with(activity) Snackbar bar = getSnackbar(activity)
.text(text) .text(text);
.type(SnackbarType.MULTI_LINE)
.duration(SnackbarDuration.LENGTH_LONG);
if (activity instanceof FabContainer) {
bar.eventListener(new EventListenerAdapter() {
@Override
public void onShow(Snackbar snackbar) {
((FabContainer) activity).fabMoveUp(snackbar.getHeight());
}
@Override
public void onDismiss(Snackbar snackbar) {
((FabContainer) activity).fabRestorePosition();
}
});
}
switch (style) { switch (style) {
case OK: case OK:
@ -82,9 +66,9 @@ public class Notify {
} }
public static Showable createNotify (Activity activity, int resId, int duration, Style style) { public static Showable createNotify (Activity activity, int resId, int duration, Style style) {
final Snackbar bar = Snackbar.with(activity) final Snackbar bar = getSnackbar(activity)
.text(resId) .text(resId);
.type(SnackbarType.MULTI_LINE);
if (duration == LENGTH_INDEFINITE) { if (duration == LENGTH_INDEFINITE) {
bar.duration(SnackbarDuration.LENGTH_INDEFINITE); bar.duration(SnackbarDuration.LENGTH_INDEFINITE);
} else { } else {
@ -118,16 +102,17 @@ public class Notify {
public static Showable createNotify(Activity activity, String msg, int duration, Style style, public static Showable createNotify(Activity activity, String msg, int duration, Style style,
final ActionListener listener, int resIdAction) { final ActionListener listener, int resIdAction) {
final Snackbar bar = Snackbar.with(activity)
final Snackbar bar = getSnackbar(activity)
.text(msg) .text(msg)
.actionLabel(resIdAction) .actionLabel(resIdAction)
.type(SnackbarType.MULTI_LINE)
.actionListener(new ActionClickListener() { .actionListener(new ActionClickListener() {
@Override @Override
public void onActionClicked(Snackbar snackbar) { public void onActionClicked(Snackbar snackbar) {
listener.onAction(); listener.onAction();
} }
}); });
if (duration == LENGTH_INDEFINITE) { if (duration == LENGTH_INDEFINITE) {
bar.duration(SnackbarDuration.LENGTH_INDEFINITE); bar.duration(SnackbarDuration.LENGTH_INDEFINITE);
} else { } else {
@ -165,6 +150,27 @@ public class Notify {
showNotify(activity, activity.getResources().getText(resId), style); showNotify(activity, activity.getResources().getText(resId), style);
} }
private static Snackbar getSnackbar(final Activity activity) {
Snackbar bar = Snackbar.with(activity)
.type(SnackbarType.MULTI_LINE)
.duration(SnackbarDuration.LENGTH_LONG);
if (activity instanceof FabContainer) {
bar.eventListener(new EventListenerAdapter() {
@Override
public void onShow(Snackbar snackbar) {
((FabContainer) activity).fabMoveUp(snackbar.getHeight());
}
@Override
public void onDismiss(Snackbar snackbar) {
((FabContainer) activity).fabRestorePosition();
}
});
}
return bar;
}
public interface Showable { public interface Showable {
public void show(); public void show();