forked from broha22/CSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSContainer.xm
More file actions
executable file
·141 lines (120 loc) · 4.51 KB
/
CSContainer.xm
File metadata and controls
executable file
·141 lines (120 loc) · 4.51 KB
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
#import "shared.h"
#import "CSContainer.h"
#import "CSView-New.h"
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
@implementation CSContainer
- (id)initWithIcon:(SBIcon *)icon snapshot:(id)snapshot {
self = [super initWithFrame:CGRectMake(0,0,62,98)];
self.contentSize = CGSizeMake(62,196);
self.delegate = self;
self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;
self.clipsToBounds = NO;
_icon = icon;
_iconView = [[%c(SBIconView) alloc] initWithDefaultSize];
_iconView.icon = _icon;
_iconView.delegate = [[CSView sharedView] iconDelegate];
_snapshot = snapshot;
_tapLaunch = [[UITapGestureRecognizer alloc] initWithTarget:[CSView sharedView] action:@selector(tappedContainer:)];
[self addGestureRecognizer:_tapLaunch];
if (_snapshot != nil) {
_page = [[%c(SBAppSwitcherPageView) alloc] initWithFrame:CGRectMake(0,0,62,98)];
_page.backgroundColor = [UIColor clearColor];
for (UIView *view in ((UIView *)_snapshot).subviews) {
view.backgroundColor = [UIColor clearColor];
}
for (UIView *view in _page.subviews) {
view.backgroundColor = [UIColor clearColor];
}
[_page setView:_snapshot animated:NO];
[self addSubview:_page];
[_iconView _iconImageView].layer.transform = CATransform3DMakeScale(0.5,0.5,0.5);
[_iconView setLabelHidden:YES];
[_iconView _applyIconAccessoryAlpha:0];
[self addSubview:_iconView];
[self adjustIconToOrientation];
}
else {
_iconView.frame = CGRectMake(0,15,60,60);
[self addSubview:_iconView];
}
return self;
}
- (void)adjustIconToOrientation {
int currentOrientation = [(SpringBoard *)[objc_getClass("SpringBoard") sharedApplication] activeInterfaceOrientation];
if (currentOrientation == 3 || currentOrientation == 4) {
self.contentSize = CGSizeMake(196,62);
_iconView.frame = CGRectMake(15,0,60,60);
}
if (currentOrientation == 1 || currentOrientation == 2) {
self.contentSize = CGSizeMake(62,196);
_iconView.frame = CGRectMake(0,15,60,60);
}
if (_snapshot !=nil) {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){
((SBAppSwitcherSnapshotView *)_snapshot).orientation = currentOrientation;
[((SBAppSwitcherSnapshotView *)_snapshot) layoutSubviews];
}
else {
((SBAppSliderSnapshotView *)_snapshot).orientation = currentOrientation;
[((SBAppSliderSnapshotView *)_snapshot) layoutSubviews];
}
_page.backgroundColor = [UIColor clearColor];
for (UIView *view in ((UIView *)_snapshot).subviews) {
view.backgroundColor = [UIColor clearColor];
}
for (UIView *view in _page.subviews) {
view.backgroundColor = [UIColor clearColor];
}
if (currentOrientation == 3 || currentOrientation == 4) {
_iconView.frame = CGRectMake(15,15,30,30);
_page.frame = CGRectMake(15,-25,62,98);
}
if (currentOrientation == 1 || currentOrientation == 2) {
_iconView.frame = CGRectMake(1.5,45,30,30);
_page.frame = CGRectMake(0,0,62,98);
}
}
}
- (void)launchApp {
SBApplication *app;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
app = [[%c(SBApplicationController) sharedInstance] applicationWithBundleIdentifier:self.id];
}
else {
app = [[%c(SBApplicationController) sharedInstance] applicationWithDisplayIdentifier:self.id];
}
[[%c(SBUIController) sharedInstance] activateApplicationAnimated:app];
}
- (void)scrollViewDidScroll:(UIScrollView *)view {
if (view.contentOffset.y > 98 && view.contentSize.height > 62) {
self.hidden = YES;
[[CSView sharedView] removeContainer:self];
}
if (view.contentOffset.x > 98 && view.contentSize.width > 62) {
self.hidden = YES;
[[CSView sharedView] removeContainer:self];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)view willDecelerate:(BOOL)decelerate {
[UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationCurveEaseOut
animations:^{
view.contentOffset = CGPointMake(0,0);
}
completion:^(BOOL finnished){
}];
}
- (void)dealloc {
[_snapshot release];
_snapshot = nil;
[_iconView release];
_iconView = nil;
[_icon release];
_icon = nil;
[_tapLaunch release];
_tapLaunch = nil;
[_page release];
_page = nil;
[super dealloc];
}
@end