-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweak.xm
More file actions
244 lines (187 loc) · 9.74 KB
/
Tweak.xm
File metadata and controls
244 lines (187 loc) · 9.74 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
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
#import "VolumeSlider.h"
%hook SpringBoard
- (void)applicationDidFinishLaunching:(id)arg1 {
%orig;
volumeSliderWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0 - screenHeightScale, screenWidth, screenHeightScale)];
volumeSliderWindow.windowLevel = UIWindowLevelStatusBar + 100.0;
volumeSliderWindow.alpha = 1.0;
volumeSliderWindow.hidden = YES;
volumeSliderWindow.backgroundColor = [UIColor clearColor];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:[%c(SBHUDController) sharedHUDController] action:@selector(volumeSliderShouldHide:)];
[volumeSliderWindow addGestureRecognizer:tap];
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:[%c(SBHUDController) sharedHUDController] action:@selector(volumeSliderShouldHide:)];
swipe.direction = UISwipeGestureRecognizerDirectionUp;
[volumeSliderWindow addGestureRecognizer:swipe];
if ([blurType isEqual:@"extralight"]) {
effectBGView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
}
else if ([blurType isEqual:@"light"]) {
effectBGView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
}
else {
effectBGView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
}
effectBGView.frame = CGRectMake(0, 0, screenWidth, screenHeightScale);
effectBGView.layer.cornerRadius = cornerRadius;
effectBGView.clipsToBounds = true;
[volumeSliderWindow addSubview:effectBGView];
volumeSlider = [[UISlider alloc] initWithFrame:CGRectMake(screenHeightScale, 0, screenWidth - (screenHeightScale * 2), screenHeightScale)];
volumeSlider.backgroundColor = [UIColor clearColor];
volumeSlider.continuous = YES;
volumeSlider.minimumValue = 0.0;
volumeSlider.maximumValue = 1.0;
volumeSlider.value = [[%c(SBMediaController) sharedInstance] volume];
volumeSlider.maximumTrackTintColor = [UIColor grayColor];
if ([mainColor isEqual:@"black"]) {
volumeSlider.minimumTrackTintColor = [UIColor blackColor];
}
else {
volumeSlider.minimumTrackTintColor = [UIColor whiteColor];
}
[volumeSlider addTarget:self action:@selector(volumeSliderMoved:) forControlEvents:UIControlEventValueChanged];
[effectBGView.contentView addSubview:volumeSlider];
if ([mainColor isEqual:@"black"]) {
volumeSliderOffImage = [[UIImageView alloc] initWithImage:[[FSSwitchPanel sharedPanel] imageOfSwitchState:FSSwitchStateOff controlState:UIControlStateNormal forSwitchIdentifier:@"com.a3tweaks.switch.ringer" usingTemplate:templateBundle2]];
}
else {
volumeSliderOffImage = [[UIImageView alloc] initWithImage:[[FSSwitchPanel sharedPanel] imageOfSwitchState:FSSwitchStateOff controlState:UIControlStateNormal forSwitchIdentifier:@"com.a3tweaks.switch.ringer" usingTemplate:templateBundle]];
}
volumeSliderOffImage.frame = CGRectMake((screenHeightScale / 2) - 15, (screenHeightScale / 2) - 15, 30, 30);
[effectBGView.contentView addSubview:volumeSliderOffImage];
if ([mainColor isEqual:@"black"]) {
volumeSliderOnImage = [[UIImageView alloc] initWithImage:[[FSSwitchPanel sharedPanel] imageOfSwitchState:FSSwitchStateOn controlState:UIControlStateNormal forSwitchIdentifier:@"com.a3tweaks.switch.ringer" usingTemplate:templateBundle2]];
}
else {
volumeSliderOnImage = [[UIImageView alloc] initWithImage:[[FSSwitchPanel sharedPanel] imageOfSwitchState:FSSwitchStateOn controlState:UIControlStateNormal forSwitchIdentifier:@"com.a3tweaks.switch.ringer" usingTemplate:templateBundle]];
}
volumeSliderOnImage.frame = CGRectMake((screenHeightScale / 2) - 15 + (screenWidth - screenHeightScale), (screenHeightScale / 2) - 15, 30, 30);
[effectBGView.contentView addSubview:volumeSliderOnImage];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateVolumeSlider:) name:@"SBMediaVolumeChangedNotification" object:[%c(SBMediaController) sharedInstance]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
%new
- (void)volumeSliderMoved:(id)sender {
[[%c(SBMediaController) sharedInstance] setVolume:volumeSlider.value];
}
%new
- (void)updateVolumeSlider:(NSNotification *)notification {
volumeSlider.value = [[%c(SBMediaController) sharedInstance] volume];
}
%new
- (void)orientationChanged:(NSNotification *)notification {
switch ([[UIApplication sharedApplication] _frontMostAppOrientation]) {
case UIInterfaceOrientationPortrait:
volumeSliderWindow.transform = CGAffineTransformIdentity;
volumeSliderWindow.frame = CGRectMake(0, 0 - screenHeightScale, screenWidth, screenHeightScale);
effectBGView.frame = CGRectMake(0, 0, screenWidth, screenHeightScale);
volumeSlider.frame = CGRectMake(screenHeightScale, 0, screenWidth - (screenHeightScale * 2), screenHeightScale);
volumeSliderOnImage.frame = CGRectMake((screenHeightScale / 2) - 15 + (screenWidth - screenHeightScale), (screenHeightScale / 2) - 15, 30, 30);
break;
case UIInterfaceOrientationLandscapeLeft:
volumeSliderWindow.transform = CGAffineTransformMakeRotation(M_PI + M_PI_2);
volumeSliderWindow.frame = CGRectMake(0 - screenHeightScale, 0, screenHeightScale, screenHeight);
effectBGView.frame = CGRectMake(0, 0, screenHeight, screenHeightScale);
volumeSlider.frame = CGRectMake(screenHeightScale, 0, screenHeight - (screenHeightScale * 2), screenHeightScale);
volumeSliderOnImage.frame = CGRectMake((screenHeightScale / 2) - 15 + (screenHeight - screenHeightScale), (screenHeightScale / 2) - 15, 30, 30);
break;
case UIInterfaceOrientationLandscapeRight:
volumeSliderWindow.transform = CGAffineTransformMakeRotation(M_PI_2);
volumeSliderWindow.frame = CGRectMake(screenWidth, 0, screenHeightScale, screenHeight);
effectBGView.frame = CGRectMake(0, 0, screenHeight, screenHeightScale);
volumeSlider.frame = CGRectMake(screenHeightScale, 0, screenHeight - (screenHeightScale * 2), screenHeightScale);
volumeSliderOnImage.frame = CGRectMake((screenHeightScale / 2) - 15 + (screenHeight - screenHeightScale), (screenHeightScale / 2) - 15, 30, 30);
break;
case UIInterfaceOrientationPortraitUpsideDown:
volumeSliderWindow.transform = CGAffineTransformMakeRotation(M_PI);
volumeSliderWindow.frame = CGRectMake(0, screenHeight + screenHeightScale, screenWidth, screenHeightScale);
effectBGView.frame = CGRectMake(0, 0, screenWidth, screenHeightScale);
volumeSlider.frame = CGRectMake(screenHeightScale, 0, screenWidth - (screenHeightScale * 2), screenHeightScale);
volumeSliderOnImage.frame = CGRectMake((screenHeightScale / 2) - 15 + (screenWidth - screenHeightScale), (screenHeightScale / 2) - 15, 30, 30);
break;
}
}
%end
%hook SBHUDController
- (void)presentHUDView:(SBHUDView *)arg1 autoDismissWithDelay:(double)arg2 {
if (enabled) {
if ([arg1.title isEqual:@"Ringer"]) {
volumeSlider.userInteractionEnabled = NO;
if ([[%c(SBMediaController) sharedInstance] isRingerMuted]) {
volumeSlider.value = 0.0;
}
else {
volumeSlider.value = 1.0;
}
}
else {
volumeSlider.userInteractionEnabled = YES;
volumeSlider.value = [[%c(SBMediaController) sharedInstance] volume];
}
[self volumeSliderShouldShow:nil];
}
else {
%orig;
}
}
%new
- (void)volumeSliderShouldShow:(id)sender {
switch ([[UIApplication sharedApplication] _frontMostAppOrientation]) {
case UIInterfaceOrientationPortrait:
[self showVolumeSliderWithFrame:CGRectMake(0, 0, screenWidth, screenHeightScale)];
break;
case UIInterfaceOrientationLandscapeLeft:
[self showVolumeSliderWithFrame:CGRectMake(0, 0, screenHeightScale, screenHeight)];
break;
case UIInterfaceOrientationLandscapeRight:
[self showVolumeSliderWithFrame:CGRectMake(screenWidth - screenHeightScale, 0, screenHeightScale, screenHeight)];
break;
case UIInterfaceOrientationPortraitUpsideDown:
[self showVolumeSliderWithFrame:CGRectMake(screenHeight - screenHeightScale, 0, screenWidth, screenHeightScale)];
break;
}
}
%new
- (void)volumeSliderShouldHide:(id)sender {
switch ([[UIApplication sharedApplication] _frontMostAppOrientation]) {
case UIInterfaceOrientationPortrait:
[self hideVolumeSliderWithFrame:CGRectMake(0, 0 - screenHeightScale, screenWidth, screenHeightScale)];
break;
case UIInterfaceOrientationLandscapeLeft:
[self hideVolumeSliderWithFrame:CGRectMake(0 - screenHeightScale, 0, screenHeightScale, screenHeight)];
break;
case UIInterfaceOrientationLandscapeRight:
[self hideVolumeSliderWithFrame:CGRectMake(screenWidth, 0, screenHeightScale, screenHeight)];
break;
case UIInterfaceOrientationPortraitUpsideDown:
[self hideVolumeSliderWithFrame:CGRectMake(0, screenHeight + screenHeightScale, screenWidth, screenHeightScale)];
break;
}
}
%new
- (void)showVolumeSliderWithFrame:(CGRect)frame {
[UIView animateWithDuration:animationDuration delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
volumeSliderWindow.hidden = NO;
CGRect newWindowFrame = frame;
volumeSliderWindow.frame = newWindowFrame;
}
completion:^(BOOL finished) {
[timer invalidate];
timer = nil;
timer = [[NSTimer scheduledTimerWithTimeInterval:delayDuration target:self selector:@selector(volumeSliderShouldHide:) userInfo:nil repeats:NO] retain];
}];
}
%new
- (void)hideVolumeSliderWithFrame:(CGRect)frame {
[UIView animateWithDuration:animationDuration delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
CGRect newWindowFrame = frame;
volumeSliderWindow.frame = newWindowFrame;
}
completion:^(BOOL finished) {
volumeSliderWindow.hidden = YES;
}];
}
%end
%ctor {
loadPrefs();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadPrefs, CFSTR("com.TweaksByLogan.VolumeSlider/saved"), NULL, CFNotificationSuspensionBehaviorCoalesce);
}