From e3b8e6c815bcc3a5f644e5648f5476ea9bde23a7 Mon Sep 17 00:00:00 2001 From: callam Date: Wed, 3 Apr 2013 18:17:27 +0200 Subject: [PATCH 1/3] Update AnimateBattery.plist Added more options to settings entry: (When device is not charging) -Show lockscreen battery -Show lockscreen battery reflection (When device is charging) -Show lockscreen battery -Show lockscreen battery reflection -Show lockscreen background --- .../Preferences/AnimateBattery.plist | 88 +++++++++++++++++-- 1 file changed, 82 insertions(+), 6 deletions(-) diff --git a/layout/Library/PreferenceLoader/Preferences/AnimateBattery.plist b/layout/Library/PreferenceLoader/Preferences/AnimateBattery.plist index 0aeefdb..e66946d 100644 --- a/layout/Library/PreferenceLoader/Preferences/AnimateBattery.plist +++ b/layout/Library/PreferenceLoader/Preferences/AnimateBattery.plist @@ -16,6 +16,44 @@ cell PSGroupCell + label + Lockscreen + footerText + When device is not charging. + + + cell + PSSwitchCell + default + + defaults + net.limneos.animatebattery + key + LSBattery + label + Battery + PostNotification + net.limneos.animatebattery.reload + + + cell + PSSwitchCell + default + + defaults + net.limneos.animatebattery + key + LSReflection + label + Reflection + PostNotification + net.limneos.animatebattery.reload + + + cell + PSGroupCell + footerText + When device is charging. cell @@ -25,9 +63,45 @@ defaults net.limneos.animatebattery key - enabled + ABBattery + label + Battery + PostNotification + net.limneos.animatebattery.reload + + + cell + PSSwitchCell + default + + defaults + net.limneos.animatebattery + key + ABReflection + label + Reflection + PostNotification + net.limneos.animatebattery.reload + + + cell + PSSwitchCell + default + + defaults + net.limneos.animatebattery + key + ABWallpaper + label + Wallpaper + PostNotification + net.limneos.animatebattery.reload + + + cell + PSGroupCell label - Enable Animation + Battery Animation cell @@ -37,12 +111,14 @@ defaults net.limneos.animatebattery key - allTiles + ABAnimation label - Full Status Animation + Enable + PostNotification + net.limneos.animatebattery.reload - + title AnimateBattery - \ No newline at end of file + From bdb1c7c91492f9b4b89663da1166e74649974237 Mon Sep 17 00:00:00 2001 From: callam Date: Wed, 3 Apr 2013 18:20:19 +0200 Subject: [PATCH 2/3] Update Tweak.xm Added code for new options updated in the .plist --- Tweak.xm | 116 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 91 insertions(+), 25 deletions(-) diff --git a/Tweak.xm b/Tweak.xm index c1d5de5..4a23803 100644 --- a/Tweak.xm +++ b/Tweak.xm @@ -1,46 +1,112 @@ #import #import #import + #define PATH @"/System/Library/CoreServices/SpringBoard.app" -static BOOL enableAnimateBattery=YES; -static BOOL animateFullStatus=YES; +static BOOL LSBattery = YES; +static BOOL LSReflection = YES; + +static BOOL ABBattery = YES; +static BOOL ABReflection = YES; +static BOOL ABWallpaper = YES; -static void getSettings(){ - NSDictionary *defaults=[NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/net.limneos.animatebattery.plist"]; - enableAnimateBattery=[defaults objectForKey:@"enabled"] ? [[defaults objectForKey:@"enabled"] boolValue] : YES; - animateFullStatus=[defaults objectForKey:@"allTiles"] ? [[defaults objectForKey:@"allTiles"] boolValue] : YES; +static BOOL ABAnimation = YES; +static BOOL ABFullStatus = YES; + +static void ABSettings(){ + NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.poynterco.chargingbattery.plist"]; + LSBattery = [settings objectForKey:@"LSBattery"] ? [[settings objectForKey:@"LSBattery"] boolValue] : YES; + LSReflection = [settings objectForKey:@"LSReflection"] ? [[settings objectForKey:@"LSReflection"] boolValue] : YES; + ABBattery = [settings objectForKey:@"ABBattery"] ? [[settings objectForKey:@"ABBattery"] boolValue] : YES; + ABReflection = [settings objectForKey:@"ABReflection"] ? [[settings objectForKey:@"ABReflection"] boolValue] : YES; + ABWallpaper = [settings objectForKey:@"ABWallpaper"] ? [[settings objectForKey:@"ABWallpaper"] boolValue] : YES; + ABAnimation = [settings objectForKey:@"ABAnimation"] ? [[settings objectForKey:@"ABAnimation"] boolValue] : YES; + ABFullStatus = [settings objectForKey:@"ABFullStatus"] ? [[settings objectForKey:@"ABFullStatus"] boolValue] : YES; } %hook SBAwayView -(void)showChargingView{ %orig; - getSettings(); - if (!enableAnimateBattery) + ABSettings(); + if (!ABAnimation) + return; + SBBatteryChargingView *chargingView = [[self chargingView] chargingView]; + UIImageView *chargingBattery = MSHookIvar (chargingView,"_topBatteryView"); + UIDeviceBatteryState batteryState = [UIDevice currentDevice].batteryState; + if (batteryState == UIDeviceBatteryStateUnplugged){ + [chargingBattery stopAnimating]; + if (LSReflection) { + [chargingView setShowsReflection:YES]; + } else { + [chargingView setShowsReflection:NO]; + } return; - SBBatteryChargingView *chargingView=[[self chargingView] chargingView]; - UIImageView *battView=MSHookIvar(chargingView,"_topBatteryView"); - if (chargingView.alpha>0 && ![battView isAnimating] ){ - [chargingView setShowsReflection:NO]; - NSMutableArray *images=[NSMutableArray array]; - int startImage=animateFullStatus ? 1 : ([chargingView _currentBatteryIndex]-1>0 ? [chargingView _currentBatteryIndex]-1 : [chargingView _currentBatteryIndex]) ; - for (int i=startImage; i<=[chargingView _currentBatteryIndex]; i++){ - [images addObject:[UIImage imageNamed:[NSString stringWithFormat:[chargingView _imageFormatString],i]]]; + } else { + if ([chargingView _currentBatteryIndex] == 17){ + [chargingBattery stopAnimating]; + %orig; + return; + } else { + if (batteryState == UIDeviceBatteryStateCharging && ![chargingBattery isAnimating]){ + if (ABReflection) { + [chargingView setShowsReflection:YES]; + } else { + [chargingView setShowsReflection:NO]; + } + NSMutableArray *batteryImages = [NSMutableArray array]; + int startImage = ABFullAnimation ? 1 : ([chargingView _currentBatteryIndex]-1 > 0 ? [chargingView _currentBatteryIndex]-1 : [chargingView _currentBatteryIndex]); + for (int i = startImage; i <= [chargingView _currentBatteryIndex]; i++){ + [batteryImages addObject:[UIImage imageNamed:[NSString stringWithFormat:[chargingView _imageFormatString],i]]]; + } + chargingBattery.animationImages = batteryImages; + chargingBattery.animationDuration = batteryImages.count > 4 ? batteryImages.count/4 : 1; + chargingBattery.animationRepeatCount = 0; + [chargingBattery startAnimating]; + } } - battView.animationImages = images; - battView.animationDuration = images.count>4 ? images.count/4 : 1; - battView.animationRepeatCount = 0; - [battView startAnimating]; } } + -(void)hideChargingView{ - if (!enableAnimateBattery){ + if (!ABAnimation){ %orig; return; } - UIImageView *charginView=[[self chargingView] chargingView]; - UIImageView *battView=MSHookIvar(charginView,"_topBatteryView"); - [battView stopAnimating]; + SBBatteryChargingView *chargingView = [[self chargingView] chargingView]; + UIImageView *chargingBattery = MSHookIvar(chargingView,"_topBatteryView"); + [chargingBattery stopAnimating]; %orig; } -%end \ No newline at end of file +%end + +%hook SBAwayChargingView ++ (BOOL)shouldShowDeviceBattery { + UIDeviceBatteryState batteryState = [UIDevice currentDevice].batteryState; + if (batteryState == UIDeviceBatteryStateUnplugged){ + if (LSBattery) return YES; + return NO; + } else { + if (ABBattery) return YES; + return NO; + } +} +%end + +%hook SBWallpaperView +- (float)alpha { + if (ABWallpaper) return 0.0f; + return %orig; +} +%end + +static void ABReloadSettings(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){ + ABSettings(); +} + +%ctor { + NSAutoreleasePool *ABPool = [NSAutoreleasePool new]; + ABSettings(); + CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &ABReloadSettings, CFSTR("net.limneos.animatebattery.reload"), NULL, 0); + [ABPool drain]; +} From aef38d5ea11dfe1cc582cf6378ec85ffd2cf4e45 Mon Sep 17 00:00:00 2001 From: callam Date: Wed, 3 Apr 2013 18:23:22 +0200 Subject: [PATCH 3/3] Update AnimateBattery.plist --- .../Preferences/AnimateBattery.plist | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/layout/Library/PreferenceLoader/Preferences/AnimateBattery.plist b/layout/Library/PreferenceLoader/Preferences/AnimateBattery.plist index e66946d..bd75a0e 100644 --- a/layout/Library/PreferenceLoader/Preferences/AnimateBattery.plist +++ b/layout/Library/PreferenceLoader/Preferences/AnimateBattery.plist @@ -117,8 +117,22 @@ PostNotification net.limneos.animatebattery.reload + + cell + PSSwitchCell + default + + defaults + net.limneos.animatebattery + key + ABFullStatus + label + Full Status + PostNotification + net.limneos.animatebattery.reload + title AnimateBattery - +