aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-03-24 15:29:02 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-03-24 15:29:58 +0100
commitf9ef1160ca764d508dafcb45fbf65f18911fff9c (patch)
tree816564326b238848669d7a0713f48c84791cd13b /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util
parentfe32e7bff4e724d37903d07cd3b4f0287ec85879 (diff)
parent8b4388e1a2d5cb2b7f0524c18ad3383e3375ba7b (diff)
downloadopen-keychain-f9ef1160ca764d508dafcb45fbf65f18911fff9c.tar.gz
open-keychain-f9ef1160ca764d508dafcb45fbf65f18911fff9c.tar.bz2
open-keychain-f9ef1160ca764d508dafcb45fbf65f18911fff9c.zip
Merge branch 'development' into linked-identities
Conflicts: OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java218
1 files changed, 105 insertions, 113 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 3bc29edb6..7e07ed818 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
@@ -18,7 +18,9 @@
package org.sufficientlysecure.keychain.ui.util;
import android.app.Activity;
-import android.content.res.Resources;
+import android.support.v4.app.Fragment;
+import android.view.View;
+import android.view.ViewGroup;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.Snackbar.SnackbarDuration;
@@ -35,157 +37,147 @@ import org.sufficientlysecure.keychain.util.FabContainer;
*/
public class Notify {
- public static enum Style {OK, WARN, INFO, ERROR}
+ public static enum Style {
+ OK, WARN, ERROR;
+
+ public void applyToBar(Snackbar bar) {
+
+ switch (this) {
+ case OK:
+ // bar.actionColorResource(R.color.android_green_light);
+ bar.lineColorResource(R.color.android_green_light);
+ break;
+ case WARN:
+ // bar.textColorResource(R.color.android_orange_light);
+ bar.lineColorResource(R.color.android_orange_light);
+ break;
+ case ERROR:
+ // bar.textColorResource(R.color.android_red_light);
+ bar.lineColorResource(R.color.android_red_light);
+ break;
+ }
+
+ }
+ }
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
- * @param text Text to show
- * @param style Notification styling
- */
- public static void showNotify(final Activity activity, CharSequence text, Style style) {
-
- Snackbar bar = getSnackbar(activity)
+ public static Showable create(final Activity activity, String text, int duration, Style style,
+ final ActionListener actionListener, int actionResId) {
+ final Snackbar snackbar = Snackbar.with(activity)
+ .type(SnackbarType.MULTI_LINE)
.text(text);
- switch (style) {
- case OK:
- break;
- case WARN:
- bar.textColor(activity.getResources().getColor(R.color.android_orange_light));
- break;
- case ERROR:
- bar.textColor(activity.getResources().getColor(R.color.android_red_light));
- break;
- }
-
- SnackbarManager.show(bar);
-
- }
-
- public static Showable createNotify (Activity activity, int resId, int duration, Style style) {
- final Snackbar bar = getSnackbar(activity)
- .text(resId);
-
if (duration == LENGTH_INDEFINITE) {
- bar.duration(SnackbarDuration.LENGTH_INDEFINITE);
+ snackbar.duration(SnackbarDuration.LENGTH_INDEFINITE);
} else {
- bar.duration(duration);
+ snackbar.duration(duration);
}
- switch (style) {
- case OK:
- bar.actionColor(activity.getResources().getColor(R.color.android_green_light));
- break;
- case WARN:
- bar.textColor(activity.getResources().getColor(R.color.android_orange_light));
- break;
- case ERROR:
- bar.textColor(activity.getResources().getColor(R.color.android_red_light));
- 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) {
- return createNotify(activity, msg, duration, style, null, 0);
- }
+ style.applyToBar(snackbar);
- public static Showable createNotify(Activity activity, String msg, int duration, Style style,
- final ActionListener listener, int resIdAction) {
+ if (actionListener != null) {
+ snackbar.actionLabel(actionResId)
+ .actionListener(new ActionClickListener() {
+ @Override
+ public void onActionClicked(Snackbar snackbar) {
+ actionListener.onAction();
+ }
+ });
+ }
- final Snackbar bar = getSnackbar(activity)
- .text(msg);
+ if (activity instanceof FabContainer) {
+ snackbar.eventListener(new EventListenerAdapter() {
+ @Override
+ public void onShow(Snackbar snackbar) {
+ ((FabContainer) activity).fabMoveUp(snackbar.getHeight());
+ }
- if (listener != null) {
- bar.actionLabel(resIdAction);
- bar.actionListener(new ActionClickListener() {
@Override
- public void onActionClicked(Snackbar snackbar) {
- listener.onAction();
+ public void onDismiss(Snackbar snackbar) {
+ ((FabContainer) activity).fabRestorePosition();
}
});
}
- if (duration == LENGTH_INDEFINITE) {
- bar.duration(SnackbarDuration.LENGTH_INDEFINITE);
- } else {
- bar.duration(duration);
- }
+ return new Showable() {
+ @Override
+ public void show() {
+ SnackbarManager.show(snackbar, activity);
+ }
- switch (style) {
- case OK:
- bar.actionColor(activity.getResources().getColor(R.color.android_green_light));
- break;
- case WARN:
- bar.textColor(activity.getResources().getColor(R.color.android_orange_light));
- break;
- case ERROR:
- bar.textColor(activity.getResources().getColor(R.color.android_red_light));
- break;
- }
+ @Override
+ public void show(Fragment fragment) {
+ if (fragment != null) {
+ View view = fragment.getView();
+
+ if (view != null && view instanceof ViewGroup) {
+ SnackbarManager.show(snackbar, (ViewGroup) view);
+ return;
+ }
+ }
+
+ show();
+ }
- return new Showable () {
@Override
- public void show() {
- SnackbarManager.show(bar);
+ public void show(ViewGroup viewGroup) {
+ if (viewGroup != null) {
+ SnackbarManager.show(snackbar, viewGroup);
+ return;
+ }
+
+ show();
}
};
+ }
+ public static Showable create(Activity activity, String text, int duration, Style style) {
+ return create(activity, text, duration, style, null, -1);
}
- /**
- * Shows a simple in-layout notification with the resource text from given id
- * @param resId ResourceId of notification text
- * @param style Notification styling
- * @throws Resources.NotFoundException
- */
- public static void showNotify(Activity activity, int resId, Style style) throws Resources.NotFoundException {
- showNotify(activity, activity.getResources().getText(resId), style);
+ public static Showable create(Activity activity, String text, Style style) {
+ return create(activity, text, LENGTH_LONG, style);
}
- private static Snackbar getSnackbar(final Activity activity) {
- Snackbar bar = Snackbar.with(activity)
- .type(SnackbarType.MULTI_LINE)
- .duration(SnackbarDuration.LENGTH_LONG);
+ public static Showable create(Activity activity, int textResId, int duration, Style style,
+ ActionListener actionListener, int actionResId) {
+ return create(activity, activity.getString(textResId), duration, style, actionListener, actionResId);
+ }
- if (activity instanceof FabContainer) {
- bar.eventListener(new EventListenerAdapter() {
- @Override
- public void onShow(Snackbar snackbar) {
- ((FabContainer) activity).fabMoveUp(snackbar.getHeight());
- }
+ public static Showable create(Activity activity, int textResId, int duration, Style style) {
+ return create(activity, activity.getString(textResId), duration, style);
+ }
- @Override
- public void onDismiss(Snackbar snackbar) {
- ((FabContainer) activity).fabRestorePosition();
- }
- });
- }
- return bar;
+ public static Showable create(Activity activity, int textResId, Style style) {
+ return create(activity, activity.getString(textResId), style);
}
public interface Showable {
+
+ /**
+ * Shows the notification on the bottom of the Activity.
+ */
public void show();
+ /**
+ * Shows the notification on the bottom of the Fragment.
+ */
+ public void show(Fragment fragment);
+
+ /**
+ * Shows the notification on the given ViewGroup.
+ * The viewGroup should be either a RelativeLayout or FrameLayout.
+ */
+ public void show(ViewGroup viewGroup);
+
}
public interface ActionListener {
+
public void onAction();
}
-} \ No newline at end of file
+}