1
0
mirror of https://github.com/Burrit0z/kai synced 2025-07-01 13:56:48 +00:00
This commit is contained in:
Burrit0z
2020-05-20 12:43:34 -04:00
parent 168bd6d3dc
commit 4a9d95086d
7 changed files with 288 additions and 21 deletions

View File

@ -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;
}
}

26
Kai.h
View File

@ -4,7 +4,6 @@
#import <objc/runtime.h>
#import <UIKit/UIKit.h>
#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;
}
}

13
Kai.xm
View File

@ -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];
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -24,6 +24,130 @@
<key>label</key>
<string>Enable</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>disableGlyphs</string>
<key>label</key>
<string>Hide Device Glyphs</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>hidePercent</string>
<key>label</key>
<string>Hide Percent Label</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Banner Height (80)</string>
</dict>
<dict>
<key>default</key>
<real>80</real>
<key>cell</key>
<string>PSSliderCell</string>
<key>min</key>
<real>20</real>
<key>max</key>
<real>200</real>
<key>isSegmented</key>
<false/>
<key>showValue</key>
<true/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>bannerHeight</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Banner Spacing (5)</string>
</dict>
<dict>
<key>default</key>
<real>5</real>
<key>cell</key>
<string>PSSliderCell</string>
<key>min</key>
<real>0.0</real>
<key>max</key>
<real>100</real>
<key>isSegmented</key>
<false/>
<key>showValue</key>
<true/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>spacing</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Glyph Size (40)</string>
</dict>
<dict>
<key>default</key>
<real>40</real>
<key>cell</key>
<string>PSSliderCell</string>
<key>min</key>
<real>10</real>
<key>max</key>
<real>100</real>
<key>isSegmented</key>
<false/>
<key>showValue</key>
<true/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>glyphSize</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Corner Radius (13)</string>
</dict>
<dict>
<key>default</key>
<real>13</real>
<key>cell</key>
<string>PSSliderCell</string>
<key>min</key>
<real>0.1</real>
<key>max</key>
<real>100</real>
<key>isSegmented</key>
<false/>
<key>showValue</key>
<true/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>cornerRadius</string>
</dict>
</array>
<key>title</key>
<string>kai</string>