171 lines
4.3 KiB
Objective-C
171 lines
4.3 KiB
Objective-C
//
|
|
// ViewControllerKeyboard.m
|
|
// FMC Planner 2
|
|
//
|
|
// Created by Kilian Hofmann on 20.03.16.
|
|
// Copyright © 2016 Kilian Hofmann. All rights reserved.
|
|
//
|
|
|
|
#import "ViewController.h"
|
|
#import "ViewControllerKeyboard.h"
|
|
|
|
@implementation ViewControllerKeyboard
|
|
|
|
#pragma mark - View management and navigation
|
|
|
|
- (void)viewDidLoad
|
|
{
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
_alphaOn = true;
|
|
_alphabet = @[
|
|
@"A",
|
|
@"B",
|
|
@"C",
|
|
@"D",
|
|
@"E",
|
|
@"F",
|
|
@"G",
|
|
@"H",
|
|
@"I",
|
|
@"J",
|
|
@"K",
|
|
@"L",
|
|
@"M",
|
|
@"N",
|
|
@"O",
|
|
@"P",
|
|
@"Q",
|
|
@"R",
|
|
@"S",
|
|
@"T",
|
|
@"U",
|
|
@"V",
|
|
@"W",
|
|
@"X",
|
|
@"Y",
|
|
@"Z",
|
|
@"SP",
|
|
@"CLR",
|
|
@"DEL",
|
|
@"NUM",
|
|
@"M\nE\nN\nU",
|
|
@"P\nE\nR\nF",
|
|
@"R\nT\nE"
|
|
];
|
|
_numeric = @[
|
|
@"1",
|
|
@"2",
|
|
@"3",
|
|
@"",
|
|
@"",
|
|
@"",
|
|
@"4",
|
|
@"5",
|
|
@"6",
|
|
@"",
|
|
@"",
|
|
@"",
|
|
@"7",
|
|
@"8",
|
|
@"9",
|
|
@"",
|
|
@"",
|
|
@"",
|
|
@".",
|
|
@"0",
|
|
@"-",
|
|
@"",
|
|
@"",
|
|
@"",
|
|
@"",
|
|
@"",
|
|
@"SP",
|
|
@"CLR",
|
|
@"DEL",
|
|
@"LET",
|
|
@"M\nE\nN\nU",
|
|
@"P\nE\nR\nF",
|
|
@"R\nT\nE"
|
|
];
|
|
// Init Board
|
|
[self switchKeyboard];
|
|
// Round button corners
|
|
for (UIButton *but in _Keys) {
|
|
but.layer.cornerRadius = 5;
|
|
but.layer.masksToBounds = YES;
|
|
}
|
|
}
|
|
|
|
#pragma mark - Keyborad actions
|
|
|
|
- (IBAction)KeyTaps:(UIButton *)sender
|
|
{
|
|
if ([sender.restorationIdentifier isEqualToString:@"Switch"]) {
|
|
_alphaOn = !_alphaOn;
|
|
[self switchKeyboard];
|
|
}
|
|
else if ([sender.restorationIdentifier isEqualToString:@"Space"]) {
|
|
_main.screen.Scratchpad.text =
|
|
[_main.screen.Scratchpad.text stringByAppendingString:@" "];
|
|
}
|
|
else if ([sender.restorationIdentifier isEqualToString:@"Clear"]) {
|
|
if ([_main.screen.Scratchpad.text isEqualToString:@"DELETE"]) {
|
|
_main.screen.Scratchpad.text = @"";
|
|
}
|
|
else if (_main.screen.Scratchpad.text.length > 0) {
|
|
_main.screen.Scratchpad.text = [_main.screen.Scratchpad.text
|
|
substringToIndex:(_main.screen.Scratchpad.text).length - 1];
|
|
}
|
|
}
|
|
else if ([sender.restorationIdentifier isEqualToString:@"Delete"]) {
|
|
_main.screen.Scratchpad.text = @"DELETE";
|
|
}
|
|
else if ([sender.restorationIdentifier isEqualToString:@"Top"]) {
|
|
[_main.screen loadScreen:@"MENU" withOptions:nil];
|
|
}
|
|
else if ([sender.restorationIdentifier isEqualToString:@"Mid"]) {
|
|
[_main.screen loadScreen:@"PERF INIT" withOptions:nil];
|
|
}
|
|
else if ([sender.restorationIdentifier isEqualToString:@"Bot"]) {
|
|
if (_main.screen.maxNumRoutePages > _main.screen.numRoutePage &&
|
|
([[_main.screen.Header.text substringToIndex:3]
|
|
isEqualToString:@"ROU"])) {
|
|
[_main.screen loadScreen:@"ROUTE" withOptions:@[ FMCNEXTRTEPAGE ]];
|
|
}
|
|
else {
|
|
[_main.screen loadScreen:@"ROUTE" withOptions:@[ FMCFIRSTRTEPAGE ]];
|
|
}
|
|
}
|
|
else {
|
|
_main.screen.Scratchpad.text = [_main.screen.Scratchpad.text
|
|
stringByAppendingString:sender.titleLabel.text];
|
|
}
|
|
}
|
|
|
|
- (void)switchKeyboard
|
|
{
|
|
if (_alphaOn) {
|
|
for (int i = 0; i < _Keys.count; i++) {
|
|
((UIButton *)_Keys[i]).titleLabel.numberOfLines = 0;
|
|
((UIButton *)_Keys[i]).titleLabel.lineBreakMode =
|
|
NSLineBreakByCharWrapping;
|
|
[((UIButton *)_Keys[i]) setTitle:_alphabet[i]
|
|
forState:UIControlStateNormal];
|
|
[((UIButton *)_Keys[i]).titleLabel sizeToFit];
|
|
}
|
|
}
|
|
else {
|
|
for (int i = 0; i < _Keys.count; i++) {
|
|
((UIButton *)_Keys[i]).titleLabel.numberOfLines = 0;
|
|
((UIButton *)_Keys[i]).titleLabel.lineBreakMode =
|
|
NSLineBreakByCharWrapping;
|
|
[((UIButton *)_Keys[i]) setTitle:_numeric[i]
|
|
forState:UIControlStateNormal];
|
|
[((UIButton *)_Keys[i]).titleLabel sizeToFit];
|
|
}
|
|
}
|
|
}
|
|
|
|
@end
|