Quellcode durchsuchen

progress

pull/1/head
Burrit0z vor 4 Jahren
Ursprung
Commit
b3297545bf
5 geänderte Dateien mit 106 neuen und 27 gelöschten Zeilen
  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 Datei anzeigen

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

+ 35
- 25
KAIBatteryCell.mm Datei anzeigen

@@ -13,21 +13,23 @@
BOOL charging = MSHookIvar<long long>(device, "_charging");
BOOL LPM = MSHookIvar<BOOL>(device, "_batterySaverModeActive");

UIView *blank;
UIView *blur;
UIView *blurPlatter = [[UIView alloc] init];
if(bannerStyle==1) {
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) {
blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
}
} else if(bannerStyle==2) {
blank = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
} 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];

@@ -77,45 +79,52 @@
self.glyphView.contentMode = UIViewContentModeScaleAspectFit;
[self.glyphView setImage:glyph];

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

blank.translatesAutoresizingMaskIntoConstraints = NO;
blurPlatter.translatesAutoresizingMaskIntoConstraints = NO;
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
[blank.leftAnchor constraintEqualToAnchor:self.leftAnchor constant:horizontalOffset].active = YES;
[blurPlatter.leftAnchor constraintEqualToAnchor:self.leftAnchor constant:horizontalOffset].active = YES;
} 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.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.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.centerYAnchor constraintEqualToAnchor:blurPlatter.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.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.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.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.heightAnchor constraintEqualToConstant:10].active = YES;

@@ -161,14 +170,15 @@
self.battery.chargePercent = (batteryPercentage*0.01);

[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 = [self.heightAnchor constraintEqualToConstant:(bannerHeight + spacing)];
self.height.active = YES;

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

+ 28
- 2
KAIBatteryStack.mm Datei anzeigen

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

if(showAll) {
shouldAdd = YES;
} else if(showAllMinusInternal && !internal) {
shouldAdd = YES;
} else if(!showAll && charging) {
shouldAdd = YES;
}
@@ -99,6 +102,29 @@ long long lastPercentage;
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)
}

}];

});

@@ -113,7 +139,7 @@ long long lastPercentage;
if(!self.heightConstraint) {
self.heightConstraint.active = NO;
self.heightConstraint = [self.heightAnchor constraintEqualToConstant:85];
self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))];
//set an initial constraint
self.heightConstraint.active = YES;

@@ -153,7 +179,7 @@ long long lastPercentage;
if(!self.heightConstraint) {
self.heightConstraint.active = NO;
self.heightConstraint = [self.heightAnchor constraintEqualToConstant:85];
self.heightConstraint = [self.heightAnchor constraintEqualToConstant:(self.number * (bannerHeight + spacing))];
//set an initial constraint
self.heightConstraint.active = YES;


+ 4
- 0
Kai.h Datei anzeigen

@@ -40,6 +40,7 @@ BOOL showAll;
BOOL belowMusic;
BOOL hideDeviceLabel;
BOOL hideChargingAnimation;
BOOL showAllMinusInternal;
NSInteger bannerStyle;
NSInteger bannerAlign;
NSInteger textColor;
@@ -49,6 +50,7 @@ double bannerHeight;
double cornerRadius;
double bannerWidthFactor;
double horizontalOffset;
double bannerAlpha;

//by importing here, I can use vars in the .mm files
#import "KAIBatteryCell.mm"
@@ -116,6 +118,8 @@ static void preferencesChanged()
belowMusic = boolValueForKey(@"belowMusic", NO);
hideChargingAnimation = boolValueForKey(@"hideChargingAnimation", YES);
textColor = numberForValue(@"textColor", 0);
bannerAlpha = numberForValue(@"bannerAlpha", 1);
showAllMinusInternal = boolValueForKey(@"showAllMinusInternal", NO);

if(disableGlyphs) {
glyphSize = 0;

+ 38
- 0
kaiprefs/Resources/Root.plist Datei anzeigen

@@ -39,6 +39,8 @@
<dict>
<key>cell</key>
<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>
<key>cell</key>
@@ -52,6 +54,18 @@
<key>label</key>
<string>Show all devices</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>showAllMinusInternal</string>
<key>label</key>
<string>Always show bluetooth devices</string>
</dict>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
@@ -328,6 +342,30 @@
<key>key</key>
<string>cornerRadius</string>
</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>
<key>title</key>
<string>kai</string>

Laden…
Abbrechen
Speichern