Class: AlertDialog
- Defined in:
- lib/project/alert_dialog/alert_dialog.rb
Overview
Generic AlertDialog
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ AlertDialog
constructor
A new instance of AlertDialog.
- #onClick(dialog, id) ⇒ Object
- #onCreateDialog(saved_instance_state) ⇒ Object
- #show(activity = rmq.activity) ⇒ Object
- #simple_text_view ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ AlertDialog
Returns a new instance of AlertDialog.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/project/alert_dialog/alert_dialog.rb', line 21 def initialize(={}, &block) # Defaults = { 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() @callback = block self.show if [:show] self end |
Instance Method Details
#onClick(dialog, id) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/project/alert_dialog/alert_dialog.rb', line 74 def onClick(dialog, id) = (id == Android::App::AlertDialog::BUTTON_POSITIVE) ? [:positive_button] : [: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(, input_text) if @callback end |
#onCreateDialog(saved_instance_state) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/project/alert_dialog/alert_dialog.rb', line 46 def onCreateDialog(saved_instance_state) builder = Android::App::AlertDialog::Builder.new(activity, [:theme]) builder.title = [:title] builder. = [:message] # Add buttons if they are set builder.setPositiveButton([:positive_button], [:positive_button_handler]) if [:positive_button] builder.setNegativeButton([:negative_button], [:negative_button_handler]) if [:negative_button] # Add custom view? [:view] = simple_text_view if [:style] == :input builder.view = [:view] if [:view] # DONE! builder.create end |
#show(activity = rmq.activity) ⇒ Object
42 43 44 |
# File 'lib/project/alert_dialog/alert_dialog.rb', line 42 def show(activity=rmq.activity) super(activity.fragmentManager, "alert_dialog") end |
#simple_text_view ⇒ Object
64 65 66 67 68 69 70 71 72 |
# 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 |