From 4a9d95086d8dd0c792c87945dd32e4cecb63493e Mon Sep 17 00:00:00 2001 From: Burrit0z Date: Wed, 20 May 2020 12:43:34 -0400 Subject: [PATCH] prefs --- KAIBattery.mm | 58 +++++++++++---- Kai.h | 26 ++++++- Kai.xm | 13 +++- control | 4 +- kaiprefs/KAIRootListController.h | 10 +++ kaiprefs/KAIRootListController.m | 74 ++++++++++++++++++ kaiprefs/Resources/Root.plist | 124 +++++++++++++++++++++++++++++++ 7 files changed, 288 insertions(+), 21 deletions(-) diff --git a/KAIBattery.mm b/KAIBattery.mm index 0775284..6d5f75b 100644 --- a/KAIBattery.mm +++ b/KAIBattery.mm @@ -60,9 +60,10 @@ long long lastPercentage; }*/ MTMaterialView *blank = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil]; //blank.recipeDynamic = NO; //makes it stay light - blank.frame = CGRectMake(0, 0 + y, self.superview.bounds.size.width - 16, 80); + blank.frame = CGRectMake(0, 0 + y, self.superview.bounds.size.width - 16, bannerHeight); blank.layer.masksToBounds = YES; - blank.layer.cornerRadius = 13; + blank.layer.continuousCorners = YES; + blank.layer.cornerRadius = cornerRadius; //[blank setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]]; NSString *labelText = [NSString stringWithFormat:@"%@", deviceName]; @@ -78,7 +79,11 @@ long long lastPercentage; battery.chargePercent = (batteryPercentage*0.01); UILabel *percentLabel = [[UILabel alloc] init]; battery.showsPercentage = NO; - [percentLabel setFont:[UIFont systemFontOfSize:14]]; + if(hidePercent) { + [percentLabel setFont:[UIFont systemFontOfSize:0]]; + } else { + [percentLabel setFont:[UIFont systemFontOfSize:14]]; + } [percentLabel setTextColor:[UIColor whiteColor]]; percentLabel.lineBreakMode = NSLineBreakByWordWrapping; [percentLabel setTextAlignment:NSTextAlignmentRight]; @@ -97,19 +102,44 @@ long long lastPercentage; glyphView.contentMode = UIViewContentModeScaleAspectFit; [glyphView setImage:glyph]; - label.frame = CGRectMake(65.5,27.5 + y,275,25); - glyphView.frame = CGRectMake(20.5,18.5 + y,40,40); - battery.frame = CGRectMake(self.superview.bounds.size.width - 16 - 49,35 + y,20,10); - percentLabel.frame = CGRectMake(self.superview.bounds.size.width - 16 - 94,35 + y,36,12); + [self addSubview:blank]; + [self addSubview:percentLabel]; + [self addSubview:label]; + [self addSubview:battery]; + [self addSubview:glyphView]; - y+=85; + //label.frame = CGRectMake(65.5,27.5 + y,275,25); + label.translatesAutoresizingMaskIntoConstraints = NO; + [label.leftAnchor constraintEqualToAnchor:glyphView.rightAnchor constant:4.5].active = YES; + [label.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES; + [label.widthAnchor constraintEqualToConstant:275].active = YES; + [label.heightAnchor constraintEqualToConstant:25].active = YES; + + //glyphView.frame = CGRectMake(20.5,18.5 + y,40,40); + + glyphView.translatesAutoresizingMaskIntoConstraints = NO; + [glyphView.leftAnchor constraintEqualToAnchor:blank.leftAnchor constant:20.5].active = YES; + [glyphView.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES; + [glyphView.widthAnchor constraintEqualToConstant:glyphSize].active = YES; + [glyphView.heightAnchor constraintEqualToConstant:glyphSize].active = YES; + + //battery.frame = CGRectMake(self.superview.bounds.size.width - 16 - 49,35 + y,20,10); + + battery.translatesAutoresizingMaskIntoConstraints = NO; + [battery.leftAnchor constraintEqualToAnchor:self.rightAnchor constant:(- 49)].active = YES; + [battery.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES; + [battery.widthAnchor constraintEqualToConstant:20].active = YES; + [battery.heightAnchor constraintEqualToConstant:10].active = YES; + + //percentLabel.frame = CGRectMake(self.superview.bounds.size.width - 16 - 94,35 + y,36,12); + percentLabel.translatesAutoresizingMaskIntoConstraints = NO; + [percentLabel.leftAnchor constraintEqualToAnchor:self.rightAnchor constant:(- 94)].active = YES; + [percentLabel.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES; + [percentLabel.widthAnchor constraintEqualToConstant:36].active = YES; + [percentLabel.heightAnchor constraintEqualToConstant:12].active = YES; + + y+=bannerHeight + spacing; self.number +=1; - - [self addSubview:blank]; - [self addSubview:percentLabel]; - [self addSubview:label]; - [self addSubview:battery]; - [self addSubview:glyphView]; //blank.alpha = 0.8; } } diff --git a/Kai.h b/Kai.h index 6f0e273..aea5006 100644 --- a/Kai.h +++ b/Kai.h @@ -4,7 +4,6 @@ #import #import -#import "KAIBattery.mm" #define KAISelf ((CSAdjunctListView *)self) @interface UIApplication (Kai) @@ -37,9 +36,20 @@ +(id)constraintWithAnchor:(id)arg1 relatedBy:(long long)arg2 toAnchor:(id)arg3 multiplier:(double)arg4 constant:(double)arg5 ; @end +@interface CALayer (kai) +@property (nonatomic, assign) BOOL continuousCorners; +@end + //prefs BOOL enabled; +BOOL disableGlyphs; +BOOL hidePercent; +double spacing; +double glyphSize; +double bannerHeight; +double cornerRadius; +#import "KAIBattery.mm" #define PLIST_PATH @"/User/Library/Preferences/com.burritoz.kaiprefs.plist" #define kIdentifier @"com.burritoz.kaiprefs" @@ -78,9 +88,9 @@ static BOOL boolValueForKey(NSString *key, BOOL defaultValue) { } -/*static double numberForValue(NSString *key, double defaultValue) { +static double numberForValue(NSString *key, double defaultValue) { return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] doubleValue] : defaultValue); -}*/ +} static void preferencesChanged() { @@ -88,4 +98,14 @@ static void preferencesChanged() reloadPrefs(); enabled = boolValueForKey(@"enabled", YES); + spacing = numberForValue(@"spacing", 5); + glyphSize = numberForValue(@"glyphSize", 40); + bannerHeight = numberForValue(@"bannerHeight", 80); + cornerRadius = numberForValue(@"cornerRadius", 13); + disableGlyphs = boolValueForKey(@"disableGlyphs", NO); + hidePercent = boolValueForKey(@"hidePercent", NO); + + if(disableGlyphs) { + glyphSize = 0; + } } \ No newline at end of file diff --git a/Kai.xm b/Kai.xm index 0c2916a..b94aab5 100644 --- a/Kai.xm +++ b/Kai.xm @@ -7,7 +7,7 @@ -(void)_layoutStackView { //NSLog(@"Kai: Laying out stack view"); - + [self KaiUpdate]; %orig; @@ -50,7 +50,7 @@ battery.heightConstraint.active = YES; } else { - int height = (battery.number * 85); + int height = (battery.number * (80 + spacing)); battery.heightConstraint.active = NO; NSLog(@"kai: setting to %d", height); battery.heightConstraint.constant = height; @@ -66,6 +66,15 @@ %new -(void)KaiInfo { + [UIView animateWithDuration:0.3 animations:^{ + [KAIBattery sharedInstance].alpha = 0; + } completion:^(BOOL finished){ + [[KAIBattery sharedInstance] updateBattery]; + [self KaiUpdate]; + [UIView animateWithDuration:0.35 animations:^{ + [KAIBattery sharedInstance].alpha = 1; + }]; + }]; [[KAIBattery sharedInstance] updateBattery]; [self KaiUpdate]; } diff --git a/control b/control index 44a13b4..995cee2 100644 --- a/control +++ b/control @@ -2,8 +2,8 @@ Package: com.burritoz.kai Name: Kai Version: 0.0.4 Architecture: iphoneos-arm -Description: An awesome MobileSubstrate tweak! +Description: Show charging banners on your lock screen! Maintainer: burrit0z Author: burrit0z Section: Tweaks -Depends: mobilesubstrate (>= 0.9.5000) +Depends: mobilesubstrate (>= 0.9.5000), preferenceloader diff --git a/kaiprefs/KAIRootListController.h b/kaiprefs/KAIRootListController.h index da601c4..b031eb2 100644 --- a/kaiprefs/KAIRootListController.h +++ b/kaiprefs/KAIRootListController.h @@ -8,7 +8,17 @@ -(void)setFrame:(CGRect)frame; @end +@interface NSTask : NSObject +@property(copy) NSArray *arguments; +@property(copy) NSString *launchPath; +- (id)init; +- (void)waitUntilExit; +- (void)launch; +@end + @interface KAIRootListController : PSListController +@property (nonatomic, strong) UILabel *titleLabel; +@property (nonatomic, strong) UIImageView *iconView; @end @protocol PreferencesTableCustomView diff --git a/kaiprefs/KAIRootListController.m b/kaiprefs/KAIRootListController.m index c0741b9..0c2260c 100644 --- a/kaiprefs/KAIRootListController.m +++ b/kaiprefs/KAIRootListController.m @@ -32,6 +32,80 @@ NSBundle *tweakBundle; } +-(void)viewDidLoad { + [super viewDidLoad]; + + UIBarButtonItem *applyButton = [[UIBarButtonItem alloc] initWithTitle:@"Respring" style:UIBarButtonItemStylePlain target:self action:@selector(respring:)]; + self.navigationItem.rightBarButtonItem = applyButton; + + self.navigationItem.titleView = [UIView new]; + self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,10,10)]; + self.titleLabel.font = [UIFont systemFontOfSize:17.5]; + self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO; + self.titleLabel.text = @"kai"; + self.titleLabel.alpha = 0.0; + self.titleLabel.textAlignment = NSTextAlignmentCenter; + [self.navigationItem.titleView addSubview:self.titleLabel]; + + self.iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,10,10)]; + self.iconView.contentMode = UIViewContentModeScaleAspectFit; + self.iconView.image = [UIImage imageWithContentsOfFile:@"/Library/PreferenceBundles/kaiPrefs.bundle/icon.png"]; + self.iconView.translatesAutoresizingMaskIntoConstraints = NO; + self.iconView.alpha = 1.0; + [self.navigationItem.titleView addSubview:self.iconView]; + + [NSLayoutConstraint activateConstraints:@[ + [self.titleLabel.topAnchor constraintEqualToAnchor:self.navigationItem.titleView.topAnchor], + [self.titleLabel.leadingAnchor constraintEqualToAnchor:self.navigationItem.titleView.leadingAnchor], + [self.titleLabel.trailingAnchor constraintEqualToAnchor:self.navigationItem.titleView.trailingAnchor], + [self.titleLabel.bottomAnchor constraintEqualToAnchor:self.navigationItem.titleView.bottomAnchor], + [self.iconView.topAnchor constraintEqualToAnchor:self.navigationItem.titleView.topAnchor], + [self.iconView.leadingAnchor constraintEqualToAnchor:self.navigationItem.titleView.leadingAnchor], + [self.iconView.trailingAnchor constraintEqualToAnchor:self.navigationItem.titleView.trailingAnchor], + [self.iconView.bottomAnchor constraintEqualToAnchor:self.navigationItem.titleView.bottomAnchor], + ]]; +} + +-(void)respring:(id)sender { + + tweakBundle = [NSBundle bundleWithPath:@"/Library/PreferenceBundles/MultiplaPrefs.bundle"]; + + UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Respring" + message:@"Are you sure you want to respring now?" + preferredStyle:UIAlertControllerStyleActionSheet]; + + UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) {}]; + + UIAlertAction* yes = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive + handler:^(UIAlertAction * action) { + NSTask *t = [[NSTask alloc] init]; + [t setLaunchPath:@"usr/bin/killall"]; + [t setArguments:[NSArray arrayWithObjects:@"backboardd", nil]]; + [t launch]; + }]; + + [alert addAction:defaultAction]; + [alert addAction:yes]; + [self presentViewController:alert animated:YES completion:nil]; +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView { + CGFloat offsetY = scrollView.contentOffset.y; + + if (offsetY > 140) { + [UIView animateWithDuration:0.2 animations:^{ + self.iconView.alpha = 1.0; + self.titleLabel.alpha = 0.0; + }]; + } else { + [UIView animateWithDuration:0.2 animations:^{ + self.iconView.alpha = 0.0; + self.titleLabel.alpha = 1.0; + }]; + } +} + @end @implementation KaiHeaderCell // Header Cell diff --git a/kaiprefs/Resources/Root.plist b/kaiprefs/Resources/Root.plist index 8aa73e4..16ab7f5 100644 --- a/kaiprefs/Resources/Root.plist +++ b/kaiprefs/Resources/Root.plist @@ -24,6 +24,130 @@ label Enable + + cell + PSGroupCell + + + cell + PSSwitchCell + default + + defaults + com.burritoz.kaiprefs + key + disableGlyphs + label + Hide Device Glyphs + + + cell + PSSwitchCell + default + + defaults + com.burritoz.kaiprefs + key + hidePercent + label + Hide Percent Label + + + cell + PSGroupCell + label + Banner Height (80) + + + default + 80 + cell + PSSliderCell + min + 20 + max + 200 + isSegmented + + showValue + + defaults + com.burritoz.kaiprefs + key + bannerHeight + + + cell + PSGroupCell + label + Banner Spacing (5) + + + default + 5 + cell + PSSliderCell + min + 0.0 + max + 100 + isSegmented + + showValue + + defaults + com.burritoz.kaiprefs + key + spacing + + + cell + PSGroupCell + label + Glyph Size (40) + + + default + 40 + cell + PSSliderCell + min + 10 + max + 100 + isSegmented + + showValue + + defaults + com.burritoz.kaiprefs + key + glyphSize + + + cell + PSGroupCell + label + Corner Radius (13) + + + default + 13 + cell + PSSliderCell + min + 0.1 + max + 100 + isSegmented + + showValue + + defaults + com.burritoz.kaiprefs + key + cornerRadius + title kai