Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift5 #136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion HostingApp/AppDelegate.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
Empty file modified HostingApp/Background.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified HostingApp/Base.lproj/Main.storyboard
100644 → 100755
Empty file.
40 changes: 40 additions & 0 deletions HostingApp/Images.xcassets/AppIcon.appiconset/Contents.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
Expand All @@ -20,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -49,6 +79,16 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified HostingApp/Info.plist
100644 → 100755
Empty file.
14 changes: 7 additions & 7 deletions HostingApp/ViewController.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class HostingAppViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

NotificationCenter.default.addObserver(self, selector: #selector(HostingAppViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(HostingAppViewController.keyboardDidHide), name: NSNotification.Name.UIKeyboardDidHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(HostingAppViewController.keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(HostingAppViewController.keyboardDidHide), name: UIResponder.keyboardDidHideNotification, object: nil)
//NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillChangeFrame:"), name: UIKeyboardWillChangeFrameNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(HostingAppViewController.keyboardDidChangeFrame(_:)), name: NSNotification.Name.UIKeyboardDidChangeFrame, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(HostingAppViewController.keyboardDidChangeFrame(_:)), name: UIResponder.keyboardDidChangeFrameNotification, object: nil)
}

override func didReceiveMemoryWarning() {
Expand All @@ -38,23 +38,23 @@ class HostingAppViewController: UIViewController {
var secondHeightTime: TimeInterval?
var referenceHeight: CGFloat = 216

func keyboardWillShow() {
@objc func keyboardWillShow() {
if startTime == nil {
startTime = CACurrentMediaTime()
}
}

func keyboardDidHide() {
@objc func keyboardDidHide() {
startTime = nil
firstHeightTime = nil
secondHeightTime = nil

self.stats?.text = "(Waiting for keyboard...)"
}

func keyboardDidChangeFrame(_ notification: Notification) {
@objc func keyboardDidChangeFrame(_ notification: Notification) {
//let frameBegin: CGRect! = notification.userInfo?[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue
let frameEnd: CGRect! = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue
let frameEnd: CGRect! = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue

if frameEnd.height == referenceHeight {
if firstHeightTime == nil {
Expand Down
14 changes: 7 additions & 7 deletions Keyboard/Catboard.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Catboard: KeyboardViewController {

if key.type == .character || key.type == .specialCharacter {
if let context = textDocumentProxy.documentContextBeforeInput {
if context.characters.count < 2 {
if context.count < 2 {
textDocumentProxy.insertText(keyOutput)
return
}
Expand Down Expand Up @@ -99,11 +99,11 @@ class Catboard: KeyboardViewController {
return CatboardBanner(globalColors: type(of: self).globalColors, darkMode: false, solidColorMode: self.solidColorMode())
}

func takeScreenshotDelay() {
@objc func takeScreenshotDelay() {
Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(Catboard.takeScreenshot), userInfo: nil, repeats: false)
}

func takeScreenshot() {
@objc func takeScreenshot() {
if !self.view.bounds.isEmpty {
UIDevice.current.beginGeneratingDeviceOrientationNotifications()

Expand All @@ -122,10 +122,10 @@ class Catboard: KeyboardViewController {
//let orientation: UIInterfaceOrientation = screenSize.width < screenSize.height ? .portrait : .landscapeLeft
//let name = (orientation.isPortrait ? "Screenshot-Portrait" : "Screenshot-Landscape")

let name = (self.interfaceOrientation.isPortrait ? "Screenshot-Portrait" : "Screenshot-Landscape")
let name = (self.isPortrait() ? "Screenshot-Portrait" : "Screenshot-Landscape")
let imagePath = "/Users/archagon/Documents/Programming/OSX/RussianPhoneticKeyboard/External/tasty-imitation-keyboard/\(name).png"

if let pngRep = UIImagePNGRepresentation(capturedImage!) {
if let pngRep = capturedImage!.pngData() {
try? pngRep.write(to: URL(fileURLWithPath: imagePath), options: [.atomic])
}

Expand All @@ -137,10 +137,10 @@ class Catboard: KeyboardViewController {
func randomCat() -> String {
let cats = "🐱😺😸😹😽😻😿😾😼🙀"

let numCats = cats.characters.count
let numCats = cats.count
let randomCat = arc4random() % UInt32(numCats)

let index = cats.characters.index(cats.startIndex, offsetBy: Int(randomCat))
let index = cats.index(cats.startIndex, offsetBy: Int(randomCat))
let character = cats[index]

return String(character)
Expand Down
4 changes: 2 additions & 2 deletions Keyboard/CatboardBanner.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CatboardBanner: ExtraView {

self.catSwitch.isOn = UserDefaults.standard.bool(forKey: kCatTypeEnabled)
self.catSwitch.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
self.catSwitch.addTarget(self, action: #selector(CatboardBanner.respondToSwitch), for: UIControlEvents.valueChanged)
self.catSwitch.addTarget(self, action: #selector(CatboardBanner.respondToSwitch), for: UIControl.Event.valueChanged)

self.updateAppearance()
}
Expand All @@ -47,7 +47,7 @@ class CatboardBanner: ExtraView {
self.catLabel.frame.origin = CGPoint(x: self.catSwitch.frame.origin.x + self.catSwitch.frame.width + 8, y: self.catLabel.frame.origin.y)
}

func respondToSwitch() {
@objc func respondToSwitch() {
UserDefaults.standard.set(self.catSwitch.isOn, forKey: kCatTypeEnabled)
self.updateAppearance()
}
Expand Down
Empty file modified Keyboard/DefaultKeyboard.swift
100644 → 100755
Empty file.
42 changes: 21 additions & 21 deletions Keyboard/DefaultSettings.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class DefaultSettings: ExtraView, UITableViewDataSource, UITableViewDelegate {
rootView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(rootView)

let left = NSLayoutConstraint(item: rootView, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 0)
let right = NSLayoutConstraint(item: rootView, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.right, multiplier: 1, constant: 0)
let top = NSLayoutConstraint(item: rootView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)
let bottom = NSLayoutConstraint(item: rootView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
let left = NSLayoutConstraint(item: rootView, attribute: NSLayoutConstraint.Attribute.left, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.left, multiplier: 1, constant: 0)
let right = NSLayoutConstraint(item: rootView, attribute: NSLayoutConstraint.Attribute.right, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.right, multiplier: 1, constant: 0)
let top = NSLayoutConstraint(item: rootView, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 0)
let bottom = NSLayoutConstraint(item: rootView, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: 0)

self.addConstraint(left)
self.addConstraint(right)
Expand All @@ -88,7 +88,7 @@ class DefaultSettings: ExtraView, UITableViewDataSource, UITableViewDelegate {

self.tableView?.register(DefaultSettingsTableViewCell.self, forCellReuseIdentifier: "cell")
self.tableView?.estimatedRowHeight = 44;
self.tableView?.rowHeight = UITableViewAutomaticDimension;
self.tableView?.rowHeight = UITableView.automaticDimension;

// XXX: this is here b/c a totally transparent background does not support scrolling in blank areas
self.tableView?.backgroundColor = UIColor.white.withAlphaComponent(0.01)
Expand Down Expand Up @@ -126,7 +126,7 @@ class DefaultSettings: ExtraView, UITableViewDataSource, UITableViewDelegate {
let key = self.settingsList[indexPath.section].1[indexPath.row]

if cell.sw.allTargets.count == 0 {
cell.sw.addTarget(self, action: #selector(DefaultSettings.toggleSetting(_:)), for: UIControlEvents.valueChanged)
cell.sw.addTarget(self, action: #selector(DefaultSettings.toggleSetting(_:)), for: UIControl.Event.valueChanged)
}

cell.sw.isOn = UserDefaults.standard.bool(forKey: key)
Expand Down Expand Up @@ -183,7 +183,7 @@ class DefaultSettings: ExtraView, UITableViewDataSource, UITableViewDelegate {
}
}

func toggleSetting(_ sender: UISwitch) {
@objc func toggleSetting(_ sender: UISwitch) {
if let cell = sender.superview as? UITableViewCell {
if let indexPath = self.tableView?.indexPath(for: cell) {
let key = self.settingsList[indexPath.section].1[indexPath.row]
Expand All @@ -201,7 +201,7 @@ class DefaultSettingsTableViewCell: UITableViewCell {
var constraintsSetForLongLabel: Bool
var cellConstraints: [NSLayoutConstraint]

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
self.sw = UISwitch()
self.label = UILabel()
self.longLabel = UITextView()
Expand Down Expand Up @@ -241,20 +241,20 @@ class DefaultSettingsTableViewCell: UITableViewCell {

let hasLongText = self.longLabel.text != nil && !self.longLabel.text.isEmpty
if hasLongText {
let switchSide = NSLayoutConstraint(item: sw, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.right, multiplier: 1, constant: -sideMargin)
let switchTop = NSLayoutConstraint(item: sw, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.top, multiplier: 1, constant: margin)
let labelSide = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.left, multiplier: 1, constant: sideMargin)
let labelCenter = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: sw, attribute: NSLayoutAttribute.centerY, multiplier: 1, constant: 0)
let switchSide = NSLayoutConstraint(item: sw, attribute: NSLayoutConstraint.Attribute.right, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.right, multiplier: 1, constant: -sideMargin)
let switchTop = NSLayoutConstraint(item: sw, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: margin)
let labelSide = NSLayoutConstraint(item: label, attribute: NSLayoutConstraint.Attribute.left, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.left, multiplier: 1, constant: sideMargin)
let labelCenter = NSLayoutConstraint(item: label, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: sw, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: 0)

self.addConstraint(switchSide)
self.addConstraint(switchTop)
self.addConstraint(labelSide)
self.addConstraint(labelCenter)

let left = NSLayoutConstraint(item: longLabel, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.left, multiplier: 1, constant: sideMargin)
let right = NSLayoutConstraint(item: longLabel, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.right, multiplier: 1, constant: -sideMargin)
let top = NSLayoutConstraint(item: longLabel, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: sw, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: margin)
let bottom = NSLayoutConstraint(item: longLabel, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: -margin)
let left = NSLayoutConstraint(item: longLabel, attribute: NSLayoutConstraint.Attribute.left, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.left, multiplier: 1, constant: sideMargin)
let right = NSLayoutConstraint(item: longLabel, attribute: NSLayoutConstraint.Attribute.right, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.right, multiplier: 1, constant: -sideMargin)
let top = NSLayoutConstraint(item: longLabel, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: sw, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: margin)
let bottom = NSLayoutConstraint(item: longLabel, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: -margin)

self.addConstraint(left)
self.addConstraint(right)
Expand All @@ -266,11 +266,11 @@ class DefaultSettingsTableViewCell: UITableViewCell {
self.constraintsSetForLongLabel = true
}
else {
let switchSide = NSLayoutConstraint(item: sw, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.right, multiplier: 1, constant: -sideMargin)
let switchTop = NSLayoutConstraint(item: sw, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.top, multiplier: 1, constant: margin)
let switchBottom = NSLayoutConstraint(item: sw, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: -margin)
let labelSide = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.left, multiplier: 1, constant: sideMargin)
let labelCenter = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: sw, attribute: NSLayoutAttribute.centerY, multiplier: 1, constant: 0)
let switchSide = NSLayoutConstraint(item: sw, attribute: NSLayoutConstraint.Attribute.right, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.right, multiplier: 1, constant: -sideMargin)
let switchTop = NSLayoutConstraint(item: sw, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: margin)
let switchBottom = NSLayoutConstraint(item: sw, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: -margin)
let labelSide = NSLayoutConstraint(item: label, attribute: NSLayoutConstraint.Attribute.left, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.left, multiplier: 1, constant: sideMargin)
let labelCenter = NSLayoutConstraint(item: label, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: sw, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: 0)

self.addConstraint(switchSide)
self.addConstraint(switchTop)
Expand Down
Empty file modified Keyboard/DefaultSettings.xib
100644 → 100755
Empty file.
Empty file modified Keyboard/DirectionEnum.swift
100644 → 100755
Empty file.
Empty file modified Keyboard/ExtraView.swift
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions Keyboard/ForwardingView.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ForwardingView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)

self.contentMode = UIViewContentMode.redraw
self.contentMode = UIView.ContentMode.redraw
self.isMultipleTouchEnabled = true
self.isUserInteractionEnabled = true
self.isOpaque = false
Expand All @@ -40,7 +40,7 @@ class ForwardingView: UIView {
}
}

func handleControl(_ view: UIView?, controlEvent: UIControlEvents) {
func handleControl(_ view: UIView?, controlEvent: UIControl.Event) {
if let control = view as? UIControl {
let targets = control.allTargets
for target in targets {
Expand Down
2 changes: 1 addition & 1 deletion Keyboard/ImageKey.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ImageKey: KeyboardKey {
didSet {
if let imageView = image {
self.addSubview(imageView)
imageView.contentMode = UIViewContentMode.scaleAspectFit
imageView.contentMode = UIView.ContentMode.scaleAspectFit
self.redrawImage()
updateColors()
}
Expand Down
Empty file modified Keyboard/Info.plist
100644 → 100755
Empty file.
Empty file modified Keyboard/KeyboardConnector.swift
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions Keyboard/KeyboardInputTraits.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ extension KeyboardViewController {
// note that KVO doesn't work on textDocumentProxy, so we have to poll
traitPollingTimer?.invalidate()
traitPollingTimer = UIScreen.main.displayLink(withTarget: self, selector: #selector(KeyboardViewController.pollTraits))
traitPollingTimer?.add(to: RunLoop.current, forMode: RunLoopMode.defaultRunLoopMode)
traitPollingTimer?.add(to: RunLoop.current, forMode: RunLoop.Mode.default)
}

func pollTraits() {
@objc func pollTraits() {
let proxy = self.textDocumentProxy

if let layout = self.layout {
Expand Down
Loading