diff --git a/1.0_release/iOS Simulator Screen shot Aug 27, 2014, 3.49.02 PM.png b/1.0_release/iOS Simulator Screen shot Aug 27, 2014, 3.49.02 PM.png deleted file mode 100755 index 7f383b3..0000000 Binary files a/1.0_release/iOS Simulator Screen shot Aug 27, 2014, 3.49.02 PM.png and /dev/null differ diff --git a/1.0_release/iOS Simulator Screen shot Aug 27, 2014, 3.55.09 PM.png b/1.0_release/iOS Simulator Screen shot Aug 27, 2014, 3.55.09 PM.png deleted file mode 100755 index 36a8b7f..0000000 Binary files a/1.0_release/iOS Simulator Screen shot Aug 27, 2014, 3.55.09 PM.png and /dev/null differ diff --git a/ColorPicker.h b/ColorPicker.h deleted file mode 100644 index 2b60536..0000000 --- a/ColorPicker.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// ColorPicker.h -// -// Created by Bailey Seymour on 8/27/14. -// Copyright (c) 2014 Bailey Seymour. All rights reserved. -// -//Place libcolorpicker.dylib in $THEOS/lib/ -//Import this header and link with libcolorpicker. - -#import "PFColorViewController.h" -#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ -extern "C" { -#endif -UIColor *LCPParseColorString(NSString *colorStringFromPrefs, NSString *colorStringFallback); -//old -UIColor *colorFromDefaultsWithKey(NSString *defaults, NSString *key, NSString *fallback); - -#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */ -} -#endif diff --git a/Makefile b/Makefile index 22b5a23..ed14021 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,32 @@ -ifdef DEBUG - ARCHS = arm64 - TARGET = iphone:clang:11.2 +ifdef SIMULATOR +TARGET = simulator:clang:latest:8.0 else - ARCHS = armv7 armv7s arm64 arm64e - TARGET = iphone:clang:9.2:6.0 + TARGET = iphone:clang:latest:7.0 + ifneq ($(debug),0) + ARCHS= arm64 arm64e + else + ARCHS= armv7 arm64 arm64e + endif endif - -include $(THEOS)/makefiles/common.mk - LIBRARY_NAME = libcolorpicker -$(LIBRARY_NAME)_FILES = libcolorpicker.mm UIColor+PFColor.m PFColorPicker.m PFColorTransparentView.m PFColorViewController.xm PFColorCell.mm PFColorAlert.m PFColorAlertViewController.xm PFHaloHueView.m PFHaloKnobView.m PFColorLitePreviewView.m PFColorLiteSlider.m PFLiteColorCell.mm PFSimpleLiteColorCell.mm PFColorPickerWelcome.mm -$(LIBRARY_NAME)_FRAMEWORKS = UIKit CoreGraphics Foundation Social Accounts -$(LIBRARY_NAME)_PRIVATE_FRAMEWORKS = Preferences -$(LIBRARY_NAME)_LDFLAGS += -Wl,-segalign,4000 -$(LIBRARY_NAME)_CFLAGS = -fobjc-arc -PFColorAlert.m_CFLAGS = -fno-objc-arc -PFSimpleLiteColorCell.mm_CFLAGS = -fno-objc-arc -PFLiteColorCell.mm_CFLAGS = -fno-objc-arc +libcolorpicker_FILES = libcolorpicker.mm UIColor+PFColor.m PFColorAlert.m PFColorAlertViewController.xm PFHaloHueView.m PFHaloKnobView.m PFColorLitePreviewView.m PFColorLiteSlider.m PFLiteColorCell.mm PFSimpleLiteColorCell.mm PFColorPickerWelcome.mm PFSimpleLiteColorCell_.mm +libcolorpicker_FRAMEWORKS = UIKit CoreGraphics Foundation Social Accounts +libcolorpicker_PRIVATE_FRAMEWORKS = Preferences +libcolorpicker_LDFLAGS += -Wl,-segalign,4000 +libcolorpicker_CFLAGS = -fobjc-arc -Wno-error=deprecated-declarations +PFColorPickerWelcome.mm_CFLAGS = -Wno-deprecated-declarations + +include $(THEOS)/makefiles/common.mk +include $(THEOS_MAKE_PATH)/library.mk after-install:: install.exec "killall -9 Preferences" -include $(THEOS_MAKE_PATH)/library.mk +setup:: + @[ -f $(SIMULATOR_ROOT)/usr/lib/$(LIBRARY_NAME).dylib ] || sudo ln -s /opt/simject/usr/lib/$(LIBRARY_NAME).dylib $(SIMULATOR_ROOT)/usr/lib/$(LIBRARY_NAME).dylib || true + @[ -f $(SIMULATOR_ROOT)/usr/lib/$(LIBRARY_NAME).dylib ] || echo -e "\x1b[1;35m>> warning: create symlink in $(SIMULATOR_ROOT)/usr/lib yourself if needed\x1b[m" || true + +remove:: + @sudo rm -f $(SIMULATOR_ROOT)/usr/lib/$(LIBRARY_NAME).dylib diff --git a/PFColorAlert.m b/PFColorAlert.m index 86ffa66..64dc272 100755 --- a/PFColorAlert.m +++ b/PFColorAlert.m @@ -21,7 +21,7 @@ @interface PFColorAlert () @implementation PFColorAlert + (PFColorAlert *)colorAlertWithStartColor:(UIColor *)startColor showAlpha:(BOOL)showAlpha { - return [[[PFColorAlert alloc] initWithStartColor:startColor showAlpha:showAlpha] autorelease]; + return [[PFColorAlert alloc] initWithStartColor:startColor showAlpha:showAlpha]; } - (PFColorAlert *)initWithStartColor:(UIColor *)startColor showAlpha:(BOOL)showAlpha { @@ -44,7 +44,7 @@ - (PFColorAlert *)initWithStartColor:(UIColor *)startColor showAlpha:(BOOL)showA if (@available(iOS 13, *)) { NSSet *connectedScenes = [[UIApplication sharedApplication] connectedScenes]; UIScene *firstScene = [[connectedScenes allObjects] objectAtIndex:0]; - self.darkeningWindow = [[UIWindow alloc] initWithWindowScene:firstScene]; + self.darkeningWindow = [[UIWindow alloc] initWithWindowScene:(UIWindowScene*)firstScene]; self.darkeningWindow.frame = winFrame; } else { self.darkeningWindow = [[UIWindow alloc] initWithFrame:winFrame]; @@ -62,7 +62,7 @@ - (PFColorAlert *)initWithStartColor:(UIColor *)startColor showAlpha:(BOOL)showA if (@available(iOS 13, *)) { NSSet *connectedScenes = [[UIApplication sharedApplication] connectedScenes]; UIScene *firstScene = [[connectedScenes allObjects] objectAtIndex:0]; - self.popWindow = [[UIWindow alloc] initWithWindowScene:firstScene]; + self.popWindow = [[UIWindow alloc] initWithWindowScene:(UIWindowScene*)firstScene]; self.popWindow.frame = winFrame; } else { self.popWindow = [[UIWindow alloc] initWithFrame:winFrame]; @@ -82,10 +82,10 @@ - (PFColorAlert *)initWithStartColor:(UIColor *)startColor showAlpha:(BOOL)showA [self.darkeningWindow makeKeyAndVisible]; self.popWindow.rootViewController = self.mainViewController; -#ifndef DEBUG + self.darkeningWindow.windowLevel = UIWindowLevelAlert - 2; self.popWindow.windowLevel = UIWindowLevelAlert - 1; -#endif + self.popWindow.backgroundColor = UIColor.clearColor; self.popWindow.hidden = NO; self.popWindow.alpha = 0.0f; @@ -115,8 +115,6 @@ - (void)displayWithCompletion:(void (^)(UIColor *pickedColor))completionBlock { self.completionBlock = completionBlock; - [self retain]; - [self.popWindow makeKeyAndVisible]; [UIView animateWithDuration:0.3f animations:^{ @@ -128,13 +126,12 @@ - (void)displayWithCompletion:(void (^)(UIColor *pickedColor))completionBlock { UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)]; self.darkeningWindow.userInteractionEnabled = YES; [self.darkeningWindow addGestureRecognizer:tapGesture]; - [tapGesture release]; - NSString *prefPath = @"/var/mobile/Library/Preferences/com.pixelfiredev.libcolorpicker.plist"; + NSString *prefPath = @THEOS_PACKAGE_INSTALL_PREFIX"/var/mobile/Library/Preferences/com.pixelfiredev.libcolorpicker.plist"; NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:prefPath]; if (!dict) - dict = [[NSMutableDictionary new] autorelease]; + dict = [NSMutableDictionary new] ; NSString *kDidShow = @"didShowWelcomeScreen"; if (!dict[kDidShow]) { @@ -161,11 +158,7 @@ - (void)displayWithCompletion:(void (^)(UIColor *pickedColor))completionBlock { - (void)showWithStartColor:(UIColor *)startColor showAlpha:(BOOL)showAlpha completion:(void (^)(UIColor *pickedColor))completionBlock { - UIAlertView *deprecated = [[UIAlertView alloc] initWithTitle:@"libcolorpicker" message:@"Hey! It appears like this preference bundle is trying to use deprecated methods to invoke the color picker and requires an update. Please inform the dev of this tweak about it." - delegate:nil - cancelButtonTitle:nil - otherButtonTitles:@"OK", nil]; - [deprecated show]; + } - (void)close { @@ -185,13 +178,4 @@ - (void)close { }]; } -- (void)dealloc { - [self.mainViewController release]; - [self.popWindow release]; - [self.darkeningWindow release]; - self.completionBlock = nil; - - [super dealloc]; -} - @end diff --git a/PFColorAlertViewController.xm b/PFColorAlertViewController.xm index 067d36a..1f270f6 100755 --- a/PFColorAlertViewController.xm +++ b/PFColorAlertViewController.xm @@ -22,10 +22,12 @@ typedef enum UIUserInterfaceStyle : NSInteger { UIUserInterfaceStyleLight, UIUserInterfaceStyleDark } UIUserInterfaceStyle; +#elif __IPHONE_OS_VERSION_MAX_ALLOWED < 120000 +#define UIUserInterfaceStyleDark 2 #endif -@interface UITraitCollection (iOS12_13) -@property (nonatomic, readonly) UIUserInterfaceStyle userInterfaceStyle; +@interface UITraitCollection_ +@property (nonatomic, readonly) NSInteger userInterfaceStyle __TVOS_AVAILABLE(10_0) __WATCHOS_PROHIBITED; // unspecified: UIUserInterfaceStyleUnspecified @end @interface _UIBackdropViewSettings : NSObject @@ -50,7 +52,7 @@ autosizesToFitSuperview:(BOOL)fitsSuperview if (%c(_UIBackdropView)) { int style = 2010; if (@available(iOS 13, *)) { - if ([UIScreen mainScreen].traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { + if (((UITraitCollection_*)[UIScreen mainScreen].traitCollection).userInterfaceStyle == UIUserInterfaceStyleDark) { _tintColor = UIColor.whiteColor; style = 1100; } diff --git a/PFColorCell.mm b/PFColorCell.mm deleted file mode 100755 index 4ffb896..0000000 --- a/PFColorCell.mm +++ /dev/null @@ -1,73 +0,0 @@ -#import "PSTableCell.h" -#import "PSSpecifier.h" -#import -#import -#import "ColorPicker.h" - -@interface PFColorCell : PSTableCell -@end - -@implementation PFColorCell - -- (SEL)action { - return @selector(openColorPicker); -} - -- (id)target { - return self; -} - -- (SEL)cellAction { - return @selector(openColorPicker); -} - -- (id)cellTarget { - return self; -} - -- (void)openColorPicker { - UIViewController *viewController = [self _viewControllerForAncestor]; - PFColorViewController *colorViewController = [[PFColorViewController alloc] initForContentSize:viewController.view.frame.size]; - - if (_specifier) { - NSDictionary *properties = _specifier.properties; - if (properties[@"color_key"] && properties[@"color_defaults"]) { - colorViewController.key = properties[@"color_key"]; - colorViewController.defaults = properties[@"color_defaults"]; - - if (properties[@"usesAlpha"]) - colorViewController.usesAlpha = [properties[@"usesAlpha"] boolValue]; - - if (properties[@"usesRGB"]) - colorViewController.usesRGB = [properties[@"usesRGB"] boolValue]; - - colorViewController.title = properties[@"title"] ?: @"Choose Color"; - colorViewController.fallback = properties[@"color_fallback"] ?: @"#a1a1a1"; - colorViewController.postNotification = properties[@"color_postNotification"]; - } - } - - colorViewController.view.frame = viewController.view.frame; - [viewController.navigationController pushViewController:colorViewController animated:YES]; -} - -- (void)didMoveToSuperview { - [super didMoveToSuperview]; - - UIView *colorPreview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 29, 29)]; - colorPreview.tag = 199; //Stop UIColors from overriding the color :P - colorPreview.layer.cornerRadius = colorPreview.frame.size.width / 2; - colorPreview.layer.borderWidth = 2; - colorPreview.layer.borderColor = [UIColor lightGrayColor].CGColor; - NSString *fallback = _specifier.properties[@"color_fallback"]; - if (!fallback) - fallback = @"#a1a1a1"; - colorPreview.backgroundColor = colorFromDefaultsWithKey([_specifier properties][@"color_defaults"], [_specifier properties][@"color_key"], fallback); - - [self setAccessoryView:colorPreview]; - - [_specifier setTarget:self]; - [_specifier setButtonAction:@selector(openColorPicker)]; -} - -@end diff --git a/PFColorPicker.h b/PFColorPicker.h deleted file mode 100644 index 2216579..0000000 --- a/PFColorPicker.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// ColorPicker.h -// ColorPicker -// -// Created by Bailey Seymour on 3/16/14. -// Copyright (c) 2011 Bailey Seymour All rights reserved. -// -#if TARGET_OS_IPHONE -#import -@protocol PFColorPickerDelegate -- (void)pickedColor:(UIColor *)color; -@end - - -@interface PFColorPicker : UIView -{ - BOOL shouldSaveNewCache; -} -@property (nonatomic, retain) id delegate; -@property (nonatomic, readonly, retain) UIColor *lastSelectedColor; -- (id)initWithFrame:(CGRect)frame; -- (void)makeReadyForDisplay; -- (void)saveCache; -@end -#endif diff --git a/PFColorPicker.m b/PFColorPicker.m deleted file mode 100755 index 964dd6f..0000000 --- a/PFColorPicker.m +++ /dev/null @@ -1,140 +0,0 @@ -// -// ColorPicker.m -// ColorPicker -// -// Created by Bailey Seymour on 3/16/14. -// Copyright (c) 2011 Bailey Seymour All rights reserved. -// - -#import -#import "PFColorPicker.h" -#import "UIColor+PFColor.h" - -#if TARGET_OS_IPHONE -@implementation PFColorPicker - -- (id)initWithFrame:(CGRect)frame { - self = [super initWithFrame:frame]; - if (self) - [self setBackgroundColor:UIColor.clearColor]; - return self; -} - -+ (NSString *)cacheImageNameWithFrame:(CGRect)frame { - return [NSString stringWithFormat:@"/tmp/_PFColorPickerImage_%gx%g.png", frame.size.width, frame.size.height]; -} - -+ (UIColor *)colorWithHueForLocation:(CGFloat)location { - return [UIColor colorWithHue:location saturation:1 brightness:1 alpha:1]; -} - -- (UIImage *)captureView { - CGRect rect = [self frame]; - - UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale); - CGContextRef context = UIGraphicsGetCurrentContext(); - [self.layer renderInContext:context]; - UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - - return img; -} - -- (void)drawRect:(CGRect)rect { - float widthX = rect.size.width; - float widthY = rect.size.height; - - CGContextRef context = UIGraphicsGetCurrentContext(); - - BOOL imageExists = [[NSFileManager defaultManager] fileExistsAtPath:[PFColorPicker cacheImageNameWithFrame:rect]]; - - UIImage *image = imageExists ? [[UIImage alloc] initWithContentsOfFile:[PFColorPicker cacheImageNameWithFrame:rect]] : nil; - - if (!image || !CGSizeEqualToSize(image.size, rect.size)) { - int size = 1; - - for (float posY = 0; posY <= widthY; posY += size) { - for (float posX = 0; posX <= widthX; posX += size) { - float h = posY / widthY; - float w = posX / widthX; - float s = (w <= 0.5 ? 1 : 1 - w) * 2; - float b = (w <= 0.5 ? w : 1) * 2; - - [[UIColor colorWithHue:h saturation:s brightness:b alpha:1] setFill]; - CGContextFillRect(context, CGRectMake(posX, posY, size, size)); - } - } - shouldSaveNewCache = YES; - } else if (image) { - [image drawInRect:rect]; - } -} - -- (void)saveCache { - if (shouldSaveNewCache) { - NSData *imageData = UIImagePNGRepresentation([self captureView]); - [imageData writeToFile:[PFColorPicker cacheImageNameWithFrame:self.frame] atomically:YES]; - shouldSaveNewCache = NO; - } -} - -- (void)makeReadyForDisplay { - UIPanGestureRecognizer *drag = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(selectColor:)]; - [self addGestureRecognizer:drag]; - [self setUserInteractionEnabled:YES]; -} - -- (UIColor *)colorAtPoint:(CGPoint)point { - unsigned char pixel[4] = {0}; - - CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - - CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast); - - CGContextTranslateCTM(context, -point.x, -point.y); - - [self.layer renderInContext:context]; - - CGContextRelease(context); - CGColorSpaceRelease(colorSpace); - - //NSLog(@"pixel: %d %d %d %d", pixel[0], pixel[1], pixel[2], pixel[3]); - - UIColor *color = [UIColor colorWithRed:pixel[0] / 255.0 - green:pixel[1] / 255.0 - blue:pixel[2] / 255.0 - alpha:pixel[3] / 255.0]; - - if (!color) - color = [self lastSelectedColor]; - - return color; -} - -- (void)selectColor:(UIPanGestureRecognizer *)gest { - CGPoint point = [gest locationInView:self]; //where user stopped dragging on image - [self useColorAtPoint:point]; -} - -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - UITouch *touch = [touches anyObject]; - CGPoint point = [touch locationInView:self]; //where image was tapped - [self useColorAtPoint:point]; -} - -- (void)useColorAtPoint:(CGPoint)point { - CGRect r = self.frame; - r.origin = CGPointZero; - - if (CGRectContainsPoint(r, point)) { - UIColor *color = [self colorAtPoint:point]; - if (!color) - return; - } - - if ([_delegate respondsToSelector:@selector(pickedColor:)]) - [_delegate performSelector:@selector(pickedColor:) withObject:_lastSelectedColor]; -} - -@end -#endif diff --git a/PFColorTransparentView.h b/PFColorTransparentView.h deleted file mode 100644 index 78df762..0000000 --- a/PFColorTransparentView.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// PFColorTransparentView.h -// ColorPickerTestApp -// -// Created by Bailey Seymour on 8/27/14. -// Copyright (c) 2014 Bailey Seymour. All rights reserved. -// - -#import - -@interface PFColorTransparentView : UIView - -@end diff --git a/PFColorTransparentView.m b/PFColorTransparentView.m deleted file mode 100755 index ece50c5..0000000 --- a/PFColorTransparentView.m +++ /dev/null @@ -1,34 +0,0 @@ -// -// PFColorTransparentView.m -// ColorPickerTestApp -// -// Created by Bailey Seymour on 8/27/14. -// Copyright (c) 2014 Bailey Seymour. All rights reserved. -// - -#import "PFColorTransparentView.h" -#import - -@implementation PFColorTransparentView - -- (id)initWithFrame:(CGRect)frame { - return [super initWithFrame:frame]; -} - -- (void)drawRect:(CGRect)rect { - int kHeight = 20; - int kWidth = 20; - NSArray *colors = [NSArray arrayWithObjects: - [UIColor whiteColor], - [UIColor grayColor], - nil]; - for (int row = 0; row < rect.size.height; row += kHeight) { - int index = row % (kHeight * 2) == 0 ? 0 : 1; - for (int col = 0; col < rect.size.width; col += kWidth) { - [[colors objectAtIndex:index++ % 2] setFill]; - UIRectFill(CGRectMake(col, row, kWidth, kHeight)); - } - } -} - -@end diff --git a/PFColorViewController.h b/PFColorViewController.h deleted file mode 100644 index 68bc384..0000000 --- a/PFColorViewController.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// ColorViewController.h -// UIColors -// -// Created by Bailey Seymour on 1/23/14. -// -// -#import -@class PSViewController; -@interface PFColorViewController : UIViewController - -- (id)initForContentSize:(CGSize)size; -// convenience initForContentSize:defaults:key:usesRGB:usesAlpha:postNotification:fallback: -- (id)initForContentSize:(CGSize)size defaults:(NSString *)cdefaults key:(NSString *)ckey usesRGB:(BOOL)cusesRGB usesAlpha:(BOOL)cusesAlpha postNotification:(NSString *)cpostNotification fallback:(NSString *)cfallback; -- (void)loadCustomViews; - -@property (nonatomic, retain) NSString *defaults; //Required example: @"com.baileyseymour.test" -@property (nonatomic, retain) NSString *key; //Required example @"aColor" -@property (nonatomic, assign) BOOL usesRGB; //Default: false -@property (nonatomic, assign) BOOL usesAlpha; //Default: false -@property (nonatomic, retain) NSString *postNotification; -@property (nonatomic, retain) NSString *fallback; - -@end diff --git a/PFColorViewController.xm b/PFColorViewController.xm deleted file mode 100755 index 0926763..0000000 --- a/PFColorViewController.xm +++ /dev/null @@ -1,474 +0,0 @@ -// -// ColorViewController.m -// UIColors -// -// Created by Bailey Seymour on 1/23/14. -// -// -#import "PSSpecifier.h" - -@interface UIViewController () -- (id)initForContentSize:(CGSize)size; -@end - - -#if TARGET_OS_IPHONE -#import "PFColorViewController.h" -#import "PFColorPicker.h" -#import "UIColor+PFColor.h" -#import "PFColorTransparentView.h" -#import - -@interface UIPushedView : UIView -@end - -@implementation UIPushedView - -- (void)setFrame:(CGRect)frame { - frame.origin.y = 64; - if (self.superview) - frame.size.height = self.superview.frame.size.height - 64; - [super setFrame:frame]; -} - -@end - -@interface PFColorViewController () { - UIColor *_loadedColor; - UIView *_backdrop; - PFColorTransparentView *_transparent; - CGSize _size; - - // HSB - UISlider *_hueSlider; - UISlider *_saturationSlider; - UISlider *_brightnessSlider; - UISlider *_alphaSlider; - - UIView *_controlsContainer; - UIBarButtonItem *_hexButton; - CGFloat _currentAlpha; - UIPushedView *_pushedView; -} - -@property (nonatomic, retain) PFColorPicker *colorPicker; -@end - -@implementation PFColorViewController - -#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ -extern "C" { -#endif -UIColor *colorFromDefaultsWithKey(NSString *defaults, NSString *key, NSString *fallback); - -#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */ -} -#endif - -- (UIColor *)colorFromDefaults:(NSString *)def withKey:(NSString *)key { - UIColor *color = colorFromDefaultsWithKey(def, key, self.fallback); - - _currentAlpha = color.alpha; - _alphaSlider.value = color.alpha; - - return color; -} - -#define isiPhone4 ([[UIScreen mainScreen] bounds].size.height == 480) - -- (id)initForContentSize:(CGSize)size { - if ([%c(PSViewController) instancesRespondToSelector:@selector(initForContentSize:)]) - self = [super initForContentSize:size]; - else - self = [super init]; - - _size = size; - - _pushedView = [[UIPushedView alloc] initWithFrame:CGRectMake(0, 64, size.width, size.height - 64)]; - _pushedView.alpha = 0; - [self.view addSubview:_pushedView]; - - return self; -} - -- (id)initForContentSize:(CGSize)size - defaults:(NSString *)cdefaults - key:(NSString *)ckey - usesRGB:(BOOL)cusesRGB - usesAlpha:(BOOL)cusesAlpha - postNotification:(NSString *)cpostNotification - fallback:(NSString *)cfallback { - self = [self initForContentSize:size]; - self.defaults = cdefaults; - self.key = ckey; - self.usesRGB = cusesRGB; - self.usesAlpha = cusesAlpha; - self.postNotification = cpostNotification; - self.fallback = cfallback; - - return self; -} - -- (void)loadCustomViews { - _pushedView.frame = CGRectMake(0, 20 + 44, _size.width, _size.height - 64); - - _currentAlpha = 1; - - if (_transparent) - [_transparent setFrame:_pushedView.frame]; - else - _transparent = [[PFColorTransparentView alloc] initWithFrame:_pushedView.frame]; - - if (!self.usesAlpha) - _transparent.hidden = YES; - - CGFloat height = _pushedView.frame.size.height / 2; - - if (isiPhone4) - height -= 40; - - CGRect colorPickerFrame = CGRectMake(0, 0, _pushedView.frame.size.width, height); - if (self.colorPicker) - [self.colorPicker setFrame:colorPickerFrame]; - else - self.colorPicker = [[PFColorPicker alloc] initWithFrame:colorPickerFrame]; - [self.colorPicker makeReadyForDisplay]; - [self.colorPicker setDelegate:self]; - - float controlsContainerHeight = self.usesAlpha ? 180 : 140; - CGRect controlsContainerFrame = CGRectMake(0, - _pushedView.frame.size.height - controlsContainerHeight, - self.colorPicker.frame.size.width, - controlsContainerHeight); - if (_controlsContainer) - [_controlsContainer setFrame:controlsContainerFrame]; - else - _controlsContainer = [[UIView alloc] initWithFrame:controlsContainerFrame]; - - float halfWidth = _controlsContainer.frame.size.width / 2; - CGPoint red = CGPointMake(halfWidth, 30); - CGPoint green = CGPointMake(halfWidth, red.y + 40); - CGPoint blue = CGPointMake(halfWidth, green.y + 40); - CGPoint alpha = CGPointMake(halfWidth, blue.y + 40); - - CGRect sliderFrame = CGRectMake(halfWidth, 0, _controlsContainer.frame.size.width - 40, 20); - - Class viewClass; - if (%c(UIBackdropView)) - viewClass = %c(UIBackdropView); - else - viewClass = [UIView class]; - - CGRect backdropFrame = CGRectMake(0, 0, _controlsContainer.frame.size.width, _controlsContainer.frame.size.height); - if (_backdrop) - [_backdrop setFrame:backdropFrame]; - else - _backdrop = [[viewClass alloc] initWithFrame:backdropFrame]; - - _hexButton = [[UIBarButtonItem alloc] initWithTitle:@"#" - style:UIBarButtonItemStylePlain - target:self - action:@selector(chooseHexColor)]; - self.navigationItem.rightBarButtonItem = _hexButton; - - if (viewClass == [UIView class]) - [_backdrop setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.5f]]; - - if (_hueSlider) - [_hueSlider setFrame:sliderFrame]; - else - _hueSlider = [[UISlider alloc] initWithFrame:sliderFrame]; - [_hueSlider addTarget:self action:@selector(hueSliderChanged) forControlEvents:UIControlEventValueChanged]; - [_hueSlider setCenter:red]; - - [_hueSlider setMaximumValue:1]; - [_hueSlider setMinimumValue:0]; - _hueSlider.continuous = YES; - - if (_saturationSlider) - [_saturationSlider setFrame:sliderFrame]; - else - _saturationSlider = [[UISlider alloc] initWithFrame:sliderFrame]; - [_saturationSlider addTarget:self action:@selector(hueSliderChanged) forControlEvents:UIControlEventValueChanged]; - [_saturationSlider setCenter:green]; - - [_saturationSlider setMaximumValue:1]; - [_saturationSlider setMinimumValue:0]; - _saturationSlider.continuous = YES; - - if (_brightnessSlider) - [_brightnessSlider setFrame:sliderFrame]; - else - _brightnessSlider = [[UISlider alloc] initWithFrame:sliderFrame]; - [_brightnessSlider addTarget:self action:@selector(hueSliderChanged) forControlEvents:UIControlEventValueChanged]; - [_brightnessSlider setCenter:blue]; - - [_brightnessSlider setMaximumValue:1]; - [_brightnessSlider setMinimumValue:0]; - _brightnessSlider.continuous = YES; - - if (_alphaSlider) - [_alphaSlider setFrame:sliderFrame]; - else - _alphaSlider = [[UISlider alloc] initWithFrame:sliderFrame]; - [_alphaSlider addTarget:self action:@selector(hueSliderChanged) forControlEvents:UIControlEventValueChanged]; - [_alphaSlider setCenter:alpha]; - - [_alphaSlider setMaximumValue:1]; - [_alphaSlider setMinimumValue:0]; - if (!self.usesAlpha) - _alphaSlider.hidden = YES; - - // UIColor *loadColor = [self colorFromDefaults:self.defaults withKey:self.key]; - // currentAlpha = loadColor.alpha; - // _alphaSlider.value = currentAlpha; - // [self pickedColor:loadColor]; - - _alphaSlider.continuous = YES; - - if (self.usesRGB) { - // Tint For RGB - if (![_hueSlider respondsToSelector:@selector(setTintColor:)]) { - _hueSlider.minimumTrackTintColor = [UIColor redColor]; - _saturationSlider.minimumTrackTintColor = [UIColor greenColor]; - _brightnessSlider.minimumTrackTintColor = [UIColor blueColor]; - _alphaSlider.minimumTrackTintColor = [UIColor grayColor]; - } else { - // iOS 7 - _hueSlider.tintColor = [UIColor redColor]; - _saturationSlider.tintColor = [UIColor greenColor]; - _brightnessSlider.tintColor = [UIColor blueColor]; - _alphaSlider.tintColor = [UIColor grayColor]; - } - - [_hueSlider setThumbImage:[PFColorViewController thumbImageWithColor:[UIColor whiteColor] letter:'R'] forState:UIControlStateNormal]; - [_saturationSlider setThumbImage:[PFColorViewController thumbImageWithColor:[UIColor whiteColor] letter:'G'] forState:UIControlStateNormal]; - [_brightnessSlider setThumbImage:[PFColorViewController thumbImageWithColor:[UIColor whiteColor] letter:'B'] forState:UIControlStateNormal]; - [_alphaSlider setThumbImage:[PFColorViewController thumbImageWithColor:[UIColor whiteColor] letter:'A'] forState:UIControlStateNormal]; - [_alphaSlider setThumbImage:[PFColorViewController thumbImageWithColor:[UIColor whiteColor] letter:'A'] forState:UIControlStateHighlighted]; - } else { - // Tint for HSB - UIColor *black = [UIColor blackColor]; - UIColor *gray = [UIColor grayColor]; - if (![_hueSlider respondsToSelector:@selector(setTintColor:)]) { - _hueSlider.minimumTrackTintColor = black; - _saturationSlider.minimumTrackTintColor = black; - _brightnessSlider.minimumTrackTintColor = black; - _alphaSlider.minimumTrackTintColor = gray; - } else { - // iOS 7 - _hueSlider.tintColor = black; - _saturationSlider.tintColor = black; - _brightnessSlider.tintColor = black; - _alphaSlider.tintColor = gray; - } - - [_hueSlider setThumbImage:[PFColorViewController thumbImageWithColor:[UIColor whiteColor] letter:'H'] forState:UIControlStateNormal]; - [_saturationSlider setThumbImage:[PFColorViewController thumbImageWithColor:[UIColor whiteColor] letter:'S'] forState:UIControlStateNormal]; - [_brightnessSlider setThumbImage:[PFColorViewController thumbImageWithColor:[UIColor whiteColor] letter:'B'] forState:UIControlStateNormal]; - [_alphaSlider setThumbImage:[PFColorViewController thumbImageWithColor:[UIColor whiteColor] letter:'A'] forState:UIControlStateNormal]; - [_alphaSlider setThumbImage:[PFColorViewController thumbImageWithColor:[UIColor whiteColor] letter:'A'] forState:UIControlStateHighlighted]; - } - - if (!_transparent.superview) - [_pushedView addSubview:_transparent]; - - if (!self.colorPicker.superview) - [_pushedView addSubview:self.colorPicker]; - - if (!_controlsContainer.superview) - [_pushedView addSubview:_controlsContainer]; - - if (!_backdrop.superview) - [_controlsContainer addSubview:_backdrop]; - - if (!_hueSlider.superview) - [_controlsContainer addSubview:_hueSlider]; - - if (!_saturationSlider.superview) - [_controlsContainer addSubview:_saturationSlider]; - - if (!_brightnessSlider.superview) - [_controlsContainer addSubview:_brightnessSlider]; - - if (!_alphaSlider.superview) - [_controlsContainer addSubview:_alphaSlider]; - - if (self.defaults && self.key) { - _loadedColor = [self colorFromDefaults:self.defaults withKey:self.key]; - _currentAlpha = _loadedColor.alpha; - _alphaSlider.value = _currentAlpha; - [self pickedColor:_loadedColor]; - } - - [UIView animateWithDuration:0.2 - delay:0 - options:UIViewAnimationOptionTransitionCrossDissolve - animations:^{ - [_pushedView setAlpha:1]; - } - completion:nil]; -} - -- (void)viewDidLoad { - [super viewDidLoad]; -} - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -- (void)chooseHexColor { - UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Hex Color" message:@"Enter a hex color or copy it to your pasteboard." delegate:self cancelButtonTitle:@"Close" otherButtonTitles:@"Set", @"Copy", nil]; - prompt.delegate = self; - [prompt setAlertViewStyle:UIAlertViewStylePlainTextInput]; - [[prompt textFieldAtIndex:0] setText:[UIColor hexFromColor:_pushedView.backgroundColor]]; - [prompt show]; -} - -- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - if (buttonIndex == 1) { - if ([[alertView textFieldAtIndex:0].text hasPrefix:@"#"] && [UIColor PF_colorWithHex:[alertView textFieldAtIndex:0].text]) - [self pickedColor:[UIColor PF_colorWithHex:[alertView textFieldAtIndex:0].text]]; - } else if (buttonIndex == 2) { - [[UIPasteboard generalPasteboard] setString:[UIColor hexFromColor:_pushedView.backgroundColor]]; - } -} -#pragma clang diagnostic pop - -+ (UIImage *)thumbImageWithColor:(UIColor *)color letter:(unichar)letter { - CGFloat size = 28.0f; - CGRect rect = CGRectMake(0.0f, 0.0f, size + 3, size + 8); - UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale); - CGContextRef context = UIGraphicsGetCurrentContext(); - CGSize shadowSize = CGSizeMake(0, 3); - CGContextSetShadowWithColor(context, shadowSize, 4, [UIColor colorWithWhite:0 alpha:0.25f].CGColor); - CGContextSetFillColorWithColor(context, [color CGColor]); - CGContextAddArc(context, rect.size.width / 2, rect.size.width / 2, size / 2, size / 2, 2 * M_PI, 1); - CGContextSetStrokeColorWithColor(context, [[UIColor PF_colorWithHex:@"#f0f0f0"] colorWithAlphaComponent:0].CGColor); - - CGContextDrawPath(context, kCGPathFill); - - CGContextSetShadow(context, CGSizeMake(0, 0), 0); - CGContextTranslateCTM(context, 0, rect.size.height); - CGContextScaleCTM(context, 1, -1); - CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 1.0f); - CGContextSetLineWidth(context, 2.0f); - - CGContextSetCharacterSpacing(context, 1.7f); - CGContextSetTextDrawingMode(context, kCGTextFill); - - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - CGContextSelectFont(context, "Helvetica Neue Bold", 15.0f, kCGEncodingMacRoman); - CGContextShowTextAtPoint(context, 10, 15, [NSString stringWithCharacters:&letter length:1].UTF8String, 1); - #pragma clang diagnostic pop - - UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - - return image; -} - -- (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - - [self performSelector:@selector(loadCustomViews) withObject:nil afterDelay:0]; - [self.colorPicker performSelector:@selector(saveCache) withObject:nil afterDelay:0.5f]; -} - -- (void)viewDidDisappear:(BOOL)animated { - [super viewDidDisappear:animated]; - if (self.postNotification && _loadedColor != [self colorFromDefaults:self.defaults withKey:self.key]) { - CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), - (CFStringRef)self.postNotification, - NULL, - NULL, - YES); - } -} - -- (void)hueSliderChanged { - UIColor *color; - if (!self.usesRGB) - color = [UIColor colorWithHue:_hueSlider.value - saturation:_saturationSlider.value - brightness:_brightnessSlider.value - alpha:_alphaSlider.value]; - else - color = [UIColor colorWithRed:_hueSlider.value - green:_saturationSlider.value - blue:_brightnessSlider.value - alpha:_alphaSlider.value]; - - [self pickedColor:color]; -} - -- (void)pickedColor:(UIColor *)color { - [_pushedView setBackgroundColor:color]; - [self.view setBackgroundColor:color]; - - if (!self.usesRGB) { - CGFloat hue; - CGFloat saturation; - CGFloat brightness; - - [color getHue:&hue saturation:&saturation brightness:&brightness alpha:NULL]; - - [_hueSlider setValue:hue]; - [_saturationSlider setValue:saturation]; - [_brightnessSlider setValue:brightness]; - } else { - CGFloat red; - CGFloat green; - CGFloat blue; - - [color getRed:&red green:&green blue:&blue alpha:NULL]; - [_hueSlider setValue:red]; - [_saturationSlider setValue:green]; - [_brightnessSlider setValue:blue]; - } - - if (self.usesAlpha) { - _transparent.alpha = 1 - _alphaSlider.value; - _currentAlpha = _alphaSlider.value; - } - - NSMutableDictionary *preferencesPlist = [NSMutableDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", self.defaults]]; - - if (!preferencesPlist) - preferencesPlist = [NSMutableDictionary new]; - - NSString *saveValue; - if (self.usesAlpha) - saveValue = [NSString stringWithFormat:@"%@:%f", [UIColor hexFromColor:color], _currentAlpha]; //should be something like @"#a1a1a1:0.5" with the the decimal being the alpha you can ge the color and alpha seperately by [value componentsSeparatedByString:@":"] - else - saveValue = [UIColor hexFromColor:color]; // should be something like @"#a1a1a1" - - if (saveValue && self.key) { - [preferencesPlist setObject:saveValue forKey:self.key]; - [preferencesPlist writeToFile:[NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", self.defaults] atomically:YES]; - CFPreferencesSetAppValue((CFStringRef)self.key,(CFStringRef)saveValue, (CFStringRef)self.defaults); - CFPreferencesAppSynchronize((CFStringRef)self.defaults); - } -} - -- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { - [self.colorPicker saveCache]; - - _size = self.view.frame.size; - _size.height = _size.height - 20 - 44; - [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ - [self loadCustomViews]; - } - completion:nil]; -} - -- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { - return UIInterfaceOrientationPortrait; -} - -- (UIInterfaceOrientationMask)supportedInterfaceOrientations { - return UIInterfaceOrientationMaskPortrait; -} - -@end -#endif diff --git a/PFLiteColorCell.mm b/PFLiteColorCell.mm index d8b4cd2..efd601a 100755 --- a/PFLiteColorCell.mm +++ b/PFLiteColorCell.mm @@ -5,25 +5,15 @@ @interface PFLiteColorCell : PSTableCell @property (nonatomic, retain) UIView *colorPreview; -- (void)updateCellDisplay; @end @interface UIColor () + (NSString *)hexFromColor:(UIColor *)color; @end -static void PFLiteColorCellNotifCB(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { - PFLiteColorCell *cell = (__bridge PFLiteColorCell *)observer; - [UIView animateWithDuration:0.45 - animations:^{ - [cell updateCellDisplay]; - } - completion:nil]; -} - @implementation PFLiteColorCell -- (id)initWithStyle:(long long)style reuseIdentifier:(id)identifier specifier:(PSSpecifier *)specifier { +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(id)identifier specifier:(PSSpecifier *)specifier { return [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier specifier:specifier]; } @@ -44,20 +34,6 @@ - (void)updateCellDisplay { - (void)didMoveToSuperview { [super didMoveToSuperview]; - NSString *notificationId = [[self specifier] propertyForKey:@"NotificationListener"]; - - if (notificationId) { - CFNotificationCenterRemoveEveryObserver (CFNotificationCenterGetDarwinNotifyCenter(), (void *)self); - - CFNotificationCenterAddObserver (CFNotificationCenterGetDarwinNotifyCenter(), - (void *)self, - PFLiteColorCellNotifCB, - (CFStringRef)notificationId, - NULL, - CFNotificationSuspensionBehaviorCoalesce - ); - } - self.colorPreview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 29, 29)]; self.colorPreview.tag = 199; // Stop UIColors from overriding the color :P self.colorPreview.layer.cornerRadius = self.colorPreview.frame.size.width / 2; @@ -68,11 +44,4 @@ - (void)didMoveToSuperview { [self updateCellDisplay]; } -- (void)dealloc { - [self.colorPreview release]; - - CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), (void *)self); - [super dealloc]; -} - @end diff --git a/PFSimpleLiteColorCell.mm b/PFSimpleLiteColorCell.mm index d290c85..161f53a 100755 --- a/PFSimpleLiteColorCell.mm +++ b/PFSimpleLiteColorCell.mm @@ -1,10 +1,10 @@ #import #import +#import #import "libcolorpicker.h" #import "PSSpecifier.h" @interface PFSimpleLiteColorCell() -- (void)openColorAlert; @property (nonatomic, retain) NSMutableDictionary *options; @property (nonatomic, retain) PFColorAlert *alert; @end @@ -17,7 +17,7 @@ - (void)openColorAlert; @implementation PFSimpleLiteColorCell -- (id)initWithStyle:(long long)style reuseIdentifier:(id)identifier specifier:(PSSpecifier *)specifier { +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(id)identifier specifier:(PSSpecifier *)specifier { self = [super initWithStyle:style reuseIdentifier:identifier specifier:specifier]; [self setLCPOptions]; @@ -26,52 +26,37 @@ - (id)initWithStyle:(long long)style reuseIdentifier:(id)identifier specifier:(P } - (void)setLCPOptions { - self.options = [[self.specifier properties][@"libcolorpicker"] mutableCopy]; - if (!self.options) + [[self.specifier properties] addEntriesFromDictionary:[self.specifier properties][@"libcolorpicker"]]; + if([self isKindOfClass:objc_getClass("HBColorPickerTableCell")]){ self.options = [NSMutableDictionary dictionary]; - - if (!self.options[kPostNotification]) { - NSString *option = [NSString stringWithFormat:@"%@_%@_libcolorpicker_refreshn", - self.options[kDefaults], self.options[kKey]]; - [self.options setObject:option forKey:kPostNotification]; + self.options[kDefaults]=[self.specifier properties][kDefaults]; + self.options[kKey]=[self.specifier properties][kKey]; + self.options[kAlpha]=[self.specifier properties][@"showAlphaSlider"]; + self.options[kFallback]=[self.specifier properties][@"default"]; + self.options[kPostNotification]=[self.specifier properties][kPostNotification]; + } + else{ + self.options = [[self.specifier properties][@"libcolorpicker"] mutableCopy]; } - [(PSSpecifier *)self.specifier setProperty:self.options[kPostNotification] - forKey:@"NotificationListener"]; + if (!self.options) self.options = [NSMutableDictionary dictionary]; } - (UIColor *)previewColor { - NSString *plistPath = [NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", self.options[kDefaults]]; - - NSMutableDictionary *prefsDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath]; - if (!prefsDict) - prefsDict = [NSMutableDictionary dictionary]; - - return LCPParseColorString([prefsDict objectForKey:self.options[kKey]], self.options[kFallback]); // this color will be used at startup -} - -- (void)didMoveToSuperview { - [self setLCPOptions]; - - [super didMoveToSuperview]; - - [self.specifier setTarget:self]; - [self.specifier setButtonAction:@selector(openColorAlert)]; + if(!self.specifier) return [UIColor clearColor]; + SEL sel=((PSSpecifier*)self.specifier)->getter; + id target=[self viewController]; + if(!target ||![target respondsToSelector:sel]) return [UIColor clearColor]; + id value=((id (*)(id, SEL, id))[target methodForSelector:sel])(target, sel, self.specifier); + return LCPParseColorString(value, self.options[kFallback]); // this color will be used at startup } - (void)openColorAlert { if (!self.options[kDefaults] || !self.options[kKey] || !self.options[kFallback]) return; + + UIColor *startColor = [self previewColor]; // this color will be used at startup - // HBLogDebug(@"Loading with options %@", self.options); - - NSString *plistPath = [NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", self.options[kDefaults]]; - - NSMutableDictionary *prefsDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath]; - if (!prefsDict) - prefsDict = [NSMutableDictionary dictionary]; - - UIColor *startColor = LCPParseColorString([prefsDict objectForKey:self.options[kKey]], self.options[kFallback]); // this color will be used at startup BOOL showAlpha = self.options[kAlpha] ? [self.options[kAlpha] boolValue] : NO; self.alert = [PFColorAlert colorAlertWithStartColor:startColor showAlpha:showAlpha]; @@ -84,19 +69,30 @@ - (void)openColorAlert { // ^^ parse fallback to ^red // save hexString to your plist if desired - [prefsDict setObject:hexString forKey:self.options[kKey]]; - [prefsDict writeToFile:plistPath atomically:YES]; + { + SEL sel=((PSSpecifier*)self.specifier)->getter; + id target=[self viewController]; + id value=((id (*)(id, SEL, id))[target methodForSelector:sel])(target, sel, self.specifier); + if([value isEqualToString:hexString]) return; + } + + SEL sel=((PSSpecifier*)self.specifier)->setter; + id target=[self viewController]; + ((void (*)(id, SEL, id, id))[target methodForSelector:sel])(target, sel, hexString, self.specifier); + [self updateCellDisplay]; - NSString *notification = self.options[kPostNotification]; - if (notification) - CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), - (CFStringRef)notification, - (CFStringRef)notification, - NULL, - YES); }]; } +- (void)didMoveToSuperview { + [self setLCPOptions]; + + [super didMoveToSuperview]; + + [self.specifier setTarget:self]; + [self.specifier setButtonAction:@selector(openColorAlert)]; +} + - (SEL)action { return @selector(openColorAlert); } @@ -113,4 +109,20 @@ - (id)cellTarget { return self; } +-(BOOL)canReload{ + return YES; +} + +-(void)reloadWithSpecifier:(id)specifier animated:(BOOL)animated{ + [self performSelector:@selector(setSpecifier:) withObject:specifier]; + [self updateCellDisplay]; +} + +- (id)viewController{ + id ret=self; + while((ret=[ret nextResponder])){ + if([ret isKindOfClass:[UIViewController class]]) return ret; + } + return nil; +} @end diff --git a/PFSimpleLiteColorCell_.mm b/PFSimpleLiteColorCell_.mm new file mode 100644 index 0000000..c3588b6 --- /dev/null +++ b/PFSimpleLiteColorCell_.mm @@ -0,0 +1,22 @@ +#import +#import +#import "libcolorpicker.h" +#import "PSSpecifier.h" + +@interface PFSimpleLiteColorCell_ : PFSimpleLiteColorCell + +@end + + +@implementation PFSimpleLiteColorCell_ + +@end + +@interface HBColorPickerTableCell : PFSimpleLiteColorCell + +@end + + +@implementation HBColorPickerTableCell + +@end diff --git a/PSTableCell.h b/PSTableCell.h index ea30c6d..63590fe 100644 --- a/PSTableCell.h +++ b/PSTableCell.h @@ -88,6 +88,6 @@ - (void)longPressed:(id)arg1; - (_Bool)canBecomeFirstResponder; - (void)dealloc; -- (id)initWithStyle:(long long)arg1 reuseIdentifier:(id)arg2 specifier:(id)arg3; +- (id)initWithStyle:(UITableViewCellStyle)arg1 reuseIdentifier:(id)arg2 specifier:(id)arg3; @end diff --git a/README.md b/README.md index 2bb646e..7140ea2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,19 @@ # libcolorpicker [](http://git.pixelfiredev.com/ci/projects/3?ref=master) +# The re-new libcolorpicker: + +#### changelog +* Using native method to read/write pref value, now you can implement your own getter/setter. +* Providing native reload interface, now cell won't reproduce when reloading specifier. +* Fix a bug which cause alpha of fallback is always 1. +* Fix a bug which cause alpha is always 0 on some low version device. +* Fix building issues with specific sdk. +* Fully use arc. +* Provide HBColorPickerTableCell(Alderis) compatibility +* Add a script by which you can test on simulator. +* Remove some legacy code to lower size of package. + # The new libcolorpicker: The new libcolorpicker `PFColorAlert` is focused on being lightweight, portable, and easy to use. diff --git a/UIColor+PFColor.m b/UIColor+PFColor.m index ac3b22b..590e7d6 100755 --- a/UIColor+PFColor.m +++ b/UIColor+PFColor.m @@ -39,7 +39,7 @@ - (NSString *)hexFromColor { #pragma mark Components - (CGFloat)alpha { CGFloat a; - [self getWhite:NULL alpha:&a]; + [self getRed:NULL green:NULL blue:NULL alpha:&a]; return a; } diff --git a/UIKitAdditions.h b/UIKitAdditions.h index 1f23f89..df5fde7 100644 --- a/UIKitAdditions.h +++ b/UIKitAdditions.h @@ -1,14 +1,16 @@ +#if __IPHONE_OS_VERSION_MAX_ALLOWED < 130000 @interface UIScene : NSObject @end @interface UIWindowScene -@property (nonatomic, retain) NSSet *windows; +@property (nonatomic, retain) NSArray *windows; @end @interface UIWindow (NewiOSMethods) --(instancetype) initWithWindowScene:(UIScene *)scene; +- (instancetype)initWithWindowScene:(UIWindowScene *)windowScene; @end @interface UIApplication (NewiOSMethods) -(id)connectedScenes; -@end \ No newline at end of file +@end +#endif \ No newline at end of file diff --git a/control b/control index a24d0f0..c6b8888 100644 --- a/control +++ b/control @@ -1,12 +1,11 @@ Package: org.thebigboss.libcolorpicker Name: libcolorpicker -Depends: firmware (>= 6.0) +Depends: firmware (>= 7.0) Version: 1.6.9 Replaces: me.nepeta.libcolorpicker, ws.hbang.alderis Provides: me.nepeta.libcolorpicker, ws.hbang.alderis Architecture: iphoneos-arm Description: An awesome library of some sort!! -Maintainer: Bailey Seymour +Maintainer: Brend0n Author: Bailey Seymour Section: System -Tag: role::developer diff --git a/libcolorpicker.h b/libcolorpicker.h index 60a8167..551255b 100644 --- a/libcolorpicker.h +++ b/libcolorpicker.h @@ -36,7 +36,7 @@ UIColor *colorFromDefaultsWithKey(NSString *defaults, NSString *key, NSString *f @end @interface PFLiteColorCell : UITableViewCell -- (id)initWithStyle:(long long)style reuseIdentifier:(id)identifier specifier:(id)specifier; +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(id)identifier specifier:(id)specifier; - (UIColor *)previewColor; // this will be used for the circle preview view. override in a subclass - (id)specifier; - (void)updateCellDisplay; diff --git a/libcolorpicker.mm b/libcolorpicker.mm index 56dc294..80aeb15 100755 --- a/libcolorpicker.mm +++ b/libcolorpicker.mm @@ -136,56 +136,19 @@ void hextodec(std::string hex, std::vector& rgb) { // do not use this method anymore UIColor *colorFromDefaultsWithKey(NSString *defaults, NSString *key, NSString *fallback) { - NSMutableDictionary *preferencesPlist = [NSMutableDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", defaults]]; - //fallback - UIColor *fallbackColor = colorFromHex(fallback); - CGFloat currentAlpha = 1.0f; - - if (preferencesPlist && [preferencesPlist objectForKey:key]) { - NSString *value = [preferencesPlist objectForKey:key]; - NSArray *colorAndOrAlpha = [value componentsSeparatedByString:@":"]; - if ([value rangeOfString:@":"].location != NSNotFound) { - if ([colorAndOrAlpha objectAtIndex:1]) - currentAlpha = [colorAndOrAlpha[1] floatValue]; - else - currentAlpha = 1; - } - - if (!value) - return fallbackColor; - - NSString *color = colorAndOrAlpha[0]; + return nil; +} - return [colorFromHex(color) colorWithAlphaComponent:currentAlpha]; - } else { - return fallbackColor; - } +UIColor *_parseColorString(NSString *colorStringWithAlpha){ + if ([colorStringWithAlpha rangeOfString:@":"].location == NSNotFound) + colorStringWithAlpha=[NSString stringWithFormat:@"%@:1.0",colorStringWithAlpha]; + NSArray *colorAndAlpha = [colorStringWithAlpha componentsSeparatedByString:@":"]; + NSString *colorString = colorAndAlpha[0]; + CGFloat alpha = [colorAndAlpha[1] floatValue]; + return [colorFromHex(colorString) colorWithAlphaComponent:alpha]; } UIColor *LCPParseColorString(NSString *colorStringFromPrefs, NSString *colorStringFallback) { - //fallback - UIColor *fallbackColor = colorFromHex(colorStringFallback); - CGFloat currentAlpha = 1.0f; - - if (colorStringFromPrefs && colorStringFromPrefs.length > 0) { - NSString *value = colorStringFromPrefs; - if (!value || value.length == 0) - return fallbackColor; - - NSArray *colorAndOrAlpha = [value componentsSeparatedByString:@":"]; - if ([value rangeOfString:@":"].location != NSNotFound) { - if ([colorAndOrAlpha objectAtIndex:1]) - currentAlpha = [colorAndOrAlpha[1] floatValue]; - else - currentAlpha = 1.0f; - } - - if (!value) - return fallbackColor; - - NSString *color = colorAndOrAlpha[0]; - return [colorFromHex(color) colorWithAlphaComponent:currentAlpha]; - } else { - return fallbackColor; - } + if(colorStringFromPrefs) return _parseColorString(colorStringFromPrefs); + return _parseColorString(colorStringFallback); } diff --git a/public_headers/ColorPicker.h b/public_headers/ColorPicker.h deleted file mode 100755 index 0cc316d..0000000 Binary files a/public_headers/ColorPicker.h and /dev/null differ diff --git a/public_headers/PFColorViewController.h b/public_headers/PFColorViewController.h deleted file mode 100755 index 957886f..0000000 Binary files a/public_headers/PFColorViewController.h and /dev/null differ