Skip to content

Commit

Permalink
merging main project
Browse files Browse the repository at this point in the history
  • Loading branch information
kgn committed Nov 8, 2012
2 parents a70efdc + 6e94717 commit 56c7a2f
Show file tree
Hide file tree
Showing 17 changed files with 259 additions and 67 deletions.
6 changes: 3 additions & 3 deletions ApptentiveConnect/ApptentiveConnect.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@
496DC3761333D35600743F65 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0440;
LastUpgradeCheck = 0450;
ORGANIZATIONNAME = "Apptentive, Inc.";
};
buildConfigurationList = 496DC3791333D35600743F65 /* Build configuration list for PBXProject "ApptentiveConnect" */;
Expand Down Expand Up @@ -1059,7 +1059,7 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.2;
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -1077,7 +1077,7 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.2;
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
2 changes: 1 addition & 1 deletion ApptentiveConnect/source/ATConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#import <Cocoa/Cocoa.h>
#endif

#define kATConnectVersionString @"0.4.6"
#define kATConnectVersionString @"0.4.7"

#if TARGET_OS_IPHONE
#define kATConnectPlatformString @"iOS"
Expand Down
6 changes: 5 additions & 1 deletion ApptentiveConnect/source/Controllers/ATFeedbackController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ typedef enum {
UIStatusBarStyle startingStatusBarStyle;
UIImageView *paperclipView;
UIImageView *paperclipBackgroundView;
UIImageView *photoFrameView;
UIView *photoFrameContainerView;
UIControl *photoControl;
UIImage *currentImage;
BOOL showEmailAddressField;
BOOL deleteCurrentFeedbackOnCancel;

UIPanGestureRecognizer *photoPanRecognizer;
CGPoint photoDragOffset;
CGAffineTransform photoFrameTransform;

UIWindow *originalPresentingWindow;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
Expand Down
169 changes: 136 additions & 33 deletions ApptentiveConnect/source/Controllers/ATFeedbackController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
kFeedbackPhotoFrameTag = 402,
kFeedbackPhotoControlTag = 403,
kFeedbackPhotoPreviewTag = 404,
kFeedbackPhotoFrameContainerTag = 405,
kFeedbackPhotoHighlightTag = 406,
kContainerViewTag = 1009,
kATEmailAlertTextFieldTag = 1010,
kFeedbackGradientLayerTag = 1011,
Expand All @@ -57,8 +59,10 @@ - (void)finishUnhide;
- (CGRect)photoControlFrame;
- (CGFloat)attachmentVerticalOffset;
- (void)updateThumbnail;
- (void)updateThumbnailOffsetWithScale:(CGSize)scale;
- (void)sendFeedbackAndDismiss;
- (void)updateSendButtonState;
- (void)photoDragged:(UIPanGestureRecognizer *)recognizer;
@end

@interface ATFeedbackController (Positioning)
Expand Down Expand Up @@ -434,12 +438,11 @@ - (void)teardown {
[paperclipView removeFromSuperview];
[paperclipView release], paperclipView = nil;

[photoFrameView removeFromSuperview];
[photoFrameView release], photoFrameView = nil;

[photoControl removeFromSuperview];
[photoControl release], photoControl = nil;


[photoFrameContainerView removeFromSuperview];
[photoFrameContainerView release], photoFrameContainerView = nil;

[feedbackContainerView release], feedbackContainerView = nil;

Expand Down Expand Up @@ -472,7 +475,10 @@ - (void)setupFeedback {
if (self.emailField && (!self.emailField.text || [@"" isEqualToString:self.emailField.text]) && self.feedback.email) {
self.emailField.text = self.feedback.email;
}
[self updateThumbnail];
if ([self isViewLoaded]) {
// Avoid touching self.view before viewDidLoad.
[self updateThumbnail];
}
}

- (BOOL)shouldReturn:(UIView *)view {
Expand Down Expand Up @@ -574,6 +580,12 @@ - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished c
[self finishHide];
} else if ([animationID isEqualToString:@"windowUnhide"]) {
[self finishUnhide];
} else if ([animationID isEqualToString:@"remove-screenshot"]) {
self.feedback.screenshot = nil;
photoDragOffset = CGPointZero;
[self updateThumbnail];
} else if ([animationID isEqualToString:@"snapback-screenshot"]) {
// do nothing.
}
}

Expand Down Expand Up @@ -670,7 +682,7 @@ - (void)finishUnhide {

- (CGRect)photoControlFrame {
if ([self shouldShowThumbnail] && [self shouldShowPaperclip]) {
return photoFrameView.frame;
return photoFrameContainerView.frame;
} else {
CGRect f = paperclipView.frame;
f.size.height += 10;
Expand All @@ -684,9 +696,12 @@ - (CGFloat)attachmentVerticalOffset {

- (void)updateThumbnail {
@synchronized(self) {
if (photoPanRecognizer) {
[photoPanRecognizer release], photoPanRecognizer = nil;
}
if ([self shouldShowPaperclip]) {
UIImage *image = feedback.screenshot;
UIImageView *thumbnailView = (UIImageView *)[self.view viewWithTag:kFeedbackPhotoPreviewTag];
UIImageView *thumbnailView = nil;

CGRect paperclipBackgroundFrame = paperclipBackgroundView.frame;
paperclipBackgroundFrame.origin.y = [self attachmentVerticalOffset] + 6.0;
Expand All @@ -699,46 +714,59 @@ - (void)updateThumbnail {
if (image == nil) {
[currentImage release], currentImage = nil;

if (thumbnailView != nil) {
[thumbnailView removeFromSuperview];
if (photoFrameContainerView != nil) {
[photoFrameContainerView removeFromSuperview];
[photoFrameContainerView release], photoFrameContainerView = nil;
}
if (photoFrameView != nil) {
[photoFrameView removeFromSuperview];
[photoFrameView release], photoFrameView = nil;
}
photoControl.frame = [self photoControlFrame];
photoControl.transform = paperclipView.transform;
photoControl.frame = [self photoControlFrame];
} else {
if (photoFrameView == nil) {
if (photoFrameContainerView == nil) {
CGRect viewBounds = self.view.bounds;
UIImage *photoFrame = [ATBackend imageNamed:@"at_photo"];
photoFrameView = [[UIImageView alloc] initWithImage:photoFrame];
photoFrameView.frame = CGRectMake(viewBounds.size.width - photoFrame.size.width - 2.0, [self attachmentVerticalOffset], photoFrame.size.width, photoFrame.size.height);
[self.view addSubview:photoFrameView];
UIImage *photoFrameImage = [ATBackend imageNamed:@"at_photo"];
CGRect photoFrameContainerFrame = CGRectMake(viewBounds.size.width - photoFrameImage.size.width - 2.0, [self attachmentVerticalOffset], photoFrameImage.size.width, photoFrameImage.size.height);
photoFrameContainerView = [[UIView alloc] initWithFrame:photoFrameContainerFrame];
photoFrameContainerView.tag = kFeedbackPhotoFrameContainerTag;
[self.view addSubview:photoFrameContainerView];

UIImageView *photoFrameView = [[[UIImageView alloc] initWithImage:photoFrameImage] autorelease];
photoFrameView.tag = kFeedbackPhotoFrameTag;
photoFrameView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;

[photoFrameContainerView addSubview:photoFrameView];
photoFrameContainerView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
}
CGRect photoFrameFrame = photoFrameView.frame;
CGRect photoFrameFrame = photoFrameContainerView.frame;
photoFrameFrame.origin.y = [self attachmentVerticalOffset];
photoFrameView.frame = photoFrameFrame;

photoFrameContainerView.frame = photoFrameFrame;
thumbnailView = (UIImageView *)[photoFrameContainerView viewWithTag:kFeedbackPhotoPreviewTag];
photoFrameTransform = photoFrameContainerView.transform;

if (thumbnailView == nil) {
thumbnailView = [[[UIImageView alloc] init] autorelease];
thumbnailView.tag = kFeedbackPhotoPreviewTag;
thumbnailView.contentMode = UIViewContentModeTop;
thumbnailView.clipsToBounds = YES;
thumbnailView.backgroundColor = [UIColor blackColor];
[self.view addSubview:thumbnailView];

UIView *highlightView = [[[UIView alloc] initWithFrame:thumbnailView.frame] autorelease];
highlightView.tag = kFeedbackPhotoHighlightTag;

//thumbnailView.backgroundColor = [UIColor blackColor];
[photoFrameContainerView addSubview:thumbnailView];
[photoFrameContainerView sendSubviewToBack:thumbnailView];
[photoFrameContainerView addSubview:highlightView];
[photoFrameContainerView bringSubviewToFront:highlightView];

[self.view bringSubviewToFront:paperclipBackgroundView];
[self.view bringSubviewToFront:thumbnailView];
[self.view bringSubviewToFront:photoFrameView];
[self.view bringSubviewToFront:photoFrameContainerView];
[self.view bringSubviewToFront:paperclipView];
[self.view bringSubviewToFront:photoControl];

thumbnailView.transform = CGAffineTransformMakeRotation(DEG_TO_RAD(3.5));
}

photoFrameView.alpha = 1.0;
photoFrameContainerView.alpha = 1.0;

CGFloat scale = [[UIScreen mainScreen] scale];

if (![image isEqual:currentImage]) {
Expand All @@ -756,16 +784,47 @@ - (void)updateThumbnail {
scaledImageSize.width = fitDimension;
}
UIImage *scaledImage = [ATUtilities imageByScalingImage:image toSize:scaledImageSize scale:scale fromITouchCamera:(feedback.imageSource == ATFeedbackImageSourceCamera)];
thumbnailView.bounds = CGRectMake(0.0, 0.0, 70.0, 70.0);
thumbnailView.image = scaledImage;
}
CGRect f = CGRectMake(11.5, 11.5, 70, 70);
f = CGRectOffset(f, photoFrameView.frame.origin.x, photoFrameView.frame.origin.y);
thumbnailView.frame = f;
thumbnailView.bounds = CGRectMake(0.0, 0.0, 70.0, 70.0);
UIView *updatingHighlightView = [photoFrameContainerView viewWithTag:kFeedbackPhotoHighlightTag];
CGRect highlightFrame = thumbnailView.frame;
highlightFrame.origin.x += 5;
highlightFrame.origin.y += 1;
highlightFrame.size.width -= 10;
highlightFrame.size.height -= 1;
updatingHighlightView.frame = highlightFrame;
updatingHighlightView.transform = thumbnailView.transform;

photoControl.frame = [self photoControlFrame];
photoControl.transform = photoFrameView.transform;
photoControl.transform = photoFrameContainerView.transform;

photoPanRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(photoDragged:)];
photoPanRecognizer.minimumNumberOfTouches = 1;
photoPanRecognizer.maximumNumberOfTouches = 1;
photoPanRecognizer.delaysTouchesBegan = YES;
photoPanRecognizer.cancelsTouchesInView = YES;
[photoControl addGestureRecognizer:photoPanRecognizer];
}
}
}
}

- (void)updateThumbnailOffsetWithScale:(CGSize)scale {
@synchronized(self) {
if ([self shouldShowPaperclip]) {
CGAffineTransform newPhotoFrameTransform = photoFrameTransform;
if (!CGPointEqualToPoint(CGPointZero, photoDragOffset)) {
newPhotoFrameTransform = CGAffineTransformTranslate(newPhotoFrameTransform, photoDragOffset.x, photoDragOffset.y);
}
if (!CGSizeEqualToSize(CGSizeZero, scale)) {
newPhotoFrameTransform = CGAffineTransformScale(newPhotoFrameTransform, scale.width, scale.height);
}
photoControl.transform = newPhotoFrameTransform;
photoFrameContainerView.transform = newPhotoFrameTransform;
}
}
}
Expand All @@ -789,6 +848,54 @@ - (void)updateSendButtonState {
self.doneButton.enabled = textLength > 1;
self.doneButton.style = textLength > 1 ? UIBarButtonItemStyleBordered : UIBarButtonItemStyleDone;
}

- (void)photoDragged:(UIPanGestureRecognizer *)recognizer {
CGFloat dragDistance = 75;
if (recognizer == photoPanRecognizer) {
if (recognizer.state == UIGestureRecognizerStateCancelled) {
photoDragOffset = CGPointZero;
[self updateThumbnailOffsetWithScale:CGSizeZero];
} else if (recognizer.state == UIGestureRecognizerStateBegan) {
photoDragOffset = CGPointZero;
[self updateThumbnailOffsetWithScale:CGSizeZero];
} else if (recognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [recognizer translationInView:self.view];
UIView *highlightView = [photoFrameContainerView viewWithTag:kFeedbackPhotoHighlightTag];
translation.x = MIN(8, translation.x);
photoDragOffset = translation;
CGFloat distance = sqrt(photoDragOffset.x*photoDragOffset.x + photoDragOffset.y*photoDragOffset.y);
if (distance > dragDistance) {
highlightView.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.2];
} else {
highlightView.backgroundColor = [UIColor clearColor];
}
[self updateThumbnailOffsetWithScale:CGSizeZero];
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
CGFloat distance = sqrt(photoDragOffset.x*photoDragOffset.x + photoDragOffset.y*photoDragOffset.y);
if (distance > dragDistance) {
[UIView beginAnimations:@"remove-screenshot" context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

[self updateThumbnailOffsetWithScale:CGSizeMake(2, 2)];
photoFrameContainerView.alpha = 0.0;

[UIView commitAnimations];
} else {
[UIView beginAnimations:@"snapback-screenshot" context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

photoDragOffset = CGPointZero;
[self updateThumbnailOffsetWithScale:CGSizeZero];

[UIView commitAnimations];
}
}
}
}
@end


Expand All @@ -799,7 +906,6 @@ - (CGRect)onscreenRectOfView {
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat w = statusBarSize.width;
CGFloat h = statusBarSize.height;
CGFloat topPadding = 0.0;
if (CGSizeEqualToSize(CGSizeZero, statusBarSize)) {
w = screenBounds.size.width;
h = screenBounds.size.height;
Expand All @@ -813,13 +919,11 @@ - (CGRect)onscreenRectOfView {
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
isLandscape = YES;
topPadding = statusBarSize.width;
windowWidth = h;
break;
case UIInterfaceOrientationPortraitUpsideDown:
case UIInterfaceOrientationPortrait:
default:
topPadding = statusBarSize.height;
windowWidth = w;
break;
}
Expand All @@ -832,7 +936,6 @@ - (CGRect)onscreenRectOfView {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
viewHeight = isLandscape ? 368.0 : 368.0;
originY = isLandscape ? 20.0 : 200;
//viewWidth = isLandscape ? 200.0 : 300.0;
viewWidth = windowWidth - 12*2 - 100.0;
originX = floorf((windowWidth - viewWidth)/2.0);
} else {
Expand Down
7 changes: 5 additions & 2 deletions ApptentiveConnect/source/Misc/ATUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,11 @@ + (NSDate *)dateFromISO8601String:(NSString *)string {
}
NSInteger hours = 0;
NSInteger minutes = 0;
NSInteger seconds = 0;
if (!([scanner scanInteger:&hours] && [scanner scanString:@":" intoString:NULL] && [scanner scanInteger:&minutes])) {
validDate = NO;
break;
}
NSInteger secondsFromGMT = hours*3600 + seconds*60;
NSInteger secondsFromGMT = hours*3600 + minutes*60;
if (!isPositiveOffset) {
secondsFromGMT = secondsFromGMT * -1;
}
Expand Down Expand Up @@ -549,6 +548,10 @@ + (void)setupDateFormatters {
@synchronized(self) {
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *enUSLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
[dateFormatter setLocale:enUSLocale];
[dateFormatter setCalendar:calendar];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
}
}
Expand Down

0 comments on commit 56c7a2f

Please sign in to comment.