forked from facebookarchive/three20
/
PlaygroundViewController.m
200 lines (151 loc) · 6.87 KB
/
PlaygroundViewController.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "PlaygroundViewController.h"
#import <Three20Core/NSDataAdditions.h>
static const CGFloat kFramePadding = 10;
static const CGFloat kElementSpacing = 5;
static const CGFloat kGroupSpacing = 10;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation PlaygroundViewController
///////////////////////////////////////////////////////////////////////////////////////////////////
- (CGFloat) addHeader:(NSString*)text yOffset:(CGFloat)yOffset {
UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = text;
label.font = [UIFont systemFontOfSize:20];
label.numberOfLines = 0;
CGRect frame = label.frame;
frame.origin.x = kFramePadding;
frame.origin.y = yOffset;
frame.size.width = 320 - kFramePadding * 2;
frame.size.height = [text sizeWithFont:label.font
constrainedToSize:CGSizeMake(frame.size.width, 10000)].height;
label.frame = frame;
[_scrollView addSubview:label];
yOffset += label.frame.size.height + kElementSpacing;
TT_RELEASE_SAFELY(label);
return yOffset;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (CGFloat) addText:(NSString*)text yOffset:(CGFloat)yOffset {
UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = text;
label.numberOfLines = 0;
CGRect frame = label.frame;
frame.origin.x = kFramePadding;
frame.origin.y = yOffset;
frame.size.width = 320 - kFramePadding * 2;
frame.size.height = [text sizeWithFont:label.font
constrainedToSize:CGSizeMake(frame.size.width, 10000)].height;
label.frame = frame;
[_scrollView addSubview:label];
yOffset += label.frame.size.height + kElementSpacing;
TT_RELEASE_SAFELY(label);
return yOffset;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void) loadView {
[super loadView];
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
_scrollView.autoresizingMask =
UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_scrollView];
CGFloat yOffset = kFramePadding;
yOffset = [self addHeader:NSLocalizedString(@"TTDebug", @"") yOffset:yOffset];
{
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:NSLocalizedString(@"Debug test", @"") forState:UIControlStateNormal];
[button addTarget: self
action: @selector(debugTestAction)
forControlEvents: UIControlEventTouchUpInside];
[button sizeToFit];
CGRect frame = button.frame;
frame.origin.x = kFramePadding;
frame.origin.y = yOffset;
button.frame = frame;
[_scrollView addSubview:button];
yOffset += frame.size.height;
}
yOffset += kGroupSpacing;
yOffset = [self addHeader:NSLocalizedString(@"TTGlobalCoreLocale", @"") yOffset:yOffset];
yOffset = [self addText:[NSString stringWithFormat:NSLocalizedString(@"Current locale: %@", @""),
[TTCurrentLocale()
displayNameForKey:NSLocaleIdentifier
value:[TTCurrentLocale() localeIdentifier]]]
yOffset:yOffset];
yOffset += kGroupSpacing;
yOffset = [self addHeader:NSLocalizedString(@"TTGlobalCorePaths", @"") yOffset:yOffset];
yOffset = [self addText:[NSString stringWithFormat:NSLocalizedString(@"Bundle path: %@", @""),
TTPathForBundleResource(@"Icon.png")]
yOffset:yOffset];
yOffset = [self addText:[NSString stringWithFormat:NSLocalizedString(@"Document path: %@", @""),
TTPathForDocumentsResource(@"document.pdf")]
yOffset:yOffset];
yOffset += kGroupSpacing;
yOffset = [self addHeader:NSLocalizedString(@"NSDataAdditions", @"") yOffset:yOffset];
yOffset = [self addText:[NSString stringWithFormat:NSLocalizedString(@"MD5 Hash of \"Three20\": %@", @""),
[[@"Three20" dataUsingEncoding:NSUTF8StringEncoding] md5Hash]]
yOffset:yOffset];
yOffset += kGroupSpacing;
[_scrollView setContentSize:CGSizeMake(320, yOffset)];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void) viewDidUnload {
[super viewDidUnload];
TT_RELEASE_SAFELY(_scrollView);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[_scrollView flashScrollIndicators];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void) debugTestAction {
#ifdef DEBUG
NSLog(@"Three20 debug logging is currently...ON");
#else
NSLog(@"Three20 debug logging is currently...OFF");
#endif
// This will print the current method name.
TTDPRINTMETHODNAME();
TTDPRINT(@"Showing TTDPRINT.");
TTDPRINT(@"-----------------");
TTDPRINT(@"Showing TTD log levels <= %d", TTMAXLOGLEVEL);
TTDERROR(@"This is TTDERROR, level %d.", TTLOGLEVEL_ERROR);
TTDWARNING(@"This is TTDWARNING, level %d.", TTLOGLEVEL_WARNING);
TTDINFO(@"This is TTDINFO, level %d.", TTLOGLEVEL_INFO);
TTDPRINT(@"");
TTDPRINT(@"Showing TTDCONDITIONLOG.");
TTDPRINT(@"------------------------");
TTDCONDITIONLOG(true, @"This will always display because the condition is \"true\"");
TTDCONDITIONLOG(false, @"This will never display because the condition is \"false\"");
TTDCONDITIONLOG(rand()%2, @"This will randomly display because the condition is \"rand()%2\"");
TTDPRINT(@"");
TTDPRINT(@"Showing TTDASSERT.");
TTDPRINT(@"------------------");
// Should do nothing at all.
TTDASSERT(true);
// This will jump you into the debugger in the simulator.
// Note that this isn't a crash! Simply the equivalent of setting
// a breakpoint in the debugger, but programmatically. These TTDASSERTs
// will be completely stripped away from your final product, assuming
// you don't declare the DEBUG preprocessor macro (and you shouldn't in
// your final product).
TTDASSERT(false);
}
@end