Device battery indicators on your Lock Screen
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

KAIBatteryCell.mm 9.5KB

il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #import "KAIBatteryCell.h"
  2. @implementation KAIBatteryCell
  3. -(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device {
  4. self = [super initWithFrame:arg1];
  5. if(self && device!=nil) {
  6. self.device = device;
  7. NSString *deviceName = device.name;
  8. double batteryPercentage = device.percentCharge;
  9. BOOL charging = MSHookIvar<long long>(device, "_charging");
  10. BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
  11. UIView *blur;
  12. UIView *blurPlatter = [[UIView alloc] init];
  13. if(bannerStyle==1) {
  14. if(kCFCoreFoundationVersionNumber > 1600) {
  15. blur = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil];
  16. } else if(kCFCoreFoundationVersionNumber < 1600) {
  17. blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  18. }
  19. } else if(bannerStyle==2) {
  20. blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
  21. } else if(bannerStyle==3) {
  22. blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  23. }
  24. blur.layer.masksToBounds = YES;
  25. blur.layer.continuousCorners = YES;
  26. blur.layer.cornerRadius = cornerRadius;
  27. blurPlatter.alpha = bannerAlpha;
  28. NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
  29. self.label = [[UILabel alloc] init];
  30. if(!hideDeviceLabel) {
  31. [self.label setFont:[UIFont systemFontOfSize:16]];
  32. } else if(hideDeviceLabel) {
  33. [self.label setFont:[UIFont systemFontOfSize:0]];
  34. }
  35. if(textColor==1) {
  36. [self.label setTextColor:[UIColor whiteColor]];
  37. } else {
  38. [self.label setTextColor:[UIColor blackColor]];
  39. }
  40. self.label.lineBreakMode = NSLineBreakByWordWrapping;
  41. self.label.numberOfLines = 1;
  42. [self.label setText:labelText];
  43. self.battery = [[_UIBatteryView alloc] init];
  44. self.battery.chargePercent = (batteryPercentage*0.01);
  45. self.percentLabel = [[UILabel alloc] init];
  46. self.battery.showsPercentage = NO;
  47. if(hidePercent) {
  48. [self.percentLabel setFont:[UIFont systemFontOfSize:0]];
  49. } else {
  50. [self.percentLabel setFont:[UIFont systemFontOfSize:14]];
  51. }
  52. if(textColor==1) {
  53. [self.percentLabel setTextColor:[UIColor whiteColor]];
  54. } else {
  55. [self.percentLabel setTextColor:[UIColor blackColor]];
  56. }
  57. self.percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
  58. [self.percentLabel setTextAlignment:NSTextAlignmentRight];
  59. self.percentLabel.numberOfLines = 1;
  60. [self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
  61. if(charging) self.battery.chargingState = 1;
  62. self.battery.showsInlineChargingIndicator = YES;
  63. if(LPM) self.battery.saverModeActive = YES;
  64. if(kCFCoreFoundationVersionNumber > 1600) {
  65. [self.battery setBodyColorAlpha:1.0];
  66. [self.battery setPinColorAlpha:1.0];
  67. }
  68. UIImage *glyph = [device glyph];
  69. self.glyphView = [[UIImageView alloc] init];
  70. self.glyphView.contentMode = UIViewContentModeScaleAspectFit;
  71. [self.glyphView setImage:glyph];
  72. [self addSubview:blurPlatter];
  73. [blurPlatter addSubview:blur];
  74. [self addSubview:self.percentLabel];
  75. [self addSubview:self.label];
  76. [self addSubview:self.battery];
  77. [self addSubview:self.glyphView];
  78. blurPlatter.translatesAutoresizingMaskIntoConstraints = NO;
  79. if(bannerAlign==2) { //center
  80. [blurPlatter.centerXAnchor constraintEqualToAnchor:self.centerXAnchor constant:horizontalOffset].active = YES;
  81. } else if(bannerAlign==1) { //left
  82. [blurPlatter.leftAnchor constraintEqualToAnchor:self.leftAnchor constant:horizontalOffset].active = YES;
  83. } else if(bannerAlign==3) { //right
  84. [blurPlatter.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:horizontalOffset].active = YES;
  85. }
  86. [blurPlatter.topAnchor constraintEqualToAnchor:self.topAnchor].active = YES;
  87. [blurPlatter.widthAnchor constraintEqualToConstant:((self.frame.size.width) + bannerWidthFactor)].active = YES;
  88. [blurPlatter.heightAnchor constraintEqualToConstant:bannerHeight].active = YES;
  89. blur.translatesAutoresizingMaskIntoConstraints = NO;
  90. [blur.centerXAnchor constraintEqualToAnchor:blurPlatter.centerXAnchor].active = YES;
  91. [blur.topAnchor constraintEqualToAnchor:blurPlatter.topAnchor].active = YES;
  92. [blur.widthAnchor constraintEqualToAnchor:blurPlatter.widthAnchor].active = YES;
  93. [blur.heightAnchor constraintEqualToAnchor:blurPlatter.heightAnchor].active = YES;
  94. self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO;
  95. [self.percentLabel.leftAnchor constraintEqualToAnchor:blurPlatter.rightAnchor constant:(- 96)].active = YES;
  96. [self.percentLabel.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES;
  97. [self.percentLabel.widthAnchor constraintEqualToConstant:37].active = YES;
  98. [self.percentLabel.heightAnchor constraintEqualToConstant:12].active = YES;
  99. self.label.translatesAutoresizingMaskIntoConstraints = NO;
  100. [self.label.leftAnchor constraintEqualToAnchor:self.glyphView.rightAnchor constant:4.5].active = YES;
  101. [self.label.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES;
  102. if(!hidePercent) {
  103. [self.label.rightAnchor constraintEqualToAnchor:self.percentLabel.leftAnchor constant:-4.5].active = YES;
  104. }
  105. [self.label.heightAnchor constraintEqualToConstant:25].active = YES;
  106. self.glyphView.translatesAutoresizingMaskIntoConstraints = NO;
  107. [self.glyphView.leftAnchor constraintEqualToAnchor:blurPlatter.leftAnchor constant:20.5].active = YES;
  108. [self.glyphView.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES;
  109. [self.glyphView.widthAnchor constraintEqualToConstant:glyphSize].active = YES;
  110. [self.glyphView.heightAnchor constraintEqualToConstant:glyphSize].active = YES;
  111. self.battery.translatesAutoresizingMaskIntoConstraints = NO;
  112. [self.battery.leftAnchor constraintEqualToAnchor:blurPlatter.rightAnchor constant:(- 49)].active = YES;
  113. [self.battery.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES;
  114. [self.battery.widthAnchor constraintEqualToConstant:20].active = YES;
  115. [self.battery.heightAnchor constraintEqualToConstant:10].active = YES;
  116. if(hidePercent) {
  117. [self.label.rightAnchor constraintEqualToAnchor:self.battery.leftAnchor constant:-4.5].active = YES;
  118. }
  119. }
  120. return self;
  121. }
  122. -(void)traitCollectionDidChange:(id)arg1 {
  123. [super traitCollectionDidChange:arg1];
  124. if(textColor==0) {
  125. if(@available(iOS 12.0, *)) {
  126. if(self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  127. [self.label setTextColor:[UIColor whiteColor]];
  128. [self.percentLabel setTextColor:[UIColor whiteColor]];
  129. } else if(self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
  130. [self.label setTextColor:[UIColor blackColor]];
  131. [self.percentLabel setTextColor:[UIColor blackColor]];
  132. }
  133. }
  134. }
  135. }
  136. -(void)updateInfo {
  137. //NSLog(@"kai: updating cell info");
  138. NSString *deviceName = MSHookIvar<NSString *>(self.device, "_name");
  139. double batteryPercentage = MSHookIvar<long long>(self.device, "_percentCharge");
  140. BOOL charging = MSHookIvar<long long>(self.device, "_charging");
  141. BOOL LPM = MSHookIvar<BOOL>(self.device, "_batterySaverModeActive");
  142. self.label.text = [NSString stringWithFormat:@"%@", deviceName];
  143. [self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
  144. self.battery.chargePercent = (batteryPercentage*0.01);
  145. if(charging) { self.battery.chargingState = 1; } else { self.battery.chargingState = 0; }
  146. self.battery.showsInlineChargingIndicator = YES;
  147. if(LPM) { self.battery.saverModeActive = YES; } else { self.battery.saverModeActive = NO; }
  148. if(kCFCoreFoundationVersionNumber > 1600) {
  149. [self.battery setBodyColorAlpha:1.0];
  150. [self.battery setPinColorAlpha:1.0];
  151. }
  152. [self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
  153. self.battery.chargePercent = (batteryPercentage*0.01);
  154. [self.glyphView setImage:[self.device glyph]];
  155. [self.heightAnchor constraintEqualToConstant:(bannerHeight)].active = YES;
  156. /*if(!self.height) {
  157. self.height.active = NO;
  158. self.height = [self.heightAnchor constraintEqualToConstant:(bannerHeight + spacing)];
  159. self.height.active = YES;
  160. }*/ //else {
  161. //int height = (bannerHeight + spacing);
  162. //self.height.constant = height;
  163. //}
  164. if(!self.width) {
  165. self.width.active = NO;
  166. self.width = [self.widthAnchor constraintEqualToConstant:(self.frame.size.width)];
  167. self.width.active = YES;
  168. } //else {
  169. //int width = self.frame.size.width;
  170. //self.width.constant = width;
  171. //}
  172. }
  173. @end