Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 91 additions & 25 deletions Tweak.xm
Original file line number Diff line number Diff line change
@@ -1,46 +1,112 @@
#import <SpringBoard/SBAwayView.h>
#import <SpringBoard/SBAwayChargingView.h>
#import <SpringBoard/SBBatteryChargingView.h>

#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 <UIImageView *>(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<UIImageView *>(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<UIImageView *>(charginView,"_topBatteryView");
[battView stopAnimating];
SBBatteryChargingView *chargingView = [[self chargingView] chargingView];
UIImageView *chargingBattery = MSHookIvar<UIImageView *>(chargingView,"_topBatteryView");
[chargingBattery stopAnimating];
%orig;
}
%end
%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];
}
102 changes: 96 additions & 6 deletions layout/Library/PreferenceLoader/Preferences/AnimateBattery.plist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,92 @@
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Lockscreen</string>
<key>footerText</key>
<string>When device is not charging.</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>net.limneos.animatebattery</string>
<key>key</key>
<string>LSBattery</string>
<key>label</key>
<string>Battery</string>
<key>PostNotification</key>
<string>net.limneos.animatebattery.reload</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>net.limneos.animatebattery</string>
<key>key</key>
<string>LSReflection</string>
<key>label</key>
<string>Reflection</string>
<key>PostNotification</key>
<string>net.limneos.animatebattery.reload</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>footerText</key>
<string>When device is charging.</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>net.limneos.animatebattery</string>
<key>key</key>
<string>ABBattery</string>
<key>label</key>
<string>Battery</string>
<key>PostNotification</key>
<string>net.limneos.animatebattery.reload</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>net.limneos.animatebattery</string>
<key>key</key>
<string>ABReflection</string>
<key>label</key>
<string>Reflection</string>
<key>PostNotification</key>
<string>net.limneos.animatebattery.reload</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>net.limneos.animatebattery</string>
<key>key</key>
<string>ABWallpaper</string>
<key>label</key>
<string>Wallpaper</string>
<key>PostNotification</key>
<string>net.limneos.animatebattery.reload</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Battery Animation</string>
</dict>
<dict>
<key>cell</key>
Expand All @@ -25,9 +111,11 @@
<key>defaults</key>
<string>net.limneos.animatebattery</string>
<key>key</key>
<string>enabled</string>
<string>ABAnimation</string>
<key>label</key>
<string>Enable Animation</string>
<string>Enable</string>
<key>PostNotification</key>
<string>net.limneos.animatebattery.reload</string>
</dict>
<dict>
<key>cell</key>
Expand All @@ -37,12 +125,14 @@
<key>defaults</key>
<string>net.limneos.animatebattery</string>
<key>key</key>
<string>allTiles</string>
<string>ABFullStatus</string>
<key>label</key>
<string>Full Status Animation</string>
<string>Full Status</string>
<key>PostNotification</key>
<string>net.limneos.animatebattery.reload</string>
</dict>
</array>
</array>
<key>title</key>
<string>AnimateBattery</string>
</dict>
</plist>
</plist>