-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMediaTrimestralViewController.m
executable file
·164 lines (121 loc) · 5.08 KB
/
MediaTrimestralViewController.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
//
// MediaTrimestralViewController.m
// _A_Z
//
// Created by Gabriel Gino Vincent on 11/23/10.
// Copyright 2010 _A_Z. All rights reserved.
//
#define BadGradeColor UIColorFromRGB(0xFC452B)
#define GoodGradeColor UIColorFromRGB(0x3B44FF)
#import "MediaTrimestralViewController.h"
@implementation MediaTrimestralViewController
- (void)colorizeGrade {
if (nota.text.floatValue >= 6.0) nota.textColor = GoodGradeColor;
else nota.textColor = BadGradeColor;
}
- (IBAction)validateString:(id)sender {
const char *tempString;
if ([TM1TextField isFirstResponder]) {
tempString = TM1TextField.text.UTF8String;
if (tempString[TM1TextField.text.length-1] == ',') TM1TextField.text = [TM1TextField.text stringByReplacingOccurrencesOfString:@"," withString:@"."];
if (TM1TextField.text.length > 5) TM1TextField.text = [TM1TextField.text substringToIndex:5];
}
else if ([TM2TextField isFirstResponder]) {
tempString = TM2TextField.text.UTF8String;
if (tempString[TM2TextField.text.length-1] == ',') TM2TextField.text = [TM2TextField.text stringByReplacingOccurrencesOfString:@"," withString:@"."];
if (TM2TextField.text.length > 5) TM2TextField.text = [TM2TextField.text substringToIndex:5];
}
else if ([ATTextField isFirstResponder]) {
tempString = ATTextField.text.UTF8String;
if (tempString[ATTextField.text.length-1] == ',') ATTextField.text = [ATTextField.text stringByReplacingOccurrencesOfString:@"," withString:@"."];
if (ATTextField.text.length > 5) ATTextField.text = [ATTextField.text substringToIndex:5];
}
}
- (IBAction)infoButton:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"As notas inseridas em \"Teste A\" e \"Teste Z\" são referentes às notas de cada teste em 10. Exemplo:\nTeste A = 6 em 10\nTeste Z = 8 em 10\nMédia de teste = 7 em 10" delegate:self cancelButtonTitle:@"Fechar" otherButtonTitles:nil];
[alert show];
}
- (void)viewDidLoad {
TM1TextField.keyboardType = UIKeyboardTypeDecimalPad;
TM2TextField.keyboardType = UIKeyboardTypeDecimalPad;
ATTextField.keyboardType = UIKeyboardTypeDecimalPad;
UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithTitle:@"Limpar" style:UIBarButtonItemStyleBordered target:self action:@selector(clearButton:)];
self.navigationItem.rightBarButtonItem = clearButton;
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:253.0/255.0 green:221.0/255.0 blue:91.0/255.0 alpha:1.0];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = [UIFont boldSystemFontOfSize:20.0];
titleLabel.shadowColor = [UIColor colorWithRed:252.0/255.0 green:234.0/255.0 blue:162.0/255.0 alpha:0.9];
titleLabel.shadowOffset = CGSizeMake(0, 1);
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.75];
self.navigationItem.titleView = titleLabel;
titleLabel.text = @"Média Trimestral";
[titleLabel sizeToFit];
scrollView.frame = CGRectMake(0, 0, 320, 367);
ATHighlight.center = ATTextField.center;
}
- (void) setElementsOpacity {
mediaTrimestralLabel.alpha = 1.0;
nota.alpha = 1.0;
mediaTrimestralLabel.hidden = YES;
nota.text = @"";
TM1TextField.alpha = 1.0;
TM2TextField.alpha = 1.0;
ATTextField.alpha = 1.0;
TM1TextField.text = @"";
TM2TextField.text = @"";
ATTextField.text = @"";
}
- (void)clearButton:(id)sender {
[UIView beginAnimations:nil context:nil];
TM1TextField.alpha = 0.0;
TM2TextField.alpha = 0.0;
ATTextField.alpha = 0.0;
mediaTrimestralLabel.alpha = 0.0;
nota.alpha = 0.0;
[UIView setAnimationDuration:0.6f];
[UIView commitAnimations];
[self performSelector:@selector(setElementsOpacity) withObject:nil afterDelay:0.6];
}
- (IBAction)TM1_TM2Next:(id)sender{
if ([TM1TextField isFirstResponder])
[TM2TextField becomeFirstResponder];
}
-(IBAction)TM2_ATNext:(id)sender{
if ([TM2TextField isFirstResponder])
[ATTextField becomeFirstResponder];
}
- (IBAction)calcularMediaTrimestral:(id)sender{
float TM1 = TM1TextField.text.floatValue;
float TM2 = TM2TextField.text.floatValue;
float AT = ATTextField.text.floatValue;
float media = (((TM1 + TM2)/2)*4 + (AT*6)) / 10;
NSString *mediaText = [[NSString alloc] initWithFormat:@"%.2f", media];
if (TM1TextField.text.length != 0 && TM2TextField.text.length != 0 && ATTextField.text.length != 0) {
mediaTrimestralLabel.hidden = NO;
nota.text = mediaText;
}
[self colorizeGrade];
[self esconderOTeclado:sender];
}
- (IBAction)esconderOTeclado:(id)sender {
[TM1TextField resignFirstResponder];
[TM2TextField resignFirstResponder];
[ATTextField resignFirstResponder];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return NO;
}
- (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 {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
@end