use Notify helper everywhere, replace supertoasts with snackbar library

This commit is contained in:
Vincent Breitmoser
2015-01-19 15:43:35 +01:00
parent 491c12d5d3
commit 198ddfeff7
8 changed files with 198 additions and 210 deletions

View File

@@ -26,6 +26,7 @@ dependencies {
compile 'com.journeyapps:zxing-android-integration:2.0.1@aar' compile 'com.journeyapps:zxing-android-integration:2.0.1@aar'
compile 'com.google.zxing:core:3.0.1' compile 'com.google.zxing:core:3.0.1'
compile 'com.jpardogo.materialtabstrip:library:1.0.8' compile 'com.jpardogo.materialtabstrip:library:1.0.8'
compile 'com.nispok:snackbar:2.7.4'
} }
android { android {

View File

@@ -21,18 +21,14 @@ package org.sufficientlysecure.keychain.operations.results;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
import com.github.johnpersano.supertoasts.SuperCardToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.SuperToast.Duration;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.Style;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment; import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
public class CertifyResult extends OperationResult { public class CertifyResult extends OperationResult {
@@ -78,30 +74,31 @@ public class CertifyResult extends OperationResult {
} }
}; };
public SuperCardToast createNotify(final Activity activity) { public Showable createNotify(final Activity activity) {
int resultType = getResult(); int resultType = getResult();
String str; String str;
int duration, color; int duration;
Style style;
// Not an overall failure // Not an overall failure
if ((resultType & OperationResult.RESULT_ERROR) == 0) { if ((resultType & OperationResult.RESULT_ERROR) == 0) {
String withWarnings; String withWarnings;
duration = Duration.EXTRA_LONG; duration = Notify.LENGTH_LONG;
color = Style.GREEN; style = Style.OK;
withWarnings = ""; withWarnings = "";
// Any warnings? // Any warnings?
if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; style = Style.WARN;
withWarnings += activity.getString(R.string.with_warnings); withWarnings += activity.getString(R.string.with_warnings);
} }
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; style = Style.WARN;
withWarnings += activity.getString(R.string.with_cancelled); withWarnings += activity.getString(R.string.with_cancelled);
} }
@@ -111,46 +108,27 @@ public class CertifyResult extends OperationResult {
if (mCertifyError > 0) { if (mCertifyError > 0) {
// definitely switch to warning-style message in this case! // definitely switch to warning-style message in this case!
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
str += " " + activity.getResources().getQuantityString( str += " " + activity.getResources().getQuantityString(
R.plurals.certify_keys_with_errors, mCertifyError, mCertifyError); R.plurals.certify_keys_with_errors, mCertifyError, mCertifyError);
} }
} else { } else {
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
str = activity.getResources().getQuantityString(R.plurals.certify_error, str = activity.getResources().getQuantityString(R.plurals.certify_error,
mCertifyError, mCertifyError); mCertifyError, mCertifyError);
} }
boolean button = getLog() != null && !getLog().isEmpty(); return Notify.createNotify(activity, str, duration, style, new ActionListener() {
SuperCardToast toast = new SuperCardToast(activity, @Override
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, public void onAction() {
Style.getStyle(color, SuperToast.Animations.POPUP)); Intent intent = new Intent(
toast.setText(str); activity, LogDisplayActivity.class);
toast.setDuration(duration); intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this);
toast.setIndeterminate(duration == 0); activity.startActivity(intent);
toast.setSwipeToDismiss(true); }
// If we have a log and it's non-empty, show a View Log button }, R.string.view_log);
if (button) {
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
activity.getResources().getString(R.string.view_log));
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
toast.setTextColor(activity.getResources().getColor(R.color.black));
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this);
activity.startActivity(intent);
}
}
));
}
return toast;
} }

View File

