Device battery indicators on your Lock Screen
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

99 lines
3.1KB

  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. [cell updateInfo];
  37. BOOL shouldAdd = NO;
  38. if(showAll) {
  39. shouldAdd = YES;
  40. } else if(!showAll && device.charging) {
  41. shouldAdd = YES;
  42. }
  43. if(![self.subviews containsObject:cell] && shouldAdd && [devices containsObject:device]) {
  44. //[cell setFrame:CGRectMake(0,0,self.frame.size.width, bannerHeight + spacing)];
  45. [self addSubview:cell];
  46. [self addArrangedSubview:cell];
  47. } else if([self.subviews containsObject:cell] && !shouldAdd){
  48. [cell removeFromSuperview];
  49. [self removeArrangedSubview:cell];
  50. }
  51. }
  52. for(KAIBatteryCell *cell in self.subviews) {
  53. //BCBatteryDevice *device = cell.device;
  54. [cell updateInfo];
  55. if(![devices containsObject:cell.device]) {
  56. [cell removeFromSuperview];
  57. [self removeArrangedSubview:cell];
  58. }
  59. }
  60. self.number = [self.subviews count];
  61. }
  62. self.isUpdating = NO;
  63. //NSLog(@"kai: finished update");
  64. //[(CSAdjunctListView *)self.superview.superview KaiUpdate];
  65. [(CSAdjunctListView *)self.superview.superview performSelector:@selector(KaiUpdate) withObject:(CSAdjunctListView *)self.superview.superview afterDelay:0.2];
  66. });
  67. self.number = [self.subviews count];
  68. }
  69. -(void)removeAllAndRefresh {
  70. for( UIView *view in self.subviews ) {
  71. @try {
  72. [view removeFromSuperview];
  73. } @catch (NSException *exception) {
  74. //Panik
  75. }
  76. }
  77. [KAIBatteryCell resetArray];
  78. [self updateBattery];
  79. }
  80. +(KAIBatteryStack *)sharedInstance {
  81. return instance;
  82. }
  83. @end