-
Notifications
You must be signed in to change notification settings - Fork 32
/
MNAlertDashboardViewController.m
295 lines (244 loc) · 10.4 KB
/
MNAlertDashboardViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
Copyright (c) 2010-2011, Peter Hajas
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Peter Hajas nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL PETER HAJAS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import <QuartzCore/QuartzCore.h>
#import "MNAlertDashboardViewController.h"
@implementation MNAlertDashboardViewController
@synthesize window;
@synthesize dashboardShowing;
@synthesize delegate = _delegate;
-(id)initWithDelegate:(id)__delegate;
{
self = [super init];
if (self)
{
_delegate = __delegate;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
// window:
window = [[UIWindow alloc]
initWithFrame:CGRectMake(0,0,screenBounds.size.width,385)];
window.windowLevel = UIWindowLevelAlert+102.0f;
window.userInteractionEnabled = YES;
window.hidden = YES;
// ClearAllButton
clearAllButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
clearAllButton.frame = CGRectMake(245,10.5,72,33);
[clearAllButton setAlpha:1.0];
clearAllButton.backgroundColor = [UIColor clearColor];
[clearAllButton setBackgroundImage:[UIImage imageWithContentsOfFile:@"/Library/Application Support/MobileNotifier/clear_btn.png"] forState:UIControlStateNormal];
// Wire up clearAllButton
[clearAllButton addTarget:self action:@selector(clearDashboardPushed:)
forControlEvents:UIControlEventTouchUpInside];
logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 32, 32)];
logoImageView.image = [UIImage imageWithContentsOfFile:@"/Library/Application Support/MobileNotifier/lockscreen-logo.png"];
backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,54)];
backgroundImageView.image = [UIImage imageWithContentsOfFile:@"/Library/Application Support/MobileNotifier/lockscreenbg.png"];
backgroundImageView.opaque = NO;
[backgroundImageView setAlpha:0.9];
numberOfPendingAlertsLabel = [[UILabel alloc] initWithFrame:CGRectMake(265,16,35,22)];
numberOfPendingAlertsLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
numberOfPendingAlertsLabel.textAlignment = UITextAlignmentCenter;
numberOfPendingAlertsLabel.textColor = [UIColor blackColor];
numberOfPendingAlertsLabel.backgroundColor = [UIColor clearColor];
numberOfPendingAlertsLabel.opaque = NO;
numberOfPendingAlertsBackground = [[UIImageView alloc] initWithFrame:CGRectMake(270,17,27,20)];
numberOfPendingAlertsBackground.image = [UIImage imageWithContentsOfFile:@"/Library/Application Support/MobileNotifier/lockscreen-count-bg.png"];
numberOfPendingAlertsBackground.opaque = NO;
mobileNotifierTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(60,16,180,22)];
mobileNotifierTextLabel.text = @"Missed Notifications";
mobileNotifierTextLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
mobileNotifierTextLabel.textAlignment = UITextAlignmentLeft;
mobileNotifierTextLabel.textColor = [UIColor whiteColor];
mobileNotifierTextLabel.shadowColor = [UIColor blackColor];
mobileNotifierTextLabel.shadowOffset = CGSizeMake(0,-1);
mobileNotifierTextLabel.backgroundColor = [UIColor clearColor];
// Table View Data Source
tableViewDataSourceEditable = [[MNAlertTableViewDataSourceEditable alloc] initWithStyle:kMNAlertTableViewDataSourceTypePending
andDelegate:_delegate];
// Create the tableview
alertListView = [[UITableView alloc] initWithFrame:CGRectMake(0,54,320,332) style:UITableViewStylePlain];
alertListView.delegate = self;
alertListView.dataSource = tableViewDataSourceEditable;
alertListView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.35];
alertListView.separatorColor = [[UIColor blackColor] colorWithAlphaComponent:0.35];
alertListView.hidden = NO;
alertListView.allowsSelection = YES;
// Create and wire up the button for showing and hiding the dashboard,
// and hiding the clear all button
showAlertsListViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
showAlertsListViewButton.frame = CGRectMake(0,0,320,54);
[showAlertsListViewButton addTarget:self action:@selector(dismissSwitcherOrClearButton) forControlEvents:UIControlEventTouchUpInside];
// Wireup swiping to the right to display clear all button
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(addClearButton)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[window addGestureRecognizer:swipeRight];
[swipeRight release];
[window addSubview:backgroundImageView];
[window addSubview:logoImageView];
[window addSubview:numberOfPendingAlertsBackground];
[window addSubview:numberOfPendingAlertsLabel];
[window addSubview:mobileNotifierTextLabel];
[window addSubview:alertListView];
[window addSubview:showAlertsListViewButton];
dashboardShowing = NO;
[self refresh];
}
return self;
}
-(void)addClearButton
{
// Make the clear all button appear
[window addSubview:clearAllButton];
isClearButtonVisible = YES;
}
-(void)removeClearButton
{
// Make the clear all button go away
[clearAllButton removeFromSuperview];
isClearButtonVisible = NO;
}
-(void)refresh
{
NSNumber *pendingCount = [NSNumber numberWithInt:[[_delegate getPendingAlerts] count]];
numberOfPendingAlertsLabel.text = [pendingCount stringValue];
[alertListView reloadData];
}
-(bool)isShowing
{
return !window.hidden;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [tableViewDataSourceEditable tableView:tableView heightForRowAtIndexPath:indexPath];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Take action on the alert
[_delegate actionOnAlertAtIndex:indexPath.row];
[self refresh];
}
-(void)dismissSwitcher
{
[_delegate dismissSwitcher];
}
-(void)dismissSwitcherOrClearButton
{
if (isClearButtonVisible == NO)
{
[self dismissSwitcher];
}
else
{
[self removeClearButton];
}
}
-(void)toggleDashboard
{
if (dashboardShowing)
{
[self fadeDashboardDown];
}
else
{
[self showDashboard];
}
}
// ---------------------------------------------------
// Animate dashboard elements down for a "fade down"
// effect similar to the multitasking drawer animation
// ---------------------------------------------------
-(void)fadeDashboardDown
{
window.userInteractionEnabled = NO;
dashboardShowing = NO;
[UIView beginAnimations:@"fadeDashboardDown" context:NULL];
[UIView setAnimationDuration:0.25];
[window setAlpha:0.0];
[UIView commitAnimations];
}
// -----------------------------------------------
// Animate dashboard elements using a "fade away"
// effect to better match the app switching effect
// -----------------------------------------------
-(void)fadeDashboardAway
{
window.userInteractionEnabled = NO;
dashboardShowing = NO;
[UIView beginAnimations:@"fadeDashboardAway" context:NULL];
[UIView setAnimationDuration:0.135];
// Shrink the elements and fade out
// to create a zoom out effect
alertListView.transform = CGAffineTransformMakeScale(0.1,0.1);
[window setAlpha:0.0];
[UIView commitAnimations];
}
// -----------------------------------------------
// Animate the dashboard elements "up" similar to
// the multitasking drawer animation to make room
// for the application switcher
// -----------------------------------------------
-(void)showDashboard
{
window.userInteractionEnabled = YES;
window.hidden = NO;
dashboardShowing = YES;
// Ensure that the clear all button
// never shows when we load the dashboard
if (isClearButtonVisible)
{
[self removeClearButton];
}
// Restore previously transformed elements
alertListView.transform = CGAffineTransformIdentity;
[UIView beginAnimations:@"fadeIn" context:NULL];
[UIView setAnimationDuration:0.25];
[window setAlpha:1.0];
[UIView commitAnimations];
}
-(void)clearDashboardPushed:(id)sender
{
[_delegate clearPending];
[self dismissSwitcher];
}
-(void)animationDidStop:(NSString*)animationID didFinish:(NSNumber*)finished inContext:(id)context
{
if ([animationID isEqualToString:@"fadeIn"])
{
window.userInteractionEnabled = YES;
}
if ([animationID isEqualToString:@"fadeDashboardDown"] || [animationID isEqualToString:@"fadeDashboardAway"])
{
window.userInteractionEnabled = NO;
window.hidden = YES;
}
if ([animationID isEqualToString:@"listAppear"])
{
alertListView.hidden = NO;
}
if ([animationID isEqualToString:@"listDisappear"] || [animationID isEqualToString:@"fadeDashboardAway"])
{
alertListView.hidden = YES;
}
}
@end