This repository has been archived by the owner on Apr 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathABVolumeHUDIconVolumeGlyph.m
52 lines (43 loc) · 1.84 KB
/
ABVolumeHUDIconVolumeGlyph.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// ABVolumeHUDIconVolumeGlyph.m
// Ultrasound
//
// Created by Ayden Panhuyzen on 9/3/18.
// Copyright © 2018 Ayden Panhuyzen. All rights reserved.
//
#import "ABVolumeHUDIconVolumeGlyph.h"
#import "CCUICAPackageView.h"
#define kGlyphPackageName @"Volume"
#define kGlyphPackageBundle [NSBundle bundleWithURL:[ControlCenterModulesRoot URLByAppendingPathComponent:@"AudioModule.bundle"]]
@implementation ABVolumeHUDIconVolumeGlyph {
CCUICAPackageView *glyphView;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) [self setupForDisplay];
return self;
}
- (void)setupForDisplay {
glyphView = [[NSClassFromString(@"CCUICAPackageView") alloc] init];
NSBundle *packageBundle = kGlyphPackageBundle;
if (@available(iOS 13.0, *)) packageBundle = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MediaControls.framework"];
glyphView.packageDescription = [NSClassFromString(@"CCUICAPackageDescription") descriptionForPackageNamed:kGlyphPackageName inBundle:packageBundle];
glyphView.translatesAutoresizingMaskIntoConstraints = NO;
glyphView.transform = CGAffineTransformMakeScale(0.7, 0.7);
[self addSubview:glyphView];
[glyphView.topAnchor constraintEqualToAnchor:self.topAnchor].active = YES;
[glyphView.leftAnchor constraintEqualToAnchor:self.leftAnchor].active = YES;
[glyphView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor].active = YES;
[glyphView.rightAnchor constraintEqualToAnchor:self.rightAnchor].active = YES;
}
- (void)setVolume:(CGFloat)volume {
NSString *stateName = @"mute";
if (volume > 0) {
if (volume <= 0.33) stateName = @"min";
else if (volume <= 0.66) stateName = @"half";
else if (volume <= 0.9) stateName = @"full";
else stateName = @"max";
}
[glyphView setStateName:stateName];
}
@end