-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathControlCenterBrightnessSectionView.xm
More file actions
159 lines (142 loc) · 6.94 KB
/
ControlCenterBrightnessSectionView.xm
File metadata and controls
159 lines (142 loc) · 6.94 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
#import "headers.h"
@implementation ControlCenterBrightnessSectionView
-(id)initWithFrame:(CGRect)frame {
if ([SCPreferences sharedInstance].isCompactSlidersEnabled)
frame.size.height = 32;
frame.origin.x += 4;
self = [super initWithFrame:frame];
if (self != nil) {
_brightnessController = [[objc_getClass("CCUIBrightnessSectionController") alloc] init];
[_brightnessController setDelegate:self];
[_brightnessController setUsesCompactHeight:YES];
_brightnessController.view.frame = CGRectMake(20, (frame.size.height - 29) / 2, frame.size.width - 40, 29);
//_brightnessController.view.center = CGPointMake(frame.size.width / 2, frame.size.height / 2);
[self addSubview:_brightnessController.view];
}
return self;
}
-(void)dealloc {
[_brightnessController release];
[super dealloc];
}
-(id)slider {
return [_brightnessController valueForKey:@"_slider"];
}
-(void)addButton:(UIButton *)button target:(id)target action:(SEL)selector isMin:(BOOL)isMin {
if (isMin) {
UIImageView *_minValueImageView = [[self slider] valueForKey:@"_minValueImageView"];
if (_minValueImageView != nil) {
if (button != nil) {
button.center = CGPointMake(_minValueImageView.frame.size.width / 2, _minValueImageView.frame.size.height / 2);
[_minValueImageView addSubview:button];
}
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:selector];
tapGesture.delegate = target;
[_minValueImageView addGestureRecognizer:tapGesture];
_minValueImageView.userInteractionEnabled = YES;
}
UIImageView *_minValueHighlightedImageView = [[self slider] valueForKey:@"_minValueHighlightedImageView"];
if (_minValueHighlightedImageView != nil) {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:selector];
tapGesture.delegate = target;
[_minValueHighlightedImageView addGestureRecognizer:tapGesture];
_minValueHighlightedImageView.userInteractionEnabled = YES;
}
} else {
UIImageView *_maxValueImageView = [[self slider] valueForKey:@"_maxValueImageView"];
if (_maxValueImageView != nil) {
if (button != nil) {
button.center = CGPointMake(_maxValueImageView.frame.size.width / 2, _maxValueImageView.frame.size.height / 2);
[_maxValueImageView addSubview:button];
}
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:selector];
tapGesture.delegate = target;
[_maxValueImageView addGestureRecognizer:tapGesture];
_maxValueImageView.userInteractionEnabled = YES;
}
UIImageView *_maxValueHighlightedImageView = [[self slider] valueForKey:@"_maxValueHighlightedImageView"];
if (_maxValueHighlightedImageView != nil) {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:selector];
tapGesture.delegate = target;
[_maxValueHighlightedImageView addGestureRecognizer:tapGesture];
_maxValueHighlightedImageView.userInteractionEnabled = YES;
}
}
}
@end
%hook CCUIControlCenterSlider
-(void)layoutSubviews {
%orig();
if ([self superview] != nil && ([[[self superview] class] isEqual:[ControlCenterBrightnessSectionView class]] || [[[[self superview] superview] class] isEqual:[ControlCenterBrightnessSectionView class]])) {
CGRect frame = self.frame;
frame.origin.x = 1;
if (%c(CCXMultiSliderSectionController)) // horseshoe fix (any horseshoe class would work actually)
frame.origin.y = -1;
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && screenSize.height <= 568)
frame.origin.y = -4;
else
frame.origin.y = -6;
self.frame = frame;
UIImageView *_minValueImageView = MSHookIvar<UIImageView *>(self, "_minValueImageView");
if (_minValueImageView != nil) {
if (![[[self superview] class] isEqual:[ControlCenterBrightnessSectionView class]]) {
CGRect frame = _minValueImageView.frame;
frame.origin.x += [self superview].frame.origin.x + self.frame.origin.x - 7.5;
frame.origin.y += [self superview].frame.origin.y + self.frame.origin.y;
[_minValueImageView removeFromSuperview];
[[[self superview] superview] addSubview:_minValueImageView];
_minValueImageView.frame = frame;
for (id view in [_minValueImageView subviews])
if ([[view class] isEqual:[UIButton class]]) {
((UIButton *)view).center = _minValueImageView.center;
[(UIButton *)view removeFromSuperview];
[[[self superview] superview] insertSubview:(UIButton *)view belowSubview:_minValueImageView];
}
}
[_minValueImageView layoutSubviews];
}
UIImageView *_minValueHighlightedImageView = MSHookIvar<UIImageView *>(self, "_minValueHighlightedImageView");
if (_minValueHighlightedImageView != nil) {
if (![[[self superview] class] isEqual:[ControlCenterBrightnessSectionView class]]) {
CGRect frame = _minValueHighlightedImageView.frame;
frame.origin.x += [self superview].frame.origin.x + self.frame.origin.x - 7.5;
frame.origin.y += [self superview].frame.origin.y + self.frame.origin.y;
[_minValueHighlightedImageView removeFromSuperview];
[[[self superview] superview] addSubview:_minValueHighlightedImageView];
_minValueHighlightedImageView.frame = frame;
}
[_minValueHighlightedImageView layoutSubviews];
}
UIImageView *_maxValueImageView = MSHookIvar<UIImageView *>(self, "_maxValueImageView");
if (_maxValueImageView != nil) {
if (![[[self superview] class] isEqual:[ControlCenterBrightnessSectionView class]]) {
CGRect frame = _maxValueImageView.frame;
frame.origin.x += [self superview].frame.origin.x + self.frame.origin.x + 2.5;
frame.origin.y += [self superview].frame.origin.y + self.frame.origin.y;
[_maxValueImageView removeFromSuperview];
[[[self superview] superview] addSubview:_maxValueImageView];
_maxValueImageView.frame = frame;
for (id view in [_maxValueImageView subviews])
if ([[view class] isEqual:[UIButton class]]) {
((UIButton *)view).center = _maxValueImageView.center;
[(UIButton *)view removeFromSuperview];
[[[self superview] superview] insertSubview:(UIButton *)view belowSubview:_minValueImageView];
}
}
[_maxValueImageView layoutSubviews];
}
UIImageView *_maxValueHighlightedImageView = MSHookIvar<UIImageView *>(self, "_maxValueHighlightedImageView");
if (_maxValueHighlightedImageView != nil) {
if (![[[self superview] class] isEqual:[ControlCenterBrightnessSectionView class]]) {
CGRect frame = _maxValueHighlightedImageView.frame;
frame.origin.x += [self superview].frame.origin.x + self.frame.origin.x + 2.5;
frame.origin.y += [self superview].frame.origin.y + self.frame.origin.y;
[_maxValueHighlightedImageView removeFromSuperview];
[[[self superview] superview] addSubview:_maxValueHighlightedImageView];
_maxValueHighlightedImageView.frame = frame;
}
[_maxValueHighlightedImageView layoutSubviews];
}
}
}
%end