Skip to content
This repository has been archived by the owner on Dec 27, 2021. It is now read-only.

Commit

Permalink
Added option to tint custom glyphs with selected color
Browse files Browse the repository at this point in the history
  • Loading branch information
Sticktron committed Mar 1, 2017
1 parent 0699f33 commit 8580793
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
- (void)_setDrawsAsBackdropOverlay:(_Bool)arg1;
@end

@interface UIImage (Private)
- (UIImage *)_flatImageWithColor:(UIColor *)color;
@end

@interface SBDashBoardViewController : UIViewController
@end

Expand Down
27 changes: 16 additions & 11 deletions LockGlyphX.xm
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static BOOL hidePressHomeToUnlockLabel;
static BOOL overridePressHomeToUnlockText;
static BOOL hideWhenMusicControlsAreVisible;
static BOOL moveBackWhenMusicControlsAreVisible;

static BOOL applyColorToCustomGlyphs;
static UIColor *primaryColorOverride;
static UIColor *secondaryColorOverride;
static BOOL overrideIsForCustomCover;
Expand All @@ -105,6 +105,7 @@ static NSString *CFColor = @"ColorFlowLockScreenColorizationNotification";
static NSString *CCRevert = @"CustomCoverLockScreenColourResetNotification";
static NSString *CCColor = @"CustomCoverLockScreenColourUpdateNotification";


static CGFloat getDefaultYOffset() {
return hidePressHomeToUnlockLabel ? kDefaultYOffsetWithLockLabelHidden : kDefaultYOffset;
}
Expand Down Expand Up @@ -177,6 +178,7 @@ static void loadPreferences() {
useHoldToReaderAnimation = !CFPreferencesCopyAppValue(CFSTR("useHoldToReaderAnimation"), kPrefsAppID) ? NO : [CFBridgingRelease(CFPreferencesCopyAppValue(CFSTR("useHoldToReaderAnimation"), kPrefsAppID)) boolValue];
hideWhenMusicControlsAreVisible = !CFPreferencesCopyAppValue(CFSTR("hideWhenMusicControlsAreVisible"), kPrefsAppID) ? YES : [CFBridgingRelease(CFPreferencesCopyAppValue(CFSTR("hideWhenMusicControlsAreVisible"), kPrefsAppID)) boolValue];
moveBackWhenMusicControlsAreVisible = !CFPreferencesCopyAppValue(CFSTR("moveBackWhenMusicControlsAreVisible"), kPrefsAppID) ? NO : [CFBridgingRelease(CFPreferencesCopyAppValue(CFSTR("moveBackWhenMusicControlsAreVisible"), kPrefsAppID)) boolValue];
applyColorToCustomGlyphs = !CFPreferencesCopyAppValue(CFSTR("applyColorToCustomGlyphs"), kPrefsAppID) ? NO : [CFBridgingRelease(CFPreferencesCopyAppValue(CFSTR("applyColorToCustomGlyphs"), kPrefsAppID)) boolValue];

// load theme bundle
NSURL *bundleURL = [NSURL fileURLWithPath:kThemePath];
Expand Down Expand Up @@ -214,6 +216,10 @@ static void loadPreferences() {
}
}

static void prefsCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
loadPreferences();
}

