tgios 0.0.33 → 0.0.34

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmQ2NjZhNDUwNmRiOTJjNTAyY2MzYmMzN2Q3ZWY1MTY2NjNjNGM5Zg==
4
+ ZGQxNmQ5YzAxNDM2MTUxYWRhYTc5ZmQ0YjIyYjVhZjgxYzljNDUyZA==
5
5
  data.tar.gz: !binary |-
6
- NGFjMWE1YWJiYmI1YzM3MTQzYjI4ODhjOWFiNDhkNzAwYzIxZWM1ZA==
6
+ MjViMzE5MmQ0ZmI4N2Q2MzU5NTc3ZTA3OWUwY2JiZWZmMWVmODJkMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDk4MDFhN2I1NzkwYWM3NmRiMTY1ZmMyOGZiYzcwOGViMWUzNGE5MGFiMzU0
10
- NWM0MDI0OTEyMTBjNDk5YzJjMGJhMGQ0YzFmNWYwY2JiYWE4YmUzN2UwZTk5
11
- OGVjNzFiZmI5MGU5OTJkZjg3MjI4MTk4MDNmMWJlZmMxYzgxZjU=
9
+ ODM3OTgyMTdjZGIzMDkxZjg0NWI4MWQzYjc4MTI1MzdhNjk2ZTE1ODEwYWVh
10
+ OTY3MmY3ZDMwNjZiZTk2N2NlNzMwYWU2YjJlZTFmMGVlMmUzMWZiZmQ2NGVh
11
+ YzY1MDFiZDgwODU5NmI3YjFiMWE5MTM0ODRiNmRlYzU4NmExZWM=
12
12
  data.tar.gz: !binary |-
13
- YzJmMDQ4NDc3ODk0MjE4NjJmNDQxYzFlYmY2N2M3MmY4ZmFiYTg0NTM0NWQ1
14
- NzJjNDQxMjEyNDFiMWMyNDJiOWQ4ZWZmOGZhNmE3Y2IyMzkyNjZhMTRmODNi
15
- MjgyYTJlNTBmM2E0OTlhNzg3MjQ3Yjc3MmZkYWNkNzYyYWZlZmI=
13
+ ZDE1YjNjMGI4ZjA0NjViOTViYjQwN2VlMGRkM2Q3NjNkN2EzZTNhZmU1ZWQ3
14
+ YjA0ZDU3OTZlNTEwN2E0OWIwMzRmYWQ3YzNhMGVlMGQyNGVjZGRiYjE4ZTQ1
15
+ NTUzOTc1NGVkZTg1MDAyZjVjOTk0NDkzMzgyZGQ4Yzc2OTI4MDI=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tgios (0.0.33)
4
+ tgios (0.0.34)
5
5
  awesome_print_motion
6
6
  motion-layout
7
7
  plastic_cup (>= 0.1.1)
@@ -11,7 +11,11 @@ module Tgios
11
11
  end
12
12
 
13
13
  class BeaconManager < BindingBase
14
- attr_accessor :rssi
14
+ attr_accessor :rssi, :current_beacon
15
+
16
+ BeaconFoundKey = 'Tgios::BeaconManager::BeaconFound'
17
+ EnterRegionKey = 'Tgios::BeaconManager::EnterRegion'
18
+ ExitRegionKey = 'Tgios::BeaconManager::ExitRegion'
15
19
 
16
20
  def self.default=(val)
17
21
  @default = val
@@ -21,9 +25,11 @@ module Tgios
21
25
  @default
22
26
  end
23
27
 
24
- def initialize(uuid, rssi=-70)
28
+ def initialize(uuid, rssi=-70, background=false, tolerance=5)
25
29
  @events = {}
26
30
  @previous_beacons = []
31
+ @background = background
32
+ @tolerance = (tolerance || 5)
27
33
 
28
34
  @uuid = NSUUID.alloc.initWithUUIDString(uuid)
29
35
  @rssi = rssi
@@ -47,38 +53,45 @@ module Tgios
47
53
  def locationManager(manager, didDetermineState: state, forRegion: region)
48
54
  NSLog "didDetermineState #{state}"
49
55
  if state == CLRegionStateInside
50
- location_manager.startRangingBeaconsInRegion(region)
56
+ manager.startRangingBeaconsInRegion(region)
51
57
  end
52
58
  end
53
59
 
54
60
  def locationManager(manager, didEnterRegion: region)
55
61
  NSLog 'didEnterRegion'
56
62
  if region.isKindOfClass(CLBeaconRegion)
57
- location_manager.startRangingBeaconsInRegion(region)
63
+ manager.startRangingBeaconsInRegion(region)
58
64
  end
59
65
  end
60
66
 
61
67
  def locationManager(manager, didExitRegion: region)
62
68
  NSLog 'didExitRegion'
63
69
  if region.isKindOfClass(CLBeaconRegion)
