Sha256: 7b6de9b754601745e9d247b7b154d8e1ef101acedb9d43a48a3275cf4cc53e0c

Contents?: true

Size: 1.81 KB

Versions: 11

Compression:

Stored size: 1.81 KB

Contents

class SurfaceHolderWrapper

  include JavaMethodHelper

  java_native_method Java::com.droiuby.client.core.wrappers.SurfaceViewHolderWrapper, :lockCanvas, [], "java_lockCanvasVoid"
  java_native_method Java::com.droiuby.client.core.wrappers.SurfaceViewHolderWrapper, :lockCanvas, [Java::android.graphics.Rect], "java_lockCanvas"
  java_native_method Java::com.droiuby.client.core.wrappers.SurfaceViewHolderWrapper, :unlockCanvasAndPost, [Java::android.graphics.Canvas]

  def initialize(surface)
    @native = surface
  end

  def native
    @native
  end

  def lock(rect = nil, &block)
    if rect.nil?
#      canvas = Canvas.new(native.lockCanvas)


      canvas_lock = java_lockCanvasVoid
      canvas = CanvasWrapper.new(canvas_lock)
    else
#      canvas = Canvas.new(native.lockCanvas(rect))
      canvas = CanvasWrapper.new(java_lockCanvas(rect.native))
    end
    block.call(canvas)
#    native.unlockCanvasAndPost(canvas.native)
    java_unlockCanvasAndPost(canvas.native)
  end

end

class SurfaceViewWrapper < ViewWrapper

  def initialize(view = nil)
    unless view.nil?
      @view = view
    else
      @view = Java::com.droiuby.client.core.wrappers.SurfaceViewWrapper.new(_current_activity, _execution_bundle)
    end
    @builder = Java::com.droiuby.client.core.builder.ViewBuilder.new
    @builder.setContext(_current_activity)
  end

  def on(event, &block)
    case(event.to_sym)
        when :surface_created
          auto_wrap_block = Proc.new { |surface| block.call(SurfaceHolderWrapper.new(surface))}
          self.native.setSurfaceCreatedBlock(auto_wrap_block)
        when :surface_destroyed
          auto_wrap_block = Proc.new { |surface| block.call(SurfaceHolderWrapper.new(surface))}
          self.native.setSurfaceDestroyedBlock(auto_wrap_block)
        else
          super(event.to_sym, &block)
      end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
droiuby-0.3.6 lib/droiuby/wrappers/surface_view_wrapper.rb
droiuby-0.3.5 lib/droiuby/wrappers/surface_view_wrapper.rb
droiuby-0.3.4 lib/droiuby/wrappers/surface_view_wrapper.rb
droiuby-0.3.3 lib/droiuby/wrappers/surface_view_wrapper.rb
droiuby-0.3.2 lib/droiuby/wrappers/surface_view_wrapper.rb
droiuby-0.3.1 lib/droiuby/wrappers/surface_view_wrapper.rb
droiuby-0.3.0 lib/droiuby/wrappers/surface_view_wrapper.rb
droiuby-0.2.9 lib/droiuby/wrappers/surface_view_wrapper.rb
droiuby-0.2.8 lib/droiuby/wrappers/surface_view_wrapper.rb
droiuby-0.2.7 lib/droiuby/wrappers/surface_view_wrapper.rb
droiuby-0.2.6 lib/droiuby/wrappers/surface_view_wrapper.rb