Class: Motionscan::Scanner

Inherits:
Object
  • Object
show all
Includes:
Flash
Defined in:
lib/motionscan/scanner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Flash

#flash

Instance Attribute Details

#flashEnabledObject

Returns the value of attribute flashEnabled.



5
6
7
# File 'lib/motionscan/scanner.rb', line 5

def flashEnabled
  @flashEnabled
end

#frameObject

Returns the value of attribute frame.



6
7
8
# File 'lib/motionscan/scanner.rb', line 6

def frame
  @frame
end

#viewObject (readonly)

Returns the value of attribute view.



8
9
10
# File 'lib/motionscan/scanner.rb', line 8

def view
  @view
end

Class Method Details

.initWithFrame(frame) ⇒ Object



10
11
12
13
14
# File 'lib/motionscan/scanner.rb', line 10

def self.initWithFrame(frame)
  instance = allocate
  instance.scannerInitializer(frame)
  instance
end

Instance Method Details

#displayScannerInView(view) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/motionscan/scanner.rb', line 26

def displayScannerInView(view)
  @session = MSScannerSession.alloc.initWithScanner(MSScanner.sharedInstance)
  @session.scanOptions = MS_RESULT_TYPE_IMAGE
  @session.delegate = self

  @view.backgroundColor = UIColor.blackColor
  @view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
  @view.autoresizesSubviews = true
  view.addSubview(@view)
end

#pauseObject



66
67
68
# File 'lib/motionscan/scanner.rb', line 66

def pause
  @session.pause
end

#resumeObject



62
63
64
# File 'lib/motionscan/scanner.rb', line 62

def resume
  @session.resume
end

#scannerInitializer(frame) ⇒ Object



16
17
18
19
20
# File 'lib/motionscan/scanner.rb', line 16

def scannerInitializer(frame)
  @frame = frame
  @flashEnabled = true
  @view = UIView.alloc.initWithFrame(frame)
end

#searchWithStatus(searchStarted, success: searchCompleted, error: searchError, notFound: searchNotFound) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/motionscan/scanner.rb', line 70

def searchWithStatus(searchStarted, success:searchCompleted,error:searchError,notFound:searchNotFound)
  @searchStarted = searchStarted
  @searchCompleted = searchCompleted
  @searchError = searchError
  @searchNotFound = searchNotFound

  self.flash if @flashEnabled
  @session.snap
  @session.pause
end

#startWithStatus(scanStarted, success: scanCompleted, error: scanError, notFound: scanNotFound) ⇒ Object

scanner session flow



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/motionscan/scanner.rb', line 38

def startWithStatus(scanStarted, success:scanCompleted, 
  error:scanError, notFound:scanNotFound)
  scanStarted.call
  @scanCompleted = scanCompleted
  @scanError = scanError
  @scanNotFound = scanNotFound

  viewLayer = @view.layer
  viewLayer.setMasksToBounds(true)

  captureLayer = @session.previewLayer
  captureLayer.setFrame(@view.bounds)
  
  viewLayer.insertSublayer(captureLayer, below:viewLayer.sublayers)

  @session.startCapture
end

#stopObject



56
57
58
59
60
# File 'lib/motionscan/scanner.rb', line 56

def stop
  @session.stopCapture
  @session.cancel
  @view.removeFromSuperview
end