/
Tweak.xm
1021 lines (713 loc) · 28.3 KB
/
Tweak.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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import <objc/runtime.h>
#import <substrate.h>
#import "UIView+Origin.h"
#import "SBIconListModel.h"
#import "SBDockIconListView.h"
#import "SBIconView.h"
#import "SBIconViewMap.h"
#import "SBIconController.h"
#import "SBIcon.h"
#import "SBScaleIconZoomAnimator.h"
#import "SBWallpaperEffectView.h"
#import "SBUIAnimationZoomUpAppFromHome.h"
#import "SBIconFadeAnimator.h"
#import "SBDockView.h"
#import "SBRootFolderView.h"
#import "SBRootFolderController.h"
#import "SBUIController.h"
#import "SBIconModelPropertyListFileStore.h"
#import "SBIconBadgeView.h"
#import "CDStructures.h"
#import "SpringBoard_Interfaces.h"
#import "HBPreferences.h"
#define DEGREES_TO_RADIANS(x) (M_PI * (x) / 180.0)
#pragma mark Declarations
#define UIApp ([UIApplication sharedApplication])
#define cur_orientation ([UIApp statusBarOrientation])
#define in_landscape (UIInterfaceOrientationIsLandscape(cur_orientation) && UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)
#define icon_animation_duration ([[prefs getanimationDuration] floatValue])
@interface SBRootFolderView ()
- (void)orientationChanged:(NSNotification*)arg1;
@end
@interface SBUIController ()
@property (nonatomic, retain) UIWindow *iconBounceWindow;
@property (nonatomic, retain) UIWindow *iconBounceWindowContainer;
@end
@interface SBDockIconListView ()
- (CGFloat)horizontalIconBounds;
- (CGFloat)iconPadding;
- (CGFloat)collapsedIconPadding;
- (CGFloat)collapsedIconScale;
- (CGFloat)collapsedIconWidth;
- (CGPoint)collapsedCenterForIcon:(SBIcon*)icon;
- (CGFloat)scaleForOffsetFromFocusPoint:(CGFloat)offset;
- (CGFloat)yTranslationForOffsetFromFocusPoint:(CGFloat)offset;
- (CGFloat)xTranslationForOffsetFromFocusPoint:(CGFloat)offset;
- (CGFloat)iconCenterY;
- (NSUInteger)columnAtX:(CGFloat)x;
- (void)removeAllBounceAnimations;
- (void)updateIconTransforms;
- (void)collapseAnimated:(BOOL)animated;
- (void)updateIndicatorForIconView:(SBIconView*)iconView animated:(BOOL)animated;
@end
@interface SBDockView ()
- (void)layoutBackgroundView;
@end
#pragma mark Constants
static const CGFloat kCancelGestureRange = 10.0;
static const CGFloat kMaxScale = 1.0;
#pragma mark -
%hook SBDockIconListView
static CGFloat focusPoint;
static BOOL trackingTouch;
static BOOL appLaunching;
static SBIconView *activatingIcon;
static CGFloat maxTranslationX;
static CGFloat xTranslationDamper;
static UIView *indicatorView;
static UILabel *indicatorLabel;
+ (NSUInteger)iconColumnsForInterfaceOrientation:(NSInteger)arg1 {
if (![[prefs getenabled] boolValue])
return %orig(arg1);
return 100;
}
- (id)initWithModel:(id)arg1 orientation:(NSInteger)arg2 viewMap:(id)arg3 {
self = %orig(arg1, arg2, arg3);
if (self) {
trackingTouch = false;
appLaunching = false;
// Set up indicator view
indicatorView = [[UIView alloc] init];
indicatorView.clipsToBounds = true;
indicatorView.layer.cornerRadius = 5;
// Add background view
SBWallpaperEffectView *indicatorBackgroundView = [[%c(SBWallpaperEffectView) alloc] initWithWallpaperVariant:1];
indicatorBackgroundView.style = 11;
indicatorBackgroundView.translatesAutoresizingMaskIntoConstraints = false;
[indicatorView addSubview:indicatorBackgroundView];
// Set up label
indicatorLabel = [[UILabel alloc] init];
indicatorLabel.font = [UIFont systemFontOfSize:14];
indicatorLabel.textColor = [UIColor whiteColor];
indicatorLabel.textAlignment = NSTextAlignmentCenter;
[indicatorView addSubview:indicatorLabel];
// Setup constraints
NSMutableArray *constraints = [NSMutableArray new];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[v]-0-|" options:0 metrics:nil views: @{ @"v" : indicatorBackgroundView }]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[v]-0-|" options:0 metrics:nil views: @{ @"v" : indicatorBackgroundView }]];
[indicatorView addConstraints:constraints];
[constraints release];
[self addSubview:indicatorView];
}
return self;
}
#pragma mark Layout
%new
- (CGFloat)horizontalIconBounds {
return (in_landscape ? self.bounds.size.height : self.bounds.size.width) - [[prefs geticonInset] floatValue] * 2;
}
%new
- (CGFloat)collapsedIconScale {
CGFloat normalIconSize = [%c(SBIconView) defaultVisibleIconImageSize].width;
CGFloat newIconSize = [self horizontalIconBounds] / self.model.numberOfIcons;
if (self.model.numberOfIcons == 0) {
return 1;
}
return MIN(newIconSize / (normalIconSize + [self iconPadding]), 1);
}
%new
- (CGFloat)collapsedIconWidth {
return [self collapsedIconScale] * ([%c(SBIconView) defaultVisibleIconImageSize].width + [self iconPadding]);
}
%new
- (CGFloat)iconPadding {
return [%c(SBIconView) defaultVisibleIconImageSize].width * [[prefs geticonPaddingMultipler] floatValue];
}
%new
- (CGFloat)collapsedIconPadding {
return [self collapsedIconScale] * [self iconPadding];
}
%new
- (CGFloat)scaleForOffsetFromFocusPoint:(CGFloat)offset {
if (fabs(offset) > [[prefs geteffectiveRange] doubleValue])
return [self collapsedIconScale];
return MAX((cos(offset / (([[prefs geteffectiveRange] doubleValue]) / M_PI)) + 1.0) / (1.0 / ((kMaxScale - [self collapsedIconScale]) / 2.0)) + [self collapsedIconScale], [self collapsedIconScale]);
}
%new
- (CGFloat)xTranslationForOffsetFromFocusPoint:(CGFloat)offset {
if (xTranslationDamper == 0)
xTranslationDamper = 1;
return -(atan(offset / (xTranslationDamper * (M_PI / 4))) * ((maxTranslationX) / (M_PI / 2)));
}
%new
- (CGFloat)yTranslationForOffsetFromFocusPoint:(CGFloat)offset {
if (fabs(offset) > [[prefs geteffectiveRange] doubleValue])
return 0;
return -((cos(offset / (([[prefs geteffectiveRange] doubleValue]) / M_PI)) + 1.0) / (1.0 / ([[prefs getevasionDistance] doubleValue] / 2.0)));
}
- (void)updateEditingStateAnimated:(BOOL)arg1 {
%orig(arg1);
if (![[prefs getenabled] boolValue])
return;
[self layoutIconsIfNeeded:0.0 domino:false];
}
%new
- (CGFloat)iconCenterY {
if ([[prefs getflushWithBottom] boolValue]) {
return (in_landscape ? self.bounds.size.width : self.bounds.size.height) - [self collapsedIconWidth] / 2 - 10.0;
} else {
return (in_landscape ? self.bounds.size.width : self.bounds.size.height) / 2;
}
}
- (void)layoutIconsIfNeeded:(NSTimeInterval)animationDuration domino:(BOOL)arg2 {
if (![[prefs getenabled] boolValue]) {
%orig(animationDuration, arg2);
return;
}
CGFloat defaultWidth = [%c(SBIconView) defaultVisibleIconImageSize].width;
xTranslationDamper = acos(([[prefs geteffectiveRange] doubleValue] * [self collapsedIconScale]) / ([[prefs geteffectiveRange] doubleValue] / 2) - 1) * ([[prefs geteffectiveRange] doubleValue] / M_PI);
maxTranslationX = 0;
// Calculate total X translation
int iconsInRange = (int)floor([[prefs geteffectiveRange] doubleValue] / [self collapsedIconWidth]);
float offset = 0;
for (int i = 0; i < 2; i++) {
// Run twice, once for left side of focus, and one for right side of focus
for (int i = 0; i < iconsInRange; i++) {
maxTranslationX += ([self scaleForOffsetFromFocusPoint:offset] * (defaultWidth + [self iconPadding])) - [self collapsedIconWidth];
offset += [self collapsedIconWidth];
}
offset = [self collapsedIconWidth]; // Set to collapsed icon width, so we skip the center icon on the second run
}
[UIView animateWithDuration:animationDuration delay:0.0 usingSpringWithDamping:0.5 initialSpringVelocity:1 options:0 animations:^{
for (int i = 0; i < self.model.numberOfIcons; i++) {
SBIcon *icon = self.model.icons[i];
SBIconView *iconView = [self.viewMap mappedIconViewForIcon:icon];
[self sendSubviewToBack:iconView];
iconView.location = [self iconLocation];
iconView.center = [self collapsedCenterForIcon:icon];
}
if (activatingIcon) {
focusPoint = in_landscape ? activatingIcon.center.y : activatingIcon.center.x;
}
[self updateIconTransforms];
if ([self.superview isKindOfClass:%c(SBDockView)]) {
if (![[prefs getuseNormalBackground] boolValue]) {
[(SBDockView*)self.superview layoutBackgroundView];
}
}
} completion:nil];
if (activatingIcon) {
[self bringSubviewToFront:activatingIcon];
}
}
%new
- (CGPoint)collapsedCenterForIcon:(SBIcon*)icon {
CGFloat defaultWidth = [%c(SBIconView) defaultVisibleIconImageSize].width;
CGFloat xOffset = MAX(([self horizontalIconBounds] - self.model.numberOfIcons * (defaultWidth + [self iconPadding])) / 2, 0);
CGPoint center = CGPointZero;
if (!in_landscape) {
center.x = xOffset + ([self collapsedIconWidth] * [self.model indexForIcon:icon]) + ([self collapsedIconWidth] / 2) + (self.bounds.size.width - [self horizontalIconBounds]) / 2;
center.y = [self iconCenterY];
} else {
center.x = [self iconCenterY];
center.y = xOffset + ([self collapsedIconWidth] * [self.model indexForIcon:icon]) + ([self collapsedIconWidth] / 2) + (self.bounds.size.height - [self horizontalIconBounds]) / 2;
}
return center;
}
%new
- (void)removeAllBounceAnimations {
for (int i = 0; i < self.model.numberOfIcons; i++) {
SBIcon *icon = self.model.icons[i];
SBIconView *iconView = [self.viewMap mappedIconViewForIcon:icon];
[iconView.layer removeAnimationForKey:@"jumping"];
}
}
%new
- (void)updateIconTransforms {
for (int i = 0; i < self.model.numberOfIcons; i++) {
SBIcon *icon = self.model.icons[i];
SBIconView *iconView = [self.viewMap mappedIconViewForIcon:icon];
const CGFloat offsetFromFocusPoint = focusPoint - (in_landscape ? iconView.center.y : iconView.center.x);
CGFloat scale = [self collapsedIconScale];
CGFloat tx = 0;
CGFloat ty = 0;
if (trackingTouch) {
scale = [self scaleForOffsetFromFocusPoint:offsetFromFocusPoint];
ty = [self yTranslationForOffsetFromFocusPoint:offsetFromFocusPoint];
tx = [self xTranslationForOffsetFromFocusPoint:offsetFromFocusPoint];
}
CGPoint center = iconView.center;
if (!in_landscape) {
center.x += tx;
center.y += ty;
} else {
center.x += ty;
center.y += tx;
}
iconView.center = center;
iconView.transform = CGAffineTransformMakeScale(scale, scale);
}
}
%new
- (void)updateIndicatorForIconView:(SBIconView*)iconView animated:(BOOL)animated {
if (![[prefs getshowIndicator] boolValue]) {
indicatorView.hidden = true;
return;
}
if (!iconView) {
if (animated) {
[UIView animateWithDuration:0.2 animations:^{
indicatorView.alpha = 0;
} completion:^(BOOL finished) {
indicatorView.hidden = true;
indicatorView.alpha = 1;
}];
} else {
indicatorView.hidden = true;
}
return;
} else {
if (animated && indicatorView.hidden) {
indicatorView.alpha = 0;
indicatorView.hidden = false;
[UIView animateWithDuration:0.2 animations:^{
indicatorView.alpha = 1;
} completion:nil];
} else {
indicatorView.hidden = false;
}
}
void (^animations) (void) = ^{
NSString *text;
if ([iconView.icon respondsToSelector:@selector(displayName)]) {
text = iconView.icon.displayName;
} else {
text = [iconView.icon displayNameForLocation:[self iconLocation]];
}
CGRect textRect = [text boundingRectWithSize:[%c(SBIconView) maxLabelSize] options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil];
indicatorView.bounds = CGRectMake(0, 0, textRect.size.width + 30, textRect.size.height + 30);
if (!in_landscape) {
indicatorView.center = CGPointMake(MAX(MIN(focusPoint, self.bounds.size.width - indicatorView.bounds.size.width / 2), indicatorView.bounds.size.width / 2), (self.bounds.size.height / 2) - [[prefs getevasionDistance] doubleValue] - indicatorView.bounds.size.height - 20.0);
} else {
indicatorView.center = CGPointMake((self.bounds.size.width / 2) - [[prefs getevasionDistance] doubleValue] - indicatorView.bounds.size.width, MAX(MIN(focusPoint, self.bounds.size.height - indicatorView.bounds.size.height / 2), indicatorView.bounds.size.height / 2));
}
indicatorLabel.text = text;
indicatorLabel.bounds = textRect;
indicatorLabel.center = CGPointMake(indicatorView.bounds.size.width / 2, indicatorView.bounds.size.height / 2);
};
if (animated)
[UIView animateWithDuration:0.1 animations:animations completion:nil];
else
animations();
}
#pragma mark Touch Handling
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (![[prefs getenabled] boolValue]) {
%orig(touches, event);
return;
}
if (appLaunching)
return;
trackingTouch = true;
focusPoint = in_landscape ? [[touches anyObject] locationInView:self].y : [[touches anyObject] locationInView:self].x;
activatingIcon = nil;
[self layoutIconsIfNeeded:icon_animation_duration domino:false];
// Update indicator
SBIconView *focusedIcon = nil;
@try {
focusedIcon = [self.viewMap mappedIconViewForIcon:self.model.icons[[self columnAtX:focusPoint]]];
} @catch (NSException *exception) { }
[self updateIndicatorForIconView:focusedIcon animated:false];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (![[prefs getenabled] boolValue]) {
%orig(touches, event);
}
if (appLaunching)
return;
SBIconView *iconView = nil;
@try {
iconView = [self.viewMap mappedIconViewForIcon:self.model.icons[[self columnAtX:focusPoint]]];
} @catch (NSException *e) { }
//cancel wave without opening an app by tapping with another finger
if ([[event allTouches] count] >= 2) {
[self collapseAnimated:YES];
trackingTouch = NO;
return;
}
if ([[touches anyObject] respondsToSelector:@selector(force)] && [[touches anyObject] force] >= 2.5) {
SBIconController *controller = [NSClassFromString(@"SBIconController") sharedInstance];
if ([controller respondsToSelector:@selector(_revealMenuForIconView:presentImmediately:)]) {
[controller _revealMenuForIconView:iconView presentImmediately:YES];
} else if ([controller respondsToSelector:@selector(_revealMenuForIconView:)]) {
//queue the shortcut object
[controller _revealMenuForIconView:iconView];
//present it if its successfully been created
if ([controller valueForKey:@"_presentedShortcutMenu"]) {
[[controller valueForKey:@"_presentedShortcutMenu"] performSelector:@selector(presentAnimated:) withObject:@(YES)];
}
}
%orig(touches, event);
}
if ((in_landscape ? [[touches anyObject] locationInView:self].x : [[touches anyObject] locationInView:self].y) < 0 && (![[%c(SBIconController) sharedInstance] grabbedIcon] && iconView) && ((![[%c(SBIconController) sharedInstance] isEditing] && [[prefs getinitiateEditMode] boolValue]) || [[%c(SBIconController) sharedInstance] isEditing])) {
// get origin, remove transform, restore origin
CGPoint origin = iconView.origin;
iconView.transform = CGAffineTransformIdentity;
iconView.origin = origin;
// fix frame (somewhere along the way, the size gets set to zero. not exactly sure where)
CGRect frame = iconView.frame;
frame.size = [%c(SBIconView) defaultIconSize];
iconView.frame = frame;
// set grabbed and begin forwarding touches to icon
[[%c(SBIconController) sharedInstance] setGrabbedIcon:iconView.icon];
[iconView touchesBegan:touches withEvent:nil];
[[iconView delegate] iconHandleLongPress:iconView withFeedbackBehavior:nil];
[[%c(SBIconController) sharedInstance] setIsEditing:true];
[self updateIndicatorForIconView:nil animated:true];
return;
}
if ([[%c(SBIconController) sharedInstance] grabbedIcon]) {
SBIconView *iconView = [self.viewMap mappedIconViewForIcon:[[%c(SBIconController) sharedInstance] grabbedIcon]];
[iconView touchesMoved:touches withEvent:nil];
return;
}
focusPoint = in_landscape ? [[touches anyObject] locationInView:self].y : [[touches anyObject] locationInView:self].x;
[self layoutIconsIfNeeded:0 domino:false];
// Update indicator
SBIconView *focusedIcon = nil;
@try {
focusedIcon = [self.viewMap mappedIconViewForIcon:self.model.icons[[self columnAtX:focusPoint]]];
} @catch (NSException *exception) { }
[self updateIndicatorForIconView:focusedIcon animated:true];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (![[prefs getenabled] boolValue]) {
%orig(touches, event);
return;
}
if ([%c(SBUIIconForceTouchController) _isPeekingOrShowing]) {
return;
}
if (appLaunching)
return;
if ([[%c(SBIconController) sharedInstance] grabbedIcon]) {
SBIconView *iconView = [self.viewMap mappedIconViewForIcon:[[%c(SBIconController) sharedInstance] grabbedIcon]];
[iconView touchesEnded:touches withEvent:nil];
return;
}
[self updateIndicatorForIconView:nil animated:true];
if (in_landscape ?
( [[touches anyObject] locationInView:self].x > self.bounds.size.width - kCancelGestureRange) :
( [[touches anyObject] locationInView:self].y > self.bounds.size.height - kCancelGestureRange)) {
// User swiped off to the bottom edge of the screen; collapse and do nothing
[self collapseAnimated:true];
return;
}
if (!trackingTouch)
return;
NSInteger index = [self columnAtX:focusPoint];
SBIconView *iconView = nil;
@try {
iconView = [self.viewMap mappedIconViewForIcon:self.model.icons[index]];
}@catch (NSException *e) {
[self collapseAnimated:true];
return;
}
[self bringSubviewToFront:iconView];
activatingIcon = iconView;
[self layoutIconsIfNeeded:icon_animation_duration domino:false];
[[%c(SBIconController) sharedInstance] iconTapped:iconView];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
if (![[prefs getenabled] boolValue]) {
%orig(touches, event);
return;
}
if (appLaunching)
return;
trackingTouch = false;
[self layoutIconsIfNeeded:0 domino:false];
[self updateIndicatorForIconView:nil animated:true];
}
#pragma mark -
%new
- (void)collapseAnimated:(BOOL)animated {
trackingTouch = false;
activatingIcon = nil;
[self layoutIconsIfNeeded:animated ? icon_animation_duration : 0.0 domino:false];
}
%new
- (NSUInteger)columnAtX:(CGFloat)x {
return in_landscape ? [self rowAtPoint:CGPointMake(0, x)] : [self columnAtPoint:CGPointMake(x, 0)];
}
- (NSUInteger)columnAtPoint:(struct CGPoint)arg1 {
if (![[prefs getenabled] boolValue])
return %orig(arg1);
if (in_landscape) {
return 0;
}
CGFloat collapsedItemWidth = [self collapsedIconWidth];
CGFloat xOffset = MAX(([self horizontalIconBounds] - self.model.numberOfIcons * ([%c(SBIconView) defaultVisibleIconImageSize].width + [self iconPadding])) / 2, 0);
NSInteger index = floorf((arg1.x - (self.bounds.size.width - [self horizontalIconBounds]) / 2 - xOffset) / collapsedItemWidth);
if (index < 0)
index = NSNotFound;
return (NSUInteger)index;
}
- (NSUInteger)rowAtPoint:(struct CGPoint)arg1 {
if (![[prefs getenabled] boolValue])
return %orig(arg1);
if (!in_landscape) {
return 0;
}
CGFloat collapsedItemWidth = [self collapsedIconWidth];
CGFloat xOffset = MAX(([self horizontalIconBounds] - self.model.numberOfIcons * ([%c(SBIconView) defaultVisibleIconImageSize].width + [self iconPadding])) / 2, 0);
NSInteger index = floorf((arg1.y - (self.bounds.size.height - [self horizontalIconBounds]) / 2 - xOffset) / collapsedItemWidth);
if (index < 0)
index = NSNotFound;
return (NSUInteger)index;
}
- (void)removeIconAtIndex:(NSUInteger)arg1 {
%orig(arg1);
if (![[prefs getenabled] boolValue])
return;
[self collapseAnimated:true];
}
%end
%hook SBUIAppIconForceTouchController
- (void)iconForceTouchController:(id)arg1 willDismissForGestureRecognizer:(id)arg2 {
%orig;
SBDockIconListView *dockListView = [[%c(SBIconController) sharedInstance] dockListView];
[dockListView collapseAnimated:true];
}
%end
#pragma mark Animators
%hook SBIconFadeAnimator
- (void)_cleanupAnimation {
%orig();
if (![[prefs getenabled] boolValue])
return;
[[[%c(SBIconController) sharedInstance] dockListView] collapseAnimated:true];
}
%end
%hook SBIconAnimator
- (void)prepare {
if (![[prefs getenabled] boolValue]) {
%orig();
return;
}
appLaunching = true;
%orig();
}
- (void)cleanup {
if (![[prefs getenabled] boolValue]) {
%orig();
return;
}
appLaunching = false;
%orig();
}
%end
%hook SBScaleIconZoomAnimator
- (void)enumerateIconsAndIconViewsWithHandler:(void (^) (id animator, SBIconView *iconView, BOOL inDock))arg1 {
if (![[prefs getenabled] boolValue]) {
%orig(arg1);
return;
}
// Prevent this method from changing the origins and transforms of the dock icons
NSMapTable *mapHolder = MSHookIvar<NSMapTable*>(self, "_dockIconToViewMap");
MSHookIvar<NSMapTable*>(self, "_dockIconToViewMap") = nil;
%orig(arg1);
MSHookIvar<NSMapTable*>(self, "_dockIconToViewMap") = mapHolder;
}
- (void)_prepareAnimation {
if (![[prefs getenabled] boolValue]) {
%orig();
return;
}
// Remove jump animation if in progress
SBDockIconListView *dockListView = [[%c(SBIconController) sharedInstance] dockListView];
[dockListView removeAllBounceAnimations];
// Focus dock on animation target icon
SBIconView *targetIconView = [dockListView.viewMap mappedIconViewForIcon:self.targetIcon];
if ([targetIconView isInDock]) {
activatingIcon = targetIconView;
trackingTouch = true;
[dockListView layoutIconsIfNeeded:0.0 domino:false];
}
%orig();
}
- (void)_cleanupAnimation {
%orig();
if (![[prefs getenabled] boolValue])
return;
[self.dockListView collapseAnimated:true];
}
%end
%hook SBDockView
- (void)layoutSubviews {
%orig();
if (![[prefs getenabled] boolValue])
return;
if (![[prefs getuseNormalBackground] boolValue]) {
MSHookIvar<UIView*>(self, "_highlightView").hidden = true;
[self layoutBackgroundView];
}
// Layout iconBounceWindow
UIWindow *bounceWindow = [(SBUIController*)[%c(SBUIController) sharedInstance] iconBounceWindow];
UIWindow *bounceWindowContainer = [(SBUIController*)[%c(SBUIController) sharedInstance] iconBounceWindowContainer];
CGFloat rotation;
switch(cur_orientation) {
case UIInterfaceOrientationPortrait:
rotation = 0;
break;
case UIInterfaceOrientationPortraitUpsideDown:
rotation = DEGREES_TO_RADIANS(180);
break;
case UIInterfaceOrientationLandscapeLeft:
rotation = DEGREES_TO_RADIANS(270);
break;
case UIInterfaceOrientationLandscapeRight:
rotation = DEGREES_TO_RADIANS(90);
break;
}
bounceWindowContainer.transform = CGAffineTransformMakeRotation(rotation);
bounceWindowContainer.frame = [[UIScreen mainScreen] bounds];
SBDockIconListView *dockListView = [[%c(SBIconController) sharedInstance] dockListView];
CGRect frame = self.frame;
if (in_landscape) {
frame.origin.x += (self.bounds.size.width - [dockListView iconCenterY]) + ([dockListView collapsedIconWidth] / 2) + ([objc_getClass("SBIconBadgeView") _overhang].x * [dockListView collapsedIconScale]);
} else {
frame.origin.y += (self.bounds.size.height - [dockListView iconCenterY]) + ([dockListView collapsedIconWidth] / 2) + ([objc_getClass("SBIconBadgeView") _overhang].y * [dockListView collapsedIconScale]);
}
[bounceWindow setFrame:frame];
}
%new
- (void)layoutBackgroundView {
SBDockIconListView *_iconListView = MSHookIvar<SBDockIconListView*>(self, "_iconListView");
UIView *firstIcon = [_iconListView.viewMap mappedIconViewForIcon:[_iconListView.model.icons firstObject]];
UIView *lastIcon = [_iconListView.viewMap mappedIconViewForIcon:[_iconListView.model.icons lastObject]];
if ([[_iconListView.model.icons lastObject] isKindOfClass:%c(SBPlaceholderIcon)]) {
lastIcon = [_iconListView.viewMap mappedIconViewForIcon:_iconListView.model.icons[([_iconListView.model.icons count]) - 2]];
}
CGFloat backgroundMargin = 25.0;
CGRect frame = CGRectZero;
if (!in_landscape) {
frame.size.width = (CGRectGetMaxX(lastIcon.frame) - CGRectGetMinX(firstIcon.frame)) + backgroundMargin;
frame.size.height = [_iconListView collapsedIconWidth] + backgroundMargin;
frame.origin.x = CGRectGetMinX(firstIcon.frame) - backgroundMargin / 2;
frame.origin.y = ([_iconListView iconCenterY]) - (backgroundMargin / 2) - ([_iconListView collapsedIconWidth] / 2);
} else {
frame.size.width = [_iconListView collapsedIconWidth] + backgroundMargin;
frame.size.height = (CGRectGetMaxY(lastIcon.frame) - CGRectGetMinY(firstIcon.frame)) + backgroundMargin;
frame.origin.x = ([_iconListView iconCenterY]) - (backgroundMargin / 2) - ([_iconListView collapsedIconWidth] / 2);
frame.origin.y = CGRectGetMinY(firstIcon.frame) - backgroundMargin / 2;
}
MSHookIvar<UIView*>(self, "_backgroundView").layer.cornerRadius = 5.0;
MSHookIvar<UIView*>(self, "_backgroundView").frame = frame;
}
%end
%hook SBRootFolderView
- (id)initWithFolder:(id)arg1 orientation:(UIInterfaceOrientation)arg2 viewMap:(id)arg3 forSnapshot:(BOOL)arg4 {
self = %orig(arg1, arg2, arg3, arg4);
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];
}
return self;
}
%new
- (void)orientationChanged:(NSNotification*)arg1 {
for (UIView *view in [[[%c(SBIconController) sharedInstance] _rootFolderController] iconListViews]) {
view.alpha = 1;
}
if (![[prefs getuseNormalBackground] boolValue]) {
CGPoint contentOffset = [self.scrollView contentOffset];
if ([self respondsToSelector:@selector(iconScrollView:willSetContentOffset:)]) {
[self iconScrollView:self.scrollView willSetContentOffset:&contentOffset];
}
}
}
- (void)iconScrollView:(UIScrollView*)arg1 willSetContentOffset:(struct CGPoint *)arg2 {
%orig(arg1, arg2);
if (![[prefs getenabled] boolValue])
return;
if (![[prefs getuseNormalBackground] boolValue]) {
if (in_landscape) {
int page = floor(arg2->x / arg1.frame.size.width);
CGFloat opacity = (arg2->x / arg1.frame.size.width) - (CGFloat)page;
UIView *nextPage = [[[%c(SBIconController) sharedInstance] _rootFolderController] iconListViewAtIndex:page + 1];
nextPage.alpha = opacity;
}
}
}
%end
%hook SBRootFolderController
- (BOOL)_shouldSlideDockOutDuringRotationFromOrientation:(UIInterfaceOrientation)arg1 toOrientation:(UIInterfaceOrientation)arg2 {
if (![[prefs getenabled] boolValue])
return %orig(arg1, arg2);
return true; // Hides animation glitch. TODO: Make a proper fix for the glitch
}
%end
%hook SBIconModelPropertyListFileStore
/*
Use different icon state plist so that SpringBoard doesn't mess up the dock
when we are in safe mode
*/
#define harborPlistStore "file:///var/mobile/Library/SpringBoard/IconState_harbor.plist"
- (BOOL)_save:(id)arg1 url:(id)arg2 error:(id *)arg3 {
if ([[prefs getenabled] boolValue])
%orig(arg1, [NSURL URLWithString:@harborPlistStore], arg3);
return %orig(arg1, arg2, arg3);
}
- (id)_load:(NSURL*)path error:(id *)arg2 {
if ([[NSFileManager defaultManager] fileExistsAtPath:@"/var/mobile/Library/SpringBoard/IconState_harbor.plist"] && [[prefs getenabled] boolValue]) {
return %orig([NSURL URLWithString:@harborPlistStore], arg2);
}
return %orig(path, arg2);
}
%end
%hook SBIconController
// _revealMenuForIconView code by @Andywiik, thank you <3
%new
- (void)_revealMenuForIconView:(SBIconView *)iconView presentImmediately:(BOOL)arg2 {
if ([iconView appIconForceTouchGestureRecognizer]) {
UIGestureRecognizer *forceGesture = [iconView appIconForceTouchGestureRecognizer];
NSMutableArray *targets = [forceGesture valueForKeyPath:@"_targets"];
for (id targetContainer in targets) {
if ([(NSObject *)targetContainer valueForKeyPath:@"_target"]) {
id target = [(NSObject *)targetContainer valueForKeyPath:@"_target"];
if (target) {
if ([(NSObject *)target isKindOfClass:NSClassFromString(@"SBUIIconForceTouchController")]) {
SBUIIconForceTouchController *forceController = [targetContainer valueForKeyPath:@"_target"];
[forceController _setupWithGestureRecognizer:forceGesture];
[forceController _presentAnimated:YES withCompletionHandler:nil];
}
}
}
}
}
}
%new
- (void)_revealMenuForIconView:(SBIconView *)iconView {
if ([iconView appIconForceTouchGestureRecognizer]) {
UIGestureRecognizer *forceGesture = [iconView appIconForceTouchGestureRecognizer];
NSMutableArray *targets = [forceGesture valueForKeyPath:@"_targets"];
for (id targetContainer in targets) {
if ([(NSObject *)targetContainer valueForKeyPath:@"_target"]) {