Browse Source

progress

pull/1/head
Burrit0z 4 years ago
parent
commit
b3297545bf
5 changed files with 106 additions and 27 deletions
  1. +1
    -0
      KAIBatteryCell.h
  2. +35
    -25
      KAIBatteryCell.mm
  3. +28
    -2
      KAIBatteryStack.mm
  4. +4
    -0
      Kai.h
  5. +38
    -0
      kaiprefs/Resources/Root.plist

+ 1
- 0
KAIBatteryCell.h View File

@property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSString *name;
@property (nonatomic, assign) long long percentCharge; @property (nonatomic, assign) long long percentCharge;
@property (nonatomic, assign) BOOL charging; @property (nonatomic, assign) BOOL charging;
@property (nonatomic, assign) BOOL internal;
@property (nonatomic, assign) BOOL batterySaverModeActive; @property (nonatomic, assign) BOOL batterySaverModeActive;
@property (nonatomic, strong) NSString *identifier; @property (nonatomic, strong) NSString *identifier;
-(id)glyph; -(id)glyph;

+ 35
- 25
KAIBatteryCell.mm View File

BOOL charging = MSHookIvar<long long>(device, "_charging"); BOOL charging = MSHookIvar<long long>(device, "_charging");
BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive"); BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");


UIView *blank;
UIView *blur;
UIView *blurPlatter = [[UIView alloc] init];
if(bannerStyle==1) { if(bannerStyle==1) {
if(kCFCoreFoundationVersionNumber > 1600) { if(kCFCoreFoundationVersionNumber > 1600) {
blank = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil];
blur = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil];
} else if(kCFCoreFoundationVersionNumber < 1600) { } else if(kCFCoreFoundationVersionNumber < 1600) {
blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
} }
} else if(bannerStyle==2) { } else if(bannerStyle==2) {
blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
} else if(bannerStyle==3) { } else if(bannerStyle==3) {
blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
} }
blank.layer.masksToBounds = YES;
blank.layer.continuousCorners = YES;
blank.layer.cornerRadius = cornerRadius;
blur.layer.masksToBounds = YES;
blur.layer.continuousCorners = YES;
blur.layer.cornerRadius = cornerRadius;
blurPlatter.alpha = bannerAlpha;


NSString *labelText = [NSString stringWithFormat:@"%@", deviceName]; NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];


self.glyphView.contentMode = UIViewContentModeScaleAspectFit; self.glyphView.contentMode = UIViewContentModeScaleAspectFit;
[self.glyphView setImage:glyph]; [self.glyphView setImage:glyph];


[self addSubview:blank];
[self addSubview:blurPlatter];
[blurPlatter addSubview:blur];
[self addSubview:self.percentLabel]; [self addSubview:self.percentLabel];
[self addSubview:self.label]; [self addSubview:self.label];
[self addSubview:self.battery]; [self addSubview:self.battery];
[self addSubview:self.glyphView]; [self addSubview:self.glyphView];


blank.translatesAutoresizingMaskIntoConstraints = NO;
blurPlatter.translatesAutoresizingMaskIntoConstraints = NO;
if(bannerAlign==2) { //center if(bannerAlign==2) { //center
[blank.centerXAnchor constraintEqualToAnchor:self.centerXAnchor constant:horizontalOffset].active = YES;
[blurPlatter.centerXAnchor constraintEqualToAnchor:self.centerXAnchor constant:horizontalOffset].active = YES;
} else if(bannerAlign==1) { //left } else if(bannerAlign==1) { //left
[blank.leftAnchor constraintEqualToAnchor:self.leftAnchor constant:horizontalOffset].active = YES;
[blurPlatter.leftAnchor constraintEqualToAnchor:self.leftAnchor constant:horizontalOffset].active = YES;
} else if(bannerAlign==3) { //right } else if(bannerAlign==3) { //right
[blank.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:horizontalOffset].active = YES;
[blurPlatter.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:horizontalOffset].active = YES;
} }
[blank.topAnchor constraintEqualToAnchor:self.topAnchor].active = YES;
[blank.widthAnchor constraintEqualToConstant:((self.frame.size.width) + bannerWidthFactor)].active = YES;
[blank.heightAnchor constraintEqualToConstant:bannerHeight].active = YES;
[blurPlatter.topAnchor constraintEqualToAnchor:self.topAnchor].active = YES;
[blurPlatter.widthAnchor constraintEqualToConstant:((self.frame.size.width) + bannerWidthFactor)].active = YES;
[blurPlatter.heightAnchor constraintEqualToConstant:bannerHeight].active = YES;

