class AlertDialog
Generic AlertDialog
Public Class Methods
new(options={}, &block)
click to toggle source
# File lib/project/alert_dialog/alert_dialog.rb, line 21 def initialize(options={}, &block) # Defaults @options = { theme: Android::App::AlertDialog::THEME_HOLO_LIGHT, title: "Alert!", message: nil, positive_button: "OK", negative_button: "Cancel", positive_button_handler: self, negative_button_handler: self, style: nil, show: true }.merge(options) @callback = block self.show if @options[:show] self end
Public Instance Methods
onClick(dialog, id)
click to toggle source
# File lib/project/alert_dialog/alert_dialog.rb, line 74 def onClick(dialog, id) button_text = (id == Android::App::AlertDialog::BUTTON_POSITIVE) ? @options[:positive_button] : @options[:negative_button] # if a text_view is present, grab what the user gave us text_view = @text_view_id && dialog.findViewById(@text_view_id) input_text = text_view ? text_view.text.toString : nil @callback.call(button_text, input_text) if @callback end
onCreateDialog(saved_instance_state)
click to toggle source
# File lib/project/alert_dialog/alert_dialog.rb, line 46 def onCreateDialog(saved_instance_state) builder = Android::App::AlertDialog::Builder.new(activity, @options[:theme]) builder.title = @options[:title] builder.message = @options[:message] # Add buttons if they are set builder.setPositiveButton(@options[:positive_button], @options[:positive_button_handler]) if @options[:positive_button] builder.setNegativeButton(@options[:negative_button], @options[:negative_button_handler]) if @options[:negative_button] # Add custom view? @options[:view] = simple_text_view if @options[:style] == :input builder.view = @options[:view] if @options[:view] # DONE! builder.create end
show(activity=rmq.activity)
click to toggle source
Calls superclass method
# File lib/project/alert_dialog/alert_dialog.rb, line 42 def show(activity=rmq.activity) super(activity.fragmentManager, "alert_dialog") end
simple_text_view()
click to toggle source
# File lib/project/alert_dialog/alert_dialog.rb, line 64 def simple_text_view # Set up the input input = Potion::EditText.new(activity) input.singleLine = true input.id = @text_view_id = Potion::ViewIdGenerator.generate # possible input types - future feature #input.inputType = (Android::Text::InputType.TYPE_CLASS_TEXT | Android::Text::InputType.TYPE_TEXT_VARIATION_PASSWORD) input end