Class: PotionDialog

Inherits:
Object show all
Defined in:
lib/project/potion_dialog/potion_dialog.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ PotionDialog



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/project/potion_dialog/potion_dialog.rb', line 3

def initialize(options)

  @width = options[:width] || options[:w]
  @height = options[:height] || options[:h]

  # err if missing required options
  raise "[BluePotion ERROR] PotionDialog#initialize Requires an xml_layout" unless options[:xml_layout]
  raise "[BluePotion ERROR] PotionDialog#initialize Cannot have width without height" if @width && !@height
  raise "[BluePotion ERROR] PotionDialog#initialize Cannot have height without width" if @height && !@width    
  
  # Merging defaults    
  opts = { 
    title: false, 
    show: true
  }.merge(options)

  built_dialog = build_dialog(opts)

  built_dialog.show if opts[:show]

  built_dialog
end

Instance Method Details

#build_dialog(options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/project/potion_dialog/potion_dialog.rb', line 26

def build_dialog(options)
  # create dialog
  dialog = Potion::Dialog.new(find.activity)

  # manage title
  if options[:title] 
    dialog.title = options[:title]
  else
    dialog.requestWindowFeature(Potion::Window::FEATURE_NO_TITLE)
  end

  # set alert content
  dialog.setContentView(options[:xml_layout])

  # set width and height of Dialog Window
  if @width && @height
    dialog.window.setLayout(@width, @height)
  end 
  dialog
end