1

I'm very new to Android development (therefore to Ruboto), I have the following code in an attempt to display a text field, a button, and a progress bar. I would like to turn this progress bar into a horizontal progress bar:

require 'ruboto/widget'
require 'ruboto/util/toast'

ruboto_import_widgets :Button, :LinearLayout, :TextView, :ProgressBar

class SplashActivity
  def onCreate(bundle)
    super
    set_title 'some title here'

    self.content_view =
        linear_layout :orientation => :vertical do
          @text_view = text_view :text => 'sample text.', :id => 42, 
                                 :layout => {:width => :match_parent},
                                 :gravity => :center, :text_size => 18.0
          button :text => 'foo', 
                 :layout => {:width => :match_parent},
                 :id => 43, :on_click_listener => proc { bar }
          progress_bar
        end
  rescue Exception
    puts "Exception creating activity: #{$!}"
    puts $!.backtrace.join("\n")
  end

  private

  def bar
    @text_view.text = 'things change.'
    toast 'cha-ching!'
  end

end

All elements display as expected. The progress_bar is the indeterminate mode by default, what attributes are needed to convert the progress_bar into horizontal?

I have found Ruboto has been super easy to pick up, I just cannot find enough API documentation for customized controls. A lot of the functionality I'm looking for in the application I'm developing could be found in the GitHub source, but a lot is commented out. Is there something I am overlooking for detailed API documentation?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Justin Williams
  • 697
  • 3
  • 12

1 Answers1

1

There is no setter for style on ProgressBar, so you have to set it at creation time in the constructor. Note that SplashActivity can conflict with the Ruboto SplashActivity.java, so I use another name (ProgressBarActivity)

require 'ruboto/widget'
require 'ruboto/util/toast'

ruboto_import_widgets :Button, :LinearLayout, :TextView, :ProgressBar

class ProgressBarActivity
  AndroidAttr = JavaUtilities.get_proxy_class('android.R$attr')

  def onCreate(bundle)
    super
    set_title 'some title here'

    self.content_view =
        linear_layout :orientation => :vertical do
          @text_view = text_view :text => 'sample text.', :id => 42,
              :layout => {:width => :match_parent},
              :gravity => :center, :text_size => 18.0
          button :text => 'foo',
              :layout => {:width => :match_parent},
              :id => 43, :on_click_listener => proc { bar }
          @pb = ProgressBar.new(self, nil, AndroidAttr::progressBarStyleHorizontal)
          @view_parent.add_view @pb
        end
  rescue Exception
    puts "Exception creating activity: #{$!}"
    puts $!.backtrace.join("\n")
  end

  def onResume
    super
    @pb.progress = @pb.max / 2
  end

  private

  def bar
    @text_view.text = 'things change.'
    @pb.progress = 2 * @pb.max / 3
    toast 'cha-ching!'
  end

end
donV
  • 1,091
  • 7
  • 15
  • Sorry to ask here but learning resources for Ruboto are not a lot yet.. so could someone tell me how widgets ID's are used and why their progressive numeration always starts at 42 in all Ruboto examples ? – Redoman Jul 30 '14 at 07:40
  • @jj_ : This deserves a separate question, not just a comment. You should also try http://ruboto.org/community.html if you want answers on Ruboto. We'll be ready for you :) Anyway: Widget's IDs are used to find the widget when it was defined elsewhere, like in XML or in another object. The numeration always starts at 42 since that is the answer to "Life, the Universe, and Everything". – donV Jul 30 '14 at 17:34
  • Ok.. but the real answer, that I found somewhere else, is that ID are used in your code mainly for testing purposes.. because they are never referenced anywhere else in code (except testing) and so can simply be omitted and are not something mandatory. Am I right? Just wanted to pinpoint this for anyone else stumbling on here.. – Redoman Jul 30 '14 at 23:31
  • 1
    Yes, we use IDs in the tests since the widgets are created in the main activity (ie. elsewhere). IDs are not mandatory. – donV Jul 31 '14 at 07:39