-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSettingsViewController.m
More file actions
373 lines (326 loc) · 11.1 KB
/
SettingsViewController.m
File metadata and controls
373 lines (326 loc) · 11.1 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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
//
// SettingsViewController.m
// TypeOver
//
// Created by Owen McGirr on 24/03/2013.
// Copyright (c) 2013 Owen McGirr. All rights reserved.
//
#import "SettingsViewController.h"
@interface SettingsViewController ()
@end
@implementation SettingsViewController
// rates to match Tecla Shield
static int scanRates[] = {5000, 4170, 3470, 2890, 2410, 2000, 1670, 1400, 1160, 970, 810, 670, 560, 480, 390, 320, 270};
#pragma mark - view controller methods
- (void)viewDidLoad
{
[super viewDidLoad];
// set variables from saved settings
inputRate = [[NSUserDefaults standardUserDefaults] floatForKey:@"scan_rate_float"];
selRate = [[NSUserDefaults standardUserDefaults] integerForKey:@"scan_rate_int"];
fontSize = [[NSUserDefaults standardUserDefaults] integerForKey:@"font_size"];
autoPred=[[NSUserDefaults standardUserDefaults] boolForKey:@"auto_pred"];
wordPred=[[NSUserDefaults standardUserDefaults] boolForKey:@"word_pred"];
shorthandPred=[[NSUserDefaults standardUserDefaults] boolForKey:@"shorthand_pred"];
autoPredAfter=[[NSUserDefaults standardUserDefaults] integerForKey:@"auto_pred_after"];
manualDwellTime=[[NSUserDefaults standardUserDefaults] boolForKey:@"manual_scan_rate"];
NSMutableString *st=[NSMutableString stringWithString:@"Predict after "];
[st appendFormat:@"%i", autoPredAfter];
if (autoPredAfter>1) {
[st appendString:@" letters"];
}
else if (autoPredAfter==1) {
[st appendString:@" letter"];
}
[autoPredAfterLabel setText:st];
if (manualDwellTime) {
manualDwellTimeToggleSwitch.on=true;
}
else {
manualDwellTimeToggleSwitch.on=false;
[dwellTimeLabel setEnabled:NO];
[dwellTimeDownButton setEnabled:NO];
[dwellTimeUpButton setEnabled:NO];
[aboutDwellTimeButton setEnabled:NO];
}
if (wordPred) {
wordPredToggleSwitch.on=true;
}
else {
wordPredToggleSwitch.on=false;
[shorthandPredLabel setEnabled:NO];
[autoPredLabel setEnabled:NO];
[autoPredAfterLabel setEnabled:NO];
[aboutShorthandPred setEnabled:NO];
[aboutAutoPredButton setEnabled:NO];
[aboutAutoPredAfterButton setEnabled:NO];
[shorthandPredToggleSwitch setEnabled:NO];
[autoPredToggleSwitch setEnabled:NO];
[autoPredAfterUpButton setEnabled:NO];
[autoPredAfterDownButton setEnabled:NO];
}
if (shorthandPred) {
shorthandPredToggleSwitch.on=true;
NSLog(@"shorthand prediction on");
}
else {
shorthandPredToggleSwitch.on=false;
NSLog(@"shorthand prediction off");
}
if (autoPred) {
autoPredToggleSwitch.on=true;
}
else {
autoPredToggleSwitch.on=false;
[autoPredAfterDownButton setEnabled:NO];
[autoPredAfterUpButton setEnabled:NO];
[aboutAutoPredAfterButton setEnabled:NO];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - methods
- (void)scanIndicator { // method to indicate dwell time rate
if (scanRateInd<=3) { // only cycle three times
if ([dwellTimeLabel.text isEqualToString:@"Dwell time"]||[dwellTimeLabel.text isEqualToString:@"rate of change"]) {
[dwellTimeLabel setText:@"This is the..."];
}
else {
[dwellTimeLabel setText:@"rate of change"];
}
scanRateInd++;
}
else {
[dwellTimeLabel setText:@"Dwell time"];
[scanRateIndicatorTimer invalidate];
scanRateInd=0;
}
}
#pragma mark - actions for ui controls
- (IBAction)manualDwellTimeToggleAct:(id)sender {
if (manualDwellTimeToggleSwitch.on) {
manualDwellTime=true;
[dwellTimeLabel setEnabled:YES];
[dwellTimeDownButton setEnabled:YES];
[dwellTimeUpButton setEnabled:YES];
[aboutDwellTimeButton setEnabled:YES];
NSLog(@"manual dwell time on");
}
else {
manualDwellTime=false;
[dwellTimeLabel setEnabled:NO];
[dwellTimeDownButton setEnabled:NO];
[dwellTimeUpButton setEnabled:NO];
[aboutDwellTimeButton setEnabled:NO];
NSLog(@"manual dwell time off");
}
}
- (IBAction)dwellTimeDownAct:(id)sender {
bool valueFound = NO;
int i = 0;
while (!valueFound && i<17) { // loop through rates until the closest is found
if (scanRates[i]==selRate) {
valueFound=YES;
}
else {
i++;
}
}
if (i<17) {
i++;
selRate=scanRates[i];
inputRate=(float)(selRate)/1000;
NSLog(@"%f", inputRate);
}
[scanRateIndicatorTimer invalidate];
scanRateInd=0;
scanRateIndicatorTimer = [NSTimer scheduledTimerWithTimeInterval:inputRate target:self selector:@selector(scanIndicator) userInfo:nil repeats:YES];
}
- (IBAction)dwellTimeUpAct:(id)sender {
bool valueFound = NO;
int i = 0;
while (!valueFound && i<17) { // loop through rates until the closest is found
if (scanRates[i]==selRate) {
valueFound=YES;
}
else {
i++;
}
}
if (i>1) {
i--;
selRate=scanRates[i];
inputRate=(float)(selRate)/1000;
NSLog(@"%f", inputRate);
}
[scanRateIndicatorTimer invalidate];
scanRateInd=0;
scanRateIndicatorTimer = [NSTimer scheduledTimerWithTimeInterval:inputRate target:self selector:@selector(scanIndicator) userInfo:nil repeats:YES];
}
- (IBAction)wordPredToggleAct:(id)sender {
if (wordPredToggleSwitch.on) {
wordPred=true;
[shorthandPredLabel setEnabled:YES];
[autoPredLabel setEnabled:YES];
[autoPredAfterLabel setEnabled:YES];
[aboutShorthandPred setEnabled:YES];
[aboutAutoPredButton setEnabled:YES];
[aboutAutoPredAfterButton setEnabled:YES];
[shorthandPredToggleSwitch setEnabled:YES];
[autoPredToggleSwitch setEnabled:YES];
[autoPredAfterUpButton setEnabled:YES];
[autoPredAfterDownButton setEnabled:YES];
NSLog(@"word prediction on");
}
else {
wordPred=false;
[shorthandPredLabel setEnabled:NO];
[autoPredLabel setEnabled:NO];
[autoPredAfterLabel setEnabled:NO];
[aboutShorthandPred setEnabled:NO];
[aboutAutoPredButton setEnabled:NO];
[aboutAutoPredAfterButton setEnabled:NO];
[shorthandPredToggleSwitch setEnabled:NO];
[autoPredToggleSwitch setEnabled:NO];
[autoPredAfterUpButton setEnabled:NO];
[autoPredAfterDownButton setEnabled:NO];
NSLog(@"word prediction off");
}
}
- (IBAction)autoPredictToggleAct:(id)sender {
if (autoPredToggleSwitch.on) {
autoPred=true;
[autoPredAfterLabel setEnabled:YES];
[autoPredAfterDownButton setEnabled:YES];
[autoPredAfterUpButton setEnabled:YES];
[aboutAutoPredAfterButton setEnabled:YES];
NSLog(@"auto predict on");
}
else {
autoPred=false;
[autoPredAfterLabel setEnabled:NO];
[autoPredAfterDownButton setEnabled:NO];
[autoPredAfterUpButton setEnabled:NO];
[aboutAutoPredAfterButton setEnabled:NO];
NSLog(@"auto predict off");
}
}
- (IBAction)autoPredAfterDownAct:(id)sender {
if (autoPredAfter>1) {
autoPredAfter=autoPredAfter-1;
}
NSMutableString *st=[NSMutableString stringWithString:@"Predict after "];
[st appendFormat:@"%i", autoPredAfter];
if (autoPredAfter>1) {
[st appendString:@" letters"];
}
else if (autoPredAfter==1) {
[st appendString:@" letter"];
}
[autoPredAfterLabel setText:st];
}
- (IBAction)autoPredAfterUpAct:(id)sender {
if (autoPredAfter<4) {
autoPredAfter=autoPredAfter+1;
NSMutableString *st=[NSMutableString stringWithString:@"Predict after "];
[st appendFormat:@"%i", autoPredAfter];
if (autoPredAfter>1) {
[st appendString:@" letters"];
}
else if (autoPredAfter==1) {
[st appendString:@" letter"];
}
[autoPredAfterLabel setText:st];
}
}
- (IBAction)shorthandPredToggleAct:(id)sender {
if ([shorthandPredToggleSwitch isOn]) {
shorthandPred=true;
}
else {
shorthandPred=false;
}
}
- (IBAction)fontSizeDownAct:(id)sender {
if (fontSize>14) {
fontSize=fontSize-2;
}
}
- (IBAction)fontSizeUpAct:(id)sender {
fontSize=fontSize+2;
}
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) { // back button pressed on navigation controller
[[NSUserDefaults standardUserDefaults] setBool:manualDwellTime forKey:@"manual_scan_rate"];
[[NSUserDefaults standardUserDefaults] setBool:shorthandPred forKey:@"shorthand_pred"];
[[NSUserDefaults standardUserDefaults] setBool:autoPred forKey:@"auto_pred"];
[[NSUserDefaults standardUserDefaults] setBool:wordPred forKey:@"word_pred"];
[[NSUserDefaults standardUserDefaults] setFloat:inputRate forKey:@"scan_rate_float"];
[[NSUserDefaults standardUserDefaults] setInteger:selRate forKey:@"scan_rate_int"];
[[NSUserDefaults standardUserDefaults] setInteger:autoPredAfter forKey:@"auto_pred_after"];
[[NSUserDefaults standardUserDefaults] setInteger:fontSize forKey:@"font_size"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"settings saved");
}
}
- (IBAction)aboutDwellTimeAct:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info"
message:@"Dwell time is the rate at which the keypad keys cycle through their content."
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles: nil];
[alert show];
}
- (IBAction)aboutAutoPredAct:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info"
message:@"Auto predict means that word prediction will automatically appear after you input a number of letters."
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles: nil];
[alert show];
}
- (IBAction)aboutPredAfterAct:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info"
message:@"This number can range from 1 to 4."
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles: nil];
[alert show];
}
- (IBAction)aboutManualDwellTimeAct:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info"
message:@"Dwell time is the rate at which the keypad keys cycle through their content. Dwell time can be automatically set by your Tecla Shield or other switch interface. To do this, simply switch manual dwell time off. Or, if you would rather set dwell time manually, switch it on."
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles: nil];
[alert show];
}
- (IBAction)aboutShorthandPredAct:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info"
message:@"Shorthand prediction provides the ability for you to just type key letters from the word you want. For example, typing 'pbl' would predict 'probably'. For optimum results, type the most distinctive letters in the word. You have to include the first letter. Also, the letters must be in the correct order."
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles: nil];
[alert show];
}
- (IBAction)aboutFontSizeAct:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info"
message:@"Font size refers to the size of the text you type."
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles: nil];
[alert show];
}
- (IBAction)aboutWordPredAct:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info"
message:@"Word prediction can be completely turned on or off."
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles: nil];
[alert show];
}
@end