Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to avoid OCLint warnings. #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Demo/AGWindowViewDemo/oclint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

xcodebuild clean build | tee xcodebuild.log
oclint-xcodebuild
oclint-json-compilation-database -v -- -rc=LONG_LINE=150


81 changes: 38 additions & 43 deletions Source/AGWindowView.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,18 @@ - (id)initAndAddToKeyWindow
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
self = [self initAndAddToWindow:window];
if(self)
{
}
return self;
}

- (void)setup
- (void)setup __attribute__((annotate("oclint:suppress[ivar assignment outside accessors or init]")))
{
_supportedInterfaceOrientations = AGInterfaceOrientationMaskAll;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameOrOrientationChanged:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameOrOrientationChanged:)
name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameOrOrientationChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameOrOrientationChanged:)
name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
}

- (void)dealloc
Expand Down Expand Up @@ -172,7 +171,9 @@ - (void)rotateAccordingToStatusBarOrientationAndSupportedOrientations
}

CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
CGRect frame = [[self class] rectInWindowBounds:self.window.bounds statusBarOrientation:statusBarOrientation statusBarHeight:statusBarHeight];
CGRect frame = [[self class] rectInWindowBounds:self.window.bounds
statusBarOrientation:statusBarOrientation
statusBarHeight:statusBarHeight];

[self setIfNotEqualTransform:transform frame:frame];
}
Expand All @@ -196,10 +197,7 @@ + (CGFloat)getStatusBarHeight
{
return [UIApplication sharedApplication].statusBarFrame.size.width;
}
else
{
return [UIApplication sharedApplication].statusBarFrame.size.height;
}
return [UIApplication sharedApplication].statusBarFrame.size.height;
}

static BOOL IS_BELOW_IOS_7()
Expand All @@ -222,7 +220,9 @@ static BOOL IS_IOS_8_OR_HIGHER()
return answer;
}

+ (CGRect)rectInWindowBounds:(CGRect)windowBounds statusBarOrientation:(UIInterfaceOrientation)statusBarOrientation statusBarHeight:(CGFloat)statusBarHeight
+ (CGRect)rectInWindowBounds:(CGRect)windowBounds
statusBarOrientation:(UIInterfaceOrientation)statusBarOrientation
statusBarHeight:(CGFloat)statusBarHeight
{
CGRect frame = windowBounds;

Expand All @@ -236,33 +236,27 @@ + (CGRect)rectInWindowBounds:(CGRect)windowBounds statusBarOrientation:(UIInterf
return frame;
}

- (UIInterfaceOrientation)desiredOrientation
- (UIInterfaceOrientation)desiredOrientation __attribute__((annotate("oclint:suppress[bitwise operator in conditional]")))
{
UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation];
AGInterfaceOrientationMask statusBarOrientationAsMask = AGInterfaceOrientationMaskFromOrientation(statusBarOrientation);
if(self.supportedInterfaceOrientations & statusBarOrientationAsMask)
{
return statusBarOrientation;
}
else
if(self.supportedInterfaceOrientations & AGInterfaceOrientationMaskPortrait)
{
if(self.supportedInterfaceOrientations & AGInterfaceOrientationMaskPortrait)
{
return UIInterfaceOrientationPortrait;
}
else if(self.supportedInterfaceOrientations & AGInterfaceOrientationMaskLandscapeLeft)
{
return UIInterfaceOrientationLandscapeLeft;
}
else if(self.supportedInterfaceOrientations & AGInterfaceOrientationMaskLandscapeRight)
{
return UIInterfaceOrientationLandscapeRight;
}
else
{
return UIInterfaceOrientationPortraitUpsideDown;
}
return UIInterfaceOrientationPortrait;
}
else if(self.supportedInterfaceOrientations & AGInterfaceOrientationMaskLandscapeLeft)
{
return UIInterfaceOrientationLandscapeLeft;
}
else if(self.supportedInterfaceOrientations & AGInterfaceOrientationMaskLandscapeRight)
{
return UIInterfaceOrientationLandscapeRight;
}
return UIInterfaceOrientationPortraitUpsideDown;
}

- (void)didMoveToWindow
Expand Down Expand Up @@ -292,11 +286,14 @@ - (void)assertCorrectHirearchy
{
if(self.superview != self.window)
{
[NSException raise:NSInternalInconsistencyException format:@"AGWindowView should only be added directly on UIWindow"];
[NSException raise:NSInternalInconsistencyException
format:@"AGWindowView should only be added directly on UIWindow"];
}
if([self.window.subviews indexOfObject:self] == 0)
{
[NSException raise:NSInternalInconsistencyException format:@"AGWindowView is not meant to be first subview on window since UIWindow automatically rotates the first view for you."];
[NSException raise:NSInternalInconsistencyException
format:@"AGWindowView is not meant to be the first subview on window since "
"UIWindow automatically rotates the first view for you."];
}
}
}
Expand All @@ -319,7 +316,8 @@ - (void)addSubViewAndKeepSamePosition:(UIView *)view
{
if(view.superview == nil)
{
[NSException raise:NSInternalInconsistencyException format:@"When calling %s we are expecting the view to be moved is already in a view hierarchy.", __PRETTY_FUNCTION__];
[NSException raise:NSInternalInconsistencyException
format:@"When calling %s we are expecting the view to be moved is already in a view hierarchy.", __PRETTY_FUNCTION__];
}

view.frame = [view convertRect:view.bounds toView:self];
Expand Down Expand Up @@ -446,26 +444,23 @@ + (AGWindowView *)activeWindowViewContainingView:(UIView *)view

@implementation AGWindowViewHelper

BOOL UIInterfaceOrientationsIsForSameAxis(UIInterfaceOrientation o1, UIInterfaceOrientation o2)
BOOL UIInterfaceOrientationsIsForSameAxis(UIInterfaceOrientation orientation1, UIInterfaceOrientation orientation2)
{
if(UIInterfaceOrientationIsLandscape(o1) && UIInterfaceOrientationIsLandscape(o2))
if(UIInterfaceOrientationIsLandscape(orientation1) && UIInterfaceOrientationIsLandscape(orientation2))
{
return YES;
}
else if(UIInterfaceOrientationIsPortrait(o1) && UIInterfaceOrientationIsPortrait(o2))
else if(UIInterfaceOrientationIsPortrait(orientation1) && UIInterfaceOrientationIsPortrait(orientation2))
{
return YES;
}
else
{
return NO;
}
return NO;
}

CGFloat UIInterfaceOrientationAngleBetween(UIInterfaceOrientation o1, UIInterfaceOrientation o2)
CGFloat UIInterfaceOrientationAngleBetween(UIInterfaceOrientation orientation1, UIInterfaceOrientation orientation2)
{
CGFloat angle1 = UIInterfaceOrientationAngleOfOrientation(o1);
CGFloat angle2 = UIInterfaceOrientationAngleOfOrientation(o2);
CGFloat angle1 = UIInterfaceOrientationAngleOfOrientation(orientation1);
CGFloat angle2 = UIInterfaceOrientationAngleOfOrientation(orientation2);

return angle1 - angle2;
}
Expand Down