Browse Source

prefs

pull/1/head
Burrit0z 4 years ago
parent
commit
4a9d95086d
7 changed files with 289 additions and 22 deletions
  1. +45
    -15
      KAIBattery.mm
  2. +23
    -3
      Kai.h
  3. +11
    -2
      Kai.xm
  4. +2
    -2
      control
  5. +10
    -0
      kaiprefs/KAIRootListController.h
  6. +74
    -0
      kaiprefs/KAIRootListController.m
  7. +124
    -0
      kaiprefs/Resources/Root.plist

+ 45
- 15
KAIBattery.mm View File

}*/ }*/
MTMaterialView *blank = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil]; MTMaterialView *blank = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil];
//blank.recipeDynamic = NO; //makes it stay light //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.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]]; //[blank setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]];


NSString *labelText = [NSString stringWithFormat:@"%@", deviceName]; NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
battery.chargePercent = (batteryPercentage*0.01); battery.chargePercent = (batteryPercentage*0.01);
UILabel *percentLabel = [[UILabel alloc] init]; UILabel *percentLabel = [[UILabel alloc] init];
battery.showsPercentage = NO; 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 setTextColor:[UIColor whiteColor]];
percentLabel.lineBreakMode = NSLineBreakByWordWrapping; percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
[percentLabel setTextAlignment:NSTextAlignmentRight]; [percentLabel setTextAlignment:NSTextAlignmentRight];
glyphView.contentMode = UIViewContentModeScaleAspectFit; glyphView.contentMode = UIViewContentModeScaleAspectFit;
[glyphView setImage:glyph]; [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);

y+=85;
[self addSubview:blank];
[self addSubview:percentLabel];
[self addSubview:label];
[self addSubview:battery];
[self addSubview:glyphView];

//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.number +=1;

[self addSubview:blank];
[self addSubview:percentLabel];
[self addSubview:label];
[self addSubview:battery];
[self addSubview:glyphView];
//blank.alpha = 0.8; //blank.alpha = 0.8;
} }
} }

+ 23
- 3
Kai.h View File

#import <objc/runtime.h> #import <objc/runtime.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>


#import "KAIBattery.mm"
#define KAISelf ((CSAdjunctListView *)self) #define KAISelf ((CSAdjunctListView *)self)


@interface UIApplication (Kai) @interface UIApplication (Kai)
+(id)constraintWithAnchor:(id)arg1 relatedBy:(long long)arg2 toAnchor:(id)arg3 multiplier:(double)arg4 constant:(double)arg5 ; +(id)constraintWithAnchor:(id)arg1 relatedBy:(long long)arg2 toAnchor:(id)arg3 multiplier:(double)arg4 constant:(double)arg5 ;
@end @end


@interface CALayer (kai)
@property (nonatomic, assign) BOOL continuousCorners;
@end

//prefs //prefs
BOOL enabled; 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 PLIST_PATH @"/User/Library/Preferences/com.burritoz.kaiprefs.plist"
#define kIdentifier @"com.burritoz.kaiprefs" #define kIdentifier @"com.burritoz.kaiprefs"
} }




/*static double numberForValue(NSString *key, double defaultValue) {
static double numberForValue(NSString *key, double defaultValue) {
return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] doubleValue] : defaultValue); return (prefs && [prefs objectForKey:key] ? [[prefs objectForKey:key] doubleValue] : defaultValue);
}*/
}


static void preferencesChanged() static void preferencesChanged()
{ {
reloadPrefs(); reloadPrefs();


enabled = boolValueForKey(@"enabled", YES); 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;
}
} }

+ 11
- 2
Kai.xm View File

-(void)_layoutStackView { -(void)_layoutStackView {


//NSLog(@"Kai: Laying out stack view"); //NSLog(@"Kai: Laying out stack view");
[self KaiUpdate]; [self KaiUpdate];


%orig; %orig;
battery.heightConstraint.active = YES; battery.heightConstraint.active = YES;


} else { } else {
int height = (battery.number * 85);
int height = (battery.number * (80 + spacing));
battery.heightConstraint.active = NO; battery.heightConstraint.active = NO;
NSLog(@"kai: setting to %d", height); NSLog(@"kai: setting to %d", height);
battery.heightConstraint.constant = height; battery.heightConstraint.constant = height;


%new %new
-(void)KaiInfo { -(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]; [[KAIBattery sharedInstance] updateBattery];
[self KaiUpdate]; [self KaiUpdate];
} }

+ 2
- 2
control View File

Name: Kai Name: Kai
Version: 0.0.4 Version: 0.0.4
Architecture: iphoneos-arm Architecture: iphoneos-arm
Description: An awesome MobileSubstrate tweak!
Description: Show charging banners on your lock screen!
Maintainer: burrit0z Maintainer: burrit0z
Author: burrit0z Author: burrit0z
Section: Tweaks Section: Tweaks
Depends: mobilesubstrate (>= 0.9.5000)
Depends: mobilesubstrate (>= 0.9.5000), preferenceloader

+ 10
- 0
kaiprefs/KAIRootListController.h View File

-(void)setFrame:(CGRect)frame; -(void)setFrame:(CGRect)frame;
@end @end


@interface NSTask : NSObject
@property(copy) NSArray *arguments;
@property(copy) NSString *launchPath;
- (id)init;
- (void)waitUntilExit;
- (void)launch;
@end

@interface KAIRootListController : PSListController @interface KAIRootListController : PSListController
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *iconView;
@end @end


@protocol PreferencesTableCustomView @protocol PreferencesTableCustomView

+ 74
- 0
kaiprefs/KAIRootListController.m View File



} }


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


@implementation KaiHeaderCell // Header Cell @implementation KaiHeaderCell // Header Cell

+ 124
- 0
kaiprefs/Resources/Root.plist View File

<key>label</key> <key>label</key>
<string>Enable</string> <string>Enable</string>
</dict> </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> </array>
<key>title</key> <key>title</key>
<string>kai</string> <string>kai</string>

Loading…
Cancel
Save