static void performFingerScanAnimation(void) {
if (fingerglyph && [fingerglyph respondsToSelector:@selector(setState:animated:completionHandler:)]) {
doingScanAnimation = YES;
Expand Down Expand Up @@ -305,29 +311,28 @@ static void performShakeFingerFailAnimation(void) {
fingerglyph.primaryColor = activePrimaryColor();
fingerglyph.secondaryColor = activeSecondaryColor();

// check for theme
// check for theme image
if (themeAssets && ([[NSFileManager defaultManager] fileExistsAtPath:[themeAssets pathForResource:@"IdleImage" ofType:@"png"]] || [[NSFileManager defaultManager] fileExistsAtPath:[themeAssets pathForResource:@"IdleImage@2x" ofType:@"png"]])) {
UIImage *customImage = [UIImage imageWithContentsOfFile:[themeAssets pathForResource:@"IdleImage" ofType:@"png"]];

// set glyph to custom image mode
[fingerglyph setCustomImage:customImage.CGImage withAlignmentEdgeInsets:UIEdgeInsetsZero];
[fingerglyph setState:kGlyphStateCustom animated:NO completionHandler:nil];
// apply color override if required
if (applyColorToCustomGlyphs && fingerglyph.secondaryColor) {
customImage = [customImage _flatImageWithColor:fingerglyph.secondaryColor];
}

// resize the custom glyph to the size of the image?
// CGRect frame = fingerglyph.frame;
// frame.size = customImage.size;
// fingerglyph.frame = frame;

[fingerglyph setCustomImage:customImage.CGImage withAlignmentEdgeInsets:UIEdgeInsetsZero];
[fingerglyph setState:kGlyphStateCustom animated:NO completionHandler:nil];
usingDefaultGlyph = NO;
} else {
[fingerglyph setState:getIdleGlyphState() animated:NO completionHandler:nil];
usingDefaultGlyph = YES;
}

// set blend mode?
// [fingerglyph _setDrawsAsBackdropOverlayWithBlendMode:kCGBlendModePlusDarker];
// fingerglyph.tintColor = [UIColor colorWithWhite:0 alpha:0.50];

// position glyph
[fingerglyph updatePositionWithOrientation:[[UIApplication sharedApplication] statusBarOrientation]];

Expand All @@ -345,7 +350,7 @@ static void performShakeFingerFailAnimation(void) {
[self addSubview:fingerglyph];

// handle when music controls are showing
SBDashBoardMainPageViewController *pvc = (SBDashBoardMainPageViewController *)self.pageViewController;
SBDashBoardMainPageViewController *pvc = (SBDashBoardMainPageViewController *)self.pageViewController;
if (pvc.contentViewController.showingMediaControls) {
if (hideWhenMusicControlsAreVisible) {
fingerglyph.hidden = YES;
Expand Down Expand Up @@ -878,7 +883,7 @@ static void performShakeFingerFailAnimation(void) {

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
(CFNotificationCallback)loadPreferences,
(CFNotificationCallback)prefsCallback,
kSettingsChangedNotification,
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately
Expand Down
19 changes: 18 additions & 1 deletion Prefs/Resources/LockGlyphXPrefs-Appearance.plist
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<key>label</key>
<string>COLOURS_HEADER_TEXT</string>
</dict>
<!-- Fingerprint Color -->
<!-- Glyph Color -->
<dict>
<key>cell</key>
<string>PSLinkCell</string>
Expand Down Expand Up @@ -114,6 +114,23 @@
<key>color_postNotification</key>
<string>com.evilgoldfish.lockglyphx.settingschanged</string>
</dict>
<!-- Apply To Custom Glyphs -->
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>cellClass</key>
<string>LGXSwitchCell</string>
<key>default</key>
<false/>
<key>defaults</key>
<string>com.evilgoldfish.lockglyphx</string>
<key>key</key>
<string>applyColorToCustomGlyphs</string>
<key>label</key>
<string>COLOURS_IDLECOLOUR_OVERRIDE_LABEL</string>
<key>PostNotification</key>
<string>com.evilgoldfish.lockglyphx.settingschanged</string>
</dict>
<!-- Reset Colors -->
<dict>
<key>cell</key>
Expand Down
4 changes: 3 additions & 1 deletion Prefs/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
"THEMES_THEMESELECT_LABEL" = "Theme";
"APPEARANCE_HIDE_RING_LABEL" = "Hide ring";
"COLOURS_HEADER_TEXT" = "Colours";
"COLOURS_IDLECOLOUR_LABEL" = "Fingerprint colour";
"COLOURS_IDLECOLOUR_LABEL" = "Glyph colour";
"COLOURS_IDLECOLOUR_OVERRIDE_LABEL" = "Apply to custom glyphs";
"COLOURS_SCANCOLOUR_LABEL" = "Scanning colour";

"COLOURS_RESET_LABEL" = "Reset colours to default";
"LOCKLABEL_HEADER_TEXT" = "Press Home To Unlock";
"LOCKLABEL_DISABLED_LABEL" = "Hide text";
Expand Down
2 changes: 1 addition & 1 deletion Prefs/Resources/en_US.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/* Appearance Page */
"COLOURS_HEADER_TEXT" = "Colors";
"COLOURS_IDLECOLOUR_LABEL" = "Fingerprint color";
"COLOURS_IDLECOLOUR_LABEL" = "Glyph color";
"COLOURS_SCANCOLOUR_LABEL" = "Scanning color";
"COLOURS_RESET_LABEL" = "Reset colors to default";

Expand Down

0 comments on commit 8580793

Please sign in to comment.