-
Notifications
You must be signed in to change notification settings - Fork 8
/
SelectionPage.xm
575 lines (448 loc) · 23 KB
/
SelectionPage.xm
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
#import "SelectionPage.h"
#import "SpringBoard.h"
#import "Tweak.h"
#import "UIImage+Tint.h"
#import "ManualLayout.h"
#import <substrate.h>
@implementation ACSearchButton
- (id)init {
CGSize size = [ACManualLayout searchButtonSize];
self = [super initWithFrame:CGRectMake(0, 0, size.width, size.height)];
if (self) {
UIImage *image = [UIImage imageWithContentsOfFile:@"/Library/Application Support/App Center/mag.png"];
[self setGlyphImage:image selectedGlyphImage:image name:@"ACSearchButton"];
}
return self;
}
- (CGSize)intrinsicContentSize {
return [ACManualLayout searchButtonSize];
}
@end
@implementation ACIconButton
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
UIImage *image = [UIImage imageWithContentsOfFile:@"/Library/Application Support/App Center/appcenter.png"];
[self setGlyphImage:image selectedGlyphImage:image name:@"ACIconButton"];
}
self.userInteractionEnabled = false;
return self;
}
- (CGSize)intrinsicContentSize {
return [ACManualLayout appCenterButtonSize];
}
@end
@implementation ACAppIconCell
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
CGFloat cornerRadius = [ACManualLayout appCellCornerRadius];
self.contentView.layer.cornerRadius = cornerRadius;
self.longPressRec = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress)];
self.longPressRec.minimumPressDuration = 0.75;
[self.contentView addGestureRecognizer:self.longPressRec];
[self.longPressRec release];
self.button = [CCUIControlCenterButton roundRectButton];
self.button.delegate = self;
self.button.userInteractionEnabled = false;
self.button.animatesStateChanges = true;
self.button.translatesAutoresizingMaskIntoConstraints = false;
[self.contentView addSubview:self.button];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[button]|" options:nil metrics:nil views:@{ @"button" : self.button }]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[button]|" options:nil metrics:nil views:@{ @"button" : self.button }]];
CGFloat appIconScale = [ACManualLayout appIconScale];
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [%c(SBIconView) defaultIconImageSize].width * appIconScale, [%c(SBIconView) defaultIconImageSize].height * appIconScale)];
self.imageView.center = CGPointMake(self.contentView.bounds.size.width / 2, (self.contentView.bounds.size.height * 0.80) / 2);
UIImage *dropShadowImage = [UIImage imageWithContentsOfFile:@"/Library/Application Support/App Center/app icon drop shadow.png"];
UIImageView *dropShadowView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.imageView.frame.size.width * 1.1, self.imageView.frame.size.height * 1.1)];
dropShadowView.center = CGPointMake(self.contentView.bounds.size.width / 2, (self.contentView.bounds.size.height * 0.80) / 2);
dropShadowView.image = dropShadowImage;
[self.button addSubview:dropShadowView];
[self.button addSubview:self.imageView];
[dropShadowView release];
[self.imageView release];
self.loadingView = [[UIActivityIndicatorView alloc] initWithFrame:self.imageView.frame];
self.loadingView.hidesWhenStopped = true;
[self.loadingView stopAnimating];
[self.button addSubview:self.loadingView];
CGPoint center = self.imageView.center;
center.x = self.bounds.size.width / 2;
self.imageView.center = center;
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.titleLabel.textColor = [UIColor whiteColor];
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.titleLabel.adjustsFontSizeToFitWidth = false;
self.titleLabel.font = [UIFont systemFontOfSize:[ACManualLayout appDisplayNameFontSize]];
self.titleLabel.translatesAutoresizingMaskIntoConstraints = false;
[self.button addSubview:self.titleLabel];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[label]|" options:nil metrics:nil views:@{ @"label" : self.titleLabel }]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageView][label]|" options:nil metrics:nil views:@{ @"label" : self.titleLabel, @"imageView" : self.imageView }]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideActivity) name:@"ACAppCellStopActivity" object:nil];
}
return self;
}
- (void)showActivity {
[self.loadingView startAnimating];
self.imageView.highlighted = true;
}
- (void)hideActivity {
[self.loadingView stopAnimating];
self.imageView.highlighted = false;
}
- (void)handleLongPress {
if ([[objc_getClass("BioProtectController") sharedInstance] requiresAuthenticationForIdentifier:self.appIdentifier]){
// Un-commenting any of these lines will lead to a crash, seems like a bug in BioProtect :(
/*[[objc_getClass("BioProtectController") sharedInstance] launchProtectedApplicationWithIdentifier:self.appIdentifier];*/
/*[[objc_getClass("BioProtectController") sharedInstance] authenticateForIdentifier:self.appIdentifier
object:self
selector:@selector(launchApp)
arrayOfArgumentsAsNSValuePointers:nil];
*/
} else {
[self launchApp];
}
}
- (void)launchApp {
[[UIApplication sharedApplication] launchApplicationWithIdentifier:self.appIdentifier suspended:NO];
}
- (void)prepareForReuse {
[self.button _updateEffects];
}
- (id)controlCenterSystemAgent {
return nil;
}
- (void)buttonTapped:(CCUIControlCenterButton *)arg1 {
}
- (void)button:(CCUIControlCenterButton *)arg1 didChangeState:(long long)arg2 {
if (arg2 == 0) {
self.titleLabel.textColor = [UIColor whiteColor];
} else {
self.titleLabel.textColor = [UIColor blackColor];
}
}
- (BOOL)isInternal {
return false;
}
- (void)configureForApplication:(NSString*)appIdentifier {
self.appIdentifier = appIdentifier;
SBIconModel *iconModel = [(SBIconController*)[%c(SBIconController) sharedInstance] model];
SBIcon *icon = [iconModel expectedIconForDisplayIdentifier:appIdentifier];
int iconFormat = [icon iconFormatForLocation:0];
self.imageView.image = [icon getCachedIconImage:iconFormat];
self.imageView.highlightedImage = [self.imageView.image tintedImageUsingColor:[UIColor colorWithWhite:0.0 alpha:0.5]];
self.titleLabel.text = [[[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:self.appIdentifier] displayName];
if ([appPages containsObject:appIdentifier]) {
self.button.selected = true;
} else {
self.button.selected = false;
}
}
@end
@implementation ACAppSelectionGridViewController
- (NSArray*)searchResults {
NSDictionary *applications = MSHookIvar<NSDictionary*>([%c(SBApplicationController) sharedInstance], "_applicationsByBundleIdentifer");
NSMutableArray *result = [NSMutableArray new];
for (NSString *key in applications) {
SBApplication *application = applications[key];
if ([[[application displayName] lowercaseString] hasPrefix:[selectionViewController.view.searchBar.text lowercaseString]]) {
if ([application hasHiddenTag]) {
continue;
}
if ([appPages containsObject:[application bundleIdentifier]]) {
continue;
}
if ([key isEqualToString:[(SpringBoard*)[%c(SpringBoard) sharedApplication] _accessibilityFrontMostApplication].bundleIdentifier]) {
continue;
}
[result addObject:application];
}
}
return [result autorelease];
}
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
ACAppIconCell *iconCell = (ACAppIconCell*)cell;
[iconCell.button _updateEffects];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (selectionViewController.searching) {
return MIN([[self searchResults] count], 9);
}
return MIN([[[%c(SBAppSwitcherModel) sharedInstance] appcenter_model] count] + appPages.count, 9);
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ACAppIconCell *cell = (ACAppIconCell*)[self.collectionView dequeueReusableCellWithReuseIdentifier:@"AppIconCell" forIndexPath:indexPath];
NSString *appIdentifier = nil;
if (selectionViewController.searching) {
appIdentifier = [[self searchResults][indexPath.row] bundleIdentifier];
} else if (indexPath.row < appPages.count) {
appIdentifier = appPages[indexPath.row];
} else {
appIdentifier = [[%c(SBAppSwitcherModel) sharedInstance] appcenter_model][indexPath.row - appPages.count];
}
[cell configureForApplication:appIdentifier];
return cell;
}
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
ACAppIconCell *cell = (ACAppIconCell*)[self.collectionView cellForItemAtIndexPath:indexPath];
cell.imageView.highlighted = true;
}
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath {
ACAppIconCell *cell = (ACAppIconCell*)[self.collectionView cellForItemAtIndexPath:indexPath];
cell.imageView.highlighted = false;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
CCUIControlCenterViewController *ccViewController = (CCUIControlCenterViewController*)self.parentViewController.parentViewController.parentViewController;
ACAppIconCell *cell = (ACAppIconCell*)[self.collectionView cellForItemAtIndexPath:indexPath];
((ACAppSelectionPageViewController*)self.parentViewController).selectedCell = cell;
if (!cell.button.selected && ![[[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:cell.appIdentifier] isRunning]) {
[cell showActivity];
}
if (selectionViewController.searching && !cell.button.selected) {
[selectionViewController endSearching];
}
cell.button.selected = !cell.button.selected;
if (cell.button.selected && [[objc_getClass("BioProtectController") sharedInstance] requiresAuthenticationForIdentifier:cell.appIdentifier]){
NSString *appID = cell.appIdentifier;
NSValue *arg1=[NSValue valueWithPointer:&appID];
NSArray *argumentsArray=[NSArray arrayWithObjects:arg1, NULL];
[[objc_getClass("BioProtectController") sharedInstance] authenticateForIdentifier:cell.appIdentifier
object:ccViewController
selector:@selector(appcenter_appSelected:)
arrayOfArgumentsAsNSValuePointers:argumentsArray];
} else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (selectionViewController.searching ? 0.5 : 0.2) * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[ccViewController appcenter_appSelected:cell.appIdentifier];
});
}
}
- (void)loadView {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = [ACManualLayout collectionViewFlowLayoutItemSize];
layout.minimumLineSpacing = [ACManualLayout collectionViewFlowLayoutItemSpacing];
layout.minimumInteritemSpacing = [ACManualLayout collectionViewFlowLayoutItemSpacing];
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.translatesAutoresizingMaskIntoConstraints = false;
self.collectionView.backgroundColor = [UIColor clearColor];
[self.collectionView registerClass:[ACAppIconCell class] forCellWithReuseIdentifier:@"AppIconCell"];
self.view = self.collectionView;
[layout release];
}
@end
@implementation ACAppSelectionContainerView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.translatesAutoresizingMaskIntoConstraints = false;
ACIconButton *iconButton = [[ACIconButton alloc] initWithFrame:CGRectZero];
self.iconButton = iconButton;
[iconButton release];
[self.iconButton setTranslatesAutoresizingMaskIntoConstraints:false];
UILabel *titleLabel = [[CCUIControlCenterLabel alloc] init];
self.titleLabel = titleLabel;
[titleLabel release];
[self.titleLabel setAllowsDefaultTighteningForTruncation:true];
[self.titleLabel setAdjustsFontSizeToFitWidth:true];
[self.titleLabel setMinimumScaleFactor:(float)0x3f400000];
[self.titleLabel setTranslatesAutoresizingMaskIntoConstraints:false];
self.titleLabel.text = @"App Center";
self.titleLabel.font = [UIFont systemFontOfSize:[ACManualLayout appCenterLabelFontSize] weight:UIFontWeightMedium];
self.searchButton = [[ACSearchButton alloc] init];
[self.searchButton setTranslatesAutoresizingMaskIntoConstraints:false];
self.searchButton.alpha = 1.0;
BOOL noctisEnabled = false;
// UISearchBar isn't supported by Noctis at the moment, this is a workaround to still make it work. Unfortunately it crashes SpringBoard.
/*NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:NOCTIS_PREFS_PATH];
if (dictionary) {
if (dictionary[@"LQDDarkModeEnabled"]) {
noctisEnabled = true;
}
}
[dictionary release];*/
self.searchBar = [[UISearchBar alloc] init];
self.searchBar.translatesAutoresizingMaskIntoConstraints = false;
self.searchBar.alpha = 0.0;
self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
self.searchBar.tintColor = noctisEnabled ? [UIColor whiteColor] : [UIColor blackColor];
self.searchBar.showsCancelButton = true;
// Tint the magnifying glass and clear button the same color as the search bar
NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
for (UIView *view in searchBarSubViews) {
if([view isKindOfClass:[UITextField class]]) {
UITextField *textField = (UITextField*)view;
UIImageView *imgView = (UIImageView*)textField.leftView;
imgView.image = [imgView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
imgView.tintColor = self.searchBar.tintColor;
UIButton *btnClear = (UIButton*)[textField valueForKey:@"clearButton"];
[btnClear setImage:[btnClear.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
btnClear.tintColor = self.searchBar.tintColor;
}
}
[self.searchBar reloadInputViews];
UIImage *backgroundImage = [UIImage new];
[self.searchBar setBackgroundImage:backgroundImage];
[self.searchBar setTranslucent:true];
[backgroundImage release];
[self addSubview:self.searchButton];
[self addSubview:self.iconButton];
[self addSubview:self.titleLabel];
[self addSubview:self.searchBar];
[self.searchButton release];
[self.iconButton release];
[self.titleLabel release];
[self.searchBar release];
NSDictionary *views = @{
@"iconButton": self.iconButton,
@"titleLabel": self.titleLabel,
@"searchButton": self.searchButton,
@"searchBar": self.searchBar
};
NSMutableArray *constraints = [NSMutableArray new];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[iconButton]" options:nil metrics:nil views:views]];
NSString *iconButtonTopSpacingVF = [NSString stringWithFormat:@"V:|-(%f)-[iconButton]", [ACManualLayout appCenterButtonTopSpacing]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:iconButtonTopSpacingVF options:nil metrics:nil views:views]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[iconButton]-(8)-[titleLabel]" options:nil metrics:nil views:views]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[searchButton]|" options:nil metrics:nil views:views]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[iconButton][searchBar]-(-8)-|" options:nil metrics:nil views:views]];
[constraints addObject:[NSLayoutConstraint constraintWithItem:self.searchBar attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.iconButton attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
[constraints addObject:[NSLayoutConstraint constraintWithItem:self.searchButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.iconButton attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
CGFloat labelBaselineOffset = [ACManualLayout appCenterLabelOffset];
NSLayoutConstraint *labelFirstBaseline = [NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeFirstBaseline relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:labelBaselineOffset];
[constraints addObject:labelFirstBaseline];
[constraints addObject:[NSLayoutConstraint constraintWithItem:self.searchButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.iconButton attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
[self addConstraints:constraints];
[constraints release];
}
return self;
}
@end
@implementation ACAppSelectionPageViewController
@dynamic view;
@synthesize delegate;
- (id)initWithNibName:(NSString*)nibName bundle:(NSBundle*)bundle {
self = [super initWithNibName:nibName bundle:bundle];
if (self) {
self.gridViewController = [[ACAppSelectionGridViewController alloc] initWithNibName:nil bundle:nil];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (UIEdgeInsets)contentInsets {
return [ACManualLayout collectionViewContentInset];
}
- (BOOL)wantsVisible {
return YES;
}
- (void)loadView {
ACAppSelectionContainerView *view = [[ACAppSelectionContainerView alloc] init];
self.view = view;
[view release];
[self.view.searchButton addTarget:self action:@selector(searchPressed:) forControlEvents:UIControlEventTouchUpInside];
self.view.searchBar.delegate = self;
[self addChildViewController:self.gridViewController];
[self.gridViewController.view setFrame:self.view.bounds];
[self.view addSubview:self.gridViewController.view];
[self.gridViewController didMoveToParentViewController:self];
NSMutableArray *constraints = [NSMutableArray new];
NSDictionary *views = @{
@"gridView": self.gridViewController.view,
@"iconButton": self.view.iconButton,
};
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[gridView]|" options:nil metrics:nil views:views]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[iconButton]-15-[gridView]|" options:nil metrics:nil views:views]];
self.lockedLabel = [[CCUIControlCenterLabel alloc] initWithFrame:CGRectMake(0,0,200,10)];
self.lockedLabel.translatesAutoresizingMaskIntoConstraints = false;
self.lockedLabel.text = @"Unlock to use App Center";
self.lockedLabel.textAlignment = NSTextAlignmentCenter;
self.lockedLabel.font = [UIFont systemFontOfSize:[ACManualLayout appDisplayNameFontSize]*3/2];
[self.lockedLabel setStyle:(unsigned long long) 0];//dark translucent text
[self.lockedLabel release];
[self.view addConstraints:constraints];
}
- (void)beginSearching {
self.searching = true;
[self.gridViewController.collectionView reloadData];
[UIView animateWithDuration:0.25 animations:^{
self.view.searchBar.alpha = 0.9;
self.view.searchButton.alpha = 0.0;
self.view.titleLabel.alpha = 0.0;
}];
CCUIControlCenterViewController *ccViewController = (CCUIControlCenterViewController*)self.parentViewController.parentViewController;
MSHookIvar<UIGestureRecognizer*>(ccViewController, "_tapGesture").enabled = false;
MSHookIvar<UIView*>(ccViewController, "_pagesScrollView").userInteractionEnabled = false;
[self.view.searchBar.window makeKeyAndVisible];
[self.view.searchBar becomeFirstResponder];
}
- (void)endSearching {
self.searching = false;
[UIView animateWithDuration:0.25 animations:^{
self.view.searchBar.alpha = 0.0;
self.view.searchButton.alpha = 1.0;
self.view.titleLabel.alpha = 1.0;
}];
CCUIControlCenterViewController *ccViewController = (CCUIControlCenterViewController*)self.parentViewController.parentViewController;
MSHookIvar<UIGestureRecognizer*>(ccViewController, "_tapGesture").enabled = true;
MSHookIvar<UIView*>(ccViewController, "_pagesScrollView").userInteractionEnabled = true;
[self.view.searchBar resignFirstResponder];
}
- (void)searchPressed:(id)sender {
[self beginSearching];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
[self endSearching];
[self.gridViewController.collectionView reloadData];
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
[self.gridViewController.collectionView reloadData];
}
- (void)controlCenterWillPresent {
if (!reloadingControlCenter) {
[self.gridViewController.collectionView reloadData];
if ([(SpringBoard*)[%c(SpringBoard) sharedApplication] isLocked]) {
self.gridViewController.view.hidden = true;
self.view.searchButton.hidden = true;
[self.view addSubview:self.lockedLabel];
self.lockedLabel.alpha = 1.0;
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.gridViewController.view attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.lockedLabel attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.gridViewController.view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.lockedLabel attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
}
}
}
- (void)controlCenterDidFinishTransition {
}
- (void)controlCenterWillBeginTransition {
}
- (void)controlCenterDidDismiss {
if (self.searching) {
[self endSearching];
}
self.gridViewController.view.hidden = false;
self.view.searchButton.hidden = false;
[self.gridViewController.collectionView reloadData];
[self.lockedLabel removeFromSuperview];
}
- (void)reloadForUnlock {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self controlCenterWillPresent];
self.gridViewController.view.alpha = 0.0;
self.gridViewController.view.hidden = false;
self.view.searchButton.alpha = 0.0;
self.view.searchButton.hidden = false;
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.gridViewController.view.alpha = 1.0;
self.view.searchButton.alpha = 1.0;
self.lockedLabel.alpha = 0.0;
} completion:nil];
});
}
@end