This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
RAAppSelectorView.xm
79 lines (69 loc) · 2.92 KB
/
RAAppSelectorView.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
#import "RAAppSelectorView.h"
@implementation RAAppSelectorView
-(id) initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
}
return self;
}
-(void) relayoutApps
{
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
static CGSize fullSize = [%c(SBIconView) defaultIconSize];
fullSize.height = fullSize.width;
CGFloat padding = 20;
NSInteger numIconsPerLine = 0;
CGFloat tmpWidth = 10;
while (tmpWidth + fullSize.width <= self.frame.size.width)
{
numIconsPerLine++;
tmpWidth += fullSize.width + 20;
}
padding = (self.frame.size.width - (numIconsPerLine * fullSize.width)) / (numIconsPerLine + 1);
CGSize contentSize = CGSizeMake(padding, 10);
int horizontal = 0;
static NSMutableArray *allApps = nil;
if (!allApps)
{
allApps = [[[[%c(SBIconViewMap) homescreenMap] iconModel] visibleIconIdentifiers] mutableCopy];
[allApps sortUsingComparator: ^(NSString* a, NSString* b) {
NSString *a_ = [[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:a].displayName;
NSString *b_ = [[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:b].displayName;
return [a_ caseInsensitiveCompare:b_];
}];
//[allApps removeObject:currentBundleIdentifier];
}
for (NSString *str in allApps)
{
SBApplication *app = [[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:str];
SBIcon *icon = [[[%c(SBIconViewMap) homescreenMap] iconModel] applicationIconForBundleIdentifier:app.bundleIdentifier];
SBIconView *iconView = [[%c(SBIconViewMap) homescreenMap] _iconViewForIcon:icon];
if (!iconView || [icon isKindOfClass:[%c(SBApplicationIcon) class]] == NO)
continue;
iconView.frame = CGRectMake(contentSize.width, contentSize.height, iconView.frame.size.width, iconView.frame.size.height);
contentSize.width += iconView.frame.size.width + padding;
horizontal++;
if (horizontal >= numIconsPerLine)
{
horizontal = 0;
contentSize.width = padding;
contentSize.height += iconView.frame.size.height + 10;
}
iconView.restorationIdentifier = app.bundleIdentifier;
UITapGestureRecognizer *iconViewTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(appViewItemTap:)];
[iconView addGestureRecognizer:iconViewTapGestureRecognizer];
[self addSubview:iconView];
}
contentSize.width = self.frame.size.width;
contentSize.height += fullSize.height * 1.5;
[self setContentSize:contentSize];
}
-(void) appViewItemTap:(UITapGestureRecognizer*)recognizer
{
if (self.target)
if ([self.target respondsToSelector:@selector(appSelector:appWasSelected:)])
[self.target appSelector:self appWasSelected:recognizer.view.restorationIdentifier];
}
@end