-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsEditBlurrinessViewController.m
More file actions
executable file
·138 lines (117 loc) · 4.91 KB
/
SettingsEditBlurrinessViewController.m
File metadata and controls
executable file
·138 lines (117 loc) · 4.91 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
//
// SettingsEditBlurrinessViewController.m
// Junction
//
// Created by Bobby Ren on 4/8/13.
//
//
#import "SettingsEditBlurrinessViewController.h"
#import "AppDelegate.h"
#import "UserInfo.h"
#import "UIImage+Resize.h"
static AppDelegate * appDelegate;
@interface SettingsEditBlurrinessViewController ()
@end
@implementation SettingsEditBlurrinessViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
UIImage * headerbg = [UIImage imageNamed:@"header_bg"];
[self.navigationController.navigationBar setBackgroundImage:headerbg forBarMetrics:UIBarMetricsDefault];
UILabel * titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[titleView setFont:[UIFont boldSystemFontOfSize:23]];
[titleView setTextColor:[UIColor whiteColor]];
[titleView setBackgroundColor:[UIColor colorWithRed:14.0/255.0 green:158.0/255.0 blue:205.0/255.0 alpha:1]];
[titleView setTextAlignment:NSTextAlignmentCenter];
titleView.text = @"Edit Blurriness";
UIFont * font = titleView.font;
CGRect frame = CGRectMake(0, 0, [self.navigationItem.title sizeWithFont:font].width, 44);
frame.origin.x = 320 - frame.size.width / 2;
[titleView setFrame:frame];
self.navigationItem.titleView = titleView;
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"icon-back"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(10, 0, 30, 30)];
UIBarButtonItem * backbutton = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setLeftBarButtonItem:backbutton];
self.view.backgroundColor = COLOR_FAINTBLUE;
UserInfo * userInfo = appDelegate.myUserInfo;
if (!userInfo.photo) {
[appDelegate loadPhotoFromWebWithBlock:^(UIImage * image) {
[photoView setImage:image];
}];
}
[photoView setImage:userInfo.photo];
// privacy level isnt actually saved! only the resulting image!
/*
privacyLevel = userInfo.privacyLevel;
if (privacyLevel > 0) {
[sliderBlur setValue:privacyLevel];
[self sliderDidChangeValue:nil];
}
*/
[sliderBlur setValue:0];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)sliderDidChangeValue:(id)sender {
UISlider * slider = (UISlider*)sender;
int newPrivacyLevel = (int) (slider.value);
//if (newPrivacyLevel == privacyLevel)
// return;
UserInfo * userInfo = appDelegate.myUserInfo;
UIImage * newImage = [appDelegate blurPhoto:userInfo.photo atPrivacyLevel:newPrivacyLevel];
NSLog(@"Privacy changed to level %d", newPrivacyLevel);
userInfo.privacyLevel = newPrivacyLevel;
[photoView setImage:newImage];
}
-(UIImage*)resizeImage:(UIImage*)image byScale:(float)scale {
CGSize frame = image.size;
CGSize target = frame;
target.width *= scale;
target.height *= scale;
UIImage * newImage = [image resizedImage:target interpolationQuality:kCGInterpolationHigh];
return newImage;
}
-(void)goBack:(id)sender {
// save
UserInfo * userInfo = appDelegate.myUserInfo;
userInfo.photoBlur = photoView.image;
[userInfo savePhotoToAWSSerial:userInfo.photo andBlur:userInfo.photoBlur withBlock:^(BOOL saved) {
NSLog(@"Saved image at %@!", userInfo.photoURL);
NSLog(@"Saved blur image at %@!", userInfo.photoBlurURL);
// prevent old images for this user from showing up
[AsyncImageView clearCacheForURL:userInfo.photoURL];
[AsyncImageView clearCacheForURL:userInfo.photoBlurURL];
[[NSNotificationCenter defaultCenter] postNotificationName:kMyUserInfoDidChangeNotification object:nil];
}];
// save thumbnails
CGSize thumbSize = CGSizeMake(BROWSE_THUMB_SIZE, BROWSE_THUMB_SIZE);
UIImage * newImageThumb = [userInfo.photo resizedImage:thumbSize interpolationQuality:kCGInterpolationHigh];
UIImage * newBlurThumb;
if (userInfo.photoBlur.size.width > BROWSE_THUMB_SIZE)
newBlurThumb = [userInfo.photoBlur resizedImage:thumbSize interpolationQuality:kCGInterpolationHigh];
else
newBlurThumb = userInfo.photoBlur;
[userInfo saveThumbsToAWSSerial:newImageThumb andBlur:newBlurThumb withBlock:^(BOOL finished) {
NSLog(@"New thumbnails saved!");
}];
// dismiss
[self.navigationController popViewControllerAnimated:YES];
}
@end