Device battery indicators on your Lock Screen
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

119 lines
4.7KB

  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( UIView *view in self.subviews ) {
  27. @try {
  28. [view removeFromSuperview];
  29. } @catch (NSException *exception) {
  30. //Panik
  31. }
  32. }
  33. for (BCBatteryDevice *device in devices) {
  34. NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
  35. double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
  36. BOOL charging = MSHookIvar<long long>(device, "_charging");
  37. BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
  38. float y;
  39. if(charging) {
  40. UIVisualEffectView *blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
  41. blank.frame = CGRectMake(0, 0 + y, self.frame.size.width, 80);
  42. blank.layer.masksToBounds = YES;
  43. blank.layer.cornerRadius = 13;
  44. blank.alpha = 0;
  45. //[blank setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]];
  46. NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
  47. UILabel *label = [[UILabel alloc] init];
  48. [label setFont:[UIFont systemFontOfSize:16]];
  49. [label setTextColor:[UIColor whiteColor]];
  50. label.lineBreakMode = NSLineBreakByWordWrapping;
  51. label.numberOfLines = 0;
  52. label.alpha = 0;
  53. [label setText:labelText];
  54. _UIBatteryView *battery = [[_UIBatteryView alloc] init];
  55. battery.chargePercent = (batteryPercentage*0.01);
  56. UILabel *percentLabel = [[UILabel alloc] init];
  57. percentLabel.alpha = 0;
  58. battery.alpha = 0;
  59. battery.showsPercentage = NO;
  60. [percentLabel setFont:[UIFont systemFontOfSize:14]];
  61. [percentLabel setTextColor:[UIColor whiteColor]];
  62. percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
  63. [percentLabel setTextAlignment:NSTextAlignmentRight];
  64. percentLabel.numberOfLines = 0;
  65. [percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
  66. if(charging) battery.chargingState = 1;
  67. battery.showsInlineChargingIndicator = YES;
  68. if(LPM) battery.saverModeActive = YES;
  69. if(kCFCoreFoundationVersionNumber > 1600) {
  70. [battery setBodyColorAlpha:1.0];
  71. [battery setPinColorAlpha:1.0];
  72. }
  73. UIImage *glyph = [device glyph];
  74. UIImageView *glyphView = [[UIImageView alloc] init];
  75. glyphView.alpha = 0;
  76. glyphView.contentMode = UIViewContentModeScaleAspectFit;
  77. [glyphView setImage:glyph];
  78. label.frame = CGRectMake(57.5,27.5 + y,275,25);
  79. glyphView.frame = CGRectMake(12.5,18.5 + y,40,40);
  80. battery.frame = CGRectMake(310,35 + y,20,10);
  81. percentLabel.frame = CGRectMake(265,35 + y,36,12);
  82. y+=85;
  83. self.number +=1;
  84. [self addSubview:blank];
  85. [self addSubview:percentLabel];
  86. [self addSubview:label];
  87. [self addSubview:battery];
  88. [self addSubview:glyphView];
  89. blank.alpha = 0.8;
  90. percentLabel.alpha = 1;
  91. battery.alpha = 1;
  92. label.alpha = 1;
  93. glyphView.alpha = 1;
  94. }
  95. }
  96. self.isUpdating = NO;
  97. }
  98. }
  99. +(KAIBattery *)sharedInstance {
  100. return instance;
  101. }
  102. @end