-
Notifications
You must be signed in to change notification settings - Fork 6
/
Vaon.xm
1842 lines (1546 loc) · 63.6 KB
/
Vaon.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//TODO:
//raise app switcher
//ios 14 1751.108
//credit to Dogbert for the icon
#import "Vaon.h"
#import <UIKit/UIKit.h>
// #import <Foundation/Foundation.h>
NSUserDefaults *prefs;
BOOL ios13;
BOOL ios14;
BOOL ios15;
//main page preference variables
BOOL isEnabled;
NSString *switcherMode = nil;
NSString *selectedModule = nil;
BOOL hideBackground;
BOOL hideAppTitles;
BOOL hideAppIcons;
BOOL hideSuggestionBanner;
BOOL displayWithNoApps;
NSString *backgroundMode = nil;
BOOL enableFlyInOut;
BOOL enableDelay;
CGFloat fadeInDelay;
BOOL customHeightEnabled;
CGFloat customHeight;
BOOL customWidthEnabled;
CGFloat customWidth;
BOOL customVerticalOffsetEnabled;
CGFloat customVerticalOffset;
BOOL customHorizontalOffsetEnabled;
CGFloat customHorizontalOffset;
BOOL customGridSwitcherAppSizeEnabled;
CGFloat customGridSwitcherAppSize;
BOOL customGridSwitcherSpacingEnabled;
CGFloat customGridSwitcherSpacing;
//battery configuration preference variables
BOOL hideInternal;
BOOL hidePercentageLabel;
BOOL hidePercent;
BOOL enableBoldPercentage;
BOOL roundOutlineCorners;
BOOL pulsateChargingOutline;
BOOL keepDisconnectedDevices;
NSString *batteryTextColor = nil;
NSString *customBatteryTextColor = nil;
NSString *batteryGlyphBackgroundMode = nil;
BOOL customDeviceGlyphSizeEnabled;
CGFloat customDeviceGlyphSize;
BOOL customBatteryCellSizeEnabled;
CGFloat customBatteryCellSize;
BOOL customPercentageFontSizeEnabled;
CGFloat customPercentageFontSize;
BOOL paddingBetweenGlyphAndLabelEnabled;
CGFloat paddingBetweenGlyphAndLabel;
BOOL horizontalSpacingBetweenDevicesEnabled;
CGFloat horizontalSpacingBetweenDevices;
UIView *vaonView;
UIView *vaonGridView;
UIScrollView *batteryScrollView;
UIStackView *batteryHStackView;
// UIScrollView *favoriteContactsScrollView;
UIStackView *favoriteContactsHStackView;
UIColor *vaonViewBackgroundColor;
UIVisualEffectView *vaonBlurView;
UIBlurEffect *blurEffect;
UILabel *titleLabel;
int vaonViewCornerRadius = 17;
CGFloat dockWidth;
BOOL vaonViewIsInitialized = FALSE;
// long long sbAppSwitcherOrientation;
SBMainSwitcherViewController *mainAppSwitcherVC;
SBSwitcherAppSuggestionContentView *switcherContentView;
long long customSwitcherStyle;
long long currentSwitcherStyle;
BOOL appSwitcherOpen = FALSE;
BOOL doneFadingIn = FALSE;
BOOL stockHidden = TRUE;
BOOL enteredApp;
NSArray *connectedBluetoothDevices;
NSMutableArray *deviceNames = [[NSMutableArray alloc] init];
NSMutableArray *deviceIdentifiers = [[NSMutableArray alloc] init];
UIColor *normalBatteryColor = [UIColor colorWithRed:0.1882352941 green:0.8196078431 blue:0.3450980392 alpha: 1];
UIColor *lowPowerModeColor = [UIColor colorWithRed:1 green:0.8 blue:0 alpha:1];
UIColor *lowBatteryColor = [UIColor redColor];
UIColor *darkGrayColor = [UIColor colorWithRed:0.1746478873 green:0.2039215686 blue:0.1960784314 alpha: 1];
//timers to initiate animations
NSTimer *delayedFadeInTimer = nil;
NSTimer *delayedPulsateTimer = nil;
BOOL firstSlideIn = false;
NSString *customConnectedDeviceColorMode;
NSString *customConnectedDeviceColor;
NSString *customDisconnectedDeviceColorMode;
NSString *customDisconnectedDeviceColor;
NSString *customLowPowerColorMode;
NSString *customLowPowerColor;
NSString *customLowBatteryColorMode;
NSString *customLowBatteryColor;
NSString *customChargingColorMode;
NSString *customChargingColor;
UIColor* colorFromHexString(NSString *hexString) {
unsigned rgbValue = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexString];
[scanner setScanLocation:1]; // bypass '#' character
[scanner scanHexInt:&rgbValue];
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
}
//delegate for outline animation
@implementation StrokeEndAnimationDelegate
-(instancetype)initWithCell:(VaonDeviceBatteryCell *)cell {
self = [super init];
self.cell = cell;
return self;
}
//keeps the outline at a static position when it finishes animating
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
if(flag && pulsateChargingOutline){
[self.cell pulsateOutline];
}
}
@end
//delegate for charging devices' pulsating color animation
@implementation PulsateColorAnimationDelegate
-(instancetype)initWithCell:(VaonDeviceBatteryCell *)cell nextAnimation:(CAAnimation *)nextAnimation {
self = [super init];
self.cell = cell;
self.nextAnimation = nextAnimation;
return self;
}
//when the animation finishes change the color and start another pulsate animation
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
if(flag && pulsateChargingOutline){
if([self.cell.device isCharging]){
[self.cell.circleOutlineLayer addAnimation:self.nextAnimation forKey:kCATransition];
}else{
self.cell.circleOutlineLayer.strokeColor = normalBatteryColor.CGColor;
}
}
}
@end
//Individual battery cell for each device
@implementation VaonDeviceBatteryCell
//initialization
-(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)connectedDevice {
self.device = connectedDevice;
self.disconnected = FALSE;
if(customBatteryCellSizeEnabled){
self.cellWidth = CGFloat(customBatteryCellSize);
} else {
self.cellWidth = CGFloat(50);
}
self.devicePercentage = [connectedDevice percentCharge];
//initialize view placement
self = [super initWithFrame:arg1];
self.axis = UILayoutConstraintAxisVertical;
self.alignment = UIStackViewAlignmentCenter;
if(paddingBetweenGlyphAndLabelEnabled){
self.spacing = paddingBetweenGlyphAndLabel;
if(paddingBetweenGlyphAndLabel > 0) {
self.distribution = UIStackViewDistributionEqualSpacing;
}
} else {
self.spacing = 10;
self.distribution = UIStackViewDistributionEqualSpacing;
}
self.clipsToBounds = FALSE;
self.backgroundColor = [UIColor clearColor];
self.translatesAutoresizingMaskIntoConstraints = FALSE;
//initialize background blur effect
if ([batteryGlyphBackgroundMode isEqualToString:@"system"]) {
self.circleBackgroundBlurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemMaterial];
} else if ([batteryGlyphBackgroundMode isEqualToString:@"dark"]) {
self.circleBackgroundBlurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemMaterialDark];
} else if ([batteryGlyphBackgroundMode isEqualToString:@"light"]) {
self.circleBackgroundBlurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemMaterialLight];
}
self.circleBackgroundVisualEffectView = [[UIVisualEffectView alloc] initWithEffect:self.circleBackgroundBlurEffect];
self.circleBackgroundVisualEffectView.layer.cornerRadius = self.cellWidth/2;
self.circleBackgroundVisualEffectView.clipsToBounds = TRUE;
self.circleBackgroundVisualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.circleBackgroundVisualEffectView.frame = self.bounds;
self.circleBackgroundVisualEffectView.contentMode = UIViewContentModeScaleAspectFill;
//battery percentage label
self.devicePercentageLabel = [[UILabel alloc] init];
[self updateDevicePercentageLabel];
[self addPercentageSymbolToLabel];
//font customization
UIFont *devicePercentageLabelFont = [[UIFont alloc] init];
//custom font size from prefs
UIFontWeight percentageFontWeight;
if(enableBoldPercentage) {
percentageFontWeight = UIFontWeightBold;
} else {
percentageFontWeight = UIFontWeightRegular;
}
if(customPercentageFontSizeEnabled){
devicePercentageLabelFont = [UIFont systemFontOfSize:customPercentageFontSize weight:percentageFontWeight];
} else{
devicePercentageLabelFont = [UIFont systemFontOfSize:12 weight:percentageFontWeight];
}
self.devicePercentageLabel.font = devicePercentageLabelFont;
self.devicePercentageLabel.frame = self.bounds;
self.devicePercentageLabel.textColor = normalBatteryColor;
// self.devicePercentageLabel.clipsToBounds = TRUE;
// self.devicePercentageLabel.layoutMargins = UIEdgeInsetsMake(0, 0, -20, 0);
// [self setLayoutMarginsRelativeArrangement:YES];
// self.devicePercentageLabel.bounds = CGRectInset(self.devicePercentageLabel.frame, 0.0f, 1.0f);
// self.devicePercentageLabel.directionalLayoutMargins = NSDirectionalEdgeInsetsMake(100, 0, 0, 0);
//view placement and constraints for background blur
// [self.circleBackgroundVisualEffectView.contentView addSubview:self.devicePercentageLabel];
self.circleBackgroundVisualEffectView.translatesAutoresizingMaskIntoConstraints = FALSE;
[self.circleBackgroundVisualEffectView.widthAnchor constraintEqualToConstant:self.cellWidth].active = TRUE;
[self.circleBackgroundVisualEffectView.heightAnchor constraintEqualToConstant:self.cellWidth].active = TRUE;
// self.circleBackgroundVisualEffectView.frame = self.circleBackgroundVisualEffectView.frame.inset() UIEdgeInsetsMake(0, 0, 10, 0);
[self addArrangedSubview:self.circleBackgroundVisualEffectView];
// if(paddingBetweenGlyphAndLabelEnabled) {
// self.paddingView = [[UIView alloc] init];
// [self.paddingView.heightAnchor constraintEqualToConstant: paddingBetweenGlyphAndLabel].active = TRUE;
// [self.paddingView.widthAnchor constraintEqualToConstant:self.cellWidth].active = TRUE;
// [self addArrangedSubview:self.paddingView];
// }
//view placement and constrains for battery percentage
// self.devicePercentageLabel.translatesAutoresizingMaskIntoConstraints = FALSE;
// [self.devicePercentageLabel.centerXAnchor constraintEqualToAnchor:self.circleBackgroundVisualEffectView.centerXAnchor].active = TRUE;
// [self.devicePercentageLabel.centerYAnchor constraintEqualToAnchor:self.circleBackgroundVisualEffectView.centerYAnchor constant:100].active = TRUE;
//initialize circular outline path
self.circleOutlinePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.circleBackgroundVisualEffectView.contentView.center.x+self.cellWidth/2,self.circleBackgroundVisualEffectView.contentView.center.y+self.cellWidth/2)
radius:self.cellWidth/2
startAngle:[self degreesToRadians:(-90)]
endAngle:[self degreesToRadians:(270)]
clockwise:TRUE];
self.circleOutlineLayer = [[CAShapeLayer alloc] init];
self.circleOutlineLayer.bounds = self.bounds;
self.circleOutlineLayer.fillColor = [UIColor clearColor].CGColor;
self.circleOutlineLayer.strokeStart = 0;
self.circleOutlineLayer.strokeEnd = 0;
self.circleOutlineLayer.path = [self.circleOutlinePath CGPath];
self.circleOutlineLayer.lineWidth = self.cellWidth/10;
self.circleOutlineLayer.masksToBounds = FALSE;
[self.layer addSublayer:self.circleOutlineLayer];
//rounds the corners of the outline layer
if(roundOutlineCorners){
self.circleOutlineLayer.lineCap = kCALineCapRound;
}
//initialize device image and its constraints
if(ios14){
//COMMENT THIS BACK IN
self.deviceGlyphView = [[UIImageView alloc] initWithImage:[connectedDevice batteryWidgetGlyph]];
self.deviceGlyphView.image = [self.deviceGlyphView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
} else {
self.deviceGlyphView = [[UIImageView alloc] initWithImage:connectedDevice.glyph];
}
if ([batteryGlyphBackgroundMode isEqualToString:@"system"]) {
[self.deviceGlyphView setTintColor:[UIColor labelColor]];
} else if ([batteryGlyphBackgroundMode isEqualToString:@"dark"]) {
[self.deviceGlyphView setTintColor:[UIColor lightTextColor]];
} else if ([batteryGlyphBackgroundMode isEqualToString:@"light"]) {
[self.deviceGlyphView setTintColor:[UIColor darkTextColor]];
}
CGFloat glyphAspectRatio = self.deviceGlyphView.frame.size.width/self.deviceGlyphView.frame.size.height;
if(customDeviceGlyphSizeEnabled) {
[self.deviceGlyphView.heightAnchor constraintEqualToConstant:customDeviceGlyphSize].active = TRUE;
[self.deviceGlyphView.widthAnchor constraintEqualToConstant:customDeviceGlyphSize * glyphAspectRatio].active = TRUE;
} else {
[self.deviceGlyphView.heightAnchor constraintEqualToConstant:self.cellWidth * 0.6 ].active = TRUE;
[self.deviceGlyphView.widthAnchor constraintEqualToConstant:self.cellWidth * 0.6 * glyphAspectRatio].active = TRUE;
}
if(ios14) {
self.deviceGlyphView.transform = CGAffineTransformMake(1, 0, 0, 1, 0 ,0);
}
// self.deviceGlyphView.contentMode = UIViewContentModeScaleAspectFit;
if(!hidePercentageLabel) {
[self addArrangedSubview:self.devicePercentageLabel];
}
[self.circleBackgroundVisualEffectView.contentView addSubview:self.deviceGlyphView];
self.deviceGlyphView.translatesAutoresizingMaskIntoConstraints = FALSE;
[self.deviceGlyphView.centerXAnchor constraintEqualToAnchor:self.circleBackgroundVisualEffectView.centerXAnchor].active = TRUE;
[self.deviceGlyphView.centerYAnchor constraintEqualToAnchor:self.circleBackgroundVisualEffectView.centerYAnchor].active = TRUE;
[self.circleBackgroundVisualEffectView setNeedsDisplay];
self.deviceName = connectedDevice.name;
self.deviceIdentifier = connectedDevice.identifier;
self.deviceProductIdentifier = connectedDevice.productIdentifier;
return self;
}
-(CGFloat)degreesToRadians:(CGFloat)arg1 {
return arg1*(M_PI/180);
}
@synthesize cellWidth;
-(CGFloat)getCellWidth {
return cellWidth;
}
-(void)setCellWidth:(CGFloat)arg1 {
cellWidth = arg1;
}
-(void)addPercentageSymbolToLabel {
if(!hidePercent){
[self.devicePercentageString appendString:@"%"];
}
}
-(long long)getDevicePercentage {
return [self.device percentCharge];
}
-(void)updateDevicePercentage {
self.devicePercentage = [self getDevicePercentage];
}
//updates a device's percentage and adjusts the label accordingly
-(void)updateDevicePercentageLabel {
[self updateDevicePercentage];
self.devicePercentageString = [NSMutableString stringWithFormat:@"%lld",self.devicePercentage];
[self addPercentageSymbolToLabel];
self.devicePercentageLabel.text = self.devicePercentageString;
}
-(void)removeFromSuperview {
[super removeFromSuperview];
}
-(CGFloat)devicePercentageAsProgress {
double progress = self.devicePercentage;
return progress/100;
}
//true if the device is the iPhone/iPad, false otherwise
-(BOOL)isDeviceInternal {
return [self.device isInternal];
}
-(BOOL)isLowPowerModeOn {
return [self.device isBatterySaverModeActive];
}
-(BOOL)isBatteryLow {
return [self.device isLowBattery];
}
//updates the outline color depending on the device's charging/connected state
-(void)updateOutlineColor {
if([self isDeviceInternal] && [self isLowPowerModeOn] && ![self.device isCharging]){
if([customLowPowerColorMode isEqualToString:@"custom"]) {
self.circleOutlineLayer.strokeColor = colorFromHexString(customLowPowerColor).CGColor;
} else if([customLowPowerColorMode isEqualToString:@"system"]) {
self.circleOutlineLayer.strokeColor = [UIColor systemBlueColor].CGColor;
} else {
self.circleOutlineLayer.strokeColor = lowPowerModeColor.CGColor;
}
} else if([self isBatteryLow] && (![self.device isCharging])){
if([customLowBatteryColorMode isEqualToString:@"custom"]) {
self.circleOutlineLayer.strokeColor = colorFromHexString(customLowPowerColor).CGColor;
} else if([customLowBatteryColorMode isEqualToString:@"system"]) {
self.circleOutlineLayer.strokeColor = [UIColor systemBlueColor].CGColor;
} else {
self.circleOutlineLayer.strokeColor = lowBatteryColor.CGColor;
}
} else if([self.device isCharging] && pulsateChargingOutline){
if([customChargingColorMode isEqualToString:@"custom"]) {
self.circleOutlineLayer.strokeColor = colorFromHexString(customChargingColor).CGColor;
} else if([customChargingColorMode isEqualToString:@"system"]) {
self.circleOutlineLayer.strokeColor = [UIColor systemBlueColor].CGColor;
} else {
self.circleOutlineLayer.strokeColor = normalBatteryColor.CGColor;
}
} else {
if(![self.device isConnected]){
if([customDisconnectedDeviceColorMode isEqualToString:@"custom"]) {
self.circleOutlineLayer.strokeColor = colorFromHexString(customDisconnectedDeviceColor).CGColor;
} else if([customDisconnectedDeviceColorMode isEqualToString:@"system"]) {
self.circleOutlineLayer.strokeColor = [UIColor systemBlueColor].CGColor;
} else {
self.circleOutlineLayer.strokeColor = [UIColor systemGrayColor].CGColor;
}
} else {
if([customConnectedDeviceColorMode isEqualToString:@"custom"]) {
self.circleOutlineLayer.strokeColor = colorFromHexString(customConnectedDeviceColor).CGColor;
} else if([customConnectedDeviceColorMode isEqualToString:@"system"]) {
self.circleOutlineLayer.strokeColor = [UIColor systemBlueColor].CGColor;
} else {
self.circleOutlineLayer.strokeColor = normalBatteryColor.CGColor;
}
}
}
}
//starts the pulsating color animation sequence for charging devices
-(void)pulsateOutline {
if([self.device isCharging]){
CAMediaTimingFunction *animationColorTimingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
//initializes animations
CABasicAnimation *normalToBright = [CABasicAnimation animationWithKeyPath:@"strokeColor"];
CABasicAnimation *brightToNormal = [CABasicAnimation animationWithKeyPath:@"strokeColor"];
//assigns delegate to animations
PulsateColorAnimationDelegate *normalToBrightDelegate = [[PulsateColorAnimationDelegate alloc] initWithCell:self nextAnimation:brightToNormal];
normalToBright.delegate = normalToBrightDelegate;
PulsateColorAnimationDelegate *brightToNormalDelegate = [[PulsateColorAnimationDelegate alloc] initWithCell:self nextAnimation:normalToBright];
brightToNormal.delegate = brightToNormalDelegate;
if([customChargingColorMode isEqualToString:@"custom"]) {
normalToBright.fromValue = id(colorFromHexString(customChargingColor).CGColor);
} else if([customChargingColorMode isEqualToString:@"system"]) {
normalToBright.fromValue = id([UIColor systemBlueColor].CGColor);
} else {
normalToBright.fromValue = id(normalBatteryColor.CGColor);
}
normalToBright.toValue = id(darkGrayColor.CGColor);
normalToBright.duration = 2;
normalToBright.timingFunction = animationColorTimingFunction;
[normalToBright setFillMode:kCAFillModeForwards];
[normalToBright setRemovedOnCompletion:FALSE];
brightToNormal.fromValue = normalToBright.toValue;
brightToNormal.toValue = normalToBright.fromValue;
brightToNormal.duration = 2;
brightToNormal.timingFunction = animationColorTimingFunction;
[brightToNormal setFillMode:kCAFillModeForwards];
[brightToNormal setRemovedOnCompletion:FALSE];
[self.circleOutlineLayer addAnimation:normalToBright forKey:kCATransition];
}
}
//makes percentage label green if charging
-(void)updatePercentageColor {
if([self.device isCharging]){
if([customChargingColorMode isEqualToString:@"custom"]) {
self.devicePercentageLabel.textColor = colorFromHexString(customChargingColor);
} else if([customChargingColorMode isEqualToString:@"system"]) {
self.devicePercentageLabel.textColor = [UIColor systemBlueColor];
} else {
self.devicePercentageLabel.textColor = normalBatteryColor;
}
}else {
// self.devicePercentageLabel.textColor = [UIColor labelColor];
if ([batteryTextColor isEqualToString:@"system"]) {
self.devicePercentageLabel.textColor = [UIColor labelColor];
} else if ([batteryTextColor isEqualToString:@"dark"]) {
self.devicePercentageLabel.textColor = [UIColor blackColor];
} else if ([batteryTextColor isEqualToString:@"light"]) {
self.devicePercentageLabel.textColor = [UIColor whiteColor];
} else if ([batteryTextColor isEqualToString:@"custom"]) {
self.devicePercentageLabel.textColor = colorFromHexString(customBatteryTextColor);
}
}
}
//animates outline position along the bezier path
-(void)newAnimateOuterLayerToCurrentPercentage{
self.percentageAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
StrokeEndAnimationDelegate *delegate = [[StrokeEndAnimationDelegate alloc] initWithCell:self];
self.percentageAnimation.delegate = delegate;
self.percentageAnimation.fromValue = @(0.0);
self.percentageAnimation.toValue = @([self devicePercentageAsProgress]);
self.percentageAnimation.duration = 0.25;
[self.percentageAnimation setFillMode:kCAFillModeForwards];
[self.percentageAnimation setRemovedOnCompletion:TRUE];
CAMediaTimingFunction *animationTimingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
self.percentageAnimation.timingFunction = animationTimingFunction;
[self.circleOutlineLayer addAnimation:self.percentageAnimation forKey:kCATransition];
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
self.circleOutlineLayer.strokeEnd = [self devicePercentageAsProgress];
[CATransaction commit];
}
//returns outline position to zero
-(void)newAnimateOuterLayerToZero {
self.circleOutlineLayer.strokeEnd = 0;
}
@end
// @implementation VaonFavoriteContactsCell
// -(instancetype)initWithFrame:(CGRect)arg1 favoriteEntry:(CNFavoriteEntry *)favoriteEntry {
// self = [super initWithFrame:arg1];
// self.axis = UILayoutConstraintAxisVertical;
// self.alignment = UIStackViewAlignmentCenter;
// self.distribution = UIStackViewDistributionEqualSpacing;
// self.spacing = 10;
// self.clipsToBounds = TRUE;
// self.backgroundColor = [UIColor clearColor];
// self.translatesAutoresizingMaskIntoConstraints = FALSE;
// self.favoriteEntry = favoriteEntry;
// self.contact = favoriteEntry.contact;
// self.contactNameLabel = [[UILabel alloc] init];
// self.contactNameLabel.text = [self.favoriteEntry originalName];
// self.contactNameLabel.adjustsFontSizeToFitWidth = TRUE;
// self.contactNameLabel.frame = self.bounds;
// self.contactNameLabel.clipsToBounds = TRUE;
// [self addArrangedSubview:self.contactNameLabel];
// NSData *imageData = self.contact.imageData;
// UIImage *contactImage = [UIImage imageWithData:imageData];
// self.contactImageView = [[UIImageView alloc] initWithImage:contactImage];
// self.contactImageView.contentMode = UIViewContentModeScaleAspectFit;
// self.contactImageView.frame = self.bounds;
// self.contactImageView.clipsToBounds = TRUE;
// [self addArrangedSubview:self.contactImageView];
// return self;
// }
// @end
//initialize the battery view
void initBatteryView(UIView *view){
//initialize horizontal scroll view
batteryScrollView = [[UIScrollView alloc] initWithFrame:view.bounds];
batteryScrollView.scrollsToTop = FALSE;
batteryScrollView.directionalLockEnabled = TRUE;
batteryScrollView.alwaysBounceVertical = FALSE;
batteryScrollView.alwaysBounceHorizontal = FALSE;
batteryScrollView.showsHorizontalScrollIndicator = TRUE;
batteryScrollView.showsVerticalScrollIndicator = FALSE;
//initialize horizontal stack view
batteryHStackView = [[UIStackView alloc] initWithFrame:batteryScrollView.bounds];
batteryHStackView.axis = UILayoutConstraintAxisHorizontal;
batteryHStackView.alignment = UIStackViewAlignmentCenter;
batteryHStackView.distribution = UIStackViewDistributionFill;
if(horizontalSpacingBetweenDevicesEnabled) {
batteryHStackView.spacing = horizontalSpacingBetweenDevices;
} else {
batteryHStackView.spacing = 30;
}
//gather bluetooth battery information
if (ios15) {
connectedBluetoothDevices = [[%c(BCBatteryDeviceController) _sharedPowerSourceController] connectedDevices];
} else {
connectedBluetoothDevices = [[%c(BCBatteryDeviceController) sharedInstance] connectedDevices];
}
//adds to the view hierarchy
[view addSubview:batteryScrollView];
[batteryScrollView addSubview:batteryHStackView];
if(!(currentSwitcherStyle == 2) && ios13){
for(BCBatteryDevice *device in connectedBluetoothDevices){
VaonDeviceBatteryCell *cell = [[VaonDeviceBatteryCell alloc] initWithFrame:batteryHStackView.bounds device:device];
if(![device isInternal]){
[batteryHStackView addArrangedSubview:cell];
} else {
if(!hideInternal){
[batteryHStackView addArrangedSubview:cell];
}
}
}
}
//scroll view constraints
batteryScrollView.translatesAutoresizingMaskIntoConstraints = FALSE;
[batteryScrollView.centerXAnchor constraintEqualToAnchor:view.centerXAnchor].active = TRUE;
[batteryScrollView.centerYAnchor constraintEqualToAnchor:view.centerYAnchor].active = TRUE;
[batteryScrollView.heightAnchor constraintEqualToAnchor:view.heightAnchor].active = TRUE;
[batteryScrollView.widthAnchor constraintEqualToAnchor:view.widthAnchor].active = TRUE;
//horizontal stack view constraints
batteryHStackView.translatesAutoresizingMaskIntoConstraints = FALSE;
[batteryHStackView.centerXAnchor constraintEqualToAnchor:batteryScrollView.centerXAnchor].active = TRUE;
[batteryHStackView.centerYAnchor constraintEqualToAnchor:batteryScrollView.centerYAnchor].active = TRUE;
if((customWidthEnabled && batteryHStackView.bounds.size.width > customWidth) || batteryHStackView.bounds.size.width > dockWidth){
batteryScrollView.scrollEnabled = TRUE;
if(currentSwitcherStyle == 2){
vaonGridView.userInteractionEnabled = TRUE;
}else {
// vaonView.userInteractionEnabled = TRUE;
}
}else{
batteryScrollView.scrollEnabled = FALSE;
if(currentSwitcherStyle == 2){
vaonGridView.userInteractionEnabled = FALSE;
}else {
// vaonView.userInteractionEnabled = FALSE;
}
}
}
// void initFavoriteContactsView(UIView *view) {
// // favoriteContactsScrollView
// favoriteContactsHStackView = [[UIStackView alloc] initWithFrame:view.bounds];
// favoriteContactsHStackView.axis = UILayoutConstraintAxisHorizontal;
// favoriteContactsHStackView.alignment = UIStackViewAlignmentCenter;
// favoriteContactsHStackView.distribution = UIStackViewDistributionEqualCentering;
// favoriteContactsHStackView.spacing = 80;
// favoriteContactsHStackView.clipsToBounds = TRUE;
// [view addSubview:favoriteContactsHStackView];
// NSArray *contactFavorites = [[%c(CNFavorites) sharedInstance] entries];
// for(CNFavoriteEntry *entry in contactFavorites){
// VaonFavoriteContactsCell *cell = [[VaonFavoriteContactsCell alloc] initWithFrame:favoriteContactsHStackView.bounds favoriteEntry:entry];
// [favoriteContactsHStackView addArrangedSubview:cell];
// }
// favoriteContactsHStackView.translatesAutoresizingMaskIntoConstraints = false;
// [favoriteContactsHStackView.centerXAnchor constraintEqualToAnchor:view.centerXAnchor].active = TRUE;
// [favoriteContactsHStackView.centerYAnchor constraintEqualToAnchor:view.centerYAnchor].active = TRUE;
// }
//initialize the base background blur view
void initBaseVaonView(UIView* view) {
vaonViewBackgroundColor = [UIColor colorNamed:@"clearColor"];
if ([backgroundMode isEqualToString:@"system"]) {
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterial];
} else if ([backgroundMode isEqualToString:@"dark"]) {
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemMaterialDark];
} else if ([backgroundMode isEqualToString:@"light"]) {
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemMaterialLight];
}
titleLabel = [[UILabel alloc] initWithFrame:view.bounds];
view.clipsToBounds = TRUE;
view.layer.cornerRadius = vaonViewCornerRadius;
view.alpha = 0;
view.backgroundColor = vaonViewBackgroundColor;
// view.userInteractionEnabled = FALSE;
// if(hideBackground) {
// vaonBlurView = [[UIVisualEffectView alloc] initWithEffect:nil];
// } else {
vaonBlurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
// }
vaonBlurView.frame = view.bounds;
vaonBlurView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
if(hideBackground) {
vaonBlurView.effect = nil;
}
[view addSubview:vaonBlurView];
}
void updateScrollWidthAndTouchPassthrough() {
NSLog(@"Vaon updateScrollWidthAndTouchPassthrough %f", batteryHStackView.bounds.size.width);
NSLog(@"Vaon updateScrollWidthAndTouchPassthrough %f", customWidth);
if((customWidthEnabled && batteryHStackView.bounds.size.width > customWidth) || batteryHStackView.bounds.size.width > dockWidth){
batteryScrollView.scrollEnabled = TRUE;
if(currentSwitcherStyle == 2){
vaonGridView.userInteractionEnabled = TRUE;
}else {
vaonView.userInteractionEnabled = TRUE;
batteryScrollView.userInteractionEnabled = TRUE;
batteryHStackView.userInteractionEnabled = TRUE;
if(switcherContentView) {
switcherContentView.userInteractionEnabled = TRUE;
}
}
}else{
batteryScrollView.scrollEnabled = FALSE;
if(currentSwitcherStyle == 2){
vaonGridView.userInteractionEnabled = FALSE;
}else {
vaonView.userInteractionEnabled = FALSE;
batteryScrollView.userInteractionEnabled = FALSE;
batteryHStackView.userInteractionEnabled = FALSE;
if(switcherContentView) {
switcherContentView.userInteractionEnabled = FALSE;
}
}
}
NSLog(@"Vaon updateScrollWidthAndTouchPassthrough %i", vaonView.userInteractionEnabled);
}
//updates battery information
void updateBattery(){
//access main loop
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Vaon iOS 13 Updating Battery Info");
[batteryScrollView setContentSize:CGSizeMake(batteryHStackView.bounds.size.width, batteryHStackView.bounds.size.height)];
if(batteryHStackView.bounds.size.width > dockWidth){
batteryScrollView.contentInset = UIEdgeInsetsMake(0,batteryHStackView.bounds.size.width/4,0,0);
}else{
batteryScrollView.contentInset = UIEdgeInsetsMake(0,0,0,0);
}
// CGFloat mainScreenWidth = [[UIScreen mainScreen] bounds].size.width;
// if( batteryScrollView.contentSize.width > mainScreenWidth){
// if(customSwitcherStyle == 2){
// vaonGridView.userInteractionEnabled = FALSE;
// } else {
// vaonView.userInteractionEnabled = FALSE;
// }
// }
//update list of bluetooth devices
if (ios15) {
connectedBluetoothDevices = [[%c(BCBatteryDeviceController) _sharedPowerSourceController] connectedDevices];
} else {
connectedBluetoothDevices = [[%c(BCBatteryDeviceController) sharedInstance] connectedDevices];
}
// connectedBluetoothDevices = [[%c(BCBatteryDeviceController) sharedInstance] _sortedDevices];
NSMutableArray *subviewsToBeAdded = [[NSMutableArray alloc] init];
//loops through and finds new devices to add
for(BCBatteryDevice *device in connectedBluetoothDevices){
VaonDeviceBatteryCell *newCell = [[VaonDeviceBatteryCell alloc] initWithFrame:batteryHStackView.bounds device:device];
BOOL duplicate = FALSE;
for(VaonDeviceBatteryCell *subview in batteryHStackView.subviews){
if([subview.deviceName isEqualToString:newCell.deviceName] || [subview.deviceIdentifier isEqualToString:newCell.deviceIdentifier]){
duplicate = TRUE;
}
}
//checks if devices are not already on the horizontal stack and the list of device names
if(![batteryHStackView.subviews containsObject:newCell] && ![deviceNames containsObject:newCell.deviceName] && !duplicate){
//add all devices that are not the iPhone/iPad
if(![device isInternal]){
[subviewsToBeAdded addObject:newCell];
[deviceIdentifiers addObject:[newCell.device identifier]];
// [deviceNames addObject:[newCell.device name]];
} else{
//displays the iphone if hideInternal is off
if(!hideInternal){
[subviewsToBeAdded addObject:newCell];
[deviceIdentifiers addObject:[newCell.device identifier]];
// [deviceNames addObject:[newCell.device name]];
}
}
}
}
//animate and add subviews to the hstack
for(VaonDeviceBatteryCell *subview in subviewsToBeAdded){
[batteryHStackView addArrangedSubview:subview];
subview.alpha = 0;
//fade in new devices
[UIView animateWithDuration:0.3 animations:^ {
subview.alpha = 1;
}
completion:^(BOOL finished) {
//when finished animate the outer layer to its percentage position
[subview newAnimateOuterLayerToCurrentPercentage];
[subviewsToBeAdded removeObject:subview];
}];
}
//counts how many times a device exists and stores all the position in the array
//then remove all the indexes except the first one
//update device view properties
for(VaonDeviceBatteryCell *subview in batteryHStackView.subviews){
//checks if the device is not connected anymore
if((![connectedBluetoothDevices containsObject:subview.device] && ![subview.device isConnected]) || subview.device == nil ){
//if keep is turned on, keep the device and just update its properties
if(keepDisconnectedDevices){
if(subview.device == nil){
for(BCBatteryDevice *device in connectedBluetoothDevices){
if([subview.deviceName isEqual:[device name]]){
subview.device = device;
[subview updateOutlineColor];
[subview updatePercentageColor];
// subview.deviceGlyphView = [[UIImageView alloc] initWithImage:subview.device.glyph];
// if(ios14){
// subview.deviceGlyphView = [[UIImageView alloc] initWithImage:[subview.device batteryWidgetGlyph]];
// } else {
// subview.deviceGlyphView = [[UIImageView alloc] initWithImage:subview.device.glyph];
// }
}
}
}
}else{
//remove subviews that aren't connected if keepDisconnectedDevices is turned off
subview.alpha = 1;
//fade out
[UIView animateWithDuration:0.3 animations:^ {
subview.alpha = 0;
}
completion:^(BOOL finished) {
[subview removeFromSuperview];
[deviceIdentifiers removeObject:[subview.device identifier]];
[deviceNames removeObject:subview.deviceName];
}];
}
}
//updates outline color and percentage values
if(keepDisconnectedDevices){
[subview updateOutlineColor];
[subview updatePercentageColor];
//if the device is still connected update its battery data
if([subview.device isConnected]){
[subview updateDevicePercentage];
[subview updateDevicePercentageLabel];
}
} else {
[subview updateDevicePercentageLabel];
[subview updateOutlineColor];
[subview updatePercentageColor];
[subview updateDevicePercentage];
}
}
});
// if(batteryHStackView.bounds.size.width > dockWidth){
// batteryScrollView.scrollEnabled = TRUE;
// if(currentSwitcherStyle == 2){
// vaonGridView.userInteractionEnabled = TRUE;
// }else {
// vaonView.userInteractionEnabled = TRUE;
// }
// }else{
// batteryScrollView.scrollEnabled = FALSE;
// if(currentSwitcherStyle == 2){
// vaonGridView.userInteractionEnabled = FALSE;
// }else {
// NSLog(@"Vaon print passthrough on");
// vaonView.userInteractionEnabled = FALSE;
// }
// }
}
void iOS14UpdateBattery(){
NSLog(@"Vaon iOS 14 Battery Updates");
// dispatch_async(dispatch_get_main_queue(), ^{
[batteryScrollView setContentSize:CGSizeMake(batteryHStackView.bounds.size.width, batteryHStackView.bounds.size.height)];
if(batteryHStackView.bounds.size.width > dockWidth){
batteryScrollView.contentInset = UIEdgeInsetsMake(0,batteryHStackView.bounds.size.width/4,0,0);
}else{
batteryScrollView.contentInset = UIEdgeInsetsMake(0,0,0,0);
}
//update list of bluetooth devices
if (ios15) {
connectedBluetoothDevices = [[%c(BCBatteryDeviceController) _sharedPowerSourceController] connectedDevices];
} else {
connectedBluetoothDevices = [[%c(BCBatteryDeviceController) sharedInstance] connectedDevices];
}
// connectedBluetoothDevices = [[%c(BCBatteryDeviceController) sharedInstance] _sortedDevices];
NSMutableArray *subviewsToBeAdded = [[NSMutableArray alloc] init];
//loops through and finds new devices to add
for(BCBatteryDevice *device in connectedBluetoothDevices){
// if(device != nil || [device.name isEqual:@"(null)"] || [device isEqual:@"(null)"]){
if(device || device != nil){
BOOL duplicate = FALSE;
VaonDeviceBatteryCell *newCell = [[VaonDeviceBatteryCell alloc] initWithFrame:batteryHStackView.bounds device:device];
// NSLog(@"Vaon contains %i", ![deviceNames containsObject:newCell.device.name]);
//checks if devices are not already on the horizontal stack and the list of device names
for(VaonDeviceBatteryCell *subview in batteryHStackView.subviews){
NSLog(@"Vaon name %@ | %@ | %@", subview.deviceName, subview.deviceIdentifier, newCell.deviceIdentifier);
[deviceNames addObject:subview.deviceName];
if([subview.deviceName isEqualToString:newCell.deviceName] || [subview.deviceIdentifier isEqualToString:newCell.deviceIdentifier]){
duplicate = TRUE;
}
}
if(![batteryHStackView.subviews containsObject:newCell] && ![deviceNames containsObject:newCell.deviceName] && !duplicate){
//add all devices that are not the iPhone/iPad
if(![device isInternal]){
[subviewsToBeAdded addObject:newCell];
[deviceIdentifiers addObject:[newCell.device identifier]];
// [deviceNames addObject:[newCell.device name]];
} else{
//displays the iphone if hideInternal is off
if(!hideInternal){
[subviewsToBeAdded addObject:newCell];
[deviceIdentifiers addObject:[newCell.device identifier]];
// [deviceNames addObject:[newCell.device name]];
}
}
}
}
}
//animate and add subviews to the hstack
for(VaonDeviceBatteryCell *subview in subviewsToBeAdded){
if(subview.device || subview.device != nil){
[batteryHStackView addArrangedSubview:subview];
subview.alpha = 0;
//fade in new devices
// subview.frame = CGRectMake(subview.frame.origin.x, -200 , subview.frame.size.width, subview.frame.size.height);
[UIView animateWithDuration:0.3 animations:^ {
subview.alpha = 1;
// subview.frame = CGRectMake(subview.frame.origin.x, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
}
completion:^(BOOL finished) {
//when finished animate the outer layer to its percentage position
if(finished){
[subview newAnimateOuterLayerToCurrentPercentage];
[subviewsToBeAdded removeObject:subview];
updateScrollWidthAndTouchPassthrough();
}
}];
}
}
//update device view properties
for(VaonDeviceBatteryCell *subview in batteryHStackView.subviews){
if(!subview.device) {
for(BCBatteryDevice *device in connectedBluetoothDevices) {
if([device.name isEqual:subview.deviceName]) {
subview.device = device;
// Didn't fix glyph not displaying correct device issue