ruboto 0.7.0 → 0.8.0
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.
- data/Gemfile +1 -1
 - data/Gemfile.lock +0 -2
 - data/Rakefile +64 -1
 - data/assets/rakelib/ruboto.rake +23 -2
 - data/assets/res/layout/get_ruboto_core.xml +0 -2
 - data/assets/samples/sample_activity.rb +3 -6
 - data/assets/samples/sample_broadcast_receiver.rb +9 -5
 - data/assets/samples/sample_service.rb +0 -3
 - data/assets/src/InheritingActivity.java +1 -1
 - data/assets/src/InheritingClass.java +10 -4
 - data/assets/src/RubotoActivity.java +90 -20
 - data/assets/src/RubotoBroadcastReceiver.java +59 -23
 - data/assets/src/RubotoService.java +103 -51
 - data/assets/src/org/ruboto/EntryPointActivity.java +2 -1
 - data/assets/src/org/ruboto/JRubyAdapter.java +158 -115
 - data/assets/src/org/ruboto/Script.java +23 -1
 - data/assets/src/org/ruboto/test/ActivityTest.java +2 -2
 - data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +30 -16
 - data/assets/src/ruboto.rb +1 -0
 - data/assets/src/ruboto/activity.rb +2 -6
 - data/assets/src/ruboto/base.rb +9 -7
 - data/assets/src/ruboto/broadcast_receiver.rb +0 -8
 - data/assets/src/ruboto/generate.rb +2 -2
 - data/assets/src/ruboto/service.rb +0 -8
 - data/assets/src/ruboto/widget.rb +17 -2
 - data/lib/java_class_gen/android_api.xml +1 -1
 - data/lib/ruboto/sdk_versions.rb +1 -1
 - data/lib/ruboto/util/build.rb +11 -10
 - data/lib/ruboto/util/code_formatting.rb +2 -2
 - data/lib/ruboto/util/update.rb +20 -7
 - data/lib/ruboto/util/xml_element.rb +42 -16
 - data/lib/ruboto/version.rb +1 -1
 - data/test/activity/call_super_activity.rb +28 -0
 - data/test/activity/call_super_activity_test.rb +15 -0
 - data/test/activity/image_button_activity.rb +2 -3
 - data/test/activity/image_button_and_button_activity.rb +1 -2
 - data/test/activity/margins_activity.rb +17 -0
 - data/test/activity/margins_activity_test.rb +25 -0
 - data/test/activity/navigation_activity.rb +85 -0
 - data/test/activity/navigation_activity_test.rb +98 -0
 - data/test/activity/option_menu_activity.rb +0 -2
 - data/test/activity/psych_activity.rb +2 -3
 - data/test/activity/stack_activity.rb +3 -2
 - data/test/activity/stack_activity_test.rb +9 -7
 - data/test/block_def_activity/margins_activity.rb +17 -0
 - data/test/block_def_activity/margins_activity_test.rb +25 -0
 - data/test/block_def_activity/option_menu_activity_test.rb +1 -2
 - data/test/block_def_activity/stack_activity_test.rb +8 -5
 - data/test/broadcast_receiver_test.rb +2 -2
 - data/test/gem_test.rb +12 -0
 - data/test/handle_activity/margins_activity.rb +15 -0
 - data/test/handle_activity/margins_activity_test.rb +25 -0
 - data/test/handle_activity/option_menu_activity.rb +4 -0
 - data/test/handle_activity/stack_activity.rb +3 -0
 - data/test/handle_activity/stack_activity_test.rb +9 -6
 - data/test/minimal_app_test.rb +1 -1
 - data/test/rake_test.rb +6 -7
 - data/test/ruboto_gen_test.rb +54 -4
 - data/test/ruboto_update_test.rb +12 -8
 - data/test/service_test.rb +1 -6
 - data/test/test_helper.rb +34 -11
 - data/test/update_test_methods.rb +22 -0
 - data/test/view_constants_test.rb +104 -0
 - metadata +17 -5
 
    
        data/Gemfile
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -31,6 +31,7 @@ end 
     | 
|
| 
       31 
31 
     | 
    
         
             
            task :install => :gem do
         
     | 
| 
       32 
32 
     | 
    
         
             
              `gem query -i -n ^ruboto$ -v #{Ruboto::VERSION}`
         
     | 
| 
       33 
33 
     | 
    
         
             
              if $? != 0
         
     | 
| 
      
 34 
     | 
    
         
            +
                puts 'Installing gem'
         
     | 
| 
       34 
35 
     | 
    
         
             
                cmd = "gem install ruboto-#{Ruboto::VERSION}.gem"
         
     | 
| 
       35 
36 
     | 
    
         
             
                output = `#{cmd}`
         
     | 
| 
       36 
37 
     | 
    
         
             
                if $? == 0
         
     | 
| 
         @@ -43,6 +44,24 @@ task :install => :gem do 
     | 
|
| 
       43 
44 
     | 
    
         
             
              end
         
     | 
| 
       44 
45 
     | 
    
         
             
            end
         
     | 
| 
       45 
46 
     | 
    
         | 
| 
      
 47 
     | 
    
         
            +
            task :uninstall do
         
     | 
| 
      
 48 
     | 
    
         
            +
              `gem query -i -n ^ruboto$ -v #{Ruboto::VERSION}`
         
     | 