blur.translatesAutoresizingMaskIntoConstraints = NO;
[blur.centerXAnchor constraintEqualToAnchor:blurPlatter.centerXAnchor].active = YES;
[blur.topAnchor constraintEqualToAnchor:blurPlatter.topAnchor].active = YES;
[blur.widthAnchor constraintEqualToAnchor:blurPlatter.widthAnchor].active = YES;
[blur.heightAnchor constraintEqualToAnchor:blurPlatter.heightAnchor].active = YES;


self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO; self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.percentLabel.leftAnchor constraintEqualToAnchor:blank.rightAnchor constant:(- 96)].active = YES;
[self.percentLabel.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES;
[self.percentLabel.leftAnchor constraintEqualToAnchor:blurPlatter.rightAnchor constant:(- 96)].active = YES;
[self.percentLabel.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES;
[self.percentLabel.widthAnchor constraintEqualToConstant:37].active = YES; [self.percentLabel.widthAnchor constraintEqualToConstant:37].active = YES;
[self.percentLabel.heightAnchor constraintEqualToConstant:12].active = YES; [self.percentLabel.heightAnchor constraintEqualToConstant:12].active = YES;


self.label.translatesAutoresizingMaskIntoConstraints = NO; self.label.translatesAutoresizingMaskIntoConstraints = NO;
[self.label.leftAnchor constraintEqualToAnchor:self.glyphView.rightAnchor constant:4.5].active = YES; [self.label.leftAnchor constraintEqualToAnchor:self.glyphView.rightAnchor constant:4.5].active = YES;
[self.label.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES;
[self.label.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES;
[self.label.rightAnchor constraintEqualToAnchor:self.percentLabel.leftAnchor constant:-4.5].active = YES; [self.label.rightAnchor constraintEqualToAnchor:self.percentLabel.leftAnchor constant:-4.5].active = YES;
[self.label.heightAnchor constraintEqualToConstant:25].active = YES; [self.label.heightAnchor constraintEqualToConstant:25].active = YES;


self.glyphView.translatesAutoresizingMaskIntoConstraints = NO; self.glyphView.translatesAutoresizingMaskIntoConstraints = NO;
[self.glyphView.leftAnchor constraintEqualToAnchor:blank.leftAnchor constant:20.5].active = YES;
[self.glyphView.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES;
[self.glyphView.leftAnchor constraintEqualToAnchor:blurPlatter.leftAnchor constant:20.5].active = YES;
[self.glyphView.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES;
[self.glyphView.widthAnchor constraintEqualToConstant:glyphSize].active = YES; [self.glyphView.widthAnchor constraintEqualToConstant:glyphSize].active = YES;
[self.glyphView.heightAnchor constraintEqualToConstant:glyphSize].active = YES; [self.glyphView.heightAnchor constraintEqualToConstant:glyphSize].active = YES;


self.battery.translatesAutoresizingMaskIntoConstraints = NO; self.battery.translatesAutoresizingMaskIntoConstraints = NO;
[self.battery.leftAnchor constraintEqualToAnchor:blank.rightAnchor constant:(- 49)].active = YES;
[self.battery.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES;
[self.battery.leftAnchor constraintEqualToAnchor:blurPlatter.rightAnchor constant:(- 49)].active = YES;
[self.battery.centerYAnchor constraintEqualToAnchor:blurPlatter.centerYAnchor].active = YES;
[self.battery.widthAnchor constraintEqualToConstant:20].active = YES; [self.battery.widthAnchor constraintEqualToConstant:20].active = YES;
[self.battery.heightAnchor constraintEqualToConstant:10].active = YES; [self.battery.heightAnchor constraintEqualToConstant:10].active = YES;


self.battery.chargePercent = (batteryPercentage*0.01); self.battery.chargePercent = (batteryPercentage*0.01);


[self.glyphView setImage:[self.device glyph]]; [self.glyphView setImage:[self.device glyph]];
[self.heightAnchor constraintEqualToConstant:(bannerHeight + spacing)].active = YES;


if(!self.height) {
/*if(!self.height) {
self.height.active = NO; self.height.active = NO;
self.height = [self.heightAnchor constraintEqualToConstant:(bannerHeight + spacing)]; self.height = [self.heightAnchor constraintEqualToConstant:(bannerHeight + spacing)];
self.height.active = YES; self.height.active = YES;


} //else {
}*/ //else {
//int height = (bannerHeight + spacing); //int height = (bannerHeight + spacing);
//self.height.constant = height; //self.height.constant = height;
//} //}

+ 28
- 2
KAIBatteryStack.mm View File

for (BCBatteryDevice *device in devices) { for (BCBatteryDevice *device in devices) {
KAIBatteryCell *cell = [device kaiCellForDevice]; KAIBatteryCell *cell = [device kaiCellForDevice];
BOOL charging = MSHookIvar<long long>(device, "_charging"); BOOL charging = MSHookIvar<long long>(device, "_charging");
BOOL internal = MSHookIvar<BOOL>(device, "_internal");
BOOL shouldAdd = NO; BOOL shouldAdd = NO;


if(showAll) { if(showAll) {
shouldAdd = YES; shouldAdd = YES;
} else if(showAllMinusInternal && !internal) {
shouldAdd = YES;
} else if(!showAll && charging) { } else if(!showAll && charging) {
shouldAdd = YES; shouldAdd = YES;
} }
self.queued = YES; self.queued = YES;
} }


self.number = [self.subviews count];

[UIView animateWithDuration:0.3 animations:^{

if(!self.heightConstraint) {
self.heightConstraint.active = NO;
self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))];
//set an initial constraint
self.heightConstraint.active = YES;

} else {
int height = (self.number * (bannerHeight + spacing)); //big brain math
//self.heightConstraint.active = NO; //deactivation
self.heightConstraint.constant = height;
//self.heightConstraint.active = YES; //forcing reactivation

UIStackView *s = (UIStackView *)(self.superview);
s.frame = CGRectMake(s.frame.origin.x, s.frame.origin.y, s.frame.size.width, (s.frame.size.height - 1));
//literally does nothing but makes the stack view lay itself out (doesnt adjust frame because translatesAutoreszingMaskIntoConstraints = NO on stack views)
}

}];


}); });


if(!self.heightConstraint) { if(!self.heightConstraint) {
self.heightConstraint.active = NO; self.heightConstraint.active = NO;
self.heightConstraint = [self.heightAnchor constraintEqualToConstant:85];
self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))];
//set an initial constraint //set an initial constraint
self.heightConstraint.active = YES; self.heightConstraint.active = YES;


