11#import "CredentialsInputController.h"
15- (void)updateScrollViewContentSize;
17- (UIView *)activeCredentialField;
18- (void)setKeyboardOverlap:(CGFloat)overlap notification:(NSNotification *)notification;
23- (id)initWithNibName:(NSString *)nibNameOrNil
24 bundle:(NSBundle *)nibBundleOrNil
26 params:(NSMutableDictionary *)params
28 self = [
super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
33 [
self setModalPresentationStyle:UIModalPresentationFormSheet];
35 [[NSNotificationCenter defaultCenter] addObserver:self
36 selector:@selector(keyboardWillShow:)
37 name:UIKeyboardWillShowNotification
39 [[NSNotificationCenter defaultCenter] addObserver:self
40 selector:@selector(keyboardWillHide:)
41 name:UIKeyboardWillHideNotification
53 setText:NSLocalizedString(
54 @"Please provide the missing user information in order to proceed and login.",
55 @"Credentials input view message")];
57 setPlaceholder:NSLocalizedString(@"Username", @"Credentials Input Username hint")];
59 setPlaceholder:NSLocalizedString(@"Password", @"Credentials Input Password hint")];
61 setPlaceholder:NSLocalizedString(@"Domain", @"Credentials Input Domain hint")];
62 [_btn_login setTitle:NSLocalizedString(@"Login", @"Login Button")
63 forState:UIControlStateNormal];
64 [_btn_cancel setTitle:NSLocalizedString(@"Cancel", @"Cancel Button")
65 forState:UIControlStateNormal];
67 [_scroll_view setKeyboardDismissMode:UIScrollViewKeyboardDismissModeInteractive];
68 [
self updateScrollViewContentSize];
71 [_textfield_username setText:[_params valueForKey:@"username"]];
72 [_textfield_password setText:[_params valueForKey:@"password"]];
73 [_textfield_domain setText:[_params valueForKey:@"domain"]];
76- (void)viewDidLayoutSubviews
78 [
super viewDidLayoutSubviews];
79 [
self updateScrollViewContentSize];
84 [
super viewDidUnload];
87- (void)viewDidDisappear:(BOOL)animated
89 [
super viewDidDisappear:animated];
91 [[_session uiRequestCompleted] signal];
94- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
101 [[NSNotificationCenter defaultCenter] removeObserver:self];
106#pragma mark iOS Keyboard Notification Handlers
108- (void)keyboardWillShow:(NSNotification *)notification
110 CGRect keyboardScreenFrame =
111 [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
112 CGRect keyboardViewFrame = [[
self view] convertRect:keyboardScreenFrame fromView:nil];
113 CGRect overlapRect = CGRectIntersection([[
self view] bounds], keyboardViewFrame);
114 CGFloat overlap = CGRectIsNull(overlapRect) ? 0.0f : CGRectGetHeight(overlapRect);
115 [
self setKeyboardOverlap:overlap notification:notification];
118- (void)keyboardWillHide:(NSNotification *)notification
120 [
self setKeyboardOverlap:0.0f notification:notification];
123- (void)updateScrollViewContentSize
125 CGFloat contentBottom = 0.0f;
126 for (UIView *subview in [_scroll_view subviews])
127 contentBottom = MAX(contentBottom, CGRectGetMaxY([subview frame]));
129 CGSize contentSize = [_scroll_view bounds].size;
130 contentSize.height = MAX(contentSize.height, contentBottom + 20.0f);
131 [_scroll_view setContentSize:contentSize];
134- (UIView *)activeCredentialField
136 if ([_textfield_username isFirstResponder])
137 return _textfield_username;
138 if ([_textfield_password isFirstResponder])
139 return _textfield_password;
140 if ([_textfield_domain isFirstResponder])
141 return _textfield_domain;
145- (void)setKeyboardOverlap:(CGFloat)overlap notification:(NSNotification *)notification
147 NSTimeInterval duration =
148 [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
149 UIViewAnimationCurve curve = (UIViewAnimationCurve)[
150 [[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
151 UIViewAnimationOptions options =
152 UIViewAnimationOptionBeginFromCurrentState | (UIViewAnimationOptions)(curve << 16);
154 [UIView animateWithDuration:duration
158 UIEdgeInsets insets = [_scroll_view contentInset];
159 insets.bottom = overlap;
160 [_scroll_view setContentInset:insets];
161 [_scroll_view setScrollIndicatorInsets:insets];
163 UIView *activeField = [
self activeCredentialField];
166 CGRect visibleRect = [activeField convertRect:[activeField bounds]
167 toView:_scroll_view];
168 visibleRect = CGRectInset(visibleRect, -12.0f, -16.0f);
169 [_scroll_view scrollRectToVisible:visibleRect animated:NO];
175#pragma mark - Action handlers
177- (IBAction)loginPressed:(
id)sender
180 [_params setValue:[_textfield_username text] forKey:@"username"];
181 [_params setValue:[_textfield_password text] forKey:@"password"];
182 [_params setValue:[_textfield_domain text] forKey:@"domain"];
183 [_params setValue:[NSNumber numberWithBool:YES] forKey:@"result"];
186 [
self dismissModalViewControllerAnimated:YES];
189- (IBAction)cancelPressed:(
id)sender
191 [_params setValue:[NSNumber numberWithBool:NO] forKey:@"result"];
194 [
self dismissModalViewControllerAnimated:YES];