| 
      
 49 
     | 
    
         
            +
              if $? == 0
         
     | 
| 
      
 50 
     | 
    
         
            +
                puts 'Uninstalling gem'
         
     | 
| 
      
 51 
     | 
    
         
            +
                cmd = "gem uninstall ruboto -v #{Ruboto::VERSION}"
         
     | 
| 
      
 52 
     | 
    
         
            +
                output = `#{cmd}`
         
     | 
| 
      
 53 
     | 
    
         
            +
                if $? == 0
         
     | 
| 
      
 54 
     | 
    
         
            +
                  puts output
         
     | 
| 
      
 55 
     | 
    
         
            +
                else
         
     | 
| 
      
 56 
     | 
    
         
            +
                  sh "sudo #{cmd}"
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
              else
         
     | 
| 
      
 59 
     | 
    
         
            +
                puts "ruboto-#{Ruboto::VERSION} is not installed."
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
            end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
            task :reinstall => [:uninstall, :clean, :install]
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
       46 
65 
     | 
    
         
             
            desc "Generate an example app"
         
     | 
| 
       47 
66 
     | 
    
         
             
            task :example => EXAMPLE_FILE
         
     | 
| 
       48 
67 
     | 
    
         | 
| 
         @@ -57,6 +76,49 @@ file EXAMPLE_FILE => :install do 
     | 
|
| 
       57 
76 
     | 
    
         
             
              end
         
     | 
| 
       58 
77 
     | 
    
         
             
            end
         
     | 
| 
       59 
78 
     | 
    
         | 
| 
      
 79 
     | 
    
         
            +
            desc 'Generate release docs for a given milestone'
         
     | 
| 
      
 80 
     | 
    
         
            +
            task :release_docs do
         
     | 
| 
      
 81 
     | 
    
         
            +
              # require 'rubygems'
         
     | 
| 
      
 82 
     | 
    
         
            +
              # require 'highline/import'
         
     | 
| 
      
 83 
     | 
    
         
            +
              print 'user name: ' ; user = STDIN.gets.chomp # ask('login   : ') { |q| q.echo = true }
         
     | 
| 
      
 84 
     | 
    
         
            +
              print 'password : ' ; pass = STDIN.gets.chomp # ask('password: ') { |q| q.echo = '*' }
         
     | 
| 
      
 85 
     | 
    
         
            +
              print 'milestone: ' ; milestone = STDIN.gets.chomp # ask('milestone: ', Integer) { |q| q.echo = true }
         
     | 
| 
      
 86 
     | 
    
         
            +
              require 'uri'
         
     | 
| 
      
 87 
     | 
    
         
            +
              require 'net/http'
         
     | 
| 
      
 88 
     | 
    
         
            +
              require 'net/https'
         
     | 
| 
      
 89 
     | 
    
         
            +
              require 'openssl'
         
     | 
| 
      
 90 
     | 
    
         
            +
              require 'yaml'
         
     | 
