-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathTweak.xm
221 lines (186 loc) · 6.96 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
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
#import "InvertedMaskLabel.h"
@interface _UIBatteryView : UIView
@property (nonatomic, assign) UIView *bodyView;
@property (nonatomic, assign) UIView *fillView;
@property (nonatomic, assign) UIView *overlayView;
@property (nonatomic, assign) InvertedMaskLabel *firstLabel;
@property (nonatomic, assign) UILabel *secondLabel;
@property (nonatomic, assign) CGFloat firstViewWidth;
@property (nonatomic, assign) CGFloat secondViewWidth;
@property CGFloat chargePercent;
@property (nonatomic, copy, readwrite) UIColor *fillColor;
@property (nonatomic,copy) UIColor * pinColor;
@property (nonatomic,retain) CALayer * fillLayer;
@property(nonatomic, assign, readwrite) NSInteger chargingState;
@property(nonatomic, assign, readwrite) BOOL saverModeActive;
-(void)_updateFillLayer;
-(void)setFillColor:(UIColor *)arg1;
-(void)setBodyColor:(UIColor *)arg1;
-(void)setPinColor:(UIColor *)arg1;
-(void)setBodyLayer:(CAShapeLayer *)arg1;
-(void)setFillLayer:(CALayer *)arg1;
-(void)setBoltLayer:(CAShapeLayer *)arg1;
-(void)setBoltMaskLayer:(CAShapeLayer *)arg1;
-(void)setShowsInlineChargingIndicator:(BOOL)arg1;
-(id)initWithFrame:(CGRect)arg1;
-(void)setChargePercent:(double)arg1;
-(void)_updatePercentage;
-(void)layoutSubviews;
-(void)updateBatteryViewPercent;
-(void)updateBatteryViewWithColor:(UIColor *)color;
-(void)updateSomeColor;
-(NSString *)getLocaleBasedString:(NSString *)string ;
-(UIColor *)halfColor;
-(UIColor *)pinColor;
@end
%hook _UIStatusBarStringView
- (void)setText:(NSString *)text {
if([text containsString:@"%"])
return;
else
%orig(text);
}
%end
%hook _UIBatteryView
%property (nonatomic, assign) UIView *bodyView;
%property (nonatomic, assign) UIView *fillView;
%property (nonatomic, assign) UIView *overlayView;
%property (nonatomic, assign) InvertedMaskLabel *firstLabel;
%property (nonatomic, assign) UILabel *secondLabel;
%property (nonatomic, assign) CGFloat firstViewWidth;
%property (nonatomic, assign) CGFloat secondViewWidth;
-(id)initWithFrame:(CGRect)arg1 {
self = %orig;
if (self) {
self.firstViewWidth = 20*self.chargePercent;
self.secondViewWidth = 20-self.firstViewWidth;
self.bodyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 22, 11.3)];
self.bodyView.clipsToBounds = YES;
self.bodyView.layer.cornerRadius = 3;
self.bodyView.layer.borderWidth = 1;
[self addSubview:self.bodyView];
CGRect frame = self.bodyView.frame;
frame.origin.x = self.frame.size.width - 24.333;
frame.origin.y = (self.frame.size.height-11)/2;
self.bodyView.frame = frame;
self.fillView = [[UIView alloc] initWithFrame:CGRectMake(1, 0, self.firstViewWidth, 11.3)];
[self.bodyView addSubview:self.fillView];
self.overlayView = [[UIView alloc] initWithFrame:CGRectMake(self.firstViewWidth+1, 0, self.secondViewWidth, 11.3)];
[self.bodyView addSubview:self.overlayView];
self.firstLabel = [[InvertedMaskLabel alloc] initWithFrame:CGRectMake(0, 0, 20, 11.3)];
self.firstLabel.text = [self getLocaleBasedString:[NSString stringWithFormat: @"%.f", self.chargePercent*100]];
self.firstLabel.font = [UIFont systemFontOfSize:8 weight:UIFontWeightSemibold];
self.firstLabel.textAlignment = NSTextAlignmentCenter;
self.firstLabel.textColor = [UIColor whiteColor];
self.fillView.maskView = self.firstLabel;
self.secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(-self.firstViewWidth, 0, 20, 11.3)];
self.secondLabel.text = self.firstLabel.text;
self.secondLabel.font = [UIFont systemFontOfSize:8 weight:UIFontWeightSemibold];
self.secondLabel.textAlignment = NSTextAlignmentCenter;
self.secondLabel.textColor = [UIColor whiteColor];
self.overlayView.maskView = self.secondLabel;
}
return self;
}
%new
-(void)updateBatteryViewPercent {
self.firstViewWidth = 20*self.chargePercent;
self.secondViewWidth = 20-self.firstViewWidth;
CGRect fillViewFrame = self.fillView.frame;
fillViewFrame.size.width = self.firstViewWidth;
self.fillView.frame = fillViewFrame;
CGRect overlayViewFrame = self.overlayView.frame;
overlayViewFrame.origin.x = self.firstViewWidth+1;
overlayViewFrame.size.width = self.secondViewWidth;
self.overlayView.frame = overlayViewFrame;
CGRect secondLabelFrame = self.secondLabel.frame;
secondLabelFrame.origin.x = -self.firstViewWidth;
self.secondLabel.frame = secondLabelFrame;
self.firstLabel.text = [self getLocaleBasedString:[NSString stringWithFormat: @"%.f", self.chargePercent*100]];
self.secondLabel.text = self.firstLabel.text;
}
%new
-(void)updateBatteryViewWithColor:(UIColor *)color {
self.pinColor = color;
self.fillView.backgroundColor = color;
self.overlayView.backgroundColor = color;
self.bodyView.layer.borderColor = [color CGColor];
}
%new
-(void)updateSomeColor {
if (self.chargingState != 0) {
[self updateBatteryViewWithColor:[UIColor colorWithRed:118.0f/255.0f green:213.0f/255.0f blue:114.0f/255.0f alpha:1.0f]];
} else if (self.saverModeActive) {
[self updateBatteryViewWithColor:[UIColor colorWithRed:247.0f/255.0f green:205.0f/255.0f blue:70.0f/255.0f alpha:1.0f]];
} else if (self.chargePercent <= 0.2) {
[self updateBatteryViewWithColor:[UIColor colorWithRed:235.0f/255.0f green:85.0f/255.0f blue:69.0f/255.0f alpha:1.0f]];
} else {
[self updateBatteryViewWithColor:self.fillColor];
}
}
%new
-(NSString *)getLocaleBasedString:(NSString *)string {
NSString *percentage;
NSDecimalNumber *percentageInNumber = [NSDecimalNumber decimalNumberWithString:string];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
percentage = [formatter stringFromNumber:percentageInNumber];
if (![percentage isEqualToString:string]) {
self.firstLabel.transform = CGAffineTransformMakeScale(-1, 1);
self.secondLabel.transform = CGAffineTransformMakeScale(-1, 1);
}
return percentage;
}
-(void)setChargingState:(long long)arg1 {
%orig(arg1);
[self updateSomeColor];
}
- (void)setSaverModeActive:(BOOL)arg1 {
%orig;
[self updateSomeColor];
}
-(void)_updateFillLayer {
%orig;
[self updateSomeColor];
}
-(void)setChargePercent:(CGFloat)percent {
%orig;
[self updateBatteryViewPercent];
}
-(UIColor *)_batteryColor {
return [UIColor clearColor];
}
-(UIColor *)bodyColor {
return [UIColor clearColor];
}
-(void)setFillLayer:(CALayer *)arg1 {
//noob
}
-(UIColor *)pinColor {
return [%orig colorWithAlphaComponent:1.0];
}
-(void)setPinColor:(UIColor *)color {
%orig([color colorWithAlphaComponent:1.0]);
}
-(void)setBoltLayer:(CAShapeLayer *)arg1 {
arg1.hidden = YES;
%orig(arg1);
}
-(void)setBoltMaskLayer:(CAShapeLayer *)arg1 {
arg1.hidden = YES;
%orig(arg1);
}
- (void)setShowsInlineChargingIndicator:(BOOL)arg1 {
%orig(NO);
}
-(void)layoutSubviews {
%orig;
CGRect frame = self.bodyView.frame;
frame.origin.x = self.frame.size.width - 24.333;
if (self.frame.size.width == 24) frame.origin.x = 0;
if (self.frame.size.width == 26.5) frame.origin.x = self.frame.size.width - 24.5;
frame.origin.y = (self.frame.size.height-11)/2;
self.bodyView.frame = frame;
[self updateSomeColor];
}
%end