@@ -24,15 +24,13 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.view.View; import android.view.View;
import com.github.johnpersano.supertoasts.SuperCardToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.SuperToast.Duration;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.Style;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment; import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
public class DeleteResult extends OperationResult { public class DeleteResult extends OperationResult {
@@ -68,31 +66,32 @@ public class DeleteResult extends OperationResult {
} }
}; };
public SuperCardToast createNotify(final Activity activity) { public Showable createNotify(final Activity activity) {
int resultType = getResult(); int resultType = getResult();
String str; String str;
int duration, color; int duration;
Style style;
// Not an overall failure // Not an overall failure
if ((resultType & OperationResult.RESULT_ERROR) == 0) { if ((resultType & OperationResult.RESULT_ERROR) == 0) {
String untilCancelled; String untilCancelled;
duration = Duration.EXTRA_LONG; duration = Notify.LENGTH_LONG;
color = Style.GREEN; style = Style.OK;
untilCancelled = ""; untilCancelled = "";
// Any warnings? // Any warnings?
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; style = Style.WARN;
untilCancelled += activity.getString(R.string.with_cancelled); untilCancelled += activity.getString(R.string.with_cancelled);
} }
// New and updated keys // New and updated keys
if (mOk > 0 && mFail > 0) { if (mOk > 0 && mFail > 0) {
color = Style.ORANGE; style = Style.WARN;
duration = 0; duration = 0;
str = activity.getResources().getQuantityString( str = activity.getResources().getQuantityString(
R.plurals.delete_ok_but_fail_1, mOk, mOk); R.plurals.delete_ok_but_fail_1, mOk, mOk);
@@ -105,13 +104,13 @@ public class DeleteResult extends OperationResult {
str = activity.getString(R.string.delete_cancelled); str = activity.getString(R.string.delete_cancelled);
} else { } else {
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
str = "internal error"; str = "internal error";
} }
} else { } else {
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
if (mFail == 0) { if (mFail == 0) {
str = activity.getString(R.string.delete_nothing); str = activity.getString(R.string.delete_nothing);
} else { } else {
@@ -119,34 +118,15 @@ public class DeleteResult extends OperationResult {
} }
} }
boolean button = getLog() != null && !getLog().isEmpty(); return Notify.createNotify(activity, str, duration, style, new ActionListener() {
SuperCardToast toast = new SuperCardToast(activity, @Override
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, public void onAction() {
Style.getStyle(color, SuperToast.Animations.POPUP)); Intent intent = new Intent(
toast.setText(str); activity, LogDisplayActivity.class);
toast.setDuration(duration); intent.putExtra(LogDisplayFragment.EXTRA_RESULT, DeleteResult.this);
toast.setIndeterminate(duration == 0); activity.startActivity(intent);
toast.setSwipeToDismiss(true); }
// If we have a log and it's non-empty, show a View Log button }, R.string.view_log);
if (button) {
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
activity.getResources().getString(R.string.view_log));
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
toast.setTextColor(activity.getResources().getColor(R.color.black));
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, DeleteResult.this);
activity.startActivity(intent);
}
}
));
}
return toast;
} }

View File

@@ -21,18 +21,14 @@ package org.sufficientlysecure.keychain.operations.results;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
import com.github.johnpersano.supertoasts.SuperCardToast;
import com.github.johnpersano.supertoasts.SuperToast;
import com.github.johnpersano.supertoasts.SuperToast.Duration;
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
import com.github.johnpersano.supertoasts.util.Style;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment; import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
public class ImportKeyResult extends OperationResult { public class ImportKeyResult extends OperationResult {
@@ -114,30 +110,31 @@ public class ImportKeyResult extends OperationResult {
} }
}; };
public SuperCardToast createNotify(final Activity activity) { public Showable createNotify(final Activity activity) {
int resultType = getResult(); int resultType = getResult();
String str; String str;
int duration, color; int duration;
Style style;
// Not an overall failure // Not an overall failure
if ((resultType & OperationResult.RESULT_ERROR) == 0) { if ((resultType & OperationResult.RESULT_ERROR) == 0) {
String withWarnings; String withWarnings;
duration = Duration.EXTRA_LONG; duration = Notify.LENGTH_LONG;
color = Style.GREEN; style = Style.OK;
withWarnings = ""; withWarnings = "";
// Any warnings? // Any warnings?
if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; style = Style.WARN;
withWarnings += activity.getString(R.string.with_warnings); withWarnings += activity.getString(R.string.with_warnings);
} }
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; style = Style.WARN;
withWarnings += activity.getString(R.string.with_cancelled); withWarnings += activity.getString(R.string.with_cancelled);
} }
@@ -155,20 +152,20 @@ public class ImportKeyResult extends OperationResult {
R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings); R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings);
} else { } else {
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
str = "internal error"; str = "internal error";
} }
if (isOkWithErrors()) { if (isOkWithErrors()) {
// definitely switch to warning-style message in this case! // definitely switch to warning-style message in this case!
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
str += " " + activity.getResources().getQuantityString( str += " " + activity.getResources().getQuantityString(
R.plurals.import_keys_with_errors, mBadKeys, mBadKeys); R.plurals.import_keys_with_errors, mBadKeys, mBadKeys);
} }
} else { } else {
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
if (isFailNothing()) { if (isFailNothing()) {
str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0 str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0
? R.string.import_error_nothing_cancelled ? R.string.import_error_nothing_cancelled
@@ -178,34 +175,15 @@ public class ImportKeyResult extends OperationResult {
} }
} }
boolean button = getLog() != null && !getLog().isEmpty(); return Notify.createNotify(activity, str, duration, style, new ActionListener() {
SuperCardToast toast = new SuperCardToast(activity, @Override
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, public void onAction() {
Style.getStyle(color, SuperToast.Animations.POPUP)); Intent intent = new Intent(
toast.setText(str); activity, LogDisplayActivity.class);
toast.setDuration(duration); intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this);
toast.setIndeterminate(duration == 0); activity.startActivity(intent);
toast.setSwipeToDismiss(true); }
// If we have a log and it's non-empty, show a View Log button }, R.string.view_log);
if (button) {
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
activity.getResources().getString(R.string.view_log));
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
toast.setTextColor(activity.getResources().getColor(R.color.black));
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this);
activity.startActivity(intent);
}
}
));
}
return toast;
} }

