-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathPageDots.xm
executable file
·221 lines (174 loc) · 6.84 KB
/
PageDots.xm
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#import "core/ANEMSettingsManager.h"
#define LegacyMagicDotsSupport YES
@interface _UILegibilityView : UIView
- (UIImageView *)imageView;
@end
@interface SBIconListPageControl : UIPageControl
- (BOOL)shouldShowSearchIndicator;
- (void)ANEMsetPageDotEnabled:(_UILegibilityView *)image enabled:(BOOL)enabled index:(long long)index;
- (void)_setIndicatorImage:(_UILegibilityView *)image toEnabled:(BOOL)enabled;
- (void)_setIndicatorImage:(_UILegibilityView *)image toEnabled:(BOOL)enabled index:(long long)index;
@end
static BOOL pageDotImagesLoaded = NO;
static UIImage *currentPageDotImage;
static UIImage *pageDotImage;
static UIImage *currentSpotlightPageDotImage;
static UIImage *spotlightPageDotImage;
static void loadPageDotImages(){
if (pageDotImagesLoaded)
return;
pageDotImagesLoaded = YES;
NSArray *themes = [[%c(ANEMSettingsManager) sharedManager] themeSettings];
NSString *themesDir = [[%c(ANEMSettingsManager) sharedManager] themesDir];
for (NSString *theme in themes)
{
NSString *themePath = [NSString stringWithFormat:@"%@/%@.theme",themesDir,theme];
if (SupportsNoExtensionDir && ![[NSFileManager defaultManager] fileExistsAtPath:themePath]){
themePath = [NSString stringWithFormat:@"%@/%@",themesDir,theme];
}
NSString *dotCurrentPath = [NSString stringWithFormat:@"%@/ANEMPageDots/Dot_CurrentSB.png", themePath];
if (!currentPageDotImage)
currentPageDotImage = [UIImage imageWithContentsOfFile:dotCurrentPath];
dotCurrentPath = [NSString stringWithFormat:@"%@/ANEMPageDots/Dot_Current.png", themePath];
if (!currentPageDotImage)
currentPageDotImage = [UIImage imageWithContentsOfFile:dotCurrentPath];
#if LegacyMagicDotsSupport
if (!currentPageDotImage){
dotCurrentPath = [NSString stringWithFormat:@"%@/Bundles/com.magicdots.images/Dot_CurrentSB.png", themePath];
currentPageDotImage = [UIImage imageWithContentsOfFile:dotCurrentPath];
dotCurrentPath = [NSString stringWithFormat:@"%@/Bundles/com.magicdots.images/Dot_Current.png", themePath];
if (!currentPageDotImage)
currentPageDotImage = [UIImage imageWithContentsOfFile:dotCurrentPath];
}
#endif
NSString *dotPath = [NSString stringWithFormat:@"%@/ANEMPageDots/Dot_PagesSB.png", themePath];
if (!pageDotImage)
pageDotImage = [UIImage imageWithContentsOfFile:dotPath];
dotPath = [NSString stringWithFormat:@"%@/ANEMPageDots/Dot_Pages.png", themePath];
if (!pageDotImage)
pageDotImage = [UIImage imageWithContentsOfFile:dotPath];
#if LegacyMagicDotsSupport
if (!pageDotImage){
dotPath = [NSString stringWithFormat:@"%@/Bundles/com.magicdots.images/Dot_PagesSB.png", themePath];
pageDotImage = [UIImage imageWithContentsOfFile:dotPath];
dotPath = [NSString stringWithFormat:@"%@/Bundles/com.magicdots.images/Dot_Pages.png", themePath];
if (!pageDotImage)
pageDotImage = [UIImage imageWithContentsOfFile:dotPath];
}
#endif
NSString *spotlightCurrentPath = [NSString stringWithFormat:@"%@/ANEMPageDots/Spotlight_Current.png", themePath];
if (!currentSpotlightPageDotImage)
currentSpotlightPageDotImage = [UIImage imageWithContentsOfFile:spotlightCurrentPath];
NSString *spotlightPath = [NSString stringWithFormat:@"%@/ANEMPageDots/Spotlight_Pages.png", themePath];
if (!spotlightPageDotImage)
spotlightPageDotImage = [UIImage imageWithContentsOfFile:spotlightPath];
if (currentPageDotImage && pageDotImage && spotlightPageDotImage && currentSpotlightPageDotImage)
break;
}
[currentPageDotImage retain];
[pageDotImage retain];
[spotlightPageDotImage retain];
[currentSpotlightPageDotImage retain];
}
%hook SBIconListPageControl
%new;
- (void)ANEMsetPageDotEnabled:(_UILegibilityView *)image enabled:(BOOL)enabled index:(long long)index {
loadPageDotImages();
if (![image respondsToSelector:@selector(imageView)])
return;
UIImageView *imageView = [image imageView];
CGSize pageDotSize = currentPageDotImage.size;
if (!currentPageDotImage)
pageDotSize = imageView.frame.size;
CGRect imageFrame = CGRectMake(0,0,pageDotSize.width, pageDotSize.height);
imageView.frame = imageFrame;
BOOL showSearchIndicator = NO;
if ([self respondsToSelector:@selector(shouldShowSearchIndicator)])
showSearchIndicator = [self shouldShowSearchIndicator];
BOOL isSearchIndicator = NO;
if (showSearchIndicator && index == 0)
isSearchIndicator = YES;
if (currentPageDotImage){
if (enabled)
if (isSearchIndicator)
[imageView setImage:currentSpotlightPageDotImage];
else
[imageView setImage:currentPageDotImage];
else
if (isSearchIndicator)
[imageView setImage:spotlightPageDotImage];
else
[imageView setImage:pageDotImage];
}
}
- (void)_setIndicatorImage:(_UILegibilityView *)image toEnabled:(BOOL)enabled { //iOS 7 - 8.4
%orig;
[self ANEMsetPageDotEnabled:image enabled:enabled index:-1];
}
- (void)_setIndicatorImage:(_UILegibilityView *)image toEnabled:(BOOL)enabled index:(long long)index { //iOS 9+
%orig;
[self ANEMsetPageDotEnabled:image enabled:enabled index:index];
}
%new;
- (void)reloadAllDots {
loadPageDotImages();
NSArray *indicators = [self valueForKey:@"_indicators"];
NSUInteger index = 0;
for (_UILegibilityView *image in indicators){
if ([self respondsToSelector:@selector(_setIndicatorImage:toEnabled:index:)])
[self _setIndicatorImage:image toEnabled:(index == [self currentPage]) index:index];
else
[self _setIndicatorImage:image toEnabled:(index == [self currentPage])];
index++;
}
[self layoutSubviews];
}
- (void)layoutSubviews {
%orig;
loadPageDotImages();
if (!currentPageDotImage)
return;
CGSize pageDotSize = currentPageDotImage.size;
NSArray *indicators = [self valueForKey:@"_indicators"];
NSInteger count = indicators.count;
CGFloat pageDotSeparators = 8.0f;
CGFloat width = (pageDotSize.width * count) + (pageDotSeparators * (count - 1));
CGFloat x = (self.frame.size.width / 2.0) - (width / 2.0);
CGFloat y = (self.frame.size.height / 2.0) - (pageDotSize.height / 2.0);
for (UIView *dotView in indicators){
dotView.frame = CGRectMake(x, y, pageDotSize.width, pageDotSize.height);
x += pageDotSize.width + pageDotSeparators;
}
}
%end
@interface AnemonePageDotsEventHandler: NSObject <AnemoneEventHandler>
- (void)reloadTheme;
@end
@implementation AnemonePageDotsEventHandler
- (void)reloadTheme {
if (currentPageDotImage){
[currentPageDotImage release];
currentPageDotImage = nil;
}
if (pageDotImage){
[pageDotImage release];
pageDotImage = nil;
}
if (currentSpotlightPageDotImage){
[currentSpotlightPageDotImage release];
currentSpotlightPageDotImage = nil;
}
if (spotlightPageDotImage){
[spotlightPageDotImage release];
spotlightPageDotImage = nil;
}
pageDotImagesLoaded = NO;
loadPageDotImages();
}
@end
%ctor {
if (objc_getClass("ANEMSettingsManager") == nil){
dlopen("/Library/MobileSubstrate/DynamicLibraries/AnemoneCore.dylib",RTLD_LAZY);
}
[[%c(ANEMSettingsManager) sharedManager] addEventHandler:[AnemonePageDotsEventHandler new]];
}