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.

106 lines
3.4KB

  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. self.number = [self.subviews count];
  63. }
  64. self.isUpdating = NO;
  65. //NSLog(@"kai: finished update");
  66. //[(CSAdjunctListView *)self.superview.superview KaiUpdate];
  67. [(CSAdjunctListView *)self.superview.superview performSelector:@selector(KaiUpdate) withObject:(CSAdjunctListView *)self.superview.superview afterDelay:0.2];
  68. });
  69. self.number = [self.subviews count];
  70. }
  71. -(void)refreshForPrefs {
  72. for( UIView *view in self.subviews ) {
  73. @try {
  74. [view removeFromSuperview];
  75. } @catch (NSException *exception) {
  76. //Panik
  77. }
  78. }
  79. BCBatteryDeviceController *bcb = [BCBatteryDeviceController sharedInstance];
  80. NSArray *devices = MSHookIvar<NSArray *>(bcb, "_sortedDevices");
  81. for(BCBatteryDevice *device in devices) {
  82. [device resetKaiCellForNewPrefs];
  83. }
  84. [self updateBattery];
  85. }
  86. +(KAIBatteryStack *)sharedInstance {
  87. return instance;
  88. }
  89. @end