Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
805 - 1
//
2
//  InAppSettingsPotiValueController.m
3
//  MK4PhoneNav
4
//
5
//  Created by Frank Blumenberg on 05.05.10.
6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
7
//
8
 
9
#import "InAppSettingsPotiValueController.h"
10
 
11
 
12
@implementation InAppSettingsPotiValueController
13
 
14
@synthesize setting;
15
@synthesize numberField;
16
@synthesize sliderLabel;
17
@synthesize potiSwitch;
18
@synthesize pickerData;
19
@synthesize potiPicker;
20
 
21
- (id) initWithSetting:(InAppSettingsSpecifier *)inputSetting {
22
 
23
  if ((self = [super initWithNibName:@"InAppSettingsPotiValueController" bundle:nil])) {
24
    self.setting=inputSetting;
25
 
26
    NSArray *array = [[NSArray alloc] initWithObjects:
27
                      @"Poti1",
28
                      @"Poti2",
29
                      @"Poti3",
30
                      @"Poti4",
31
                      @"Poti5",
32
                      @"Poti6",
33
                      @"Poti7",
34
                      @"Poti8",
35
                      nil];
36
    self.pickerData = array;
37
    [array release];
38
 
39
  }
40
  return self;
41
}
42
 
43
 
44
- (void) viewDidLoad {
45
  [super viewDidLoad];
46
 
47
  self.title = [self.setting localizedTitle];
48
}
49
 
50
- (void)viewWillAppear:(BOOL)animated {
51
 
52
  int value = [[setting getValue] intValue];
53
  if (value<248) {
54
    potiSwitch.on = NO;
55
    numberField.alpha = 1.0f;
56
    potiPicker.alpha = 0.0f;
57
    numberField.text =[NSString stringWithFormat:@"%d",value];
58
  }
59
  else {
60
    potiSwitch.on = YES;
61
    numberField.alpha = 0.0f;
62
    potiPicker.alpha = 1.0f;
63
    numberField.text =@"0";
64
    [potiPicker selectRow:255-value inComponent:0 animated:NO];
65
  }
66
}
67
 
68
-(void) viewWillDisappear:(BOOL)animated
69
{
70
  int value=0;
71
  if(potiSwitch.on)
72
  {
73
    int row = [potiPicker selectedRowInComponent:0];
74
    value = 255-row;
75
  }
76
  else
77
  {
78
    value = [numberField.text intValue];
79
  }
80
 
81
  [setting setValue:[NSNumber numberWithInt:value]];
82
}
83
 
84
- (void) dealloc {
85
  [setting release];
86
  [numberField release];
87
  [sliderLabel release];
88
  [potiSwitch release];
89
  [pickerData release];
90
  [potiPicker release];
91
  [super dealloc];
92
}
93
 
94
- (id) getValue {
95
  return nil;
96
}
97
 
98
- (void) setValue:(id)newValue {
99
 
100
}
101
 
102
- (IBAction)textFieldDoneEditing:(id)sender {
103
        [sender resignFirstResponder];
104
}
105
 
106
- (IBAction)backgroundTap:(id)sender {
107
        [numberField resignFirstResponder];    
108
 
109
}
110
 
111
- (IBAction)toggleControls:(id)sender {
112
 
113
  [UIView beginAnimations:nil context:nil];
114
  [UIView setAnimationDuration:0.3];
115
  numberField.alpha = potiSwitch.on?0.0f:1.0f;
116
  potiPicker.alpha = potiSwitch.on?1.0f:0.0f;
117
  [UIView commitAnimations];   
118
}
119
 
120
 
121
- (void)didReceiveMemoryWarning {
122
    // Releases the view if it doesn't have a superview.
123
    [super didReceiveMemoryWarning];
124
 
125
    // Release any cached data, images, etc that aren't in use.
126
}
127
 
128
- (void)viewDidUnload {
129
  self.numberField = nil;
130
  self.sliderLabel = nil;
131
  self.potiSwitch = nil;
132
  self.pickerData = nil;
133
  self.potiPicker = nil;
134
  [super viewDidUnload];
135
}
136
 
137
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
138
 
139
  NSMutableString* s = [textField.text mutableCopy];
140
  [s replaceCharactersInRange:range withString:string];
141
 
142
  int value = [s intValue];
143
  [s release];
144
  if (value <=245 ) {
145
    return YES;
146
  }
147
  return NO;
148
}
149
 
150
#pragma mark -
151
#pragma mark Picker Data Source Methods
152
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
153
{
154
        return 1;
155
}
156
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
157
{
158
        return [pickerData count];
159
}
160
#pragma mark Picker Delegate Methods
161
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
162
{
163
        return [pickerData objectAtIndex:row];
164
}
165
 
166
@end