Skip to content
Browse files

Uncrustified code

  • Loading branch information...
1 parent 0653713 commit f8666cb3d2018ef77461a827292b625d2cf8ca8c @angelolloqui committed Sep 27, 2012
View
10 src/AGImageChecker.h
@@ -18,10 +18,10 @@
@interface AGImageChecker : NSObject
-@property(readonly) BOOL running;
-@property(readonly, strong) UILongPressGestureRecognizer *tapGesture;
-@property(nonatomic, strong) UIViewController *rootViewController;
-@property(readonly, strong) NSArray *plugins;
+@property (readonly) BOOL running;
+@property (readonly, strong) UILongPressGestureRecognizer *tapGesture;
+@property (nonatomic, strong) UIViewController *rootViewController;
+@property (readonly, strong) NSArray *plugins;
+ (AGImageChecker *)sharedInstance;
+ (void)setSharedInstance:(AGImageChecker *)instance;
@@ -31,4 +31,4 @@
- (void)addPlugin:(id<AGImageCheckerPluginProtocol>)plugin;
- (void)removePlugin:(id<AGImageCheckerPluginProtocol>)plugin;
-@end
+@end
View
56 src/AGImageChecker.m
@@ -12,8 +12,8 @@
#import "AGImageCheckerBasePlugin.h"
#import <dlfcn.h>
-@interface AGImageChecker()
-@property(readwrite) BOOL running;
+@interface AGImageChecker ()
+@property (readwrite) BOOL running;
@end
@implementation AGImageChecker
@@ -31,6 +31,7 @@ + (void)load {
NSDictionary *environment = [[NSProcessInfo processInfo] environment];
NSString *simulatorRoot = [environment objectForKey:@"IPHONE_SIMULATOR_ROOT"];
+
if (simulatorRoot) {
appSupportLocation = [simulatorRoot stringByAppendingString:appSupportLocation];
}
@@ -47,30 +48,35 @@ + (void)load {
CFRelease(accessibilityDomain);
}
}
+
#endif
}
static AGImageChecker *sharedInstance = nil;
-+ (AGImageChecker *)sharedInstance
-{
++ (AGImageChecker *)sharedInstance {
+
#if AGIMAGECHECKER
if (sharedInstance == nil) {
- sharedInstance = [[self alloc] init];
+ sharedInstance = [[self alloc] init];
}
#endif
- return sharedInstance;
+
+ return sharedInstance;
}
+
+ (void)setSharedInstance:(AGImageChecker *)instance {
sharedInstance = instance;
}
- (id)init {
self = [super init];
+
if (self) {
running = NO;
tapGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnWindow)];
plugins = [[NSMutableArray alloc] initWithObjects:[[AGImageCheckerBasePlugin alloc] init], nil];
}
+
return self;
}
@@ -81,15 +87,19 @@ - (void)start {
self.running = YES;
[UIImageView startCheckingImages];
__block id blockSelf = self;
+
[UIImageView setImageIssuesHandler:^(UIImageView *imageView) {
[blockSelf changeIssues:imageView];
}];
+
[UIImageView setImageCheckHandler:^(UIImageView *imageView) {
[blockSelf checkIssues:imageView];
}];
+
[UIImage startSavingNames];
[self.rootWindow addGestureRecognizer:tapGesture];
NSArray *loadedImageViews = [self imageViewsInto:self.rootWindow];
+
for (UIImageView *imageView in loadedImageViews) {
[self checkIssues:imageView];
}
@@ -105,6 +115,7 @@ - (void)stop {
[UIImage stopSavingNames];
[tapGesture.view removeGestureRecognizer:tapGesture];
NSArray *loadedImageViews = [self imageViewsInto:self.rootWindow];
+
for (UIImageView *imageView in loadedImageViews) {
imageView.issues = AGImageCheckerIssueNone;
}
@@ -113,25 +124,32 @@ - (void)stop {
- (void)setRootViewController:(UIViewController *)viewController {
if (rootViewController == viewController) return;
+
[self willChangeValueForKey:@"rootViewController"];
BOOL run = self.running;
+
if (run) {
[self stop];
}
+
rootViewController = viewController;
+
if (run) {
[self start];
}
+
if (rootViewController) {
NSAssert(self.rootWindow, @"The view controller must be added to the window before setting it to as the AGImageChecker root controller");
}
+
[self didChangeValueForKey:@"rootViewController"];
}
- (UIViewController *)rootViewController {
if (!rootViewController) {
return [[[UIApplication sharedApplication] keyWindow] rootViewController];
}
+
return rootViewController;
}
@@ -140,6 +158,7 @@ - (UIWindow *)rootWindow {
if ([self.rootViewController.view isDescendantOfView:wnd])
return wnd;
}
+
return [[UIApplication sharedApplication] keyWindow];
}
@@ -149,7 +168,7 @@ - (void)addPlugin:(id<AGImageCheckerPluginProtocol>)plugin {
}
}
-- (void)removePlugin:(id<AGImageCheckerPluginProtocol>)plugin {
+- (void)removePlugin:(id<AGImageCheckerPluginProtocol>)plugin {
[(NSMutableArray *)self.plugins removeObject:plugin];
}
@@ -165,11 +184,13 @@ - (void)changeIssues:(UIImageView *)imageView {
- (void)checkIssues:(UIImageView *)imageView {
AGImageCheckerIssue issues = AGImageCheckerIssueNone;
+
for (id<AGImageCheckerPluginProtocol> plugin in plugins) {
if ([plugin respondsToSelector:@selector(calculateIssues:withIssues:)]) {
issues = [plugin calculateIssues:imageView withIssues:issues];
}
}
+
imageView.issues = issues;
}
@@ -181,6 +202,7 @@ - (void)tapOnWindow {
CGPoint location = [self.tapGesture locationInView:touchView];
UIImageView *imageView = [self imageViewAtPosition:location inView:touchView];
+
if (imageView) {
[self openImageDetail:imageView];
}
@@ -189,42 +211,48 @@ - (void)tapOnWindow {
- (void)openImageDetail:(UIImageView *)imageView {
UIViewController *viewController = self.rootViewController;
+
if (viewController.presentedViewController)
viewController = viewController.presentedViewController;
+
[AGImageDetailViewController presentModalForImageView:imageView inViewController:viewController];
}
-
#pragma mark View traversing
- (UIImageView *)imageViewAtPosition:(CGPoint)point inView:(UIView *)view {
NSEnumerator *subviews = [view.subviews reverseObjectEnumerator];
+
for (UIView *subview in subviews) {
if ((!subview.hidden) &&
(subview.alpha > 0) &&
(CGRectContainsPoint(subview.frame, point))) {
-
- CGPoint newPoint = [view convertPoint:point toView:subview];
+ CGPoint newPoint = [view convertPoint:point toView:subview];
UIImageView *imgView = [self imageViewAtPosition:newPoint inView:subview];
+
if (imgView) return imgView;
- }
+ }
}
if ([view isKindOfClass:[UIImageView class]]) {
- return (UIImageView *) view;
+ return (UIImageView *)view;
}
+
return nil;
}
- (NSArray *)imageViewsInto:(UIView *)view {
NSMutableArray *images = [NSMutableArray arrayWithCapacity:10];
+
for (UIView *subview in view.subviews) {
[images addObjectsFromArray:[self imageViewsInto:subview]];
}
- if ([view isKindOfClass:[UIImageView class]]){
+
+ if ([view isKindOfClass:[UIImageView class]]) {
[images addObject:view];
}
+
return images;
}
-@end
+@end
View
2 src/UI/AGImageDetailViewController.h
@@ -18,4 +18,4 @@
- (void)refreshContentView;
-@end
+@end
View
23 src/UI/AGImageDetailViewController.m
@@ -30,12 +30,12 @@ @implementation AGImageDetailViewController
+ (AGImageDetailViewController *)presentModalForImageView:(UIImageView *)imageView inViewController:(UIViewController *)viewController {
NSAssert(imageView, @"imageView not set");
NSAssert(viewController, @"viewController not set");
-
- AGImageDetailViewController *vc = [[self alloc] init];
+
+ AGImageDetailViewController *vc = [[self alloc] init];
vc.targetImageView = imageView;
vc.targetIssues = imageView.issues;
[viewController presentModalViewController:vc animated:YES];
- return vc;
+ return vc;
}
#pragma mark Instance methods
@@ -46,28 +46,29 @@ - (void)refreshContentView {
self.contentScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.contentScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.contentScrollView];
-
+
CGPoint lastPoint = CGPointZero;
- for (id<AGImageCheckerPluginProtocol>plugin in [[AGImageChecker sharedInstance] plugins]) {
+
+ for (id<AGImageCheckerPluginProtocol> plugin in [[AGImageChecker sharedInstance] plugins]) {
if ([plugin respondsToSelector:@selector(detailForViewController:withImageView:withIssues:)]) {
UIView *view = [plugin detailForViewController:self withImageView:targetImageView withIssues:targetIssues];
+
if (view) {
CGRect frame = view.frame;
frame.origin.y = lastPoint.y;
view.frame = frame;
[self.contentScrollView addSubview:view];
lastPoint.y = CGRectGetMaxY(frame);
- lastPoint.x = MAX(lastPoint.x , CGRectGetMaxX(frame));
+ lastPoint.x = MAX(lastPoint.x, CGRectGetMaxX(frame));
}
}
}
+
self.contentScrollView.contentSize = CGSizeMake(lastPoint.x, lastPoint.y);
[self.view bringSubviewToFront:self.indicator];
}
-
-- (void)viewDidLoad
-{
+- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
self.indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
@@ -100,8 +101,8 @@ - (void)dismissView {
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UIButton class]])
return NO;
+
return YES;
}
-
-@end
+@end
View
2 src/categories/UIImage+AGImageChecker.h
@@ -18,4 +18,4 @@
- (BOOL)isEmptyImage;
-@end
+@end
View
32 src/categories/UIImage+AGImageChecker.m
@@ -33,20 +33,25 @@ + (void)stopSavingNames {
//Code based on http://stackoverflow.com/questions/3284185/get-pixel-color-of-uiimage
- (BOOL)isEmptyImage {
if (CGSizeEqualToSize(self.size, CGSizeZero)) return YES;
-
+
//Interface Builder sets a 1x1 image when no image found. 0 for every component (RGBA)
if (CGSizeEqualToSize(self.size, CGSizeMake(1, 1))) {
CGImageRef image = [self CGImage];
+
if (image == NULL) return NO;
-
+
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(image));
+
if (data == NULL) return NO;
-
+
CFIndex length = CFDataGetLength(data);
+
if (length < 4) return NO;
- const UInt32 *buffer = (UInt32 *) CFDataGetBytePtr(data);
+
+ const UInt32 *buffer = (UInt32 *)CFDataGetBytePtr(data);
return *buffer == 0;
}
+
return NO;
}
@@ -58,17 +63,17 @@ + (void)swizzle {
Method imagedNamedOriginal = class_getClassMethod(self, @selector(imageNamed:));
Method imagedNamedCustom = class_getClassMethod(self, @selector(imageNamedCustom:));
method_exchangeImplementations(imagedNamedOriginal, imagedNamedCustom);
-
+
//Swizzle the original imageWithContentsOfFile method to add our own calls
Method imageWithContentsOfFileOriginal = class_getClassMethod(self, @selector(imageWithContentsOfFile:));
Method imageWithContentsOfFileCustom = class_getClassMethod(self, @selector(imageWithContentsOfFileCustom:));
method_exchangeImplementations(imageWithContentsOfFileOriginal, imageWithContentsOfFileCustom);
-
+
//Swizzle the original resizableImageWithCapInsetsCustom method to add our own calls
Method resizableImageWithCapInsetsOriginal = class_getInstanceMethod(self, @selector(resizableImageWithCapInsets:));
Method resizableImageWithCapInsetsCustom = class_getInstanceMethod(self, @selector(resizableImageWithCapInsetsCustom:));
method_exchangeImplementations(resizableImageWithCapInsetsOriginal, resizableImageWithCapInsetsCustom);
-
+
//Swizzle the original resizableImageWithCapInsetsCustom method to add our own calls
Method stretchableImageWithLeftCapWidthOriginal = class_getInstanceMethod(self, @selector(stretchableImageWithLeftCapWidth:topCapHeight:));
Method stretchableImageWithLeftCapWidthCustom = class_getInstanceMethod(self, @selector(stretchableImageWithLeftCapWidthCustom:topCapHeight:));
@@ -79,30 +84,36 @@ + (void)swizzle {
#if AGIMAGECHECKER
+ (UIImage *)imageNamedCustom:(NSString *)name {
UIImage *image = [self imageNamedCustom:name];
+
if (image == nil) {
- image = [[UIImage alloc] init];
+ image = [[UIImage alloc] init];
}
+
image.name = name;
return image;
}
+ (UIImage *)imageWithContentsOfFileCustom:(NSString *)path {
UIImage *image = [self imageWithContentsOfFileCustom:path];
+
if (image == nil) {
image = [[UIImage alloc] init];
}
+
image.name = path;
return image;
}
- (UIImage *)resizableImageWithCapInsetsCustom:(UIEdgeInsets)capInsets {
UIImage *image = [self resizableImageWithCapInsetsCustom:capInsets];
+
image.name = self.name;
return image;
}
- (UIImage *)stretchableImageWithLeftCapWidthCustom:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight {
UIImage *image = [self stretchableImageWithLeftCapWidthCustom:leftCapWidth topCapHeight:topCapHeight];
+
image.name = self.name;
return image;
}
@@ -111,7 +122,7 @@ - (UIImage *)stretchableImageWithLeftCapWidthCustom:(NSInteger)leftCapWidth topC
#pragma mark Properties
-static void * const kMyAssociatedNameKey = (void*)&kMyAssociatedNameKey;
+static void *const kMyAssociatedNameKey = (void *)&kMyAssociatedNameKey;
- (NSString *)name {
return (NSString *)objc_getAssociatedObject(self, kMyAssociatedNameKey);
}
@@ -122,5 +133,4 @@ - (void)setName:(NSString *)name {
[self didChangeValueForKey:@"name"];
}
-
-@end
+@end
View
6 src/categories/UIImageView+AGImageChecker.h
@@ -15,9 +15,9 @@ typedef enum {
AGImageCheckerIssuePartiallyHidden = 1 << 4,
AGImageCheckerIssueMissaligned = 1 << 5,
AGImageCheckerIssueMissing = 1 << 6
-}AGImageCheckerIssue;
+} AGImageCheckerIssue;
-typedef void(^AGImageViewHandler)(UIImageView *imageView);
+typedef void (^AGImageViewHandler)(UIImageView * imageView);
@interface UIImageView (AGImageChecker)
@@ -28,4 +28,4 @@ typedef void(^AGImageViewHandler)(UIImageView *imageView);
+ (void)setImageIssuesHandler:(AGImageViewHandler)handler;
+ (void)setImageCheckHandler:(AGImageViewHandler)handler;
-@end
+@end
View
38 src/categories/UIImageView+AGImageChecker.m
@@ -47,27 +47,27 @@ + (void)swizzle {
//Swizzle the original setImage method to add our own calls
Method setImageOriginal = class_getInstanceMethod(self, @selector(setImage:));
Method setImageCustom = class_getInstanceMethod(self, @selector(setImageCustom:));
- method_exchangeImplementations(setImageOriginal, setImageCustom);
-
+ method_exchangeImplementations(setImageOriginal, setImageCustom);
+
//Swizzle the original setFrame method to add our own calls
Method setFrameOriginal = class_getInstanceMethod(self, @selector(setFrame:));
Method setFrameCustom = class_getInstanceMethod(self, @selector(setFrameCustom:));
- method_exchangeImplementations(setFrameOriginal, setFrameCustom);
-
+ method_exchangeImplementations(setFrameOriginal, setFrameCustom);
+
//Swizzle the original setContentMode method to add our own calls
Method setContentModeOriginal = class_getInstanceMethod(self, @selector(setContentMode:));
Method setContentModeCustom = class_getInstanceMethod(self, @selector(setContentModeCustom:));
- method_exchangeImplementations(setContentModeOriginal, setContentModeCustom);
-
+ method_exchangeImplementations(setContentModeOriginal, setContentModeCustom);
+
//Swizzle the original initWithCoder method to add our own calls
Method initWithCoderOriginal = class_getInstanceMethod(self, @selector(initWithCoder:));
Method initWithCoderCustom = class_getInstanceMethod(self, @selector(initWithCoderCustom:));
- method_exchangeImplementations(initWithCoderOriginal, initWithCoderCustom);
-
+ method_exchangeImplementations(initWithCoderOriginal, initWithCoderCustom);
+
//Swizzle the original layoutSubviews method to add our own calls
Method setLayoutSubviewsOriginal = class_getInstanceMethod(self, @selector(layoutSubviews));
Method setLayoutSubviewsCustom = class_getInstanceMethod(self, @selector(layoutSubviewsCustom));
- method_exchangeImplementations(setLayoutSubviewsOriginal, setLayoutSubviewsCustom);
+ method_exchangeImplementations(setLayoutSubviewsOriginal, setLayoutSubviewsCustom);
#endif
}
@@ -76,7 +76,8 @@ - (void)setImageCustom:(UIImage *)image {
if ([self isKindOfClass:[UIImageView class]]) {
UIImage *oldImage = self.image;
//Call the original method (was swizzled)
- [self setImageCustom:image];
+ [self setImageCustom:image];
+
if (image != oldImage) {
if (sCheckHandler) {
sCheckHandler(self);
@@ -89,7 +90,8 @@ - (void)setFrameCustom:(CGRect)frame {
if ([self isKindOfClass:[UIImageView class]]) {
CGRect oldFrame = self.frame;
//Call the original method (was swizzled)
- [self setFrameCustom:frame];
+ [self setFrameCustom:frame];
+
if (!CGRectEqualToRect(frame, oldFrame)) {
if (sCheckHandler) {
sCheckHandler(self);
@@ -102,7 +104,8 @@ - (void)setContentModeCustom:(UIViewContentMode)mode {
if ([self isKindOfClass:[UIImageView class]]) {
UIViewContentMode oldMode = self.contentMode;
//Call the original method (was swizzled)
- [self setContentModeCustom:mode];
+ [self setContentModeCustom:mode];
+
if (mode != oldMode) {
if (sCheckHandler) {
sCheckHandler(self);
@@ -114,18 +117,21 @@ - (void)setContentModeCustom:(UIViewContentMode)mode {
- (id)initWithCoderCustom:(NSCoder *)aDecoder {
if ([self isKindOfClass:[UIImageView class]]) {
//Call the original method (was swizzled)
- self = [self initWithCoderCustom:aDecoder];
+ self = [self initWithCoderCustom:aDecoder];
+
if (sCheckHandler) {
sCheckHandler(self);
}
}
+
return self;
}
- (void)layoutSubviewsCustom {
if ([self isKindOfClass:[UIImageView class]]) {
//Call the original method (was swizzled)
[self layoutSubviewsCustom];
+
if (sCheckHandler) {
sCheckHandler(self);
}
@@ -136,18 +142,20 @@ - (void)layoutSubviewsCustom {
#pragma mark Properties
-static void * const kMyAssociatedIssuesKey = (void*)&kMyAssociatedIssuesKey;
+static void *const kMyAssociatedIssuesKey = (void *)&kMyAssociatedIssuesKey;
- (AGImageCheckerIssue)issues {
return (AGImageCheckerIssue)[(NSNumber *)objc_getAssociatedObject(self, kMyAssociatedIssuesKey) intValue];
}
- (void)setIssues:(AGImageCheckerIssue)issues {
[self willChangeValueForKey:@"issues"];
objc_setAssociatedObject(self, kMyAssociatedIssuesKey, [NSNumber numberWithInt:issues], OBJC_ASSOCIATION_RETAIN);
+
if (sIssuesHandler) {
sIssuesHandler(self);
}
+
[self didChangeValueForKey:@"issues"];
}
-@end
+@end
View
2 src/plugins/AGImageCheckerPluginProtocol.h
@@ -24,4 +24,4 @@
- (UIView *)detailForViewController:(AGImageDetailViewController *)viewController withImageView:(UIImageView *)imageView withIssues:(AGImageCheckerIssue)issues;
-@end
+@end
View
2 src/plugins/base/AGImageCheckerBaseDetailView.h
@@ -24,4 +24,4 @@
- (id)initWithImageView:(UIImageView *)targetImageView andIssues:(AGImageCheckerIssue)targetIssues andWidth:(CGFloat)width;
-@end
+@end
View
22 src/plugins/base/AGImageCheckerBaseDetailView.m
@@ -13,7 +13,7 @@
static NSInteger titleWidth = 120;
static NSInteger padding = 10;
-@interface AGImageCheckerBaseDetailView()
+@interface AGImageCheckerBaseDetailView ()
@property (readwrite, strong) UILabel *imageViewPositionLabel;
@property (readwrite, strong) UILabel *imageViewSizeLabel;
@@ -48,6 +48,7 @@ - (id)initWithImageView:(UIImageView *)targetImageView andIssues:(AGImageChecker
if (self) {
self.maxPoint = CGPointMake(padding, padding);
NSString *imageName = targetImageView.accessibilityLabel;
+
if ([imageName length] <= 0) {
imageName = targetImageView.image.name;
}
@@ -72,6 +73,7 @@ - (id)initWithImageView:(UIImageView *)targetImageView andIssues:(AGImageChecker
- (UILabel *)addLabelWithTitle:(NSString *)title andText:(NSString *)text {
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(padding, maxPoint.y, titleWidth, 22)];
+
titleLabel.textColor = [UIColor grayColor];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = title;
@@ -86,12 +88,11 @@ - (UILabel *)addLabelWithTitle:(NSString *)title andText:(NSString *)text {
[label sizeToFit];
[self addSubview:label];
- maxPoint.y += MAX(22, label.frame.size.height) + (int) (padding / 2);
+ maxPoint.y += MAX(22, label.frame.size.height) + (int)(padding / 2);
maxPoint.x = MAX(maxPoint.x, CGRectGetMaxX(label.frame) + padding);
return label;
}
-
- (UIImageView *)addImageViewWithTitle:(NSString *)title andImage:(UIImage *)image andSize:(CGSize)size andMode:(UIViewContentMode)mode {
[self addLabelWithTitle:title andText:@""];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(padding, maxPoint.y, size.width, size.height)];
@@ -107,7 +108,6 @@ - (UIImageView *)addImageViewWithTitle:(NSString *)title andImage:(UIImage *)ima
return imageView;
}
-
- (NSArray *)descriptionsForIssues:(AGImageCheckerIssue)issues {
NSMutableArray *issuesDescriptions = [[NSMutableArray alloc] initWithCapacity:6];
@@ -118,40 +118,50 @@ - (NSArray *)descriptionsForIssues:(AGImageCheckerIssue)issues {
if (issues & AGImageCheckerIssueResized) {
[issuesDescriptions addObject:@"Image resized"];
}
+
if (issues & AGImageCheckerIssueBlurry) {
[issuesDescriptions addObject:@"Image may be blurry"];
}
+
if (issues & AGImageCheckerIssueStretched) {
[issuesDescriptions addObject:@"Image is streteched"];
}
+
if (issues & AGImageCheckerIssuePartiallyHidden) {
[issuesDescriptions addObject:@"Image may be partially hidden"];
}
+
if (issues & AGImageCheckerIssueMissaligned) {
[issuesDescriptions addObject:@"Image is missaligned"];
}
+
if (issues & AGImageCheckerIssueMissing) {
[issuesDescriptions addObject:@"Image not found"];
}
}
+
return issuesDescriptions;
}
- (id)controllerForView:(UIView *)view {
id responder = view;
UIView *superview = view.superview;
+
while ((responder = [responder nextResponder])) {
- if (responder != superview){
+ if (responder != superview) {
return responder;
}
+
superview = [responder superview];
}
+
return responder;
}
- (NSString *)contentModeToString:(UIViewContentMode)mode {
static NSArray *modes = nil;
static dispatch_once_t modesToken;
+
dispatch_once(&modesToken, ^{
modes = [NSArray arrayWithObjects:
@"UIViewContentModeScaleToFill",
@@ -172,4 +182,4 @@ - (NSString *)contentModeToString:(UIViewContentMode)mode {
return [modes objectAtIndex:mode];
}
-@end
+@end
View
2 src/plugins/base/AGImageCheckerBasePlugin.h
@@ -11,4 +11,4 @@
@interface AGImageCheckerBasePlugin : NSObject <AGImageCheckerPluginProtocol>
-@end
+@end
View
23 src/plugins/base/AGImageCheckerBasePlugin.m
@@ -16,13 +16,12 @@
#define CGSizeIsBiggerThan(size1, size2) ((size1.width > size2.width) || (size1.height > size2.height))
#define CGSizeIsStrictlyBiggerThan(size1, size2) ((size1.width > size2.width) && (size1.height > size2.height))
#define CGSizeIsProportionalTo(size1, size2) ((size1.width / size2.width) == (size1.height / size2.height))
-#define floatIsDecimal(num) (num - ((int) num) != 0.0f)
+#define floatIsDecimal(num) (num - ((int)num) != 0.0f)
@implementation AGImageCheckerBasePlugin
- (AGImageCheckerIssue)calculateIssues:(UIImageView *)imageView withIssues:(AGImageCheckerIssue)issues {
-
//Check Missing images
if (imageView.image == nil || [imageView.image isEmptyImage]) {
issues = AGImageCheckerIssueMissing;
@@ -42,10 +41,12 @@ - (AGImageCheckerIssue)calculateIssues:(UIImageView *)imageView withIssues:(AGIm
if ((imgSize.width != viewSize.width) || (imgSize.height != viewSize.height)) {
issues |= AGImageCheckerIssueResized;
}
+
if (CGSizeIsBiggerThan(viewSize, imgSize)) {
issues |= AGImageCheckerIssueBlurry;
}
- if (!CGSizeIsProportionalTo(viewSize, imgSize)){
+
+ if (!CGSizeIsProportionalTo(viewSize, imgSize)) {
issues |= AGImageCheckerIssuePartiallyHidden;
}
}
@@ -66,7 +67,8 @@ - (AGImageCheckerIssue)calculateIssues:(UIImageView *)imageView withIssues:(AGIm
else if (CGSizeIsBiggerThan(imgSize, viewSize)) {
issues |= AGImageCheckerIssueResized;
}
- if (!CGSizeIsProportionalTo(viewSize, imgSize)){
+
+ if (!CGSizeIsProportionalTo(viewSize, imgSize)) {
issues |= AGImageCheckerIssueStretched;
}
}
@@ -79,6 +81,7 @@ - (AGImageCheckerIssue)calculateIssues:(UIImageView *)imageView withIssues:(AGIm
if (imageView.contentMode == UIViewContentModeCenter) {
CGFloat deltaX = (imgSize.width - viewSize.width) / 2.0;
CGFloat deltaY = (imgSize.height - viewSize.height) / 2.0;
+
if ((floatIsDecimal(deltaX)) || (floatIsDecimal(deltaY))) {
issues |= AGImageCheckerIssueBlurry;
issues |= AGImageCheckerIssueMissaligned;
@@ -92,14 +95,17 @@ - (AGImageCheckerIssue)calculateIssues:(UIImageView *)imageView withIssues:(AGIm
//Note: we can not check the image against the window because it may be in a scrollview, animating, with a float contentOffset, but that is correct if the image is correctly aligned within the scroll
if (!(issues & AGImageCheckerIssueMissaligned)) {
UIView *view = imageView;
+
while (view) {
//Check if the view is correctly aligned
CGPoint viewPosition = view.frame.origin;
+
if ((floatIsDecimal(viewPosition.x)) || (floatIsDecimal(viewPosition.y))) {
issues |= AGImageCheckerIssueBlurry;
issues |= AGImageCheckerIssueMissaligned;
break;
}
+
view = view.superview;
}
}
@@ -109,6 +115,7 @@ - (AGImageCheckerIssue)calculateIssues:(UIImageView *)imageView withIssues:(AGIm
- (void)didFinishCalculatingIssues:(UIImageView *)imageView {
AGImageCheckerIssue issues = imageView.issues;
+
imageView.layer.borderWidth = 0;
imageView.layer.borderColor = nil;
@@ -131,6 +138,7 @@ - (void)didFinishCalculatingIssues:(UIImageView *)imageView {
if (issues & AGImageCheckerIssueMissing) {
imageView.layer.borderWidth = 4;
imageView.layer.borderColor = [UIColor redColor].CGColor;
+
if (imageView.image.name) {
NSLog(@"[AGImageChecker] Could not load the image named \"%@\"", imageView.image.name);
}
@@ -139,12 +147,13 @@ - (void)didFinishCalculatingIssues:(UIImageView *)imageView {
}
- (UIView *)detailForViewController:(UIViewController *)viewController
- withImageView:(UIImageView *)imageView
- withIssues:(AGImageCheckerIssue)issues {
+ withImageView:(UIImageView *)imageView
+ withIssues:(AGImageCheckerIssue)issues {
AGImageCheckerBaseDetailView *detailView = [[AGImageCheckerBaseDetailView alloc] initWithImageView:imageView
andIssues:issues
andWidth:viewController.view.frame.size.width];
+
return detailView;
}
-@end
+@end
View
2 src/plugins/dropbox/AGImageCheckerDropboxPlugin.h
@@ -14,4 +14,4 @@
+ (void)addPluginWithAppKey:(NSString *)appKey appSecret:(NSString *)appSecret;
+ (BOOL)handleOpenURL:(NSURL *)url;
-@end
+@end
View
53 src/plugins/dropbox/AGImageCheckerDropboxPlugin.m
@@ -30,34 +30,38 @@ @implementation AGImageCheckerDropboxPlugin
@synthesize targetImageView;
static AGImageCheckerDropboxPlugin *pluginInstance = nil;
-+ (void)addPluginWithAppKey:(NSString *)appKey appSecret:(NSString *)appSecret {
++ (void)addPluginWithAppKey:(NSString *)appKey appSecret:(NSString *)appSecret {
static dispatch_once_t onceToken;
+
dispatch_once(&onceToken, ^{
pluginInstance = [[self alloc] initWithAppKey:appKey appSecret:appSecret];
- });
+ });
[[AGImageChecker sharedInstance] addPlugin:pluginInstance];
}
-
-+ (BOOL)handleOpenURL:(NSURL *)url {
++ (BOOL)handleOpenURL:(NSURL *)url {
if ([[DBSession sharedSession] handleOpenURL:url]) {
if (![[DBSession sharedSession] isLinked]) {
- NSLog(@"Problem login with Dropbox!");
+ NSLog(@"Problem login with Dropbox!");
}
+
[pluginInstance.detailController refreshContentView];
return YES;
}
+
return NO;
}
- (id)initWithAppKey:(NSString *)appKey appSecret:(NSString *)appSecret {
self = [super init];
+
if (self) {
- DBSession* dbSession = [[AGDBSession alloc] initWithAppKey:appKey
- appSecret:appSecret
- root:kDBRootAppFolder];
+ DBSession *dbSession = [[AGDBSession alloc] initWithAppKey:appKey
+ appSecret:appSecret
+ root:kDBRootAppFolder];
[DBSession setSharedSession:dbSession];
}
+
return self;
}
@@ -67,13 +71,15 @@ - (void)didFinishCalculatingIssues:(UIImageView *)imageView {
if ([imageView localDropboxImageExists]) {
if (imageView.originalImage == nil) {
UIImage *image = [UIImage imageWithContentsOfFile:[imageView localDropboxImagePath]];
+
if (image) {
imageView.originalImage = imageView.image;
imageView.image = image;
}
}
else {
imageView.layer.borderWidth = 1;
+
if (imageView.issues) {
imageView.layer.borderColor = [UIColor colorWithRed:0.5 green:0 blue:1 alpha:1].CGColor;
}
@@ -97,13 +103,14 @@ - (UIView *)detailForViewController:(AGImageDetailViewController *)viewControlle
AGImageCheckerDropboxView *detailView = [[AGImageCheckerDropboxView alloc] initWithImageView:imageView
andIssues:issues
andWidth:viewController.view.frame.size.width];
+
detailView.uploadOriginalHandler = ^(UIImageView *imageView) {
[self uploadToDropbox:imageView original:YES];
};
detailView.uploadRenderedHandler = ^(UIImageView *imageView) {
[self uploadToDropbox:imageView original:NO];
};
-
+
detailView.downloadHandler = ^(UIImageView *imageView) {
[self downloadFromDropbox:imageView];
};
@@ -129,10 +136,12 @@ - (UIView *)detailForViewController:(AGImageDetailViewController *)viewControlle
- (void)uploadToDropbox:(UIImageView *)imageView original:(BOOL)original {
NSString *remotePath = [imageView dropboxImagePath];
+
if (remotePath) {
[detailController.indicator startAnimating];
detailController.view.userInteractionEnabled = NO;
UIImage *image = nil;
+
if (original) {
image = imageView.image;
}
@@ -141,17 +150,19 @@ - (void)uploadToDropbox:(UIImageView *)imageView original:(BOOL)original {
renderedImageView.image = imageView.image;
renderedImageView.contentMode = imageView.contentMode;
renderedImageView.clipsToBounds = YES;
- image = [self imageWithView:renderedImageView];
+ image = [self imageWithView:renderedImageView];
}
+
NSString *tempImagePath = [self saveImageIntoTemporaryLocation:image];
NSString *destDir = @"/";
[self.dbClient uploadFile:remotePath toPath:destDir
withParentRev:nil fromPath:tempImagePath];
- }
+ }
}
- (void)downloadFromDropbox:(UIImageView *)imageView {
NSString *remotePath = [imageView dropboxImagePath];
+
if (remotePath) {
[detailController.indicator startAnimating];
detailController.view.userInteractionEnabled = NO;
@@ -160,11 +171,12 @@ - (void)downloadFromDropbox:(UIImageView *)imageView {
NSString *directory = [localPath stringByDeletingLastPathComponent];
[[NSFileManager defaultManager] createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:nil];
[self.dbClient loadFile:remotePath intoPath:localPath];
- }
+ }
}
- (void)removeFromLocalStorage:(UIImageView *)imageView {
NSString *localImagePath = [imageView localDropboxImagePath];
+
[[NSFileManager defaultManager] removeItemAtPath:localImagePath error:nil];
[self didFinishCalculatingIssues:imageView];
[detailController refreshContentView];
@@ -188,14 +200,15 @@ - (void)logoutFromDropbox {
- (UIImage *)imageWithView:(UIView *)view {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
- UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
+ UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
- (NSString *)saveImageIntoTemporaryLocation:(UIImage *)image {
NSString *randomPath = [NSString stringWithFormat:@"%@%d.png", NSTemporaryDirectory(), rand()];
NSData *binaryImageData = UIImagePNGRepresentation(image);
+
[binaryImageData writeToFile:randomPath atomically:YES];
return randomPath;
}
@@ -207,33 +220,33 @@ - (DBRestClient *)dbClient {
dbClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
dbClient.delegate = self;
}
+
return dbClient;
}
#pragma mark DBRestClientDelegate
-- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)destPath {
+- (void)restClient:(DBRestClient *)client loadedFile:(NSString *)destPath {
[self didFinishCalculatingIssues:targetImageView];
[detailController refreshContentView];
[detailController.indicator stopAnimating];
detailController.view.userInteractionEnabled = YES;
}
-- (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error {
+- (void)restClient:(DBRestClient *)client loadFileFailedWithError:(NSError *)error {
[detailController.indicator stopAnimating];
detailController.view.userInteractionEnabled = YES;
}
-- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath from:(NSString*)srcPath
- metadata:(DBMetadata*)metadata {
+- (void)restClient:(DBRestClient *)client uploadedFile:(NSString *)destPath from:(NSString *)srcPath
+ metadata:(DBMetadata *)metadata {
[detailController.indicator stopAnimating];
detailController.view.userInteractionEnabled = YES;
}
-- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error {
+- (void)restClient:(DBRestClient *)client uploadFileFailedWithError:(NSError *)error {
[detailController.indicator stopAnimating];
detailController.view.userInteractionEnabled = YES;
}
-
-@end
+@end
View
2 src/plugins/dropbox/AGImageCheckerDropboxView.h
@@ -28,4 +28,4 @@
- (id)initWithImageView:(UIImageView *)targetImageView andIssues:(AGImageCheckerIssue)targetIssues andWidth:(CGFloat)width;
- (void)updateStatusWithLogin:(BOOL)logged;
-@end
+@end
View
17 src/plugins/dropbox/AGImageCheckerDropboxView.m
@@ -12,7 +12,7 @@
@interface AGImageCheckerDropboxView ()
-@property(nonatomic, strong) UIImageView *imageView;
+@property (nonatomic, strong) UIImageView *imageView;
@end
@@ -38,13 +38,13 @@ - (id)initWithImageView:(UIImageView *)targetImageView andIssues:(AGImageChecker
if (self) {
self.imageView = targetImageView;
- UIColor *color = [UIColor colorWithRed:15/255.0f green:102/255.0f blue:162/255.0f alpha:1];
- UIColor *redColor = [UIColor colorWithRed:126/255.0f green:0/255.0f blue:6/255.0f alpha:1];
- UIColor *grayColor = [UIColor colorWithRed:60/255.0f green:60/255.0f blue:60/255.0f alpha:1];
+ UIColor *color = [UIColor colorWithRed:15 / 255.0f green:102 / 255.0f blue:162 / 255.0f alpha:1];
+ UIColor *redColor = [UIColor colorWithRed:126 / 255.0f green:0 / 255.0f blue:6 / 255.0f alpha:1];
+ UIColor *grayColor = [UIColor colorWithRed:60 / 255.0f green:60 / 255.0f blue:60 / 255.0f alpha:1];
loginButton = [self buttonWithFrame:CGRectMake(10, 5, 200, 30) title:@"Login To Dropbox" andColor:color];
[loginButton addTarget:self action:@selector(loginToDropbox) forControlEvents:UIControlEventTouchUpInside];
-
+
uploadOriginalButton = [self buttonWithFrame:CGRectMake(10, 5, 200, 30) title:@"Upload original To Dropbox" andColor:color];
[uploadOriginalButton addTarget:self action:@selector(uploadOriginalToDropbox) forControlEvents:UIControlEventTouchUpInside];
@@ -65,14 +65,15 @@ - (id)initWithImageView:(UIImageView *)targetImageView andIssues:(AGImageChecker
uploadRenderButton.enabled = NO;
downloadButton.enabled = NO;
removeButton.enabled = NO;
- }
+ }
}
return self;
}
- (UIButton *)buttonWithFrame:(CGRect)frame title:(NSString *)title andColor:(UIColor *)color {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
+
button.frame = frame;
[button setTitle:title forState:UIControlStateNormal];
[button setTitleColor:[UIColor colorWithWhite:0.85 alpha:1] forState:UIControlStateNormal];
@@ -129,8 +130,8 @@ - (void)updateStatusWithLogin:(BOOL)logged {
loginButton.hidden = logged;
logoutButton.hidden = !logged;
uploadOriginalButton.hidden = !logged;
- uploadRenderButton.hidden = !logged;
+ uploadRenderButton.hidden = !logged;
downloadButton.hidden = !removeButton.hidden || !logged;
}
-@end
+@end
View
2 src/plugins/dropbox/UIImageView+AGImageCheckerDropbox.h
@@ -16,4 +16,4 @@
- (NSString *)localDropboxImagePath;
- (BOOL)localDropboxImageExists;
-@end
+@end
View
13 src/plugins/dropbox/UIImageView+AGImageCheckerDropbox.m
@@ -16,38 +16,45 @@ @implementation UIImageView (AGImageCheckerDropbox)
- (NSString *)dropboxBasePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
+
return [basePath stringByAppendingPathComponent:@"AGImageChekerDropbox/"];
}
- (NSString *)dropboxImagePath {
NSString *filename = self.accessibilityLabel;
+
if ([filename length] <= 0) {
filename = self.originalImage.name;
+
if (!filename)
filename = self.image.name;
}
+
NSString *basePath = [self dropboxBasePath];
filename = [filename stringByReplacingOccurrencesOfString:basePath withString:@""];
return [[filename stringByReplacingOccurrencesOfString:@"//" withString:@"/"] stringByReplacingOccurrencesOfString:@":" withString:@""];
}
- (NSString *)localDropboxImagePath {
NSString *filename = [self dropboxImagePath];
+
if (!filename)
return nil;
+
return [[self dropboxBasePath] stringByAppendingString:filename];
}
- (BOOL)localDropboxImageExists {
NSString *localImagePath = [self localDropboxImagePath];
+
if (!localImagePath) return NO;
+
return [[NSFileManager defaultManager] fileExistsAtPath:localImagePath];
}
-
#pragma mark Properties
-static void * const kMyAssociatedDropboxKey = (void*)&kMyAssociatedDropboxKey;
+static void *const kMyAssociatedDropboxKey = (void *)&kMyAssociatedDropboxKey;
- (UIImage *)originalImage {
return objc_getAssociatedObject(self, kMyAssociatedDropboxKey);
}
@@ -56,4 +63,4 @@ - (void)setOriginalImage:(UIImage *)originalImage {
objc_setAssociatedObject(self, kMyAssociatedDropboxKey, originalImage, OBJC_ASSOCIATION_RETAIN);
}
-@end
+@end
View
2 src/plugins/dropbox/fixes/AGDBSession.h
@@ -10,4 +10,4 @@
@interface AGDBSession : DBSession
-@end
+@end
View
21 src/plugins/dropbox/fixes/AGDBSession.m
@@ -11,37 +11,38 @@
#include <objc/runtime.h>
#include <objc/message.h>
-@interface DBSession(private)
+@interface DBSession (private)
- (BOOL)appConformsToScheme;
@end
@implementation AGDBSession
- (id) initWithAppKey:(NSString *)key appSecret:(NSString *)secret root:(NSString *)rootParam {
self = [super initWithAppKey:key appSecret:secret root:rootParam];
+
if (self) {
NSAssert([super respondsToSelector:@selector(appConformsToScheme)], @"The Dropbox version used is not compatible with AGImageChecker");
-
+
// Swizzled UIApplication delegate methods to allow opening Dropbox urls in the app even if the Info.plist is not configured
if (![super appConformsToScheme]) {
-
Method method = class_getInstanceMethod([[UIApplication sharedApplication] class], @selector(canOpenURL:));
UIApplication_canOpenURL_original = method_getImplementation(method);
- method_setImplementation(method, (IMP)UIApplication_canOpenURL);
+ method_setImplementation(method, (IMP)UIApplication_canOpenURL);
}
//Handle OpenURL automatically
id appDelegate = [[UIApplication sharedApplication] delegate];
Method method = class_getInstanceMethod([appDelegate class], @selector(application:openURL:sourceApplication:annotation:));
+
if (method) {
UIApplicationDelegate_handleOpenURL_original = method_getImplementation(method);
method_setImplementation(method, (IMP)UIApplicationDelegate_handleOpenURL);
}
else {
class_addMethod([appDelegate class], @selector(application:openURL:sourceApplication:annotation:), (IMP)UIApplicationDelegate_handleOpenURL, "c24@0:4@8@12@16@20");
}
-
}
+
return self;
}
@@ -56,17 +57,19 @@ static BOOL UIApplication_canOpenURL(id self, SEL _cmd, NSURL *url) {
if ([[url scheme] isEqualToString:@"dbapi-1"]) {
return NO;
}
- return (BOOL) UIApplication_canOpenURL_original(self, _cmd, url);
+
+ return (BOOL)UIApplication_canOpenURL_original(self, _cmd, url);
}
static IMP UIApplicationDelegate_handleOpenURL_original;
static BOOL UIApplicationDelegate_handleOpenURL(id self, SEL _cmd, UIApplication *application, NSURL *url, NSString *sourceApplication, id annotation) {
BOOL handled = NO;
+
if (UIApplicationDelegate_handleOpenURL_original) {
- handled = (BOOL) UIApplicationDelegate_handleOpenURL_original(self, _cmd, application, url, sourceApplication, annotation);
+ handled = (BOOL)UIApplicationDelegate_handleOpenURL_original(self, _cmd, application, url, sourceApplication, annotation);
}
+
return [AGImageCheckerDropboxPlugin handleOpenURL:url] || handled;
}
-
-@end
+@end

0 comments on commit f8666cb

Please sign in to comment.
Something went wrong with that request. Please try again.