View File

@@ -20,19 +20,24 @@ package org.sufficientlysecure.keychain.operations.results;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.view.View; import android.view.View;
import com.github.johnpersano.supertoasts.SuperCardToast; import com.nispok.snackbar.Snackbar;
import com.github.johnpersano.supertoasts.SuperToast; import com.nispok.snackbar.Snackbar.SnackbarDuration;
import com.github.johnpersano.supertoasts.util.OnClickWrapper; import com.nispok.snackbar.SnackbarManager;
import com.github.johnpersano.supertoasts.util.Style; import com.nispok.snackbar.listeners.ActionClickListener;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment; import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@@ -195,58 +200,44 @@ public abstract class OperationResult implements Parcelable {
} }
public SuperCardToast createNotify(final Activity activity) { public Showable createNotify(final Activity activity) {
int color;
Log.d(Constants.TAG, "mLog.getLast()"+mLog.getLast()); Log.d(Constants.TAG, "mLog.getLast()"+mLog.getLast());
Log.d(Constants.TAG, "mLog.getLast().mType"+mLog.getLast().mType); Log.d(Constants.TAG, "mLog.getLast().mType"+mLog.getLast().mType);
Log.d(Constants.TAG, "mLog.getLast().mType.getMsgId()"+mLog.getLast().mType.getMsgId()); Log.d(Constants.TAG, "mLog.getLast().mType.getMsgId()"+mLog.getLast().mType.getMsgId());
// Take the last message as string // Take the last message as string
String str = activity.getString(mLog.getLast().mType.getMsgId()); int msgId = mLog.getLast().mType.getMsgId();
Style style;
// Not an overall failure // Not an overall failure
if (cancelled()) { if (cancelled()) {
color = Style.RED; style = Style.ERROR;
} else if (success()) { } else if (success()) {
if (getLog().containsWarnings()) { if (getLog().containsWarnings()) {
color = Style.ORANGE; style = Style.WARN;
} else { } else {
color = Style.GREEN; style = Style.OK;
} }
} else { } else {
color = Style.RED; style = Style.ERROR;
} }
boolean button = getLog() != null && !getLog().isEmpty(); if (getLog() == null || getLog().isEmpty()) {
SuperCardToast toast = new SuperCardToast(activity, return Notify.createNotify(activity, msgId, Notify.LENGTH_LONG, style);
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
Style.getStyle(color, SuperToast.Animations.POPUP));
toast.setText(str);
toast.setDuration(SuperToast.Duration.EXTRA_LONG);
toast.setIndeterminate(false);
toast.setSwipeToDismiss(true);
// If we have a log and it's non-empty, show a View Log button
if (button) {
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
activity.getResources().getString(R.string.view_log));
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
toast.setTextColor(activity.getResources().getColor(R.color.black));
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResult.this);
activity.startActivity(intent);
}
}
));
} }
return toast; return Notify.createNotify(activity, msgId, Notify.LENGTH_LONG, style,
new ActionListener() {
@Override
public void onAction() {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResult.this);
activity.startActivity(intent);
}
}, R.string.view_log);
} }

View File

@@ -40,35 +40,6 @@ public class SingletonResult extends OperationResult {
mLog.add(reason, 0); mLog.add(reason, 0);
} }
@Override
public SuperCardToast createNotify(final Activity activity) {
// there is exactly one error msg - use that one
String str = activity.getString(mLog.iterator().next().mType.getMsgId());
int color;
// Determine color by result type
if (cancelled()) {
color = Style.RED;
} else if (success()) {
if (getLog().containsWarnings()) {
color = Style.ORANGE;
} else {
color = Style.GREEN;
}
} else {
color = Style.RED;
}
SuperCardToast toast = new SuperCardToast(activity, SuperToast.Type.STANDARD,
Style.getStyle(color, SuperToast.Animations.POPUP));
toast.setText(str);
toast.setDuration(SuperToast.Duration.EXTRA_LONG);
toast.setIndeterminate(false);
toast.setSwipeToDismiss(true);
return toast;
}
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags); super.writeToParcel(dest, flags);

