Class: BW::UIAlertView

Inherits:
UIAlertView
  • Object
show all
Defined in:
motion/ui/ui_alert_view.rb

Defined Under Namespace

Classes: ClickedButton

Constant Summary collapse

KEYBOARD_TYPES =
{
  default: UIKeyboardTypeDefault,
  ascii: UIKeyboardTypeASCIICapable,
  numbers_punctuation: UIKeyboardTypeNumbersAndPunctuation,
  url: UIKeyboardTypeURL,
  number_pad: UIKeyboardTypeNumberPad,
  phone_pad: UIKeyboardTypePhonePad,
  name_phone_pad: UIKeyboardTypeNamePhonePad,
  email_address: UIKeyboardTypeEmailAddress,
  email: UIKeyboardTypeEmailAddress, # Duplicate to help developers
  decimal_pad: UIKeyboardTypeDecimalPad,
  twitter: UIKeyboardTypeTwitter,
  web_search: UIKeyboardTypeWebSearch,
  alphabet: UIKeyboardTypeASCIICapable
}

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.callbacksObject (readonly)

Returns the value of attribute callbacks.



30
31
32
# File 'motion/ui/ui_alert_view.rb', line 30

def callbacks
  @callbacks
end

Instance Attribute Details

#clicked_buttonObject

Returns the value of attribute clicked_button.



110
111
112
# File 'motion/ui/ui_alert_view.rb', line 110

def clicked_button
  @clicked_button
end

Class Method Details

.default(options = {}, &block) ⇒ Object



58
59
60
61
62
# File 'motion/ui/ui_alert_view.rb', line 58

def default(options = {}, &block)
  options = {buttons: "OK"}.merge!(options)
  options[:style] = :default
  new(options, &block)
end

.login_and_password_input(options = {}, &block) ⇒ Object



84
85
86
87
88
89
# File 'motion/ui/ui_alert_view.rb', line 84

def (options = {}, &block)
  options = {buttons: ["Cancel", "Log in"],
             cancel_button_index: 0}.merge!(options)
  options[:style] = :login_and_password_input
  new(options, &block)
end

.new(options = {}, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'motion/ui/ui_alert_view.rb', line 32

def new(options = {}, &block)
  view = alloc.initWithTitle(options[:title],
    message: options[:message],
    delegate: nil,
    cancelButtonTitle: nil,
    otherButtonTitles: nil
  )

  Array(options[:buttons]).each { |title| view.addButtonWithTitle(title) }

  view.style               = options[:style]
  view.delegate            = view
  view.cancel_button_index = options[:cancel_button_index]

  view.instance_variable_set(:@handlers, {})
  block.weak! if block && BubbleWrap.use_weak_callbacks?

  options[:on_click] ||= block

  callbacks.each do |callback|
    view.send(callback, &options[callback]) if options[callback]
  end

  view
end

.plain_text_input(options = {}, &block) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'motion/ui/ui_alert_view.rb', line 64

def plain_text_input(options = {}, &block)
  options = {buttons: ["Cancel", "OK"],
             cancel_button_index: 0}.merge!(options)
  options[:style] = :plain_text_input
  new(options, &block).tap do |view|
    view.textFieldAtIndex(0).tap do |tf|
      tf.text = options[:text] if options[:text]
      tf.placeholder = options[:placeholder] if options[:placeholder]
      tf.keyboardType = (KEYBOARD_TYPES[options[:keyboard_type]] || options[:keyboard_type]) if options[:keyboard_type]
    end
  end
end

.secure_text_input(options = {}, &block) ⇒ Object



77
78
79
80
81
82
# File 'motion/ui/ui_alert_view.rb', line 77

def secure_text_input(options = {}, &block)
  options = {buttons: ["Cancel", "OK"],
             cancel_button_index: 0}.merge!(options)
  options[:style] = :secure_text_input
  new(options, &block)
end

Instance Method Details

#alertView(alert, didDismissWithButtonIndex: index) ⇒ Object



160
161
162
163
# File 'motion/ui/ui_alert_view.rb', line 160

def alertView(alert, clickedButtonAtIndex:index)
  alert.clicked_button = ClickedButton.new(alert, index)
  handlers[:on_click].call(alert) if handlers[:on_click]
end

#alertViewCancel(alert) ⇒ Object



150
151
152
153
# File 'motion/ui/ui_alert_view.rb', line 150

def alertViewCancel(alert)
  alert.clicked_button = nil
  handlers[:on_system_cancel].call(alert) if handlers[:on_system_cancel]
end

#alertViewShouldEnableFirstOtherButton(alert) ⇒ Object



155
156
157
158
# File 'motion/ui/ui_alert_view.rb', line 155

def alertViewShouldEnableFirstOtherButton(alert)
  alert.clicked_button = nil
  handlers[:enable_first_other_button?].call(alert) if handlers[:enable_first_other_button?]
end

#cancel_button_indexObject



100
101
102
# File 'motion/ui/ui_alert_view.rb', line 100

def cancel_button_index
  cancelButtonIndex
end

#cancel_button_index=(value) ⇒ Object



104
105
106
# File 'motion/ui/ui_alert_view.rb', line 104

def cancel_button_index=(value)
  self.cancelButtonIndex = value if value
end

#didPresentAlertView(alert) ⇒ Object



145
146
147
148
# File 'motion/ui/ui_alert_view.rb', line 145

def didPresentAlertView(alert)
  alert.clicked_button = nil
  handlers[:did_present].call(alert) if handlers[:did_present]
end

#login_text_fieldObject



185
186
187
# File 'motion/ui/ui_alert_view.rb', line 185

def 
  textFieldAtIndex(0) if style == UIAlertViewStyleLoginAndPasswordInput
end

#password_text_fieldObject



189
190
191
# File 'motion/ui/ui_alert_view.rb', line 189

def password_text_field
  textFieldAtIndex(1) if style == UIAlertViewStyleLoginAndPasswordInput
end

#plain_text_fieldObject



177
178
179
# File 'motion/ui/ui_alert_view.rb', line 177

def plain_text_field
  textFieldAtIndex(0) if style == UIAlertViewStylePlainTextInput
end

#secure_text_fieldObject



181
182
183
# File 'motion/ui/ui_alert_view.rb', line 181

def secure_text_field
  textFieldAtIndex(0) if style == UIAlertViewStyleSecureTextInput
end

#styleObject



92
93
94
# File 'motion/ui/ui_alert_view.rb', line 92

def style
  alertViewStyle
end

#style=(value) ⇒ Object



96
97
98
# File 'motion/ui/ui_alert_view.rb', line 96

def style=(value)
  self.alertViewStyle = Constants.get("UIAlertViewStyle", value) if value
end

#willPresentAlertView(alert) ⇒ Object

UIAlertViewDelegate protocol ################################################################



140
141
142
143
# File 'motion/ui/ui_alert_view.rb', line 140

def willPresentAlertView(alert)
  alert.clicked_button = nil
  handlers[:will_present].call(alert) if handlers[:will_present]
end