|
| 1 | +// |
| 2 | +// JDStatusBarNotification.h |
| 3 | +// |
| 4 | +// Based on KGStatusBar by Kevin Gibbon |
| 5 | +// |
| 6 | +// Created by Markus Emrich on 10/28/13. |
| 7 | +// Copyright 2013 Markus Emrich. All rights reserved. |
| 8 | +// |
| 9 | + |
| 10 | +#import <UIKit/UIKit.h> |
| 11 | + |
| 12 | +#import "JDStatusBarStyle.h" |
| 13 | +#import "JDStatusBarView.h" |
| 14 | + |
| 15 | +/** |
| 16 | + * A block that is used to define the appearance of a notification. |
| 17 | + * A JDStatusBarStyle instance defines the notification appeareance. |
| 18 | + * |
| 19 | + * @param style The current default JDStatusBarStyle instance. |
| 20 | + * |
| 21 | + * @return The modified JDStatusBarStyle instance. |
| 22 | + */ |
| 23 | +typedef JDStatusBarStyle*(^JDPrepareStyleBlock)(JDStatusBarStyle *style); |
| 24 | + |
| 25 | +/** |
| 26 | + * This class is a singletion which is used to present notifications |
| 27 | + * on top of the status bar. To present a notification, use one of the |
| 28 | + * given class methods. |
| 29 | + */ |
| 30 | +@interface JDStatusBarNotification : NSObject |
| 31 | + |
| 32 | +#pragma mark Presentation |
| 33 | + |
| 34 | +/** |
| 35 | + * Show a notification. It won't hide automatically, |
| 36 | + * you have to dimiss it on your own. |
| 37 | + * |
| 38 | + * @param status The message to display |
| 39 | + * |
| 40 | + * @return The presented notification view for further customization |
| 41 | + */ |
| 42 | ++ (JDStatusBarView*)showWithStatus:(NSString *)status; |
| 43 | + |
| 44 | +/** |
| 45 | + * Show a notification with a specific style. It won't |
| 46 | + * hide automatically, you have to dimiss it on your own. |
| 47 | + * |
| 48 | + * @param status The message to display |
| 49 | + * @param styleName The name of the style. You can use any JDStatusBarStyle constant |
| 50 | + * (JDStatusBarStyleDefault, etc.), or a custom style identifier, after you added a |
| 51 | + * custom style. If this is nil, the default style will be used. |
| 52 | + * |
| 53 | + * @return The presented notification view for further customization |
| 54 | + */ |
| 55 | ++ (JDStatusBarView*)showWithStatus:(NSString *)status |
| 56 | + styleName:(NSString*)styleName; |
| 57 | + |
| 58 | +/** |
| 59 | + * Same as showWithStatus:, but the notification will |
| 60 | + * automatically dismiss after the given timeInterval. |
| 61 | + * |
| 62 | + * @param status The message to display |
| 63 | + * @param timeInterval The duration, how long the notification |
| 64 | + * is displayed. (Including the animation duration) |
| 65 | + * |
| 66 | + * @return The presented notification view for further customization |
| 67 | + */ |
| 68 | ++ (JDStatusBarView*)showWithStatus:(NSString *)status |
| 69 | + dismissAfter:(NSTimeInterval)timeInterval; |
| 70 | + |
| 71 | +/** |
| 72 | + * Same as showWithStatus:styleName:, but the notification |
| 73 | + * will automatically dismiss after the given timeInterval. |
| 74 | + * |
| 75 | + * @param status The message to display |
| 76 | + * @param timeInterval The duration, how long the notification |
| 77 | + * is displayed. (Including the animation duration) |
| 78 | + * @param styleName The name of the style. You can use any JDStatusBarStyle constant |
| 79 | + * (JDStatusBarStyleDefault, etc.), or a custom style identifier, after you added a |
| 80 | + * custom style. If this is nil, the default style will be used. |
| 81 | + * |
| 82 | + * @return The presented notification view for further customization |
| 83 | + */ |
| 84 | ++ (JDStatusBarView*)showWithStatus:(NSString *)status |
| 85 | + dismissAfter:(NSTimeInterval)timeInterval |
| 86 | + styleName:(NSString*)styleName; |
| 87 | + |
| 88 | +#pragma mark Dismissal |
| 89 | + |
| 90 | +/** |
| 91 | + * Calls dismissAnimated: with animated set to YES |
| 92 | + */ |
| 93 | ++ (void)dismiss; |
| 94 | + |
| 95 | +/** |
| 96 | + * Dismisses any currently displayed notification immediately |
| 97 | + * |
| 98 | + * @param animated If this is YES, the animation style used |
| 99 | + * for presentation will also be used for the dismissal. |
| 100 | + */ |
| 101 | ++ (void)dismissAnimated:(BOOL)animated; |
| 102 | + |
| 103 | +/** |
| 104 | + * Same as dismissAnimated:, but you can specify a delay, |
| 105 | + * so the notification wont be dismissed immediately |
| 106 | + * |
| 107 | + * @param delay The delay, how long the notification should stay visible |
| 108 | + */ |
| 109 | ++ (void)dismissAfter:(NSTimeInterval)delay; |
| 110 | + |
| 111 | +#pragma mark Styles |
| 112 | + |
| 113 | +/** |
| 114 | + * This changes the default style, which is always used |
| 115 | + * when a method without styleName is used for presentation, or |
| 116 | + * styleName is nil, or no style is found with this name. |
| 117 | + * |
| 118 | + * @param prepareBlock A block, which has a JDStatusBarStyle instance as |
| 119 | + * parameter. This instance can be modified to suit your needs. You need |
| 120 | + * to return the modified style again. |
| 121 | + */ |
| 122 | ++ (void)setDefaultStyle:(JDPrepareStyleBlock)prepareBlock; |
| 123 | + |
| 124 | +/** |
| 125 | + * Adds a custom style, which than can be used |
| 126 | + * in the presentation methods. |
| 127 | + * |
| 128 | + * @param identifier The identifier, which will |
| 129 | + * later be used to reference the configured style. |
| 130 | + * @param prepareBlock A block, which has a JDStatusBarStyle instance as |
| 131 | + * parameter. This instance can be modified to suit your needs. You need |
| 132 | + * to return the modified style again. |
| 133 | + * |
| 134 | + * @return Returns the given identifier, so it can |
| 135 | + * be directly used as styleName parameter. |
| 136 | + */ |
| 137 | ++ (NSString*)addStyleNamed:(NSString*)identifier |
| 138 | + prepare:(JDPrepareStyleBlock)prepareBlock; |
| 139 | + |
| 140 | +#pragma mark progress & activity |
| 141 | + |
| 142 | +/** |
| 143 | + * Show the progress below the label. |
| 144 | + * |
| 145 | + * @param progress Relative progress from 0.0 to 1.0 |
| 146 | + */ |
| 147 | ++ (void)showProgress:(CGFloat)progress; |
| 148 | + |
| 149 | +/** |
| 150 | + * Shows an activity indicator in front of the notification text |
| 151 | + * |
| 152 | + * @param show Use this flag to show or hide the activity indicator |
| 153 | + * @param indicatorStyle Sets the style of the activity indicator |
| 154 | + */ |
| 155 | ++ (void)showActivityIndicator:(BOOL)show |
| 156 | + indicatorStyle:(UIActivityIndicatorViewStyle)style; |
| 157 | + |
| 158 | +#pragma mark state |
| 159 | + |
| 160 | +/** |
| 161 | + * This method tests, if a notification is currently displayed. |
| 162 | + * |
| 163 | + * @return YES, if a notification is currently displayed. Otherwise NO. |
| 164 | + */ |
| 165 | ++ (BOOL)isVisible; |
| 166 | + |
| 167 | +@end |
| 168 | + |
| 169 | + |
0 commit comments