-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCCNoiseControlProvider.m
85 lines (74 loc) · 2.34 KB
/
CCNoiseControlProvider.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#import "CCNoiseControlProvider.h"
#import "CCNoiseControl.h"
#import "CCNoiseControlNormal.h"
#import "CAPackage.h"
#import <ControlCenterUIKit/CCUICAPackageDescription.h>
#import <objc/runtime.h>
@implementation CCNoiseControlProvider
- (instancetype)init
{
self = [super init];
_moduleInstancesByIdentifier = [NSMutableDictionary new];
return self;
}
- (NSUInteger)numberOfProvidedModules
{
return 2;
}
- (NSString*)identifierForModuleAtIndex:(NSUInteger)index
{
if(index==0){
return @"com.brend0n.ccnoisecontrol";
}
else{
return @"com.brend0n.ccnoisecontrolnormal";
}
}
- (id)moduleInstanceForModuleIdentifier:(NSString*)identifier
{
id module = [_moduleInstancesByIdentifier objectForKey:identifier];
if(!module)
{
if([identifier isEqualToString:@"com.brend0n.ccnoisecontrol"]){
module = [[CCNoiseControl alloc] init];
}
else{
module = [[CCNoiseControlNormal alloc] init];
}
[_moduleInstancesByIdentifier setObject:module forKey:identifier];
}
return module;
}
- (NSString*)displayNameForModuleIdentifier:(NSString*)identifier
{
if([identifier isEqualToString:@"com.brend0n.ccnoisecontrol"]){
return @"CCNoiseControl(NC/Trans)";
}
else{
return @"CCNoiseControl(NC/Off)";
}
}
- (UIImage*)settingsIconForModuleIdentifier:(NSString*)identifier
{
CCUICAPackageDescription *description = [objc_getClass("CCUICAPackageDescription") descriptionForPackageNamed:@"CCNoiseControlIcon" inBundle:[NSBundle bundleForClass:[self class]]];
CAPackage* package = [CAPackage packageWithContentsOfURL:[description packageURL] type:@"com.apple.coreanimation-bundle" options:0 error:nil];
return [self imageFromLayer:[package rootLayer] flip:1];
}
//https://stackoverflow.com/questions/3454356/uiimage-from-calayer-in-ios
//https://stackoverflow.com/questions/1135631/vertical-flip-of-cgcontext
- (UIImage *)imageFromLayer:(CALayer *)layer flip:(BOOL)flip
{
UIGraphicsBeginImageContextWithOptions(layer.frame.size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
if(flip){
CGAffineTransform flipVertical = CGAffineTransformMake(
1, 0, 0, -1, 0, layer.frame.size.height
);
CGContextConcatCTM(context, flipVertical);
}
[layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end