Sha256: e08580b75bd1b3a2e41de2fed8f9d64ddd855fb08f58a247458bf0c7f8db7852

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'ruboto/base'
require 'ruboto/package'

#######################################################
#
# ruboto/service.rb
#
# Basic service set up and callback configuration.
#
#######################################################

#
# Context
#

module Ruboto
  module Context
    def initialize_ruboto()
      eval("#{$new_context_global} = self")
      $new_context_global = nil

      instance_eval &$context_init_block if $context_init_block
      $context_init_block = nil
      setup_ruboto_callbacks 

      @initialized = true
      self
    end
  
    def start_ruboto_service(global_variable_name = '$service', klass=RubotoService, &block)
      $context_init_block = block
      $new_context_global = global_variable_name
  
      if @initialized or (self == $service) or ($service == nil) # FIx mix between activity and service
        self.startService Java::android.content.Intent.new(self, klass.java_class)
      else
        initialize_ruboto
        on_create
      end
  
      self
    end
  end
end

java_import "android.content.Context"
Context.class_eval do
  include Ruboto::Context
end

#
# Leave for legacy Service Subclass Setup
#

module Ruboto
  module Service
    def initialize(java_instance)
      @java_instance = java_instance
    end

    def method_missing(method, *args, &block)
      return @java_instance.send(method, *args, &block) if @java_instance.respond_to?(method)
      super
    end
  end
end

#
# Basic Service Setup
#

def ruboto_configure_service(klass)
  klass.class_eval do
    include Ruboto::Service
    
    def on_create
    end
  end
end

ruboto_import "org.ruboto.RubotoService"
ruboto_configure_service(RubotoService)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruboto-0.7.0 assets/src/ruboto/service.rb