| 
      
 91 
     | 
    
         
            +
              uri = URI(%Q{https://api.github.com/repos/ruboto/ruboto/issues?milestone=#{milestone}&state=closed&per_page=1000})
         
     | 
| 
      
 92 
     | 
    
         
            +
              https = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
      
 93 
     | 
    
         
            +
              https.use_ssl = true
         
     | 
| 
      
 94 
     | 
    
         
            +
              https.verify_mode = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
      
 95 
     | 
    
         
            +
              req = Net::HTTP::Get.new(uri.request_uri)
         
     | 
| 
      
 96 
     | 
    
         
            +
              req.basic_auth(user, pass)
         
     | 
| 
      
 97 
     | 
    
         
            +
              res = https.start { |http| http.request(req) }
         
     | 
| 
      
 98 
     | 
    
         
            +
              issues = YAML.load(res.body).sort_by { |i| i['number'] }
         
     | 
| 
      
 99 
     | 
    
         
            +
              milestone_name = issues[0] ? issues[0]['milestone']['title'] : "No issues for milestone #{milestone}"
         
     | 
| 
      
 100 
     | 
    
         
            +
              categories = {'Features' => 'feature', 'Bugfixes' => 'bug', 'Internal' => 'internal', 'Support' => 'support', 'Documentation' => 'documentation', 'Other' => nil}
         
     | 
| 
      
 101 
     | 
    
         
            +
              grouped_issues = issues.group_by do |i|
         
     | 
| 
      
 102 
     | 
    
         
            +
                labels = i['labels'].map { |l| l['name']}
         
     | 
| 
      
 103 
     | 
    
         
            +
                cat = nil
         
     | 
| 
      
 104 
     | 
    
         
            +
                categories.each do |k,v|
         
     | 
| 
      
 105 
     | 
    
         
            +
                  if labels.include? v
         
     | 
| 
      
 106 
     | 
    
         
            +
                    cat = k
         
     | 
| 
      
 107 
     | 
    
         
            +
                    break
         
     | 
| 
      
 108 
     | 
    
         
            +
                  end
         
     | 
| 
      
 109 
     | 
    
         
            +
                end
         
     | 
| 
      
 110 
     | 
    
         
            +
                cat || 'Other'
         
     | 
| 
      
 111 
     | 
    
         
            +
              end
         
     | 
| 
      
 112 
     | 
    
         
            +
              puts "\nNew in version #{milestone_name}:\n\n"
         
     | 
| 
      
 113 
     | 
    
         
            +
              (categories.keys & grouped_issues.keys).each do |cat|
         
     | 
| 
      
 114 
     | 
    
         
            +
                puts "#{cat}:\n\n"
         
     | 
| 
      
 115 
     | 
    
         
            +
                grouped_issues[cat].each { |i| puts %Q{* Issue ##{i['number']} #{i['title']}} }
         
     | 
| 
      
 116 
     | 
    
         
            +
                puts
         
     | 
| 
      
 117 
     | 
    
         
            +
              end
         
     | 
| 
      
 118 
     | 
    
         
            +
              puts "You can find a complete list of issues here:\n\n"
         
     | 
| 
      
 119 
     | 
    
         
            +
              puts "* https://github.com/ruboto/ruboto/issues?state=closed&milestone=#{milestone}\n\n"
         
     | 
| 
      
 120 
     | 
    
         
            +
            end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
       60 
122 
     | 
    
         
             
            desc "Push the gem to RubyGems"
         
     | 
| 
       61 
123 
     | 
    
         
             
            task :release => [:clean, :gem] do
         
     | 
| 
       62 
124 
     | 
    
         
             
              output = `git status --porcelain`
         
     | 
| 
         @@ -67,6 +129,7 @@ task :release => [:clean, :gem] do 
     | 
|
| 
       67 
129 
     | 
    
         | 
| 
       68 
130 
     | 
    
         
             
              Rake::Task[:example].invoke
         
     | 
| 
       69 
131 
     | 
    
         
             
              sh "git add #{EXAMPLE_FILE}"
         
     | 
| 
      
 132 
     | 
    
         
            +
              sh "git rm #{EXAMPLE_FILE.slice(/^\d+\.\d+\.\d+/)}.*"
         
     | 
| 
       70 
133 
     | 
    
         
             
              sh "git commit -m '* Added example app for Ruboto #{Ruboto::VERSION} tools r#{Ruboto::SdkVersions::ANDROID_TOOLS_REVISION}' #{EXAMPLE_FILE}"
         
     | 
| 
       71 
134 
     | 
    
         
             
              sh "git push"
         
     | 
| 
       72 
135 
     | 
    
         
             
            end
         
     | 
| 
         @@ -74,7 +137,7 @@ end 
     | 
|
| 
       74 
137 
     | 
    
         
             
            desc "Run the tests"
         
     | 
| 
       75 
138 
     | 
    
         
             
            task :test do
         
     | 
| 
       76 
139 
     | 
    
         
             
              FileUtils.rm_rf Dir['tmp/RubotoTestApp_template*']
         
     | 
| 
       77 
     | 
    
         
            -
              Dir['test/*_test.rb'].each do |f|
         
     | 
| 
      
 140 
     | 
    
         
            +
              Dir['./test/*_test.rb'].each do |f|
         
     | 
| 
       78 
141 
     | 
    
         
             
                require f.chomp('.rb')
         
     | 
| 
       79 
142 
     | 
    
         
             
              end
         
     | 
| 
       80 
143 
     | 
    
         
             
            end
         
     | 
    
        data/assets/rakelib/ruboto.rake
    CHANGED
    
    | 
         @@ -207,7 +207,12 @@ file BUNDLE_JAR => [GEM_FILE, GEM_LOCK_FILE] do 
     | 
|
| 
       207 
207 
     | 
    
         | 
| 
       208 
208 
     | 
    
         
             
              FileUtils.mkdir_p BUNDLE_PATH
         
     | 
| 
       209 
209 
     | 
    
         
             
              sh "bundle install --gemfile #{GEM_FILE} --path=#{BUNDLE_PATH}"
         
     | 
| 
       210 
     | 
    
         
            -
             
     | 
| 
      
 210 
     | 
    
         
            +
             
     | 
| 
      
 211 
     | 
    
         
            +
              gem_paths = Dir["#{BUNDLE_PATH}/{{,j}ruby,rbx}/{1.8,1.9{,.1},shared}/gems"]
         
     | 
| 
      
 212 
     | 
    
         
            +
              raise "Gem path not found" if gem_paths.empty?
         
     | 
| 
      
 213 
     | 
    
         
            +
              raise "Found multiple gem paths: #{gem_paths}" if gem_paths.size > 1
         
     | 
| 
      
 214 
     | 
    
         
            +
              gem_path = gem_paths[0]
         
     | 
| 
      
 215 
     | 
    
         
            +
              puts "Found gems in #{gem_path}"
         
     | 
| 
       211 
216 
     | 
    
         | 
| 
       212 
217 
     | 
    
         
             
              if package != 'org.ruboto.core' && JRUBY_JARS.none? { |f| File.exists? f }
         
     | 
| 
       213 
218 
     | 
    
         
             
                Dir.chdir gem_path do
         
     | 
| 
         @@ -350,6 +355,17 @@ def package_installed? test = false 
     | 
|
| 
       350 
355 
     | 
    
         
             
                    return false
         
     | 
| 
       351 
356 
     | 
    
         
             
                  end
         
     | 
| 
       352 
357 
     | 
    
         
             
                end
         
     | 
| 
      
 358 
     | 
    
         
            +
             
     | 
| 
      
 359 
     | 
    
         
            +
                sdcard_path = "/mnt/asec/#{package_name}#{i}/pkg.apk"
         
     | 
| 
      
 360 
     | 
    
         
            +
                o = `adb shell ls -l #{sdcard_path}`.chomp
         
     | 
| 
      
 361 
     | 
    
         
            +
                if o =~ /^-r-xr-xr-x system\s+root\s+(\d+) \d{4}-\d{2}-\d{2} \d{2}:\d{2} #{File.basename(sdcard_path)}$/
         
     | 
| 
      
 362 
     | 
    
         
            +
                  apk_file = test ? TEST_APK_FILE : APK_FILE
         
     | 
| 
      
 363 
     | 
    
         
            +
                  if !File.exists?(apk_file) || $1.to_i == File.size(apk_file)
         
     | 
| 
      
 364 
     | 
    
         
            +
                    return true
         
     | 
| 
      
 365 
     | 
    
         
            +
                  else
         
     | 
| 
      
 366 
     | 
    
         
            +
                    return false
         
     | 
| 
      
 367 
     | 
    
         
            +
                  end
         
     | 
| 
      
 368 
     | 
    
         
            +
                end
         
     | 
| 
       353 
369 
     | 
    
         
             
              end
         
     | 
| 
       354 
370 
     | 
    
         
             
              return nil
         
     | 
| 
       355 
371 
     | 
    
         
             
            end
         
     | 
| 
         @@ -397,7 +413,10 @@ def install_apk 
     | 
|
| 
       397 
413 
     | 
    
         
             
              when false
         
     | 
| 
       398 
414 
     | 
    
         
             
                puts "Package #{package} already installed, but of different size.  Replacing package."
         
     | 
| 
       399 
415 
     | 
    
         
             
                output = `adb install -r #{APK_FILE} 2>&1`
         
     | 
| 
       400 
     | 
    
         
            -
                 
     | 
| 
      
 416 
     | 
    
         
            +
                if $? == 0 && output !~ failure_pattern && output =~ success_pattern
         
     | 
| 
      
 417 
     | 
    
         
            +
                  clear_update
         
     | 
| 
      
 418 
     | 
    
         
            +
                  return
         
     | 
| 
      
 419 
     | 
    
         
            +
                end
         
     | 
| 
       401 
420 
     | 
    
         
             
                case $1
         
     | 
| 
       402 
421 
     | 
    
         
             
                when 'INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES'
         
     | 
| 
       403 
422 
     | 
    
         
             
                  puts "Found package signed with different certificate.  Uninstalling it and retrying install."
         
     | 
| 
         @@ -407,7 +426,9 @@ def install_apk 
     | 
|
| 
       407 
426 
     | 
    
         
             
                end
         
     | 
| 
       408 
427 
     | 
    
         
             
                uninstall_apk
         
     | 
| 
       409 
428 
     | 
    
         
             
              end
         
     | 
| 
      
 429 
     | 
    
         
            +
              puts "Installing package #{package}"
         
     | 
| 
       410 
430 
     | 
    
         
             
              output = `adb install #{APK_FILE} 2>&1`
         
     | 
| 
      
 431 
     | 
    
         
            +
              puts output
         
     | 
| 
       411 
432 
     | 
    
         
             
              raise "Install failed (#{$?}) #{$1 ? "[#$1}]" : output}" if $? != 0 || output =~ failure_pattern || output !~ success_pattern
         
     | 
| 
       412 
433 
     | 
    
         
             
              clear_update
         
     | 
| 
       413 
434 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,4 +1,3 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'ruboto/activity'
         
     | 
| 
       2 
1 
     | 
    
         
             
            require 'ruboto/widget'
         
     | 
| 
       3 
2 
     | 
    
         
             
            require 'ruboto/util/toast'
         
     | 
| 
       4 
3 
     | 
    
         | 
| 
         @@ -7,16 +6,14 @@ ruboto_import_widgets :Button, :LinearLayout, :TextView 
     | 
|
| 
       7 
6 
     | 
    
         
             
            # http://xkcd.com/378/
         
     | 
| 
       8 
7 
     | 
    
         | 
| 
       9 
8 
     | 
    
         
             
            class SampleActivity
         
     | 
| 
       10 
     | 
    
         
            -
              include Ruboto::Activity
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
9 
     | 
    
         
             
              def on_create(bundle)
         
     | 
| 
       13 
10 
     | 
    
         
             
                set_title 'Domo arigato, Mr Ruboto!'
         
     | 
| 
       14 
11 
     | 
    
         | 
| 
       15 
12 
     | 
    
         
             
                self.content_view =
         
     | 
| 
       16 
13 
     | 
    
         
             
                    linear_layout :orientation => :vertical do
         
     | 
| 
       17 
     | 
    
         
            -
                      @text_view = text_view :text 
     | 
| 
       18 
     | 
    
         
            -
                                             :gravity =>  
     | 
| 
       19 
     | 
    
         
            -
                      button :text => 'M-x butterfly', :width => : 
     | 
| 
      
 14 
     | 
    
         
            +
                      @text_view = text_view :text => 'What hath Matz wrought?', :id => 42, :width => :match_parent,
         
     | 
| 
      
 15 
     | 
    
         
            +
                                             :gravity => :center, :text_size => 48.0
         
     | 
| 
      
 16 
     | 
    
         
            +
                      button :text => 'M-x butterfly', :width => :match_parent, :id => 43, :on_click_listener => proc { butterfly }
         
     | 
| 
       20 
17 
     | 
    
         
             
                    end
         
     | 
| 
       21 
18 
     | 
    
         
             
              rescue
         
     | 
| 
       22 
19 
     | 
    
         
             
                puts "Exception creating activity: #{$!}"
         
     | 
| 
         @@ -1,15 +1,19 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'ruboto/broadcast_receiver'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
1 
     | 
    
         
             
            import android.util.Log
         
     | 
| 
       4 
2 
     | 
    
         | 
| 
       5 
3 
     | 
    
         
             
            class SampleBroadcastReceiver
         
     | 
| 
       6 
     | 
    
         
            -
              include Ruboto::BroadcastReceiver
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
4 
     | 
    
         
             
              # will get called whenever the BroadcastReceiver receives an intent (whenever onReceive is called)
         
     | 
| 
       9 
5 
     | 
    
         
             
              def on_receive(context, intent)
         
     | 
| 
       10 
6 
     | 
    
         
             
                Log.v "SampleBroadcastReceiver", 'Broadcast received!'
         
     | 
| 
       11 
7 
     | 
    
         
             
                Log.v "SampleBroadcastReceiver", intent.getExtras.to_s
         
     | 
| 
       12 
     | 
    
         
            -
                context.run_on_ui_thread 
     | 
| 
      
 8 
     | 
    
         
            +
                context.run_on_ui_thread do
         
     | 
| 
      
 9 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 10 
     | 
    
         
            +
                    $activity.title = 'Broadcast received!'
         
     | 
| 
      
 11 
     | 
    
         
            +
                  rescue Exception
         
     | 
| 
      
 12 
     | 
    
         
            +
                    Log.e "Exception setting title: #{$!.message}\n#{$!.backtrace.join("\n")}"
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
       13 
15 
     | 
    
         
             
                Log.v "SampleBroadcastReceiver", 'Broadcast processed OK!'
         
     | 
| 
      
 16 
     | 
    
         
            +
              rescue Exception
         
     | 
| 
      
 17 
     | 
    
         
            +
                Log.e "Exception processing broadcast: #{$!.message}\n#{$!.backtrace.join("\n")}"
         
     | 
| 
       14 
18 
     | 
    
         
             
              end
         
     | 
| 
       15 
19 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,4 +1,3 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'ruboto/service'
         
     | 
| 
       2 
1 
     | 
    
         
             
            require 'ruboto/util/toast'
         
     | 
| 
       3 
2 
     | 
    
         | 
| 
       4 
3 
     | 
    
         
             
            # Services are complicated and don't really make sense unless you
         
     | 
| 
         @@ -8,8 +7,6 @@ require 'ruboto/util/toast' 
     | 
|
| 
       8 
7 
     | 
    
         
             
            # online:
         
     | 
| 
       9 
8 
     | 
    
         
             
            # http://developer.android.com/reference/android/app/Service.html
         
     | 
| 
       10 
9 
     | 
    
         
             
            class SampleService
         
     | 
| 
       11 
     | 
    
         
            -
              include Ruboto::Service
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
10 
     | 
    
         
             
              def on_start_command(intent, flags, startId)
         
     | 
| 
       14 
11 
     | 
    
         
             
                toast "Hello from the service"
         
     | 
| 
       15 
12 
     | 
    
         
             
                android.app.Service::START_NOT_STICKY
         
     | 
| 
         @@ -1,18 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // Generated Ruboto subclass with method base "THE_METHOD_BASE"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            package THE_PACKAGE;
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            import org.ruboto.JRubyAdapter;
         
     | 
| 
      
 6 
     | 
    
         
            +
            import org.ruboto.Log;
         
     | 
| 
      
 7 
     | 
    
         
            +
            import org.ruboto.Script;
         
     | 
| 
       4 
8 
     | 
    
         | 
| 
       5 
9 
     | 
    
         
             
            public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
10 
     | 
    
         
             
            THE_CONSTANTS
         
     | 
| 
       8 
11 
     | 
    
         | 
| 
      
 12 
     | 
    
         
            +
                private String rubyClassName = "THE_RUBOTO_CLASS";
         
     | 
| 
      
 13 
     | 
    
         
            +
                private String scriptName = "THE_RUBOTO_CLASS";
         
     | 
| 
      
 14 
     | 
    
         
            +
                private Object rubyInstance = this;
         
     | 
| 
       9 
15 
     | 
    
         
             
                private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
         
     | 
| 
       10 
16 
     | 
    
         | 
| 
       11 
17 
     | 
    
         
             
            THE_CONSTRUCTORS
         
     | 
| 
       12 
18 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
                public void setCallbackProc(int id, Object obj) {
         
     | 
| 
      
 20 
     | 
    
         
            +
                    callbackProcs[id] = obj;
         
     | 
| 
      
 21 
     | 
    
         
            +
                }
         
     | 
| 
       16 
22 
     | 
    
         | 
| 
       17 
23 
     | 
    
         
             
            THE_METHODS
         
     | 
| 
       18 
24 
     | 
    
         | 
| 
         @@ -8,15 +8,15 @@ import android.app.ProgressDialog; 
     | 
|
| 
       8 
8 
     | 
    
         
             
            import android.os.Bundle;
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
         
     | 
| 
      
 11 
     | 
    
         
            +
            THE_CONSTANTS
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                private String rubyClassName;
         
     | 
| 
       11 
14 
     | 
    
         
             
                private String scriptName;
         
     | 
| 
      
 15 
     | 
    
         
            +
                private Object rubyInstance;
         
     | 
| 
      
 16 
     | 
    
         
            +
                private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
         
     | 
| 
       12 
17 
     | 
    
         
             
                private String remoteVariable = null;
         
     | 
| 
       13 
18 
     | 
    
         
             
                private Object[] args;
         
     | 
| 
       14 
19 
     | 
    
         
             
                private Bundle configBundle = null;
         
     | 
| 
       15 
     | 
    
         
            -
                private Object rubyInstance;
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
            THE_CONSTANTS
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                private Object[] callbackProcs = new Object[CONSTANTS_COUNT];
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
                public void setCallbackProc(int id, Object obj) {
         
     | 
| 
       22 
22 
     | 
    
         
             
                    callbackProcs[id] = obj;
         
     | 
| 
         @@ -31,6 +31,10 @@ THE_CONSTANTS 
     | 
|
| 
       31 
31 
     | 
    
         
             
                    return (remoteVariable == null ? "" : (remoteVariable + ".")) + call;
         
     | 
| 
       32 
32 
     | 
    
         
             
                }
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
      
 34 
     | 
    
         
            +
                public void setRubyClassName(String name) {
         
     | 
| 
      
 35 
     | 
    
         
            +
                    rubyClassName = name;
         
     | 
| 
      
 36 
     | 
    
         
            +
                }
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
       34 
38 
     | 
    
         
             
                public void setScriptName(String name) {
         
     | 
| 
       35 
39 
     | 
    
         
             
                    scriptName = name;
         
     | 
| 
       36 
40 
     | 
    
         
             
                }
         
     | 
| 
         @@ -42,6 +46,7 @@ THE_CONSTANTS 
     | 
|
| 
       42 
46 
     | 
    
         | 
| 
       43 
47 
     | 
    
         
             
                @Override
         
     | 
| 
       44 
48 
     | 
    
         
             
                public void onCreate(Bundle bundle) {
         
     | 
| 
      
 49 
     | 
    
         
            +
                    System.out.println("RubotoActivity onCreate(): " + getClass().getName());
         
     | 
| 
       45 
50 
     | 
    
         
             
                    args = new Object[1];
         
     | 
| 
       46 
51 
     | 
    
         
             
                    args[0] = bundle;
         
     | 
| 
       47 
52 
     | 
    
         | 
| 
         @@ -51,6 +56,13 @@ THE_CONSTANTS 
     | 
|
| 
       51 
56 
     | 
    
         
             
                        if (configBundle.containsKey("Theme")) {
         
     | 
| 
       52 
57 
     | 
    
         
             
                            setTheme(configBundle.getInt("Theme"));
         
     | 
| 
       53 
58 
     | 
    
         
             
                        }
         
     | 
| 
      
 59 
     | 
    
         
            +
                        if (configBundle.containsKey("ClassName")) {
         
     | 
| 
      
 60 
     | 
    
         
            +
                            if (this.getClass().getName() == RubotoActivity.class.getName()) {
         
     | 
| 
      
 61 
     | 
    
         
            +
                                setRubyClassName(configBundle.getString("ClassName"));
         
     | 
| 
      
 62 
     | 
    
         
            +
                            } else {
         
     | 
| 
      
 63 
     | 
    
         
            +
                                throw new IllegalArgumentException("Only local Intents may set class name.");
         
     | 
| 
      
 64 
     | 
    
         
            +
                            }
         
     | 
| 
      
 65 
     | 
    
         
            +
                        }
         
     | 
| 
       54 
66 
     | 
    
         
             
                        if (configBundle.containsKey("Script")) {
         
     | 
| 
       55 
67 
     | 
    
         
             
                            if (this.getClass().getName() == RubotoActivity.class.getName()) {
         
     | 
| 
       56 
68 
     | 
    
         
             
                                setScriptName(configBundle.getString("Script"));
         
     | 
| 
         @@ -60,8 +72,15 @@ THE_CONSTANTS 
     | 
|
| 
       60 
72 
     | 
    
         
             
                        }
         
     | 
| 
       61 
73 
     | 
    
         
             
                    }
         
     | 
| 
       62 
74 
     | 
    
         | 
| 
      
 75 
     | 
    
         
            +
                    if (rubyClassName == null && scriptName != null) {
         
     | 
| 
      
 76 
     | 
    
         
            +
                        rubyClassName = Script.toCamelCase(scriptName);
         
     | 
| 
      
 77 
     | 
    
         
            +
                    }
         
     | 
| 
      
 78 
     | 
    
         
            +
                    if (scriptName == null && rubyClassName != null) {
         
     | 
| 
      
 79 
     | 
    
         
            +
                        setScriptName(Script.toSnakeCase(rubyClassName) + ".rb");
         
     | 
| 
      
 80 
     | 
    
         
            +
                    }
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
       63 
82 
     | 
    
         
             
                    super.onCreate(bundle);
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
       65 
84 
     | 
    
         
             
                    if (JRubyAdapter.isInitialized()) {
         
     | 
| 
       66 
85 
     | 
    
         
             
                        prepareJRuby();
         
     | 
| 
       67 
86 
     | 
    
         
             
                	    loadScript();
         
     | 
| 
         @@ -81,26 +100,77 @@ THE_CONSTANTS 
     | 
|
| 
       81 
100 
     | 
    
         
             
                protected void loadScript() {
         
     | 
| 
       82 
101 
     | 
    
         
             
                    try {
         
     | 
| 
       83 
102 
     | 
    
         
             
                        if (scriptName != null) {
         
     | 
| 
       84 
     | 
    
         
            -
                            String rubyClassName = Script.toCamelCase(scriptName);
         
     | 
| 
       85 
103 
     | 
    
         
             
                            System.out.println("Looking for Ruby class: " + rubyClassName);
         
     | 
| 
       86 
104 
     | 
    
         
             
                            Object rubyClass = JRubyAdapter.get(rubyClassName);
         
     | 
| 
       87 
     | 
    
         
            -
                             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
                                 
     | 
| 
       90 
     | 
    
         
            -
                                 
     | 
| 
      
 105 
     | 
    
         
            +
                            Script rubyScript = new Script(scriptName);
         
     | 
| 
      
 106 
     | 
    
         
            +
                            if (rubyScript.exists()) {
         
     | 
| 
      
 107 
     | 
    
         
            +
                                String script = rubyScript.getContents();
         
     | 
| 
      
 108 
     | 
    
         
            +
                                if (script.matches("(?s).*class " + rubyClassName + ".*")) {
         
     | 
| 
      
 109 
     | 
    
         
            +
                                    if (!rubyClassName.equals(getClass().getSimpleName())) {
         
     | 
| 
      
 110 
     | 
    
         
            +
                                        System.out.println("Script defines methods on meta class");
         
     | 
| 
      
 111 
     | 
    
         
            +
                                        // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
         
     | 
| 
      
 112 
     | 
    
         
            +
                                        if (JRubyAdapter.isJRubyPreOneSeven() || JRubyAdapter.isRubyOneEight()) {
         
     | 
| 
      
 113 
     | 
    
         
            +
                                            JRubyAdapter.put("$java_instance", this);
         
     | 
| 
      
 114 
     | 
    
         
            +
                                            JRubyAdapter.put(rubyClassName, JRubyAdapter.runScriptlet("class << $java_instance; self; end"));
         
     | 
| 
      
 115 
     | 
    
         
            +
                                        } else if (JRubyAdapter.isJRubyOneSeven() && JRubyAdapter.isRubyOneNine()) {
         
     | 
| 
      
 116 
     | 
    
         
            +
                                            JRubyAdapter.runScriptlet("Java::" + getClass().getName() + ".__persistent__ = true");
         
     | 
| 
      
 117 
     | 
    
         
            +
                                            JRubyAdapter.put(rubyClassName, JRubyAdapter.runRubyMethod(this, "singleton_class"));
         
     | 
| 
      
 118 
     | 
    
         
            +
                                        } else {
         
     | 
| 
      
 119 
     | 
    
         
            +
                                            throw new RuntimeException("Unknown JRuby/Ruby version: " + JRubyAdapter.get("JRUBY_VERSION") + "/" + JRubyAdapter.get("RUBY_VERSION"));
         
     | 
| 
      
 120 
     | 
    
         
            +
                                        }
         
     | 
| 
      
 121 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 122 
     | 
    
         
            +
                                }
         
     | 
| 
      
 123 
     | 
    
         
            +
                                if (rubyClass == null) {
         
     | 
| 
      
 124 
     | 
    
         
            +
                                    System.out.println("Loading script: " + scriptName);
         
     | 
| 
      
 125 
     | 
    
         
            +
                                    if (script.matches("(?s).*class " + rubyClassName + ".*")) {
         
     | 
| 
      
 126 
     | 
    
         
            +
                                        System.out.println("Script contains class definition");
         
     | 
| 
      
 127 
     | 
    
         
            +
                                        if (rubyClassName.equals(getClass().getSimpleName())) {
         
     | 
| 
      
 128 
     | 
    
         
            +
                                            System.out.println("Script has separate Java class");
         
     | 
| 
      
 129 
     | 
    
         
            +
                                            // FIXME(uwe): Simplify when we stop support for JRuby < 1.7.0
         
     | 
| 
      
 130 
     | 
    
         
            +
                                            if (!JRubyAdapter.isJRubyPreOneSeven()) {
         
     | 
| 
      
 131 
     | 
    
         
            +
                                                JRubyAdapter.runScriptlet("Java::" + getClass().getName() + ".__persistent__ = true");
         
     | 
| 
      
 132 
     | 
    
         
            +
                                            }
         
     | 
| 
      
 133 
     | 
    
         
            +
                                            JRubyAdapter.put(rubyClassName, JRubyAdapter.runScriptlet("Java::" + getClass().getName()));
         
     | 
| 
      
 134 
     | 
    
         
            +
                                        }
         
     | 
| 
      
 135 
     | 
    
         
            +
                                        System.out.println("Set class: " + JRubyAdapter.get(rubyClassName));
         
     | 
| 
      
 136 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 137 
     | 
    
         
            +
                                    JRubyAdapter.setScriptFilename(scriptName);
         
     | 
| 
      
 138 
     | 
    
         
            +
                                    JRubyAdapter.runScriptlet(script);
         
     | 
| 
      
 139 
     | 
    
         
            +
                                    rubyClass = JRubyAdapter.get(rubyClassName);
         
     | 
| 
      
 140 
     | 
    
         
            +
                                }
         
     | 
| 
      
 141 
     | 
    
         
            +
                                rubyInstance = this;
         
     | 
| 
      
 142 
     | 
    
         
            +
                            } else if (rubyClass != null) {
         
     | 
| 
      
 143 
     | 
    
         
            +
                                // We have a predefined Ruby class without corresponding Ruby source file.
         
     | 
| 
      
 144 
     | 
    
         
            +
                                System.out.println("Create separate Ruby instance for class: " + rubyClass);
         
     | 
| 
      
 145 
     | 
    
         
            +
                                rubyInstance = JRubyAdapter.runRubyMethod(rubyClass, "new");
         
     | 
| 
      
 146 
     | 
    
         
            +
                                JRubyAdapter.runRubyMethod(rubyInstance, "instance_variable_set", "@ruboto_java_instance", this);
         
     | 
| 
      
 147 
     | 
    
         
            +
                            } else {
         
     | 
| 
      
 148 
     | 
    
         
            +
                                // Neither script file nor predefined class
         
     | 
| 
      
 149 
     | 
    
         
            +
                                throw new RuntimeException("Either script or predefined class must be present.");
         
     | 
| 
       91 
150 
     | 
    
         
             
                            }
         
     | 
| 
       92 
151 
     | 
    
         
             
                            if (rubyClass != null) {
         
     | 
| 
       93 
     | 
    
         
            -
                                System.out.println(" 
     | 
| 
       94 
     | 
    
         
            -
                                 
     | 
| 
       95 
     | 
    
         
            -
                                JRubyAdapter. 
     | 
| 
      
 152 
     | 
    
         
            +
                                System.out.println("Call on_create on: " + rubyInstance + ", " + JRubyAdapter.get("JRUBY_VERSION"));
         
     | 
| 
      
 153 
     | 
    
         
            +
                                // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
         
     | 
| 
      
 154 
     | 
    
         
            +
                                if (JRubyAdapter.isJRubyPreOneSeven()) {
         
     | 
| 
      
 155 
     | 
    
         
            +
                                    JRubyAdapter.put("$ruby_instance", rubyInstance);
         
     | 
| 
      
 156 
     | 
    
         
            +
                                    JRubyAdapter.runScriptlet("$ruby_instance.on_create($bundle)");
         
     | 
| 
      
 157 
     | 
    
         
            +
                                } else if (JRubyAdapter.isJRubyOneSeven()) {
         
     | 
| 
      
 158 
     | 
    
         
            +
                                    JRubyAdapter.runRubyMethod(rubyInstance, "on_create", args[0]);
         
     | 
| 
      
 159 
     | 
    
         
            +
                                } else {
         
     | 
| 
      
 160 
     | 
    
         
            +
                                    throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));
         
     | 
| 
      
 161 
     | 
    
         
            +
                                }
         
     | 
| 
       96 
162 
     | 
    
         
             
                            }
         
     | 
| 
       97 
163 
     | 
    
         
             
                        } else if (configBundle != null) {
         
     | 
| 
       98 
     | 
    
         
            -
                            //  
     | 
| 
       99 
     | 
    
         
            -
                             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
                             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
      
 164 
     | 
    
         
            +
                            // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
         
     | 
| 
      
 165 
     | 
    
         
            +
                            if (JRubyAdapter.isJRubyPreOneSeven()) {
         
     | 
| 
      
 166 
     | 
    
         
            +
                        	    JRubyAdapter.runScriptlet("$activity.initialize_ruboto");
         
     | 
| 
      
 167 
     | 
    
         
            +
                        	    JRubyAdapter.runScriptlet("$activity.on_create($bundle)");
         
     | 
| 
      
 168 
     | 
    
         
            +
                            } else if (JRubyAdapter.isJRubyOneSeven()) {
         
     | 
| 
      
 169 
     | 
    
         
            +
                        	    JRubyAdapter.runRubyMethod(this, "initialize_ruboto");
         
     | 
| 
      
 170 
     | 
    
         
            +
                                JRubyAdapter.runRubyMethod(this, "on_create", args[0]);
         
     | 
| 
      
 171 
     | 
    
         
            +
                            } else {
         
     | 
| 
      
 172 
     | 
    
         
            +
                                throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));
         
     | 
| 
      
 173 
     | 
    
         
            +
                        	}
         
     | 
| 
       104 
174 
     | 
    
         
             
                        }
         
     | 
| 
       105 
175 
     | 
    
         
             
                    } catch(IOException e){
         
     | 
| 
       106 
176 
     | 
    
         
             
                        e.printStackTrace();
         
     |