androidrubyjrubyruboto

Ruboto horizontal progress bar?


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?


Solution

  • 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