|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #import "KAIBatteryCell.h"
-
- @implementation KAIBatteryCell
-
- -(instancetype)initWithFrame:(CGRect)arg1 device:(BCBatteryDevice *)device {
- self = [super initWithFrame:arg1];
- if(self && device!=nil) {
-
- self.device = device;
-
- NSString *deviceName = device.name;
- double batteryPercentage = device.percentCharge;
- BOOL charging = MSHookIvar<long long>(device, "_charging");
- BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");
-
- UIView *blank;
- if(bannerStyle==1) {
- if(kCFCoreFoundationVersionNumber > 1600) {
- blank = [[[objc_getClass("MTMaterialView") class] alloc] _initWithRecipe:1 configuration:1 initialWeighting:1 scaleAdjustment:nil];
- } else if(kCFCoreFoundationVersionNumber < 1600) {
- blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
- }
- } else if(bannerStyle==2) {
- blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
- } else if(bannerStyle==3) {
- blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
- }
- blank.layer.masksToBounds = YES;
- blank.layer.continuousCorners = YES;
- blank.layer.cornerRadius = cornerRadius;
-
- NSString *labelText = [NSString stringWithFormat:@"%@", deviceName];
-
- self.label = [[UILabel alloc] init];
- if(!hideDeviceLabel) {
- [self.label setFont:[UIFont systemFontOfSize:16]];
- } else if(hideDeviceLabel) {
- [self.label setFont:[UIFont systemFontOfSize:0]];
- }
- [self.label setTextColor:[UIColor whiteColor]];
- self.label.lineBreakMode = NSLineBreakByWordWrapping;
- self.label.numberOfLines = 1;
- [self.label setText:labelText];
-
- self.battery = [[_UIBatteryView alloc] init];
- self.battery.chargePercent = (batteryPercentage*0.01);
- self.percentLabel = [[UILabel alloc] init];
- self.battery.showsPercentage = NO;
- if(hidePercent) {
- [self.percentLabel setFont:[UIFont systemFontOfSize:0]];
- } else {
- [self.percentLabel setFont:[UIFont systemFontOfSize:14]];
- }
- [self.percentLabel setTextColor:[UIColor whiteColor]];
- self.percentLabel.lineBreakMode = NSLineBreakByWordWrapping;
- [self.percentLabel setTextAlignment:NSTextAlignmentRight];
- self.percentLabel.numberOfLines = 1;
- [self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
- if(charging) self.battery.chargingState = 1;
- self.battery.showsInlineChargingIndicator = YES;
- if(LPM) self.battery.saverModeActive = YES;
- if(kCFCoreFoundationVersionNumber > 1600) {
- [self.battery setBodyColorAlpha:1.0];
- [self.battery setPinColorAlpha:1.0];
- }
-
- UIImage *glyph = [device glyph];
- self.glyphView = [[UIImageView alloc] init];
- self.glyphView.contentMode = UIViewContentModeScaleAspectFit;
- [self.glyphView setImage:glyph];
-
- [self addSubview:blank];
- [self addSubview:self.percentLabel];
- [self addSubview:self.label];
- [self addSubview:self.battery];
- [self addSubview:self.glyphView];
-
- blank.translatesAutoresizingMaskIntoConstraints = NO;
- if(bannerAlign==2) { //center
- [blank.centerXAnchor constraintEqualToAnchor:self.centerXAnchor constant:horizontalOffset].active = YES;
- } else if(bannerAlign==1) { //left
- [blank.leftAnchor constraintEqualToAnchor:self.leftAnchor constant:horizontalOffset].active = YES;
- } else if(bannerAlign==3) { //right
- [blank.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;
-
- self.percentLabel.translatesAutoresizingMaskIntoConstraints = NO;
- [self.percentLabel.leftAnchor constraintEqualToAnchor:blank.rightAnchor constant:(- 96)].active = YES;
- [self.percentLabel.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES;
- [self.percentLabel.widthAnchor constraintEqualToConstant:37].active = YES;
- [self.percentLabel.heightAnchor constraintEqualToConstant:12].active = YES;
-
- self.label.translatesAutoresizingMaskIntoConstraints = NO;
- [self.label.leftAnchor constraintEqualToAnchor:self.glyphView.rightAnchor constant:4.5].active = YES;
- [self.label.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES;
- [self.label.rightAnchor constraintEqualToAnchor:self.percentLabel.leftAnchor constant:-4.5].active = YES;
- [self.label.heightAnchor constraintEqualToConstant:25].active = YES;
-
- 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.widthAnchor constraintEqualToConstant:glyphSize].active = YES;
- [self.glyphView.heightAnchor constraintEqualToConstant:glyphSize].active = YES;
-
- self.battery.translatesAutoresizingMaskIntoConstraints = NO;
- [self.battery.leftAnchor constraintEqualToAnchor:blank.rightAnchor constant:(- 49)].active = YES;
- [self.battery.centerYAnchor constraintEqualToAnchor:blank.centerYAnchor].active = YES;
- [self.battery.widthAnchor constraintEqualToConstant:20].active = YES;
- [self.battery.heightAnchor constraintEqualToConstant:10].active = YES;
-
- }
-
- return self;
- }
-
- -(void)updateInfo {
- //NSLog(@"kai: updating cell info");
-
- NSString *deviceName = MSHookIvar<NSString *>(self.device, "_name");
- double batteryPercentage = MSHookIvar<long long>(self.device, "_percentCharge");
- BOOL charging = MSHookIvar<long long>(self.device, "_charging");
- BOOL LPM = MSHookIvar<BOOL>(self.device, "_batterySaverModeActive");
-
- self.label.text = [NSString stringWithFormat:@"%@", deviceName];
- [self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
- self.battery.chargePercent = (batteryPercentage*0.01);
- if(charging) { self.battery.chargingState = 1; } else { self.battery.chargingState = 0; }
- self.battery.showsInlineChargingIndicator = YES;
- if(LPM) { self.battery.saverModeActive = YES; } else { self.battery.saverModeActive = NO; }
- if(kCFCoreFoundationVersionNumber > 1600) {
- [self.battery setBodyColorAlpha:1.0];
- [self.battery setPinColorAlpha:1.0];
- }
- [self.percentLabel setText:[NSString stringWithFormat:@"%ld%%", (long)((NSInteger) batteryPercentage)]];
- self.battery.chargePercent = (batteryPercentage*0.01);
-
- [self.glyphView setImage:[self.device glyph]];
-
- if(!self.height) {
-
- self.height.active = NO;
- self.height = [self.heightAnchor constraintEqualToConstant:(bannerHeight + spacing)];
- self.height.active = YES;
-
- } //else {
- //int height = (bannerHeight + spacing);
- //self.height.constant = height;
- //}
-
- if(!self.width) {
-
- self.width.active = NO;
- self.width = [self.widthAnchor constraintEqualToConstant:(self.frame.size.width)];
- self.width.active = YES;
-
- } //else {
- //int width = self.frame.size.width;
- //self.width.constant = width;
- //}
-
- }
-
- @end
|