Skip to content

Commit

Permalink
#26 color hold to select view and size pop chars across devices
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Feb 23, 2022
1 parent cd5ad21 commit b6b0424
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 145 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Emojis for the following are chosen based on [gitmoji](https://gitmoji.dev/).
- The messages that tell the user a noun is already plural have been translated to the keyboard's language.
- The keyboard height has been increased for landscape mode on iPads.
- Characters on keys have been made larger so they reflect the system keyboards better.
<!--- All letter, number and special keys now pop up after being pressed. -->
- All letter, number and special keys now pop up after being pressed.
<!--- Hold to select characters have been redesigned to reflect the addition of keys popping up. -->
<!--- All App Store media has been redone to reflect these changes.-->

Expand Down
116 changes: 0 additions & 116 deletions Keyboards/KeyboardsBase/InterfaceVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,122 +121,6 @@ func setKeyboardLayout() {
allPrompts = [translatePromptAndCursor, conjugatePromptAndCursor, pluralPromptAndCursor]
}

// MARK: Alternate Key Variables

/// Sets the alternates for certain keys given the chosen keyboard.
func setKeyboardAlternateKeys() {
if DeviceType.isPhone {
keysWithAlternates += symbolKeysWithAlternatesLeft
keysWithAlternates += symbolKeysWithAlternatesRight
keysWithAlternates.append(currencySymbol)
keysWithAlternatesLeft += symbolKeysWithAlternatesLeft
keysWithAlternatesRight += symbolKeysWithAlternatesRight
keysWithAlternatesRight.append(currencySymbol)
}

keyAlternatesDict = [
"a": aAlternateKeys,
"e": eAlternateKeys,
"е": еAlternateKeys, // Russian е
"i": iAlternateKeys,
"o": oAlternateKeys,
"u": uAlternateKeys,
"ä": äAlternateKeys,
"ö": öAlternateKeys,
"y": yAlternateKeys,
"s": sAlternateKeys,
"l": lAlternateKeys,
"z": zAlternateKeys,
"d": dAlternateKeys,
"c": cAlternateKeys,
"n": nAlternateKeys,
"ь": ьAlternateKeys,
"/": backslashAlternateKeys,
"?": questionMarkAlternateKeys,
"!": exclamationAlternateKeys,
"%": percentAlternateKeys,
"&": ampersandAlternateKeys,
"'": apostropheAlternateKeys,
"\"": quotationAlternateKeys,
"=": equalSignAlternateKeys,
currencySymbol: currencySymbolAlternates
]
}

var alternatesKeyView: UIView!
var keyCancelled = false
var keyPopChar = UILabel()
var keyHoldPopChar = UILabel()
var keyPopLayer = CAShapeLayer()
var keyHoldPopLayer = CAShapeLayer()
var keysWithAlternates = [String]()
var alternateKeys = [String]()

// Variables for alternate key view appearance.
var alternateBtnStartX = CGFloat(0)
var alternatesViewWidth = CGFloat(0)
var alternateKeyWidth = CGFloat(0)
var alternatesViewX = CGFloat(0)
var alternatesViewY = CGFloat(0)
var alternatesBtnHeight = CGFloat(0)
var alternatesCharHeight = CGFloat(0)

// The main currency symbol that will receive the alternates view for iPhones.
var currencySymbol: String = ""
var currencySymbolAlternates = [String]()
let dollarAlternateKeys = ["", "¢", "", "", "¥", "£", ""]
let euroAlternateKeys = ["", "¢", "", "", "¥", "£", "$"]
let roubleAlternateKeys = ["", "¢", "", "¥", "£", "$", ""]
let kronaAlternateKeys = ["", "¢", "", "¥", "£", "$", ""]
// Symbol keys that have consistent alternates for iPhones.
var symbolKeysWithAlternatesLeft = ["/", "?", "!", "%", "&"]
let backslashAlternateKeys = ["\\"]
let questionMarkAlternateKeys = ["¿"]
let exclamationAlternateKeys = ["¡"]
let percentAlternateKeys = [""]
let ampersandAlternateKeys = ["§"]
var symbolKeysWithAlternatesRight = ["'", "\"", "="]
let apostropheAlternateKeys = ["`", "´", "'"]
let quotationAlternateKeys = ["«", "»", "", "", "\""]
let equalSignAlternateKeys = ["", "±", ""]
var keysWithAlternatesLeft = [String]()
var keysWithAlternatesRight = [String]()
var keyAlternatesDict = [String: [String]]()
var aAlternateKeys = [String]()
var eAlternateKeys = [String]()
var еAlternateKeys = [String]() // Russian е
var iAlternateKeys = [String]()
var oAlternateKeys = [String]()
var uAlternateKeys = [String]()
var yAlternateKeys = [String]()
var äAlternateKeys = [String]()
var öAlternateKeys = [String]()
var sAlternateKeys = [String]()
var lAlternateKeys = [String]()
var zAlternateKeys = [String]()
var dAlternateKeys = [String]()
var cAlternateKeys = [String]()
var nAlternateKeys = [String]()
var ьAlternateKeys = [String]()

// MARK: Callout Variables

// Variables that define which keys are positioned on the very left, right or in the center of the keyboard.
// The purpose of these is to define which key pop up functions should be ran.
var centralKeyChars: [String] = [String]()
var leftKeyChars: [String] = [String]()
var rightKeyChars: [String] = [String]()

// Variables for call out positioning.
var horizStart = CGFloat(0)
var vertStart = CGFloat(0)
var widthMultiplier = CGFloat(0)
var maxHeightMultiplier = CGFloat(0)
var maxHeight = CGFloat(0)
var heightBeforeTopCurves = CGFloat(0)
var maxHeightCurveControl = CGFloat(0)
var minHeightCurveControl = CGFloat(0)

// MARK: English Interface Variables
// Note: here only until there is an English keyboard.

Expand Down
100 changes: 100 additions & 0 deletions Keyboards/KeyboardsBase/KeyAltChars.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// KeyAltChars.swift
//
// Functions and variables to create alternate key views.
//

import UIKit

/// Sets the alternates for certain keys given the chosen keyboard.
func setKeyboardAlternateKeys() {
if DeviceType.isPhone {
keysWithAlternates += symbolKeysWithAlternatesLeft
keysWithAlternates += symbolKeysWithAlternatesRight
keysWithAlternates.append(currencySymbol)
keysWithAlternatesLeft += symbolKeysWithAlternatesLeft
keysWithAlternatesRight += symbolKeysWithAlternatesRight
keysWithAlternatesRight.append(currencySymbol)
}

keyAlternatesDict = [
"a": aAlternateKeys,
"e": eAlternateKeys,
"е": еAlternateKeys, // Russian е
"i": iAlternateKeys,
"o": oAlternateKeys,
"u": uAlternateKeys,
"ä": äAlternateKeys,
"ö": öAlternateKeys,
"y": yAlternateKeys,
"s": sAlternateKeys,
"l": lAlternateKeys,
"z": zAlternateKeys,
"d": dAlternateKeys,
"c": cAlternateKeys,
"n": nAlternateKeys,
"ь": ьAlternateKeys,
"/": backslashAlternateKeys,
"?": questionMarkAlternateKeys,
"!": exclamationAlternateKeys,
"%": percentAlternateKeys,
"&": ampersandAlternateKeys,
"'": apostropheAlternateKeys,
"\"": quotationAlternateKeys,
"=": equalSignAlternateKeys,
currencySymbol: currencySymbolAlternates
]
}

var alternatesKeyView: UIView!
var keyCancelled = false
var keysWithAlternates = [String]()
var alternateKeys = [String]()

// Variables for alternate key view appearance.
var alternateBtnStartX = CGFloat(0)
var alternatesViewWidth = CGFloat(0)
var alternateKeyWidth = CGFloat(0)
var alternatesViewX = CGFloat(0)
var alternatesViewY = CGFloat(0)
var alternatesBtnHeight = CGFloat(0)
var alternatesCharHeight = CGFloat(0)

// The main currency symbol that will receive the alternates view for iPhones.
var currencySymbol: String = ""
var currencySymbolAlternates = [String]()
let dollarAlternateKeys = ["¢", "", "", "¥", "£", ""]
let euroAlternateKeys = ["¢", "", "", "¥", "£", "$"]
let roubleAlternateKeys = ["¢", "", "¥", "£", "$", ""]
let kronaAlternateKeys = ["¢", "", "¥", "£", "$", ""]

// Symbol keys that have consistent alternates for iPhones.
var symbolKeysWithAlternatesLeft = ["/", "?", "!", "%", "&"]
let backslashAlternateKeys = ["\\"]
let questionMarkAlternateKeys = ["¿"]
let exclamationAlternateKeys = ["¡"]
let percentAlternateKeys = [""]
let ampersandAlternateKeys = ["§"]
var symbolKeysWithAlternatesRight = ["'", "\"", "="]
let apostropheAlternateKeys = ["`", "´", "'"]
let quotationAlternateKeys = ["«", "»", "", "", "\""]
let equalSignAlternateKeys = ["", "±", ""]
var keysWithAlternatesLeft = [String]()
var keysWithAlternatesRight = [String]()
var keyAlternatesDict = [String: [String]]()
var aAlternateKeys = [String]()
var eAlternateKeys = [String]()
var еAlternateKeys = [String]() // Russian е
var iAlternateKeys = [String]()
var oAlternateKeys = [String]()
var uAlternateKeys = [String]()
var yAlternateKeys = [String]()
var äAlternateKeys = [String]()
var öAlternateKeys = [String]()
var sAlternateKeys = [String]()
var lAlternateKeys = [String]()
var zAlternateKeys = [String]()
var dAlternateKeys = [String]()
var cAlternateKeys = [String]()
var nAlternateKeys = [String]()
var ьAlternateKeys = [String]()
81 changes: 54 additions & 27 deletions Keyboards/KeyboardsBase/KeyAnimation.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
//
// KeyAnimation.swift
//
// Functions to pop up key characters and present alternate keys.
// Functions to animate key pressed with pop up characters.
//

import UIKit

// Variables that define which keys are positioned on the very left, right or in the center of the keyboard.
// The purpose of these is to define which key pop up functions should be ran.
var centralKeyChars: [String] = [String]()
var leftKeyChars: [String] = [String]()
var rightKeyChars: [String] = [String]()

// Variables for call out positioning.
var horizStart = CGFloat(0)
var vertStart = CGFloat(0)
var widthMultiplier = CGFloat(0)
var maxHeightMultiplier = CGFloat(0)
var maxHeight = CGFloat(0)
var heightBeforeTopCurves = CGFloat(0)
var maxHeightCurveControl = CGFloat(0)
var minHeightCurveControl = CGFloat(0)

var keyPopChar = UILabel()
var keyHoldPopChar = UILabel()
var keyPopLayer = CAShapeLayer()
var keyHoldPopLayer = CAShapeLayer()

/// Creates the shape that allows left most buttons to pop up after being pressed.
///
/// - Parameters
Expand All @@ -28,6 +49,12 @@ func setPopPathState(
if DeviceType.isPad {
widthMultiplier = 0.2
maxHeightMultiplier = 2.05
if isLandscapeView == true {
maxHeightMultiplier = 1.95
}
} else if DeviceType.isPhone && isLandscapeView == true {
widthMultiplier = 0.2
maxHeightMultiplier = 2.125
} else if DeviceType.isPhone && [".", ",", "?", "!", "'"].contains(char) {
widthMultiplier = 0.2
maxHeightMultiplier = 2.125
Expand All @@ -45,7 +72,7 @@ func setPopPathState(

if DeviceType.isPhone {
heightBeforeTopCurves = vertStart - ( keyHeight * 1.8 )
} else if DeviceType.isPad {
} else if DeviceType.isPad || ( DeviceType.isPhone && isLandscapeView == true ) {
heightBeforeTopCurves = vertStart - ( keyHeight * 1.6 )
}
}
Expand Down Expand Up @@ -233,41 +260,41 @@ func getKeyPopPath(key: UIButton, layer: CAShapeLayer, char: String, displayChar
// Get the frame in respect to the superview.
let frame: CGRect = (key.superview?.convert(key.frame, to: nil))!
var labelVertPosition = frame.origin.y - key.frame.height / 1.75
if displayChar == char && DeviceType.isPhone { // non-capital characters should be highter
// non-capital characters should be higher for portrait phone views.
if displayChar == char && DeviceType.isPhone && isLandscapeView == false
&& !["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].contains(char) {
labelVertPosition = frame.origin.y - key.frame.height / 1.6
} else if DeviceType.isPad
&& isLandscapeView == true {
labelVertPosition = frame.origin.y - key.frame.height / 2
}

if centralKeyChars.contains(char) {
layer.path = centerKeyPopPath(
startX: frame.origin.x,
startY: frame.origin.y,
keyWidth: key.frame.width,
keyHeight: key.frame.height,
char: char).cgPath
startX: frame.origin.x, startY: frame.origin.y,
keyWidth: key.frame.width, keyHeight: key.frame.height, char: char).cgPath
keyPopChar.center = CGPoint(x: frame.origin.x + key.frame.width * 0.5, y: labelVertPosition)
keyHoldPopChar.center = CGPoint(x: frame.origin.x + key.frame.width * 0.5, y: labelVertPosition)
} else if leftKeyChars.contains(char) {
layer.path = leftKeyPopPath(
startX: frame.origin.x,
startY: frame.origin.y,
keyWidth: key.frame.width,
keyHeight: key.frame.height,
char: char).cgPath
startX: frame.origin.x, startY: frame.origin.y,
keyWidth: key.frame.width, keyHeight: key.frame.height, char: char).cgPath
keyPopChar.center = CGPoint(x: frame.origin.x + key.frame.width * 0.85, y: labelVertPosition)
keyHoldPopChar.center = CGPoint(x: frame.origin.x + key.frame.width * 0.85, y: labelVertPosition)
if DeviceType.isPad {
if DeviceType.isPad || ( DeviceType.isPhone && isLandscapeView == true ) {
keyPopChar.center = CGPoint(x: frame.origin.x + key.frame.width * 0.65, y: labelVertPosition)
keyHoldPopChar.center = CGPoint(x: frame.origin.x + key.frame.width * 0.65, y: labelVertPosition)
}
} else if rightKeyChars.contains(char) {
layer.path = rightKeyPopPath(
startX: frame.origin.x,
startY: frame.origin.y,
keyWidth: key.frame.width,
keyHeight: key.frame.height,
char: char).cgPath
startX: frame.origin.x, startY: frame.origin.y,
keyWidth: key.frame.width, keyHeight: key.frame.height, char: char).cgPath
keyPopChar.center = CGPoint(x: frame.origin.x + key.frame.width * 0.15, y: labelVertPosition)
keyHoldPopChar.center = CGPoint(x: frame.origin.x + key.frame.width * 0.15, y: labelVertPosition)
if DeviceType.isPad || ( DeviceType.isPhone && isLandscapeView == true ) {
keyPopChar.center = CGPoint(x: frame.origin.x + key.frame.width * 0.35, y: labelVertPosition)
keyHoldPopChar.center = CGPoint(x: frame.origin.x + key.frame.width * 0.35, y: labelVertPosition)
}
}

layer.strokeColor = keyShadowColor
Expand All @@ -290,8 +317,8 @@ func setPhoneKeyPopCharSize(char: String) {
}
} else if shiftButtonState == .shift || shiftButtonState == .caps {
if isLandscapeView == true {
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.25)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.25)
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.15)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.15)
} else {
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 1)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 1)
Expand All @@ -314,24 +341,24 @@ func setPhoneKeyPopCharSize(char: String) {
func setPadKeyPopCharSize(char: String) {
if keyboardState != .letters && !["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].contains(char) {
if isLandscapeView == true {
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 3)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 3)
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.75)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.75)
} else {
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.5)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.5)
}
} else if keyboardState == .letters && ( shiftButtonState == .shift || shiftButtonState == .caps ) {
if isLandscapeView == true {
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 3)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 3)
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.5)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.5)
} else {
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 2)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 2)
}
} else {
if isLandscapeView == true {
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.75)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.75)
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.25)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 2.25)
} else {
keyPopChar.font = .systemFont(ofSize: letterKeyWidth / 1.75)
keyHoldPopChar.font = .systemFont(ofSize: letterKeyWidth / 1.75)
Expand Down
Loading

0 comments on commit b6b0424

Please sign in to comment.