View File

@@ -19,18 +19,23 @@ package org.sufficientlysecure.keychain.ui.util;
import android.app.Activity; import android.app.Activity;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Color;
import com.github.johnpersano.supertoasts.SuperCardToast; import com.nispok.snackbar.Snackbar;
import com.github.johnpersano.supertoasts.SuperToast; import com.nispok.snackbar.Snackbar.SnackbarDuration;
import com.nispok.snackbar.SnackbarManager;
import com.nispok.snackbar.listeners.ActionClickListener;
/** /**
* @author danielhass
* Notify wrapper which allows a more easy use of different notification libraries * Notify wrapper which allows a more easy use of different notification libraries
*/ */
public class Notify { public class Notify {
public static enum Style {OK, WARN, INFO, ERROR} public static enum Style {OK, WARN, INFO, ERROR}
public static final int LENGTH_INDEFINITE = 0;
public static final int LENGTH_LONG = 3500;
/** /**
* Shows a simple in-layout notification with the CharSequence given as parameter * Shows a simple in-layout notification with the CharSequence given as parameter
* @param activity * @param activity
@@ -39,21 +44,94 @@ public class Notify {
*/ */
public static void showNotify(Activity activity, CharSequence text, Style style) { public static void showNotify(Activity activity, CharSequence text, Style style) {
SuperCardToast st = new SuperCardToast(activity); Snackbar bar = Snackbar.with(activity)
st.setText(text); .text(text)
st.setDuration(SuperToast.Duration.MEDIUM); .duration(SnackbarDuration.LENGTH_LONG);
switch (style){
switch (style) {
case OK: case OK:
st.setBackground(SuperToast.Background.GREEN);
break; break;
case WARN: case WARN:
st.setBackground(SuperToast.Background.ORANGE); bar.textColor(Color.YELLOW);
break; break;
case ERROR: case ERROR:
st.setBackground(SuperToast.Background.RED); bar.textColor(Color.RED);
break; break;
} }
st.show();
SnackbarManager.show(bar);
}
public static Showable createNotify (Activity activity, int resId, int duration, Style style) {
final Snackbar bar = Snackbar.with(activity)
.text(resId);
if (duration == LENGTH_INDEFINITE) {
bar.duration(SnackbarDuration.LENGTH_INDEFINITE);
} else {
bar.duration(duration);
}
switch (style) {
case OK:
bar.actionColor(Color.GREEN);
break;
case WARN:
bar.textColor(Color.YELLOW);
break;
case ERROR:
bar.textColor(Color.RED);
break;
}
return new Showable () {
@Override
public void show() {
SnackbarManager.show(bar);
}
};
}
public static Showable createNotify(Activity activity, int resId, int duration, Style style,
final ActionListener listener, int resIdAction) {
return createNotify(activity, activity.getString(resId), duration, style, listener, resIdAction);
}
public static Showable createNotify(Activity activity, String msg, int duration, Style style,
final ActionListener listener, int resIdAction) {
final Snackbar bar = Snackbar.with(activity)
.text(msg)
.actionLabel(resIdAction)
.actionListener(new ActionClickListener() {
@Override
public void onActionClicked(Snackbar snackbar) {
listener.onAction();
}
});
if (duration == LENGTH_INDEFINITE) {
bar.duration(SnackbarDuration.LENGTH_INDEFINITE);
} else {
bar.duration(duration);
}
switch (style) {
case OK:
bar.actionColor(Color.GREEN);
break;
case WARN:
bar.textColor(Color.YELLOW);
break;
case ERROR:
bar.textColor(Color.RED);
break;
}
return new Showable () {
@Override
public void show() {
SnackbarManager.show(bar);
}
};
} }
@@ -67,4 +145,15 @@ public class Notify {
public static void showNotify(Activity activity, int resId, Style style) throws Resources.NotFoundException { public static void showNotify(Activity activity, int resId, Style style) throws Resources.NotFoundException {
showNotify(activity, activity.getResources().getText(resId), style); showNotify(activity, activity.getResources().getText(resId), style);
} }
public interface Showable {
public void show();
}
public interface ActionListener {
public void onAction();
}
} }

View File

@@ -398,7 +398,7 @@
<string name="import_qr_code_text">"Place your camera over the QR Code!"</string> <string name="import_qr_code_text">"Place your camera over the QR Code!"</string>
<!-- Generic result toast --> <!-- Generic result toast -->
<string name="view_log">"View Log"</string> <string name="view_log">"Details"</string>
<string name="with_warnings">", with warnings"</string> <string name="with_warnings">", with warnings"</string>
<string name="with_cancelled">", until cancelled"</string> <string name="with_cancelled">", until cancelled"</string>