Module: Briar::Control::Slider

Defined in:
lib/briar/control/slider.rb

Instance Method Summary collapse

Instance Method Details

#briar_args_for_slider_set_value(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/briar/control/slider.rb', line 7

def briar_args_for_slider_set_value(options)
  args = []
  if options.has_key?(:notify_targets)
    args << options[:notify_targets] ? 1 : 0
  else
    args << 1
  end

  if options.has_key?(:animate)
    args << options[:animate] ? 1 : 0
  else
    args << 1
  end
  args
end

#briar_slider_set_value(slider_id, value, options = {:animate => true, :notify_targets => true}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/briar/control/slider.rb', line 23

def briar_slider_set_value(slider_id, value, options = {:animate => true,
                                                        :notify_targets => true})
  value_str = value.to_f.to_s
  args = briar_args_for_slider_set_value(options)
  query_str = "slider marked:'#{slider_id}'"
  views_touched = map(query_str, :changeSlider, value_str, *args)
  msg = "could not slider marked '#{slider_id}' to '#{value}' using query '#{query_str}' with options '#{options}'"
  assert_map_results(views_touched, msg)
end

#change_slider_value_to(slider_id, value) ⇒ Object

WARNING: requires a tap gesture recognizer on the slider you have been warned



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/briar/control/slider.rb', line 36

def change_slider_value_to(slider_id, value)
  target = value.to_f
  if target < 0
    pending "value '#{value}' must be >= 0"
  end
  min_val = query("slider marked:'#{slider_id}'", :minimumValue).first
  # will not work for min_val != 0
  if min_val != 0
    pending "sliders with non-zero minimum values are not supported - slider '#{slider_id}' has minimum value of '#{min_val}'"
  end
  max_val = query("slider marked:'#{slider_id}'", :maximumValue).first
  if target > max_val
    screenshot_and_raise "cannot change slider '#{slider_id}' to '#{value}' because the maximum allowed value is '#{max_val}'"
  end
  # the x offset is from the middle of the slider.
  # ex.  slider from 0 to 5
  #      to touch 3, x must be 0
  #      to touch 0, x must be -2.5
  #      to touch 5, x must be 2.5
  half_val = (max_val/2)
  width = query("slider marked:'#{slider_id}'", :frame).first["Width"]
  x = ((width/2) * ((target - half_val)/half_val)).ceil
  touch("slider marked:'#{slider_id}'", {:offset => {:x => x, :y => 0}})
  #current = query("slider marked:'#{slider_id}'", :value).first
  #puts "current => at '#{current}' with x => '#{x}'"
end