Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
805 | - | 1 | // |
2 | // PSToggleSwitchSpecifier.m |
||
3 | // InAppSettingsTestApp |
||
4 | // |
||
5 | // Created by David Keegan on 11/21/09. |
||
6 | // Copyright 2009 InScopeApps{+}. All rights reserved. |
||
7 | // |
||
8 | |||
9 | #import "InAppSettingsPSTextFieldSpecifierCell.h" |
||
10 | #import "InAppSettingsConstants.h" |
||
11 | |||
12 | @implementation InAppSettingsPSTextFieldSpecifierCell |
||
13 | |||
14 | @synthesize textField; |
||
15 | |||
16 | #pragma mark helper methods |
||
17 | |||
18 | - (BOOL)isSecure{ |
||
19 | NSNumber *isSecure = [self.setting valueForKey:@"IsSecure"]; |
||
20 | if(!isSecure){ |
||
21 | return NO; |
||
22 | } |
||
23 | return [isSecure boolValue]; |
||
24 | } |
||
25 | |||
26 | - (UIKeyboardType)getKeyboardType{ |
||
27 | NSString *keyboardType = [self.setting valueForKey:@"KeyboardType"]; |
||
28 | if([keyboardType isEqualToString:@"NumbersAndPunctuation"]){ |
||
29 | return UIKeyboardTypeNumbersAndPunctuation; |
||
30 | } |
||
31 | else if([keyboardType isEqualToString:@"NumberPad"]){ |
||
32 | return UIKeyboardTypeNumberPad; |
||
33 | } |
||
34 | else if([keyboardType isEqualToString:@"URL"]){ |
||
35 | return UIKeyboardTypeURL; |
||
36 | } |
||
37 | else if([keyboardType isEqualToString:@"EmailAddress"]){ |
||
38 | return UIKeyboardTypeEmailAddress; |
||
39 | } |
||
40 | |||
41 | return UIKeyboardTypeAlphabet; |
||
42 | } |
||
43 | |||
44 | - (UITextAutocapitalizationType)getAutocapitalizationType{ |
||
45 | //this works, but the real settings don't seem to respect these values eventhough they are in the docs |
||
46 | NSString *autoCapitalizationType = [self.setting valueForKey:@"AutoCapitalizationType"]; |
||
47 | if([autoCapitalizationType isEqualToString:@"Words"]){ |
||
48 | return UITextAutocapitalizationTypeWords; |
||
49 | } |
||
50 | else if([autoCapitalizationType isEqualToString:@"Sentences"]){ |
||
51 | return UITextAutocapitalizationTypeSentences; |
||
52 | } |
||
53 | else if([autoCapitalizationType isEqualToString:@"AllCharacters"]){ |
||
54 | return UITextAutocapitalizationTypeAllCharacters; |
||
55 | } |
||
56 | return UITextAutocapitalizationTypeNone; |
||
57 | } |
||
58 | |||
59 | - (UITextAutocorrectionType)getAutocorrectionType{ |
||
60 | NSString *autocorrectionType = [self.setting valueForKey:@"AutocorrectionType"]; |
||
61 | if([autocorrectionType isEqualToString:@"Yes"]){ |
||
62 | return UITextAutocorrectionTypeYes; |
||
63 | } |
||
64 | else if([autocorrectionType isEqualToString:@"No"]){ |
||
65 | return UITextAutocorrectionTypeNo; |
||
66 | } |
||
67 | return UITextAutocorrectionTypeDefault; |
||
68 | } |
||
69 | |||
70 | - (void)textChangeAction{ |
||
71 | NSNumber* isNumtype = [self.setting valueForKey:InAppSettingsSpecifierInAppNumtype]; |
||
72 | |||
73 | if ( [isNumtype boolValue] ){ |
||
74 | NSNumber* n = [NSNumber numberWithInt:[self.textField.text intValue]]; |
||
75 | [self.setting setValue:n]; |
||
76 | } |
||
77 | else |
||
78 | [self.setting setValue:self.textField.text]; |
||
79 | } |
||
80 | |||
81 | #pragma mark cell controlls |
||
82 | |||
83 | - (void)setValueDelegate:(id)delegate{ |
||
84 | self.textField.delegate = delegate; |
||
85 | [super setValueDelegate:delegate]; |
||
86 | } |
||
87 | |||
88 | - (void)setUIValues{ |
||
89 | [super setUIValues]; |
||
90 | |||
91 | [self setTitle]; |
||
92 | |||
93 | CGRect textFieldFrame = self.textField.frame; |
||
94 | CGSize titleSize = [titleLabel.text sizeWithFont:titleLabel.font]; |
||
95 | textFieldFrame.origin.x = (CGFloat)round(titleSize.width+InAppSettingsTotalTablePadding); |
||
96 | if(textFieldFrame.origin.x < InAppSettingsCellTextFieldMinX){ |
||
97 | textFieldFrame.origin.x = InAppSettingsCellTextFieldMinX; |
||
98 | } |
||
99 | textFieldFrame.origin.y = (CGFloat)round((self.contentView.frame.size.height*0.5f)-(titleSize.height*0.5f))-InAppSettingsOffsetY; |
||
100 | textFieldFrame.size.width = (CGFloat)round((InAppSettingsScreenWidth-(InAppSettingsTotalTablePadding+InAppSettingsCellPadding))-textFieldFrame.origin.x); |
||
101 | textFieldFrame.size.height = titleSize.height; |
||
102 | self.textField.frame = textFieldFrame; |
||
103 | self.textField.text = [[self.setting getValue] description]; |
||
104 | |||
105 | //keyboard traits |
||
106 | self.textField.secureTextEntry = [self isSecure]; |
||
107 | self.textField.keyboardType = [self getKeyboardType]; |
||
108 | self.textField.autocapitalizationType = [self getAutocapitalizationType]; |
||
109 | self.textField.autocorrectionType = [self getAutocorrectionType]; |
||
110 | |||
111 | //these are set here so they are set per cell |
||
112 | //self.textField.delegate = self; |
||
113 | self.valueInput = self.textField; |
||
114 | } |
||
115 | |||
116 | - (void)setupCell{ |
||
117 | [super setupCell]; |
||
118 | |||
119 | //create text field |
||
120 | self.textField =[[UITextField alloc] initWithFrame:CGRectZero]; |
||
121 | self.textField.textColor = InAppSettingsBlue; |
||
122 | self.textField.adjustsFontSizeToFitWidth = YES; |
||
123 | |||
124 | //THIS IS NOT THE BEHAVIOR OF THE SETTINGS APP |
||
125 | //but we need a way to dismiss the keyboard |
||
126 | self.textField.returnKeyType = UIReturnKeyDone; |
||
127 | |||
128 | [self.textField addTarget:self action:@selector(textChangeAction) forControlEvents:UIControlEventEditingChanged]; |
||
129 | [self.contentView addSubview:self.textField]; |
||
130 | } |
||
131 | |||
132 | - (void)dealloc{ |
||
133 | [textField release]; |
||
134 | [super dealloc]; |
||
135 | } |
||
136 | |||
137 | @end |