if(!self.heightConstraint) { if(!self.heightConstraint) {
self.heightConstraint.active = NO; self.heightConstraint.active = NO;
self.heightConstraint = [self.heightAnchor constraintEqualToConstant:85];
self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))];
//set an initial constraint //set an initial constraint
self.heightConstraint.active = YES; self.heightConstraint.active = YES;



+ 4
- 0
Kai.h View File

BOOL belowMusic; BOOL belowMusic;
BOOL hideDeviceLabel; BOOL hideDeviceLabel;
BOOL hideChargingAnimation; BOOL hideChargingAnimation;
BOOL showAllMinusInternal;
NSInteger bannerStyle; NSInteger bannerStyle;
NSInteger bannerAlign; NSInteger bannerAlign;
NSInteger textColor; NSInteger textColor;
double cornerRadius; double cornerRadius;
double bannerWidthFactor; double bannerWidthFactor;
double horizontalOffset; double horizontalOffset;
double bannerAlpha;


//by importing here, I can use vars in the .mm files //by importing here, I can use vars in the .mm files
#import "KAIBatteryCell.mm" #import "KAIBatteryCell.mm"
belowMusic = boolValueForKey(@"belowMusic", NO); belowMusic = boolValueForKey(@"belowMusic", NO);
hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES); hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES);
textColor = numberForValue(@"textColor", 0); textColor = numberForValue(@"textColor", 0);
bannerAlpha = numberForValue(@"bannerAlpha", 1);
showAllMinusInternal = boolValueForKey(@"showAllMinusInternal", NO);


if(disableGlyphs) { if(disableGlyphs) {
glyphSize = 0; glyphSize = 0;

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

<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSGroupCell</string> <string>PSGroupCell</string>
<key>footerText</key>
<string>By having the show all devices option on, all deviecs, not only devices that are charging, will show. When the always show bluetooth devices option is on, kai will show all connected bluetooth devices if they are charging or not.</string>
</dict> </dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<key>label</key> <key>label</key>
<string>Show all devices</string> <string>Show all devices</string>
</dict> </dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>showAllMinusInternal</string>
<key>label</key>
<string>Always show bluetooth devices</string>
</dict>
<dict> <dict>
<key>cell</key> <key>cell</key>
<string>PSSwitchCell</string> <string>PSSwitchCell</string>
<key>key</key> <key>key</key>
<string>cornerRadius</string> <string>cornerRadius</string>
</dict> </dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Banner Blur Alpha (1)</string>
</dict>
<dict>
<key>default</key>
<real>1</real>
<key>cell</key>
<string>PSSliderCell</string>
<key>min</key>
<real>0.0</real>
<key>max</key>
<real>1</real>
<key>isSegmented</key>
<false/>
<key>showValue</key>
<true/>
<key>defaults</key>
<string>com.burritoz.kaiprefs</string>
<key>key</key>
<string>bannerAlpha</string>
</dict>
</array> </array>
<key>title</key> <key>title</key>
<string>kai</string> <string>kai</string>

Loading…
Cancel
Save