Device battery indicators on your Lock Screen
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

102 lines
4.2KB

  1. #import "KAIBattery.h"
  2. KAIBattery *instance;
  3. @implementation KAIBattery
  4. -(instancetype)initWithFrame:(CGRect)arg1 {
  5. self = [super initWithFrame:arg1];
  6. instance = self;
  7. if (self) {
  8. /*self.batteryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25,-10,220,120)];
  9. [self.batteryLabel setFont:[UIFont systemFontOfSize:13]];
  10. [self.batteryLabel setTextColor:[UIColor whiteColor]];
  11. self.batteryLabel.lineBreakMode = NSLineBreakByWordWrapping;
  12. self.batteryLabel.numberOfLines = 0;*/
  13. [self updateBattery];
  14. //[self addSubview:self.batteryLabel];
  15. }
  16. return self;
  17. }
  18. long long batteryPercentage;
  19. long long lastPercentage;
  20. -(void)updateBattery {
  21. if(!self.isUpdating) {
  22. self.isUpdating = YES;
  23. self.number = 0;
  24. BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
  25. NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
  26. for (BCBatteryDevice *device in devices) {
  27. NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
  28. double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
  29. BOOL charging = MSHookIvar<long long>(device, "_charging");
  30. BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
  31. float y;
  32. if(charging) {
  33. UIVisualEffectView *blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
  34. blank.frame = CGRectMake(0, 0 + y, self.frame.size.width, 80);
  35. blank.layer.masksToBounds = YES;
  36. blank.layer.cornerRadius = 13;
  37. blank.alpha = 0.8;
  38. //[blank setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]];
  39. [self addSubview:blank];
  40. NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
  41. UILabel *label = [[UILabel alloc] init];
  42. [label setFont:[UIFont systemFontOfSize:16]];
  43. [label setTextColor:[UIColor whiteColor]];
  44. label.lineBreakMode = NSLineBreakByWordWrapping;
  45. label.numberOfLines = 0;
  46. [label setText:labelText];
  47. [self addSubview:label];
  48. _UIBatteryView *battery = [[_UIBatteryView alloc] init];
  49. battery.chargePercent = (batteryPercentage*0.01);
  50. UILabel *percentLabel = [[UILabel alloc] init];
  51. battery.showsPercentage = NO;
  52. [percentLabel setFont:[UIFont systemFontOfSize:14]];
  53. [percentLabel setTextColor:[UIColor whiteColor]];
  54. percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
  55. [percentLabel setTextAlignment:NSTextAlignmentRight];
  56. percentLabel.numberOfLines = 0;
  57. [percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
  58. [self addSubview:percentLabel];
  59. if(charging) battery.chargingState = 1;
  60. battery.showsInlineChargingIndicator = YES;
  61. if(LPM) battery.saverModeActive = YES;
  62. if(kCFCoreFoundationVersionNumber > 1600) {
  63. [battery setBodyColorAlpha:1.0];
  64. [battery setPinColorAlpha:1.0];
  65. }
  66. [self addSubview:battery];
  67. UIImage *glyph = [device glyph];
  68. UIImageView *glyphView = [[UIImageView alloc] init];
  69. glyphView.contentMode = UIViewContentModeScaleAspectFit;
  70. [glyphView setImage:glyph];
  71. [self addSubview:glyphView];
  72. label.frame = CGRectMake(57.5,27.5 + y,275,25);
  73. glyphView.frame = CGRectMake(12.5,18.5 + y,40,40);
  74. battery.frame = CGRectMake(310,35 + y,20,10);
  75. percentLabel.frame = CGRectMake(265,35 + y,36,12);
  76. y+=85;
  77. self.number +=1;
  78. }
  79. }
  80. self.isUpdating = NO;
  81. }
  82. }
  83. +(KAIBattery *)sharedInstance {
  84. return instance;
  85. }
  86. @end