-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tweak.xm
100 lines (88 loc) · 2.78 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
#import <SpringBoard/SpringBoard.h>
#import <substrate.h>
#import <UIKit/UIView.h>
@interface SpringBoard (iOS4)
- (SBDisplay *)_accessibilityTopDisplay;
@end
@interface SBIconListView : UIView
- (NSArray *)icons;
@end
@interface SBIconController (iOS4)
- (SBIconListView *)currentRootIconList;
- (id)dock;
@end
@interface SBDockIconListView : SBIconListView
@end
@interface SBIcon (iOS4)
- (BOOL)isGrabbed;
- (UIImageView *)iconImageView;
@end
static BOOL hasAnimatingIcon=0;
static BOOL hasUnscattered=NO;
@interface RandomIconFlipManager : NSObject
+(RandomIconFlipManager *)sharedFlipManager;
-(BOOL)isSpringBoardVisible;
-(void)performRandomAnimation;
@end
@implementation RandomIconFlipManager
static RandomIconFlipManager *sharedManager;
+ (void)initialize
{
if (self == [RandomIconFlipManager class]) {
sharedManager = [[self alloc] init];
}
}
+ (RandomIconFlipManager *)sharedFlipManager
{
return sharedManager;
}
-(BOOL)isSpringBoardVisible{
return ![(SpringBoard *)[objc_getClass("SpringBoard") sharedApplication] _accessibilityTopDisplay];
}
-(void)clearAnimatingIconState{
hasAnimatingIcon=0;
}
-(void)performRandomAnimation{
SBIconController *sbic=[objc_getClass("SBIconController") sharedInstance];
if ([self isSpringBoardVisible] && ![sbic isShowingSearch] && ![sbic isScrolling] && !hasAnimatingIcon)
{
NSArray *icons=[[sbic currentRootIconList] icons];
SBDockIconListView *dock=[sbic dock];
unsigned count=[icons count];
unsigned dockcount=[[dock icons] count];
unsigned r = rand() % count+dockcount ;
SBIcon *icon=r<count ? [icons objectAtIndex:r] : [[dock icons] objectAtIndex:r-count];
srand(time(0));
int transition=rand() % 2 ;
if (icon && ![icon isGrabbed]){
hasAnimatingIcon=1;
float duration = (rand() % 10 )+5;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration/10];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(clearAnimatingIconState)];
UIViewAnimationTransition realTrans;
realTrans= transition == 1 ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight;
if ([icon isInDock]){
[UIView setAnimationTransition:realTrans forView:[[icon subviews] objectOfClass:objc_getClass("SBIconImageContainerView")] cache:1];
}
else{
[UIView setAnimationTransition:realTrans forView:[icon iconImageView] cache:1];
}
[UIView commitAnimations];
}
}
float repeat = (rand() % 360) +50 ;
repeat=repeat/100;
[self performSelector:@selector(performRandomAnimation) withObject:nil afterDelay:repeat];
}
@end
%hook SBUIController
-(void)finishedUnscattering{
%orig;
if (!hasUnscattered)
[[RandomIconFlipManager sharedFlipManager] performRandomAnimation];
hasUnscattered=YES;
}
%end