-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.m
More file actions
272 lines (198 loc) · 8.53 KB
/
ViewController.m
File metadata and controls
272 lines (198 loc) · 8.53 KB
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
272
//
// ViewController.m
// myKEA
//
// Created by Novall Khan on 11/17/14.
// Copyright (c) 2014 Novall Khan. All rights reserved.
//
#import "ViewController.h"
#import <iAd/iAd.h>
#import "GoogleAnalytics.h"
#import "Theme+Colors.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController () < ADBannerViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet ADBannerView *adBanner;
@property (nonatomic, assign) BOOL isAisleTag;
@end
@implementation ViewController
- (void)viewWillAppear:(BOOL)animated
{
self.adBanner.delegate = self;
self.adBanner.alpha = 0;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.dottedLine1.hidden = NO;
self.isAisleTag = NO;
self.view.backgroundColor = [Theme myKEALightGrey];
[self setUpHolderViews];
self.dottedLine1.frame = CGRectMake(self.buttonHolderView.frame.origin.x,
4,
2,
2);
[UIView animateWithDuration:1.0 animations:^{
self.dottedLine1.frame = CGRectMake(160, 6, 140, 138);
}];
}
- (void)setUpHolderViews
{
NSArray *holderViewArray = @[self.cartHolderView, self.buttonHolderView];
for (UIView *holderView in holderViewArray)
{
holderView.backgroundColor = [UIColor whiteColor];
// Border
[holderView.layer setCornerRadius:5.0f];
[holderView.layer setBorderColor:[Theme myKEABorderColor].CGColor];
[holderView.layer setBorderWidth:1.5f];
// Shadow
[holderView.layer setShadowColor:[UIColor grayColor].CGColor];
[holderView.layer setShadowOpacity:0.9];
[holderView.layer setShadowRadius:3.0];
[holderView.layer setShadowOffset:CGSizeMake(2.0, 2.0)];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Camera Actions
- (IBAction)furnitureButtonPressed:(id)sender {
[GoogleAnalytics trackUIActionCategoryWithAction:GoogleAnalyticsActionCameraButtonPressed
label:GoogleAnalyticsLabelCameraFurnitureActivated];
self.isAisleTag = NO;
[UIView animateWithDuration:0.3 animations:^{
self.dottedLine1.frame = CGRectMake(160, 6, 140, 138);
}];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Oops!"
message:@"This device doesn't seem to have camera."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[myAlertView show];
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self presentViewController:picker animated:YES completion:nil];
});
}
- (IBAction)aisleButtonPressed:(id)sender {
[GoogleAnalytics trackUIActionCategoryWithAction:GoogleAnalyticsActionCameraButtonPressed
label:GoogleAnalyticsLabelCameraRedTagActivated];
[UIView animateWithDuration:0.3 animations:^{
self.dottedLine1.frame = CGRectMake(10, 6, 140, 138);
}];
self.isAisleTag = YES;
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Oops!"
message:@"This device doesn't seem to have a camera."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[myAlertView show];
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self presentViewController:picker animated:YES completion:nil];
});
}
- (IBAction)doneButtonPressed:(id)sender
{
[GoogleAnalytics trackUIActionCategoryWithAction:GoogleAnalyticsActionNewItemAdded
label:GoogleAnalyticsLabelNewItemAddedToCart];
self.isAisleTag = NO;
// Reset
[self.aisleButton setImage:[UIImage imageNamed:@"aisle_tag"] forState:UIControlStateNormal];
[self.furnitureButton setImage:[UIImage imageNamed:@"chairButton"] forState:UIControlStateNormal];
[UIView animateWithDuration:2.0 animations:^{
self.photoImageView1.hidden = NO;
self.photoImageView2.hidden = NO;
// Shrink photoImageView to 0 to give the illusion that the items are being placed in the cart.
self.photoImageView1.frame = CGRectMake([[UIScreen mainScreen]bounds].size.width/2,
self.cartButton.frame.origin.y,
0,
0);
self.photoImageView2.frame = CGRectMake([[UIScreen mainScreen]bounds].size.width/2,
self.cartButton.frame.origin.y,
0,
0);
}];
// [self.photoImageView1 setImage:nil];
// [self.photoImageView2 setImage:nil];
}
#pragma mark - UIImageView Delegate Methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
if (self.isAisleTag == YES)
{
self.photoImageView1.image = chosenImage;
[self.aisleButton setImage:chosenImage forState:UIControlStateNormal];
if (!(self.photoImageView2.image))
{
[UIView animateWithDuration:0.7 animations:^{
self.dottedLine1.frame = CGRectMake(160, 6, 140, 138);
}];
}
}
else
{
self.photoImageView2.image = chosenImage;
[self.furnitureButton setImage:chosenImage forState:UIControlStateNormal];
if (self.isAisleTag == NO)
{
self.dottedLine1.hidden = NO;
}
}
if (self.photoImageView1.image && self.photoImageView2.image)
{
// Display Large dotted line to prompt user to click done.
self.dottedLine1.hidden = YES;
}
self.isAisleTag = NO;
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Text Field Delegate Methods
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[GoogleAnalytics trackUIActionCategoryWithAction:GoogleAnalyticsActionTextAdded
label:GoogleAnalyticsLabelTextFieldActivated];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
self.noteTextField.text = @"";
[self.noteTextField resignFirstResponder];
#warning COMPLETE IMPLEMENTATION - Save note bundled w/ items.
return YES;
}
#pragma mark - Ad Delegate Methods
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(@"Ad Banner did load ad.");
// Show the ad banner.
[UIView animateWithDuration:0.5 animations:^{
self.adBanner.alpha = 1.0;
}];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(@"Unable to show ads. Error: %@", [error localizedDescription]);
// Hide the ad banner.
[UIView animateWithDuration:0.5 animations:^{
self.adBanner.alpha = 0.0;
}];
}
@end