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

4 лет назад
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #import "KAIBattery.h"
  2. @implementation KAIBattery
  3. -(instancetype)initWithFrame:(CGRect)arg1 {
  4. self = [super initWithFrame:arg1];
  5. if (self) {
  6. /*self.batteryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25,-10,220,120)];
  7. [self.batteryLabel setFont:[UIFont systemFontOfSize:13]];
  8. [self.batteryLabel setTextColor:[UIColor whiteColor]];
  9. self.batteryLabel.lineBreakMode = NSLineBreakByWordWrapping;
  10. self.batteryLabel.numberOfLines = 0;*/
  11. [self updateBattery];
  12. //[self addSubview:self.batteryLabel];
  13. }
  14. return self;
  15. }
  16. long long batteryPercentage;
  17. long long lastPercentage;
  18. -(void)updateBattery {
  19. NSArray* subViews = self.subviews;
  20. for( UIView *view in subViews ) {
  21. @try {
  22. [view removeFromSuperview];
  23. } @catch (NSException *exception) {
  24. //Panik
  25. }
  26. BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
  27. NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
  28. for (BCBatteryDevice *device in devices) {
  29. NSString *deviceName = MSHookIvar<NSString *>(device, "_name");
  30. double batteryPercentage = MSHookIvar<long long>(device, "_percentCharge");
  31. BOOL charging = MSHookIvar<long long>(device, "_charging");
  32. BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
  33. NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
  34. UILabel *label = [[UILabel alloc] init];
  35. if([devices count]>=4) {
  36. [label setFont:[UIFont systemFontOfSize:19]];
  37. }
  38. [label setTextColor:[UIColor whiteColor]];
  39. label.lineBreakMode = NSLineBreakByWordWrapping;
  40. label.numberOfLines = 0;
  41. [label setText:labelText];
  42. [self addSubview:label];
  43. _UIBatteryView *battery = [[_UIBatteryView alloc] init];
  44. battery.chargePercent = (batteryPercentage*0.01);
  45. UILabel *percentLabel = [[UILabel alloc] init];
  46. battery.showsPercentage = NO;
  47. [percentLabel setFont:[UIFont systemFontOfSize:14]];
  48. [percentLabel setTextColor:[UIColor whiteColor]];
  49. percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
  50. [percentLabel setTextAlignment:NSTextAlignmentRight];
  51. percentLabel.numberOfLines = 0;
  52. [percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
  53. [self addSubview:percentLabel];
  54. if(charging) battery.chargingState = 1;
  55. if(LPM) battery.saverModeActive = YES;
  56. if(kCFCoreFoundationVersionNumber > 1600) {
  57. [battery setBodyColorAlpha:1.0];
  58. [battery setPinColorAlpha:1.0];
  59. }
  60. [self addSubview:battery];
  61. UIImage *glyph = [device glyph];
  62. UIImageView *glyphView = [[UIImageView alloc] init];
  63. glyphView.contentMode = UIViewContentModeScaleAspectFit;
  64. [glyphView setImage:glyph];
  65. [self addSubview:glyphView];
  66. label.frame = CGRectMake(57.5,27.5,275,25);
  67. glyphView.frame = CGRectMake(12.5,18.5,40,40);
  68. battery.frame = CGRectMake(310,35,20,10);
  69. percentLabel.frame = CGRectMake(265,35,36,12);
  70. }
  71. }
  72. }
  73. /*
  74. label.frame = CGRectMake(57.5,27.5,275,25);
  75. glyphView.frame = CGRectMake(12.5,18.5,40,40);
  76. battery.frame = CGRectMake(310,35,20,10);
  77. percentLabel.frame = CGRectMake(265,35,36,12);*/
  78. @end