-
Notifications
You must be signed in to change notification settings - Fork 12
/
SMFPasscodeController.m
195 lines (158 loc) · 5.62 KB
/
SMFPasscodeController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
// SMFPasscodeController.m
// SMFramework
//
// Created by Thomas on 4/19/09.
// Copyright 2010 Thomas Cool. All rights reserved.
//
// Entry Control frame position by nito
#import "SMFPasscodeController.h"
#import "SMFPreferences.h"
@interface SMFPasscodeController (Private)
-(void)_drawSelf;
-(void) textDidEndEditing: (id) sender;
-(void) textDidChange: (id) sender;
@end
@implementation SMFPasscodeController
@synthesize boxes;
@synthesize initialValue;
@synthesize delegate;
@synthesize key;
@synthesize domain;
@synthesize description;
@synthesize icon;
@synthesize title;
+(SMFPasscodeController *)passcodeWithTitle:(NSString *)t
withDescription:(NSString *)desc
withBoxes:(int)b
withKey:(NSString *)k
withDomain:(NSString *)dom
{
SMFPasscodeController *obj=[[SMFPasscodeController alloc] initWithTitle:t withDescription:desc withBoxes:b withKey:k withDomain:dom];
return [obj autorelease];
}
+(SMFPasscodeController *)passcodeWithTitle:(NSString *)t withDescription:(NSString *)desc withBoxes:(int)b withDelegate:(id)del
{
SMFPasscodeController *obj=[[SMFPasscodeController alloc] initWithTitle:t withDescription:desc withBoxes:b withKey:nil withDomain:nil];
obj.delegate=del;
return [obj autorelease];
}
- (id)initWithTitle:(NSString *)t withDescription:(NSString *)desc withBoxes:(int)b withKey:(NSString *)k withDomain:(NSString *)d
{
self = [super init];
self.delegate = nil;
self.icon=nil;
self.title=t;
self.description=desc;
self.boxes=b;
self.key=k;
self.domain=d;
self.initialValue=0;
return self;
}
- (void) dealloc
{
self.title=nil;
self.delegate=nil;
self.description=nil;
self.key=nil;
self.domain=nil;
self.icon=nil;
[super dealloc];
}
-(void)controlWasActivated
{
[self _drawSelf];
[super controlWasActivated];
}
@end
@implementation SMFPasscodeController (Private)
-(void)_drawSelf
{
/*
* Getting the Master Frame
*/
CGRect master ;
// if ([SMFCompatibilityMethods usingTakeTwoDotThree])
// master = [(BRControl *)[self parent] frame];
// else
master = [self frame];
/*
* Drawing the Header
*/
BRHeaderControl *header = [[BRHeaderControl alloc] init];
[header setTitle:self.title withAttributes:[[BRThemeInfo sharedTheme]menuTitleTextAttributes]];
if(self.icon)
[header setIcon:self.icon horizontalOffset:0.5f kerningFactor:0.2f];
CGRect frame = CGRectMake(master.origin.x,
master.size.height * 0.82f,
master.size.width,
[[BRThemeInfo sharedTheme] listIconHeight]);
[header setFrame:frame];
[self addControl:header];
[header autorelease];
BRTextControl *descriptionText = [[BRTextControl alloc] init];
[descriptionText setText:self.description
withAttributes:[[BRThemeInfo sharedTheme] promptTextAttributes]];
frame.size = [descriptionText renderedSize];
frame.origin.y = master.origin.y + (master.size.height * 0.72f);
frame.origin.x = (master.origin.x+master.size.width)*0.5f-frame.size.width*0.5f+master.origin.x;
[descriptionText setFrame: frame];
[self addControl:descriptionText];
[descriptionText autorelease];
/*
* Passcode Control
*/
BRPasscodeEntryControl *entryControl = [[BRPasscodeEntryControl alloc] initWithNumDigits:self.boxes
userEditable:YES
hideDigits:NO];
/*
* Initial Value
*/
if (self.initialValue!=0) {
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4];
[numberFormatter setFormatWidth: self.boxes];
[numberFormatter setPaddingCharacter: @"0"];
NSNumber *four = [NSNumber numberWithInt:self.initialValue];
NSString * str =[numberFormatter stringFromNumber:four];
[numberFormatter release];
[entryControl setInitialPasscode:str];
}
[entryControl setDelegate:self];
frame.size = [entryControl preferredSizeFromScreenSize:master.size];
frame.origin.y = master.origin.y + (master.size.height * 0.40f);
frame.origin.x = (master.size.width)*0.5f-frame.size.width*((float)self.boxes*0.5f)/((float)self.boxes+0.6f);
[entryControl setFrame:frame];
[self addControl:entryControl];
[entryControl autorelease];
}
#pragma mark entryControl Delegate Methods
- (void) textDidChange: (id) sender
{
if (delegate ) {
if ([delegate respondsToSelector:@selector(passcodeTextDidChange:)])
[delegate passcodeTextDidChange:sender];
else if([delegate respondsToSelector:@selector(textDidChange:)])
[delegate textDidChange:sender];
}
}
- (void) textDidEndEditing: (id) sender
{
if (delegate) {
if ([delegate respondsToSelector:@selector(passcodeTextDidEndEditing:)])
[delegate passcodeTextDidEndEditing:sender];
else if([delegate respondsToSelector:@selector(textDidEndEditing:)])
[delegate textDidEndEditing:sender];
}
else
{
if (key && domain) {
SMFPreferences *p = [[SMFPreferences alloc] initWithPersistentDomainName:domain];
[p setObject:[NSNumber numberWithInt:[[sender stringValue] intValue]] forKey:key];
[p release];
}
[[self stack] popController];
}
}
@end