64
- location_manager.stopRangingBeaconsInRegion(region)
70
+ manager.stopRangingBeaconsInRegion(region)
71
+ if has_event(:exit_region)
72
+ @events[:exit_region].call(region)
73
+ end
65
74
  end
66
75
  end
67
76
 
68
77
  def locationManager(manager, didRangeBeacons: beacons, inRegion: region)
69
78
  if has_event(:beacons_found)
70
- @events[:beacons_found].call(beacons.select{|b| b.proximity != CLProximityUnknown && b.rssi >= @rssi})
79
+ @events[:beacons_found].call(beacons.select{|b| b.proximity != CLProximityUnknown && b.rssi >= @rssi}, beacons)
71
80
  end
72
- if has_event(:beacon_found)
73
- known_beacons = beacons.select{|b| b.proximity != CLProximityUnknown}.sort_by{|b| b.rssi}
74
- if known_beacons.present?
75
- beacon = known_beacons.last if known_beacons.last.rssi >= @rssi
76
- beacon ||= known_beacons.last if known_beacons.length == 1 && known_beacons.last.rssi >= @rssi - 1
77
- end
78
81
 
79
- push_beacon(beacon)
82
+ known_beacons = beacons.select{|b| b.proximity != CLProximityUnknown}.sort_by{|b| b.rssi}
83
+ if known_beacons.present?
84
+ beacon = known_beacons.last if known_beacons.last.rssi >= @rssi
85
+ beacon ||= known_beacons.last if known_beacons.length == 1 && known_beacons.last.rssi >= @rssi - 1
86
+ end
87
+
88
+ push_beacon(beacon)
89
+
90
+ if has_event(:beacon_found)
80
91
  @events[:beacon_found].call(@current_beacon)
81
92
  end
93
+
94
+ BeaconFoundKey.post_notification(self, {region: region, beacon: @current_beacon})
82
95
  end
83
96
 
84
97
  def location_manager
@@ -86,10 +99,26 @@ module Tgios
86
99
  begin
87
100
  manager = CLLocationManager.alloc.init
88
101
  manager.delegate = self
102
+ request_authorization(manager)
89
103
  manager
90
104
  end
91
105
  end
92
106
 
107
+ def request_authorization(manager)
108
+ if manager.respond_to?(:requestAlwaysAuthorization)
109
+ status = CLLocationManager.authorizationStatus
110
+ if status == KCLAuthorizationStatusAuthorizedWhenInUse || status == KCLAuthorizationStatusDenied
111
+ title = (status == kCLAuthorizationStatusDenied) ? "Location services are off" : "Background location is not enabled"
112
+ message = "To use background location you must turn on 'Always' in the Location Services Settings"
113
+
114
+ UIAlertView.alert(title, message: message)
115
+ else
116
+ manager.requestAlwaysAuthorization
117
+ end
118
+ end
119
+
120
+ end
121
+
93
122
  def start_monitor
94
123
  location_manager.startMonitoringForRegion(@region)
95
124
  location_manager.requestStateForRegion(@region)
@@ -107,7 +136,7 @@ module Tgios
107
136
 
108
137
  def on_enter_background(noti)
109
138
  NSLog 'on_enter_background'
110
- stop_monitor
139
+ stop_monitor unless @background
111
140
  end
112
141
 
113
142
  def has_event(event)
@@ -125,7 +154,7 @@ module Tgios
125
154
  end
126
155
  end
127
156
  @previous_beacons << beacon
128
- @previous_beacons.delete_at(0) if @previous_beacons.length > 3
157
+ @previous_beacons.delete_at(0) if @previous_beacons.length > @tolerance
129
158
  end
130
159
 
131
160
  def beacon_eqs(beacon1, beacon2)
@@ -1,5 +1,7 @@
1
1
  module Tgios
2
2
  class ScanQrController < UIViewController
3
+ attr_accessor :types
4
+
3
5
  def viewDidLoad
4
6
  super
5
7
  self.view.backgroundColor = :dark_gray.uicolor
@@ -39,25 +41,13 @@ module Tgios
39
41
  @output = AVCaptureMetadataOutput.alloc.init
40
42
  @output.setMetadataObjectsDelegate self, queue: @queue.dispatch_object
41
43
 
42
- @session.addInput @input
43
- @session.addOutput @output
44
- @output.metadataObjectTypes = [ AVMetadataObjectTypeQRCode ]
45
-
46
- @isScanning = true
47
-
48
- @session.startRunning
49
- #NSLog "session running: #{@session.running?}"
50
-
51
-
52
-
53
44
  camera_size = layerRect.size
54
45
  sq_size = 240
55
46
  sq_border = 20
56
47
  line_length = 60
48
+ border_color = :white.cgcolor(0.8)
57
49
  sq_x = (camera_size.width - sq_size) / 2
58
50
  sq_y = (camera_size.height - sq_size) / 2
