Class: Debugmotion::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/debugmotion/logger.rb

Constant Summary collapse

@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



7
8
9
10
# File 'lib/debugmotion/logger.rb', line 7

def self.instance
  return @@instance unless @@instance.nil?
  @@instance = Logger.alloc.init
end

Instance Method Details

#log(value) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/debugmotion/logger.rb', line 23

def log(value)
  # hack for when you try to use debug motion in your root view controller
  # and your application:didFinishLaunchingWithOptions: has not yet ended
  unless UIApplication.sharedApplication.keyWindow.nil?
    App.notification_center.post("DebugMotionEventLogged", value)
  else
    App.run_after(0.1) { log(value) }
  end
end

#start(frame) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/debugmotion/logger.rb', line 12

def start(frame)
  @debug_view = Console.alloc.initWithFrame(frame)
  @debug_view.backgroundColor = UIColor.darkGrayColor
  UIApplication.sharedApplication.keyWindow.addSubview(@debug_view)

  App.notification_center.observe "DebugMotionEventLogged" do |notification|
    time = Time.new
    @debug_view.append_text("[#{time.hour}:#{time.min}:#{time.sec}] #{notification.object}")
  end
end