-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLocationEditView.j
300 lines (239 loc) · 17.2 KB
/
LocationEditView.j
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
@implementation LocationEditView : CPView
{
CPTextField locationTitle;
CPPopUpButton locationType;
CPTextField locationAddress;
CPShadowView shadowView;
CPView contentView;
MKMapView map;
CPButton closeButton;
id target;
SEL saveAndCloseAction @accessors;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if (self)
{
var bundle = [CPBundle mainBundle];
shadowView = [[CPShadowView alloc] initWithFrame:CGRectMake(0,0,aFrame.size.width,aFrame.size.height)];
[shadowView setWeight:CPHeavyShadow];
[self addSubview:shadowView];
contentView = [[CPView alloc] initWithFrame:CGRectMake(7, 5, aFrame.size.width - 14, aFrame.size.height - 10)];
[contentView setBackgroundColor:[CPColor colorWithHexString:@"e7eaee"]];
[self addSubview:contentView];
[self setAutoresizingMask:CPViewHeightSizable|CPViewWidthSizable];
[shadowView setAutoresizingMask:CPViewHeightSizable|CPViewWidthSizable];
[contentView setAutoresizingMask:CPViewHeightSizable|CPViewWidthSizable];
//newParentView = [[CPView alloc] initWithFrame:frame];
//var colorImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"content-background.png"] size:CGSizeMake(159,159)];]
locationTitle = [[self class] customTextField];
[locationTitle setStringValue:@""];
[locationTitle setPlaceholderString:@"Location Name"];
[contentView addSubview:locationTitle];
var lineView = [[CPView alloc] initWithFrame:CGRectMake(50,80,425,1)];
[lineView setBackgroundColor:[CPColor colorWithHexString:@"999999"]];
[contentView addSubview:lineView];
locationType = [[CPPopUpButton alloc] initWithFrame:CGRectMake(55, 90, 250, 24)];
[locationType setBordered:NO];
[locationType addItems:[LocationItemTypes menuItems]];
[contentView addSubview:locationType];
locationAddress = [[self class] customMultiLineTextField];
[locationAddress setStringValue:@""];
[locationAddress setDelegate:self];
// [locationAddress setFrame:CGRectMake(50, 130, 425, 60)];
[locationAddress setFont:[CPFont boldSystemFontOfSize:20]];
[locationAddress setPlaceholderString:@"Location Address"];
[contentView addSubview:locationAddress];
map = [[RLMapView alloc] initWithFrame:CGRectMake(635, 15, aFrame.size.width - 700, 300)];
[map setAutoresizingMask:CPViewWidthSizable];
[contentView addSubview:map];
closeButton = [[CPButton alloc] initWithFrame:CGRectMake(5,5,20,21)];
[closeButton setBordered:NO];
[closeButton setImage: [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"CloseButton.png"] size:CGSizeMake(20,21)]];
[closeButton setImagePosition:CPImageOnly];
[closeButton setTarget:self];
[closeButton setAction:@selector(close:)];
[contentView addSubview:closeButton];
var doneButton = [[self class] customBigButton];
// [doneButton setFrame:CGRectMake(100, 300, 150, 44)];
[doneButton setTitle:@"Done"];
[doneButton setTarget:self];
[doneButton setAction:@selector(close:)];
[contentView addSubview:doneButton];
}
return self;
}
// update the views with this data man
- (void)setLocationData:(CPDictionary)aDict
{
[locationTitle setStringValue:[aDict valueForKey:@"name"]];
[locationType selectItemWithTitle:[aDict valueForKey:@"type"]];
[locationAddress setStringValue:[aDict valueForKey:@"address"]];
[map setAddress:[aDict valueForKey:@"address"]];
}
- (CPDictionary)locationData
{
var dictionary = [CPDictionary new];
[dictionary setValue:[locationTitle stringValue] forKey:@"name"];
[dictionary setValue:[locationType titleOfSelectedItem] forKey:@"type"];
[dictionary setValue:[locationAddress stringValue] forKey:@"address"];
return dictionary;
}
- (void)controlTextDidEndEditing:(CPNotification)anote
{
[map setAddress:[[anote object] stringValue]];
}
- (void)close:(SEL)aSelector
{
objj_msgSend(target, saveAndCloseAction, self);
}
- (void)setTarget:(id)aTarget
{
target = aTarget;
}
- (void)setLocationTitle:(CPString)aTitle
{
[locationTitle setStringValue:aTitle];
[locationTitle sizeToFit];
}
- (void)animateToFrame:(CGRect)aTargetFrame willRemove:(BOOL)willRemove
{
var animationDict = [CPDictionary new];
[animationDict setValue:self forKey:CPViewAnimationTargetKey];
[animationDict setValue:[self frame] forKey:CPViewAnimationStartFrameKey];
[animationDict setValue:aTargetFrame forKey:CPViewAnimationEndFrameKey];
[animationDict setValue:(willRemove) ? CPViewAnimationFadeOutEffect : CPViewAnimationFadeInEffect forKey:CPViewAnimationEffectKey];
// [animationDict setValue:nil forKey:CPViewAnimationEffectKey];
var animation = [[CPViewAnimation alloc] initWithViewAnimations:[animationDict]];
[animation setDelegate:self];
[animation startAnimation];
}
- (void)animationDidEnd:(CPAnimation)anAnimation
{
// this gets called when the fading view (in this case the "edit location view") wants to get removed. kthx
if ([[anAnimation viewAnimations][0] valueForKey:CPViewAnimationEffectKey] === CPViewAnimationFadeOutEffect)
[[[anAnimation viewAnimations][0] valueForKey:CPViewAnimationTargetKey] removeFromSuperview];
//else
// [map setHidden:NO];
}
-(void)drawRect:(id)aRect
{
var context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextSetStrokeColor(context, [CPColor colorWithHexString:@"000000"]);
var points = [
CGPointMake(50, 80),
CGPointMake(425, 80)
];
CGContextStrokeLineSegments(context, points, 2);
}
+ (CPTextField)customTextField
{
var bundle = [CPBundle mainBundle],
textfield = [[CPTextField alloc] initWithFrame:CGRectMake(50, 15, 425, 52)];
[textfield setBezeled:YES];
[textfield setEditable:YES];
[textfield setFont:[CPFont boldSystemFontOfSize:32]];
[textfield setValue:[CPColor colorWithWhite:0.6 alpha:1.0] forThemeAttribute:@"text-color" inState:CPTextFieldStatePlaceholder];
[textfield setValue:CGInsetMakeZero() forThemeAttribute:@"bezel-inset" inState:CPThemeStateNormal];
[textfield setValue:CGInsetMake(-1.0, 10.0, 0.0, 10.0) forThemeAttribute:@"content-inset" inState:CPThemeStateNormal];
[textfield setVerticalAlignment:CPCenterVerticalTextAlignment];
var textFieldBackgroundImage = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-0.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-1.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-2.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-3.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-4.png"] size:CGSizeMake(1.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-5.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-6.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-7.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-8.png"] size:CGSizeMake(11.0, 9.0)]
]]],
textFieldFocusedBackground = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-0.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-1.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-2.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-3.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-4.png"] size:CGSizeMake(1.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-5.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-6.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-7.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-8.png"] size:CGSizeMake(11.0, 9.0)]
]]];
[textfield setValue:textFieldBackgroundImage forThemeAttribute:@"bezel-color" inState:CPThemeStateBezeled];
[textfield setValue:textFieldFocusedBackground forThemeAttribute:@"bezel-color" inState:CPThemeStateBezeled|CPThemeStateEditing];
return textfield;
}
+ (CPTextField)customMultiLineTextField
{
var bundle = [CPBundle mainBundle],
textfield = [[LPMultiLineTextField alloc] initWithFrame:CGRectMake(50, 130, 425, 80)];
[textfield setBezeled:YES];
[textfield setEditable:YES];
[textfield setFont:[CPFont boldSystemFontOfSize:32]];
[textfield setTextColor:[CPColor grayColor]];
[textfield setValue:[CPColor colorWithWhite:0.6 alpha:1.0] forThemeAttribute:@"text-color" inState:CPTextFieldStatePlaceholder];
[textfield setValue:CGInsetMakeZero() forThemeAttribute:@"bezel-inset" inState:CPThemeStateNormal];
[textfield setValue:CGInsetMake(5.0, 10.0, 0.0, 10.0) forThemeAttribute:@"content-inset" inState:CPThemeStateNormal];
[textfield setVerticalAlignment:CPCenterVerticalTextAlignment];
var textFieldBackgroundImage = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-0.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-1.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-2.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-3.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-4.png"] size:CGSizeMake(1.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-5.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-6.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-7.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-8.png"] size:CGSizeMake(11.0, 9.0)]
]]],
textFieldFocusedBackground = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-0.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-1.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-2.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-3.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-4.png"] size:CGSizeMake(1.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-5.png"] size:CGSizeMake(11.0, 1.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-6.png"] size:CGSizeMake(11.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-7.png"] size:CGSizeMake(1.0, 9.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"TextField/textfield-focused-8.png"] size:CGSizeMake(11.0, 9.0)]
]]];
[textfield setValue:textFieldBackgroundImage forThemeAttribute:@"bezel-color" inState:CPThemeStateBezeled];
[textfield setValue:textFieldFocusedBackground forThemeAttribute:@"bezel-color" inState:CPThemeStateBezeled|CPThemeStateEditing];
return textfield;
}
+ (CPButton)customBigButton
{
var bundle = [CPBundle mainBundle],
button = [[CPButton alloc] initWithFrame:CGRectMake(275.0, 235.0, 200.0, 39.0)],
bezelColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"Buttons/gradient-button-left.png"] size:CGSizeMake(2.0, 39.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"Buttons/gradient-button-center.png"] size:CGSizeMake(1.0, 39.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"Buttons/gradient-button-right.png"] size:CGSizeMake(2.0, 39.0)]
]
isVertical:NO]],
highlightedBezelColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:
[
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"Buttons/gradient-button-left-active.png"] size:CGSizeMake(2.0, 39.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"Buttons/gradient-button-center-active.png"] size:CGSizeMake(1.0, 39.0)],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"Buttons/gradient-button-right-active.png"] size:CGSizeMake(2.0, 39.0)]
]
isVertical:NO]]
[button setValue:[CPFont systemFontOfSize:18.0] forThemeAttribute:@"font" inState:CPThemeStateBordered];
[button setValue:[CPColor colorWithCalibratedWhite:0.0 / 255.0 alpha:0.9] forThemeAttribute:@"text-color"];
[button setValue:[CPColor colorWithCalibratedWhite:240.0 / 255.0 alpha:1.0] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateBordered];
[button setValue:CGSizeMake(0.0, 1.0) forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateBordered];
[button setValue:CPLineBreakByTruncatingTail forThemeAttribute:@"line-break-mode"];
[button setValue:bezelColor forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
[button setValue:highlightedBezelColor forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered|CPThemeStateHighlighted];
[button setValue:CGInsetMake(0.0, 5.0, 0.0, 5.0) forThemeAttribute:@"content-inset" inState:CPThemeStateBordered];
[button setValue:CGSizeMake(0.0, 24.0) forThemeAttribute:@"min-size"];
[button setValue:CGSizeMake(-1.0, 24.0) forThemeAttribute:@"max-size"];
return button;
}
@end