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.

114 lines
3.7KB

  1. #import "KAIBatteryStack.h"
  2. KAIBatteryStack *instance;
  3. //NSMutableArray *showingCells = [[NSMutableArray alloc] init];
  4. @implementation KAIBatteryStack
  5. -(instancetype)init {
  6. self = [super init];
  7. instance = self;
  8. if (self) {
  9. self.displayingDevices = [[NSMutableArray alloc] init];
  10. self.axis = 1;
  11. self.distribution = 0;
  12. self.spacing = 0;
  13. self.alignment = 0;
  14. [self updateBattery];
  15. //self.clipsToBounds = YES;
  16. self.userInteractionEnabled = NO;
  17. }
  18. return self;
  19. }
  20. long long batteryPercentage;
  21. long long lastPercentage;
  22. -(void)updateBattery {
  23. self.spacing = spacing;
  24. dispatch_async(dispatch_get_main_queue(), ^{
  25. //NSLog(@"kai: battery platter called to update");
  26. if(!self.isUpdating) {
  27. //NSLog(@"kai: IS Updating");
  28. self.isUpdating = YES;
  29. //self.number = 0;
  30. //float y = 0;
  31. BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
  32. NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
  33. NSLog(@"kai: devices are %@", devices);
  34. for (BCBatteryDevice *device in devices) {
  35. KAIBatteryCell *cell = [device kaiCellForDevice];
  36. BOOL charging = MSHookIvar<long long>(device, "_charging");
  37. [cell updateInfo];
  38. BOOL shouldAdd = NO;
  39. if(showAll) {
  40. shouldAdd = YES;
  41. } else if(!showAll && charging) {
  42. shouldAdd = YES;
  43. }
  44. if(![self.subviews containsObject:cell] && shouldAdd && [devices containsObject:device]) {
  45. //[cell setFrame:CGRectMake(0,0,self.frame.size.width, bannerHeight)];
  46. cell.alpha = 0;
  47. [self addSubview:cell];
  48. [self addArrangedSubview:cell];
  49. [UIView animateWithDuration:0.3 animations:^{
  50. cell.alpha = 1;
  51. }];
  52. } else if([self.subviews containsObject:cell] && !shouldAdd){
  53. [UIView animateWithDuration:0.3 animations:^{
  54. cell.alpha = 0;
  55. } completion:^(BOOL finished) {
  56. [cell removeFromSuperview];
  57. [self removeArrangedSubview:cell];
  58. cell.alpha = 1;
  59. }];
  60. }
  61. }
  62. for(KAIBatteryCell *cell in self.subviews) {
  63. //BCBatteryDevice *device = cell.device;
  64. [cell updateInfo];
  65. if(![devices containsObject:cell.device]) {
  66. [UIView animateWithDuration:0.3 animations:^{
  67. cell.alpha = 0;
  68. } completion:^(BOOL finished) {
  69. [cell removeFromSuperview];
  70. [self removeArrangedSubview:cell];
  71. cell.alpha = 1;
  72. }];
  73. }
  74. }
  75. self.number = [self.subviews count];
  76. }
  77. self.isUpdating = NO;
  78. //NSLog(@"kai: finished update");
  79. //[(CSAdjunctListView *)self.superview.superview KaiUpdate];
  80. [(CSAdjunctListView *)self.superview.superview performSelector:@selector(KaiUpdate) withObject:(CSAdjunctListView *)self.superview.superview afterDelay:0.2];
  81. });
  82. self.number = [self.subviews count];
  83. }
  84. -(void)removeAllAndRefresh {
  85. for( UIView *view in self.subviews ) {
  86. @try {
  87. [view removeFromSuperview];
  88. } @catch (NSException *exception) {
  89. //Panik
  90. }
  91. }
  92. [KAIBatteryCell resetArray];
  93. [self updateBattery];
  94. }
  95. +(KAIBatteryStack *)sharedInstance {
  96. return instance;
  97. }
  98. @end