motion-ipkeyboard 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +53 -0
- data/lib/RMIPKeyboard/RMIPKeyboard.rb +65 -68
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16debd0148e6df1c6a68d7a85a35e1e09b982637
|
4
|
+
data.tar.gz: 3bf895763f884c60385bd5ace7bcba28f2965fa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bce6b1beb7a1e3370854a1a8fc1515f519c34657dfa1f3173632f556561c78dbb97f4a50d09c6b2340f1a7f459fc74160f8246be45ba00bb26483197ce4c8451
|
7
|
+
data.tar.gz: 0c0f0be38a6702b0454325cfca4c47c297ad5fdb825123d67c26265ce9b013e0a2f4335c1bdb01b3898aba143de5b818c0cf093864154a435903329d1ed319ae
|
data/README.md
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
#motion-ipkeyboard
|
2
|
+
|
3
|
+
A simple custom keyboard meant for typing ip addresses.
|
4
|
+
|
5
|
+
## Installing
|
6
|
+
|
7
|
+
### With Bundler
|
8
|
+
|
9
|
+
1. Add motion-ipkeyboard gem to your Gemfile
|
10
|
+
```ruby
|
11
|
+
gem 'motion-ipkeyboard'
|
12
|
+
```
|
13
|
+
|
14
|
+
2. ```$ bundle install```
|
15
|
+
|
16
|
+
### Without Bundler
|
17
|
+
|
18
|
+
1. install the motion-ipkeyboard gem
|
19
|
+
```$ gem install motion-ipkeyboard```
|
20
|
+
2. add to your RubyMotion app Rakefile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'rubygems'
|
24
|
+
require 'motion-ipkeyboard'
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# IPv6 keyboard
|
31
|
+
ipv6_input_field = UITextField.alloc.initWithFrame(CGRectMake(10, 100, 300, 45))
|
32
|
+
ipv6_input_field.setBackgroundColor(UIColor.whiteColor)
|
33
|
+
ipv6_input_field.inputView = RMIPKeyboard::Keyboard.alloc.initWithTextFieldAndLayout(ipv6_input_field,"ipv6")
|
34
|
+
ipv6_input_field.setDelegate(self)
|
35
|
+
self.view.addSubview(ipv6_input_field)
|
36
|
+
|
37
|
+
# IPv4 keyboard
|
38
|
+
ipv4_input_field = UITextField.alloc.initWithFrame(CGRectMake(10, 50, 300, 45))
|
39
|
+
ipv4_input_field.setBackgroundColor(UIColor.whiteColor)
|
40
|
+
ipv4_input_field.inputView = RMIPKeyboard::Keyboard.alloc.initWithTextFieldAndLayout(ipv4_input_field,"ipv4")
|
41
|
+
ipv4_input_field.setDelegate(self)
|
42
|
+
self.view.addSubview(ipv4_input_field)
|
43
|
+
```
|
44
|
+
|
45
|
+
## Screenshots
|
46
|
+
|
47
|
+
|IPv6|IPv4|
|
48
|
+
|---|---|
|
49
|
+
|||
|
50
|
+
|
51
|
+
## Thanks
|
52
|
+
|
53
|
+
The keyboard implementation is basicaly a translation of [doofyus/HexKeyboard](https://github.com/doofyus/HexKeyboard) to RubyMotion.
|
@@ -1,120 +1,117 @@
|
|
1
1
|
module RMIPKeyboard
|
2
2
|
class Keyboard < UIView
|
3
|
-
HEX_KEYBOARD_HEIGHT = 305
|
4
|
-
DEC_KEYBOARD_HEIGHT = 205
|
5
|
-
SGRAYCOLOUR = UIColor.lightTextColor
|
6
3
|
|
7
4
|
def initWithTextFieldAndLayout(textField, klayout="ipv6")
|
5
|
+
|
6
|
+
define_constants
|
7
|
+
calc_sizes(klayout)
|
8
|
+
|
9
|
+
self.initWithFrame(CGRectMake(0.0, 0.0, @screen_width, @keyboardHeight))
|
10
|
+
|
11
|
+
@textField = WeakRef.new(textField)
|
12
|
+
self.backgroundColor = @bg_color
|
13
|
+
self.createButtons
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def define_constants
|
18
|
+
@bg_color = UIColor.lightGrayColor
|
19
|
+
@text_color = UIColor.lightTextColor
|
20
|
+
@screen_width = UIScreen.mainScreen.bounds.size.width
|
21
|
+
@screen_height = UIScreen.mainScreen.bounds.size.height
|
22
|
+
end
|
23
|
+
|
24
|
+
def calc_sizes(klayout)
|
25
|
+
|
8
26
|
if klayout == "ipv6"
|
9
|
-
@
|
27
|
+
@key_height = 49
|
10
28
|
@numrows = 6.0
|
11
29
|
@dividerChar = ":"
|
12
|
-
@numberOfKeys =
|
30
|
+
@numberOfKeys = 18
|
13
31
|
else
|
14
|
-
@
|
32
|
+
@key_height = 54
|
15
33
|
@numrows = 4.0
|
16
34
|
@dividerChar = "."
|
17
|
-
@numberOfKeys =
|
35
|
+
@numberOfKeys = 12
|
36
|
+
@first_origin
|
18
37
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@
|
23
|
-
self.backgroundColor = UIColor.lightGrayColor
|
24
|
-
self.createButtons
|
25
|
-
|
26
|
-
self
|
38
|
+
|
39
|
+
@keyboardHeight = @key_height * @numrows
|
40
|
+
@key_width = @screen_width / 3.0
|
41
|
+
@rect = CGRectMake(0.0, 0.0, @key_width, @key_height)
|
27
42
|
end
|
28
43
|
|
29
44
|
def createButtons
|
30
|
-
rect = CGRectMake(0.0, 0.0, ((self.bounds.size.width / 3.0) + 0.3).floor, (((@keyboardHeight - 5.0) / @numrows) + 0.3))
|
31
|
-
|
32
|
-
# Makes the numerical buttons
|
33
45
|
(1..@numberOfKeys).each do |num|
|
34
|
-
rect.origin = self.buttonOriginPointForNumber(num)
|
35
|
-
|
36
|
-
self.makeButtonWithRect(rect,self.buttonTitleForNumber(num),false)
|
46
|
+
@rect.origin = self.buttonOriginPointForNumber(num)
|
47
|
+
self.makeButtonWithRect(@rect,num,false)
|
37
48
|
end
|
38
|
-
# Makes the ':' button
|
39
|
-
rect.origin = self.buttonOriginPointForNumber(@numberOfKeys + 1)
|
40
|
-
|
41
|
-
self.makeButtonWithRect(rect,@dividerChar,true)
|
42
|
-
|
43
|
-
# Makes the '0' button
|
44
|
-
rect.origin = self.buttonOriginPointForNumber(@numberOfKeys + 2)
|
45
|
-
|
46
|
-
self.makeButtonWithRect(rect,"0",false)
|
47
|
-
|
48
|
-
# Makes the 'delete' button
|
49
|
-
rect.origin = self.buttonOriginPointForNumber(@numberOfKeys + 3)
|
50
|
-
|
51
|
-
button = UIButton.alloc.initWithFrame(rect)
|
52
|
-
button.tag = @numberOfKeys + 3
|
53
|
-
button.backgroundColor = SGRAYCOLOUR
|
54
|
-
button.setImage(UIImage.imageNamed("deleteButton"), forState:UIControlStateNormal)
|
55
|
-
button.addTarget(self, action:"changeButtonBackgroundColourForHighlight:", forControlEvents:(UIControlEventTouchDown|UIControlEventTouchDragEnter|UIControlEventTouchDragExit))
|
56
|
-
button.addTarget(self, action:"changeTextFieldText:", forControlEvents:UIControlEventTouchUpInside)
|
57
|
-
|
58
|
-
self.addSubview(button)
|
59
49
|
end
|
60
50
|
|
61
|
-
def makeButtonWithRect(rect,
|
51
|
+
def makeButtonWithRect(rect, num, grayBackground)
|
62
52
|
button = UIButton.buttonWithType(UIButtonTypeCustom)
|
63
53
|
button.frame = rect
|
64
54
|
fontSize = 25.0
|
65
55
|
|
66
|
-
|
67
|
-
|
56
|
+
button.backgroundColor = grayBackground ? @text_color : UIColor.whiteColor
|
57
|
+
|
58
|
+
if num != @numberOfKeys
|
59
|
+
button.titleLabel.font = UIFont.systemFontOfSize(fontSize)
|
60
|
+
button.setTitleColor(UIColor.darkTextColor, forState:UIControlStateNormal)
|
61
|
+
button.setTitle(buttonTitleForNumber(num), forState:UIControlStateNormal)
|
62
|
+
else
|
63
|
+
#button.backgroundColor = @text_color
|
64
|
+
button.setImage(UIImage.imageNamed("deleteButton"), forState:UIControlStateNormal)
|
65
|
+
button.setAccessibilityLabel("delete")
|
68
66
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
button.
|
67
|
+
|
68
|
+
if num == @numberOfKeys || num == (@numberOfKeys - 2)
|
69
|
+
button.backgroundColor = @text_color
|
70
|
+
end
|
71
|
+
|
72
|
+
button.tag = num
|
75
73
|
button.addTarget(self, action:"changeButtonBackgroundColourForHighlight:", forControlEvents: (UIControlEventTouchDown|UIControlEventTouchDragEnter|UIControlEventTouchDragExit))
|
76
74
|
button.addTarget(self, action:"changeTextFieldText:", forControlEvents: UIControlEventTouchUpInside)
|
77
|
-
|
75
|
+
|
78
76
|
self.addSubview(button)
|
79
77
|
end
|
80
78
|
|
81
79
|
def buttonTitleForNumber(num)
|
82
80
|
str = num.to_s
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
str = "F#%K"
|
81
|
+
|
82
|
+
if num > 9 && @numberOfKeys == 18
|
83
|
+
str = ["a", "b", "c", "d", "e", "f",@dividerChar,"0","del"][num - 10]
|
84
|
+
elsif num > 9
|
85
|
+
str = [@dividerChar,"0","del"][num - 10]
|
89
86
|
end
|
90
87
|
str
|
91
88
|
end
|
92
|
-
|
89
|
+
|
93
90
|
def buttonOriginPointForNumber(num)
|
94
91
|
point = CGPointMake(0.0,0.0)
|
95
|
-
|
92
|
+
|
96
93
|
if (num % 3) == 2 # 2nd button in the row
|
97
|
-
point.x =
|
94
|
+
point.x = @key_width.ceil
|
98
95
|
elsif (num % 3) == 0 # 3rd button in the row
|
99
|
-
point.x = (
|
96
|
+
point.x = (@key_width * 2.0).ceil
|
100
97
|
end
|
101
|
-
|
98
|
+
|
102
99
|
if num > 3 # The row multiplied by row's height
|
103
|
-
point.y = ((num - 1) / 3.0).floor * (@
|
100
|
+
point.y = ((num - 1) / 3.0).floor * (@key_height + 0.5)
|
104
101
|
end
|
105
102
|
point
|
106
103
|
end
|
107
104
|
|
108
105
|
def changeButtonBackgroundColourForHighlight(button)
|
109
|
-
if button.backgroundColor ==
|
106
|
+
if button.backgroundColor == @text_color
|
110
107
|
button.backgroundColor = UIColor.whiteColor
|
111
108
|
else
|
112
|
-
button.backgroundColor =
|
109
|
+
button.backgroundColor = @text_color
|
113
110
|
end
|
114
111
|
end
|
115
112
|
|
116
113
|
def changeTextFieldText(button)
|
117
|
-
if button.tag == @numberOfKeys
|
114
|
+
if button.tag == @numberOfKeys # Last key
|
118
115
|
@textField.text = "#{@textField.text.chop}"
|
119
116
|
else
|
120
117
|
@textField.text = "#{@textField.text}#{button.titleLabel.text}"
|
@@ -123,4 +120,4 @@ module RMIPKeyboard
|
|
123
120
|
end
|
124
121
|
|
125
122
|
end
|
126
|
-
end
|
123
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-ipkeyboard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diogo André
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Custom iPhone keyboard. Made for iOS7
|
14
14
|
email: diogo@regattapix.com
|