-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTweet3ViewController.m
271 lines (210 loc) · 9.16 KB
/
Tweet3ViewController.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//
// Tweet3ViewController.m
// Tweet3
//
// Created by Stefan Gorzkiewicz on 8/21/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//
#import "Tweet3ViewController.h"
@implementation Tweet3ViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
- (void)viewDidLoad {
[super viewDidLoad];
jsonData = [[NSMutableString alloc] initWithString:@""];
NSString *searchQuery = [NSString stringWithString:@"q=iosdevcamp"];
NSString *urlString = [NSString stringWithFormat:@"http://search.twitter.com/search.json?%@", searchQuery];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection release];
[request release];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSString *partialData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[jsonData appendString:partialData];
[partialData release];
}
/*
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSDictionary *twitterJSON = [jsonData JSONValue];
NSArray *tweets = [twitterJSON objectForKey:@"results"];
NSLog(@"found %d tweets", [tweets count]);
NSDictionary *tweet = [tweets objectAtIndex:0]; // get the last tweet
// textView for Tweet text
CGRect tweetFrame = CGRectMake(40.0, 210.0, 950.0, 250.0);
UITextView *textView = [[UITextView alloc] initWithFrame:tweetFrame];
textView.text = [tweet objectForKey:@"text"];
textView.font = [UIFont fontWithName:@"Arial" size:44.0f];
UIColor *bcolor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
[textView setBackgroundColor: bcolor];
[self.view addSubview:textView];
// end textview
// begin uilabel for user name
CGRect labelFrame = CGRectMake(230.0, 580.0, 200.0, 50.0);
UILabel *userName = [[UILabel alloc] initWithFrame:labelFrame];
userName.text = [tweet objectForKey:@"from_user"];
userName.font = [UIFont fontWithName:@"Arial" size:34.0f];
[userName setBackgroundColor: bcolor];
[self.view addSubview:userName];
// end uilable
// create imageView
NSURL *url = [NSURL URLWithString:[tweet objectForKey:@"profile_image_url"]];
NSData *data = [NSData dataWithContentsOfURL:url];
CGRect Imageframe = CGRectMake(36.0, 574.0, 130.0, 130.0);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:Imageframe];
imageView.image = [UIImage imageWithData:data];
[self.view addSubview:imageView];
// end imageView
[bcolor release];
}
*/
/*
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// version 2
NSDictionary *twitterJSON = [jsonData JSONValue];
NSArray *tweets = [twitterJSON objectForKey:@"results"];
NSLog(@"found %d tweets", [tweets count]);
NSDictionary *tweet = [tweets objectAtIndex:0]; // get the last tweet
// create imageView for tweet text bubble background
CGRect Imageframe2 = CGRectMake(20.0, 196.0, 990.0, 360.0);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:Imageframe2];
NSString *fileLocation = [[NSBundle mainBundle] pathForResource:@"large-speech-bubble" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];
[UIImage imageWithData:imageData];
imageView2.image = [UIImage imageWithData:imageData];
[self.view addSubview:imageView2];
// end bubble background
// create imageView for user image background
CGRect Imageframe3 = CGRectMake(20.0, 562.0, 600.0, 164.0);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:Imageframe3];
NSString *fileLocation3 = [[NSBundle mainBundle] pathForResource:@"user-block-bg" ofType:@"png"];
NSData *imageData3 = [NSData dataWithContentsOfFile:fileLocation3];
[UIImage imageWithData:imageData3];
imageView3.image = [UIImage imageWithData:imageData3];
[self.view addSubview:imageView3];
// end bubble background
// textView for Tweet text
CGRect tweetFrame = CGRectMake(40.0, 210.0, 950.0, 250.0);
UITextView *textView = [[UITextView alloc] initWithFrame:tweetFrame];
textView.text = [tweet objectForKey:@"text"];
textView.font = [UIFont fontWithName:@"Arial" size:44.0f];
UIColor *bcolor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
[textView setBackgroundColor: bcolor];
[self.view addSubview:textView];
// end textview
// begin uilabel for user name
CGRect labelFrame = CGRectMake(230.0, 580.0, 300.0, 50.0);
UILabel *userName = [[UILabel alloc] initWithFrame:labelFrame];
userName.text = [tweet objectForKey:@"from_user"];
userName.font = [UIFont fontWithName:@"Arial" size:34.0f];
[userName setBackgroundColor: bcolor];
[self.view addSubview:userName];
// end uilable
// create imageView
NSURL *url = [NSURL URLWithString:[tweet objectForKey:@"profile_image_url"]];
NSData *data = [NSData dataWithContentsOfURL:url];
CGRect Imageframe = CGRectMake(36.0, 574.0, 130.0, 130.0);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:Imageframe];
imageView.image = [UIImage imageWithData:data];
[self.view addSubview:imageView];
// end imageView
[bcolor release];
}
*/
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// version 2
NSDictionary *twitterJSON = [jsonData JSONValue];
NSArray *tweets = [twitterJSON objectForKey:@"results"];
NSLog(@"found %d tweets", [tweets count]);
NSDictionary *tweet = [tweets objectAtIndex:0]; // get the last tweet
// create imageView for tweet text bubble background
CGRect Imageframe2 = CGRectMake(20.0, 196.0, 990.0, 360.0);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:Imageframe2];
NSString *fileLocation = [[NSBundle mainBundle] pathForResource:@"large-speech-bubble" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];
[UIImage imageWithData:imageData];
imageView2.image = [UIImage imageWithData:imageData];
[self.view addSubview:imageView2];
// end bubble background
// create imageView for user image background
CGRect Imageframe3 = CGRectMake(20.0, 562.0, 600.0, 164.0);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:Imageframe3];
NSString *fileLocation3 = [[NSBundle mainBundle] pathForResource:@"user-block-bg" ofType:@"png"];
NSData *imageData3 = [NSData dataWithContentsOfFile:fileLocation3];
[UIImage imageWithData:imageData3];
imageView3.image = [UIImage imageWithData:imageData3];
[self.view addSubview:imageView3];
// end bubble background
//image view for twitpic
CGRect Imageframe4 = CGRectMake(40.0, 214.0, 940.0, 268.0);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:Imageframe4];
NSString *fileLocation4 = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"];
NSData *imageData4 = [NSData dataWithContentsOfFile:fileLocation4];
[UIImage imageWithData:imageData4];
imageView4.image = [UIImage imageWithData:imageData4];
[self.view addSubview:imageView4];
// end twitpic
// textView for Tweet text
CGRect tweetFrame = CGRectMake(40.0, 400.0, 940.0, 80.0);
UITextView *textView = [[UITextView alloc] initWithFrame:tweetFrame];
textView.text = [tweet objectForKey:@"text"];
textView.font = [UIFont fontWithName:@"Arial" size:26.0f];
UIColor *bcolor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.6];
UIColor *fcolor = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
[textView setBackgroundColor: bcolor];
textView.textColor = fcolor;
[self.view addSubview:textView];
// end textview
// begin uilabel for user name
CGRect labelFrame = CGRectMake(230.0, 580.0, 300.0, 50.0);
UILabel *userName = [[UILabel alloc] initWithFrame:labelFrame];
userName.text = [tweet objectForKey:@"from_user"];
userName.font = [UIFont fontWithName:@"Arial" size:34.0f];
UIColor *bcolor2 = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
[userName setBackgroundColor: bcolor2];
[self.view addSubview:userName];
// end uilable
// create imageView
NSURL *url = [NSURL URLWithString:[tweet objectForKey:@"profile_image_url"]];
NSData *data = [NSData dataWithContentsOfURL:url];
CGRect Imageframe = CGRectMake(36.0, 574.0, 130.0, 130.0);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:Imageframe];
imageView.image = [UIImage imageWithData:data];
[self.view addSubview:imageView];
// end imageView
[bcolor release];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end