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


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

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


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

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
# 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.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


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

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


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

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


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

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

#alertViewShouldEnableFirstOtherButton(alert) ⇒ Object


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

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

#cancel_button_indexObject


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

def cancel_button_index
  cancelButtonIndex
end

#cancel_button_index=(value) ⇒ Object


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

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

#didPresentAlertView(alert) ⇒ Object


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

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

#login_text_fieldObject


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

def 
  textFieldAtIndex(0) if style == UIAlertViewStyleLoginAndPasswordInput
end

#password_text_fieldObject


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

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

#plain_text_fieldObject


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

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

#secure_text_fieldObject


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

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

#styleObject


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

def style
  alertViewStyle
end

#style=(value) ⇒ Object


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

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

#willPresentAlertView(alert) ⇒ Object

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


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

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