59
- v_height = sq_size - sq_border * 2
60
- border_color = :white.cgcolor(0.8)
61
51
 
62
52
  square = Base.style(CALayer.layer, {frame: [[sq_x, sq_y],[sq_size, sq_size]]})
63
53
 
@@ -81,25 +71,30 @@ module Tgios
81
71
 
82
72
  self.view.layer.addSublayer square
83
73
 
74
+ @output.rectOfInterest = [[sq_y / camera_size.height, sq_x / camera_size.width], [sq_size / camera_size.height, sq_size / camera_size.width]]
75
+
76
+ @session.addInput @input
77
+ @session.addOutput @output
78
+ @output.metadataObjectTypes = ( @types || [AVMetadataObjectTypeQRCode] )
79
+
80
+ @isScanning = true
81
+
82
+ @session.startRunning
83
+
84
84
  true
85
85
  end
86
86
 
87
87
  def captureOutput(captureOutput, didOutputMetadataObjects: metadataObjects, fromConnection: connection)
88
-
89
88
  metadataObject = metadataObjects[0]
90
89
 
91
- if !@scanned && metadataObject.present? && metadataObject.type == AVMetadataObjectTypeQRCode
90
+ if !@scanned && metadataObject.present?
92
91
  @scanned = true
93
- #NSLog "#{metadataObjects[0].stringValue}"
94
-
95
92
 
96
93
  self.performSelectorOnMainThread('openQRCode:', withObject: metadataObject.stringValue, waitUntilDone: false)
97
94
  end
98
95
  end
99
96
 
100
97
  def openQRCode(result)
101
- #NSLog "openQRCode()"
102
-
103
98
  stop_scanning
104
99
 
105
100
  @events[:result_scanned].call(result)
@@ -114,7 +109,6 @@ module Tgios
114
109
  @isScanning = false
115
110
 
116
111
  @session.stopRunning
117
- #NSLog "session running: #{@session.running?}"
118
112
 
119
113
  @previewLayer.removeFromSuperlayer
120
114
  @previewLayer = nil
@@ -66,6 +66,15 @@ module Tgios
66
66
  end
67
67
 
68
68
  def tableView(tableView, heightForRowAtIndexPath: index_path)
69
+ height = if @events.has_key?(:cell_height)
70
+ record = @list[index_path.row]
71
+ @events[:cell_height].call(index_path, record)
72
+ end
73
+ return height if height.is_a?(Numeric)
74
+ cell_height
75
+ end
76
+
77
+ def cell_height
69
78
  return @options[:height] unless @options[:height].nil?
70
79
  if @options[:lines]
71
80
  26 + 19 * (@options[:lines] || 2)
@@ -88,6 +97,32 @@ module Tgios
88
97
  end
89
98
  end
90
99
  end
100
+
101
+ def tableView(tableView, commitEditingStyle: editingStyle, forRowAtIndexPath: index_path)
102
+ if editingStyle == UITableViewCellEditingStyleDelete
103
+ if @events[:delete_row].present?
104
+ @events[:delete_row].call(@list[index_path.row], {tableView: tableView, commitEditingStyle: editingStyle, forRowAtIndexPath:index_path}) do |success|
105
+ tableView.deleteRowsAtIndexPaths([index_path], withRowAnimation: UITableViewRowAnimationFade) if success
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ def tableView(tableView, canEditRowAtIndexPath: index_path)
112
+ can_edit = false
113
+
114
+ if @events[:delete_row].present?
115
+ if @events[:can_edit].present?
116
+ @events[:can_edit].call(tableView, index_path) do |success|
117
+ can_edit = success
118
+ end
119
+ else
120
+ can_edit = true
121
+ end
122
+ end
123
+
124
+ can_edit
125
+ end
91
126
 
92
127
  def onPrepareForRelease
93
128
  @events=nil
@@ -103,4 +138,4 @@ module Tgios
103
138
 
104
139
  end
105
140
 
106
- end
141
+ end
@@ -45,10 +45,14 @@ module Tgios
45
45
  bindings_prepare_release
46
46
  @bindings={}
47
47
  @tv_bindings={}
48
- self.model=model
49
48
  @tableView.dataSource=self
50
49
  @tableView.delegate=self
51
- @table_utility_binding = UITableViewUtilityBinding.new.bind(@tableView)
50
+ self.model=model
51
+ if @table_utility_binding.nil?
52
+ @table_utility_binding = UITableViewUtilityBinding.new.bind(@tableView)
53
+ else
54
+ @table_utility_binding.bind(@tableView)
55
+ end
52
56
  self
53
57
  end
54
58
 
data/lib/tgios/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tgios
2
- VERSION = '0.0.33'
2
+ VERSION = '0.0.34'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tgios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33
4
+ version: 0.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - April Tsang
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-22 00:00:00.000000000 Z
12
+ date: 2014-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sugarcube