Class: RMIPKeyboard::Keyboard
- Inherits:
-
UIView
- Object
- UIView
- RMIPKeyboard::Keyboard
- Defined in:
- lib/RMIPKeyboard/RMIPKeyboard.rb
Instance Method Summary collapse
- #buttonOriginPointForNumber(num) ⇒ Object
- #buttonTitleForNumber(num) ⇒ Object
- #calc_sizes(klayout) ⇒ Object
- #changeButtonBackgroundColourForHighlight(button) ⇒ Object
- #changeTextFieldText(button) ⇒ Object
- #createButtons ⇒ Object
- #define_constants ⇒ Object
- #initWithTextFieldAndLayout(textField, klayout = "ipv6") ⇒ Object
- #makeButtonWithRect(rect, num, grayBackground) ⇒ Object
Instance Method Details
#buttonOriginPointForNumber(num) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/RMIPKeyboard/RMIPKeyboard.rb', line 90 def (num) point = CGPointMake(0.0,0.0) if (num % 3) == 2 # 2nd button in the row point.x = @key_width.ceil elsif (num % 3) == 0 # 3rd button in the row point.x = (@key_width * 2.0).ceil end if num > 3 # The row multiplied by row's height point.y = ((num - 1) / 3.0).floor * (@key_height + 0.5) end point end |
#buttonTitleForNumber(num) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/RMIPKeyboard/RMIPKeyboard.rb', line 79 def (num) str = num.to_s if num > 9 && @numberOfKeys == 18 str = ["a", "b", "c", "d", "e", "f",@dividerChar,"0","del"][num - 10] elsif num > 9 str = [@dividerChar,"0","del"][num - 10] end str end |
#calc_sizes(klayout) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/RMIPKeyboard/RMIPKeyboard.rb', line 24 def calc_sizes(klayout) if klayout == "ipv6" @key_height = 49 @numrows = 6.0 @dividerChar = ":" @numberOfKeys = 18 else @key_height = 54 @numrows = 4.0 @dividerChar = "." @numberOfKeys = 12 @first_origin end @keyboardHeight = @key_height * @numrows @key_width = @screen_width / 3.0 @rect = CGRectMake(0.0, 0.0, @key_width, @key_height) end |
#changeButtonBackgroundColourForHighlight(button) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/RMIPKeyboard/RMIPKeyboard.rb', line 105 def changeButtonBackgroundColourForHighlight() if .backgroundColor == @text_color .backgroundColor = UIColor.whiteColor else .backgroundColor = @text_color end end |
#changeTextFieldText(button) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/RMIPKeyboard/RMIPKeyboard.rb', line 113 def changeTextFieldText() if .tag == @numberOfKeys # Last key @textField.text = "#{@textField.text.chop}" else @textField.text = "#{@textField.text}#{.titleLabel.text}" end self.changeButtonBackgroundColourForHighlight() end |
#createButtons ⇒ Object
44 45 46 47 48 49 |
# File 'lib/RMIPKeyboard/RMIPKeyboard.rb', line 44 def createButtons (1..@numberOfKeys).each do |num| @rect.origin = self.(num) self.makeButtonWithRect(@rect,num,false) end end |
#define_constants ⇒ Object
17 18 19 20 21 22 |
# File 'lib/RMIPKeyboard/RMIPKeyboard.rb', line 17 def define_constants @bg_color = UIColor.lightGrayColor @text_color = UIColor.lightTextColor @screen_width = UIScreen.mainScreen.bounds.size.width @screen_height = UIScreen.mainScreen.bounds.size.height end |
#initWithTextFieldAndLayout(textField, klayout = "ipv6") ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/RMIPKeyboard/RMIPKeyboard.rb', line 4 def initWithTextFieldAndLayout(textField, klayout="ipv6") define_constants calc_sizes(klayout) self.initWithFrame(CGRectMake(0.0, 0.0, @screen_width, @keyboardHeight)) @textField = WeakRef.new(textField) self.backgroundColor = @bg_color self.createButtons self end |
#makeButtonWithRect(rect, num, grayBackground) ⇒ Object
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 |
# File 'lib/RMIPKeyboard/RMIPKeyboard.rb', line 51 def makeButtonWithRect(rect, num, grayBackground) = UIButton.(UIButtonTypeCustom) .frame = rect fontSize = 25.0 .backgroundColor = grayBackground ? @text_color : UIColor.whiteColor if num != @numberOfKeys .titleLabel.font = UIFont.systemFontOfSize(fontSize) .setTitleColor(UIColor.darkTextColor, forState:UIControlStateNormal) .setTitle((num), forState:UIControlStateNormal) else #button.backgroundColor = @text_color .setImage(UIImage.imageNamed("deleteButton"), forState:UIControlStateNormal) .setAccessibilityLabel("delete") end if num == @numberOfKeys || num == (@numberOfKeys - 2) .backgroundColor = @text_color end .tag = num .addTarget(self, action:"changeButtonBackgroundColourForHighlight:", forControlEvents: (UIControlEventTouchDown|UIControlEventTouchDragEnter|UIControlEventTouchDragExit)) .addTarget(self, action:"changeTextFieldText:", forControlEvents: UIControlEventTouchUpInside) self.addSubview() end |