diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-02-28 02:30:59 +0100 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-02-28 02:30:59 +0100 |
commit | f3710b12f6a9c40b43f973c02790136fb17065ac (patch) | |
tree | 8e28a586759647c70ddcfdea552fc4bff3204e63 | |
parent | e4d91de8d299e01b11faf8e72278025c428eac8e (diff) | |
download | open-keychain-f3710b12f6a9c40b43f973c02790136fb17065ac.tar.gz open-keychain-f3710b12f6a9c40b43f973c02790136fb17065ac.tar.bz2 open-keychain-f3710b12f6a9c40b43f973c02790136fb17065ac.zip |
fab support for all notify types
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java index 1c35ec9cc..8686b605f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java @@ -47,24 +47,8 @@ public class Notify { */ public static void showNotify(final Activity activity, CharSequence text, Style style) { - Snackbar bar = Snackbar.with(activity) - .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(); - } - }); - } + Snackbar bar = getSnackbar(activity) + .text(text); switch (style) { case OK: @@ -82,9 +66,9 @@ public class Notify { } public static Showable createNotify (Activity activity, int resId, int duration, Style style) { - final Snackbar bar = Snackbar.with(activity) - .text(resId) - .type(SnackbarType.MULTI_LINE); + final Snackbar bar = getSnackbar(activity) + .text(resId); + if (duration == LENGTH_INDEFINITE) { bar.duration(SnackbarDuration.LENGTH_INDEFINITE); } else { @@ -118,16 +102,17 @@ public class Notify { public static Showable createNotify(Activity activity, String msg, int duration, Style style, final ActionListener listener, int resIdAction) { - final Snackbar bar = Snackbar.with(activity) + + final Snackbar bar = getSnackbar(activity) .text(msg) .actionLabel(resIdAction) - .type(SnackbarType.MULTI_LINE) .actionListener(new ActionClickListener() { @Override public void onActionClicked(Snackbar snackbar) { listener.onAction(); } }); + if (duration == LENGTH_INDEFINITE) { bar.duration(SnackbarDuration.LENGTH_INDEFINITE); } else { @@ -165,6 +150,27 @@ public class Notify { 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 void show(); |