Module: Accessibility::Console
- Defined in:
- lib/project/motion-accessibility-console/tree.rb,
lib/project/motion-accessibility-console/touch.rb,
lib/project/motion-accessibility-console/browser.rb
Defined Under Namespace
Classes: Tree
Constant Summary collapse
- Update_Delay =
1.0
Class Method Summary collapse
- .browse(request = nil) ⇒ Object
- .display_views ⇒ Object
- .init(view = nil) ⇒ Object
- .refresh ⇒ Object
- .scrollable_view?(view) ⇒ Boolean
- .start_refreshing ⇒ Object
- .touch(request, arg = nil, options = {}) ⇒ Object
- .touch_pickerview(view, arg) ⇒ Object
- .touch_segmented(view, arg) ⇒ Object
- .touchable_type(view) ⇒ Object
- .view(request = nil) ⇒ Object
Class Method Details
.browse(request = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/project/motion-accessibility-console/browser.rb', line 52 def browse(request=nil) A11y::Console.init unless $browser_current A11y::Console.start_refreshing request=0 if request==:back if request.nil? elsif request==:top A11y::Console.init $browser_current=$browser_tree $browser_path.clear elsif request==0 raise "You cannot go back any further" if $browser_path.length<2 $browser_path.pop $browser_current=$browser_path.last A11y::Console.init unless A11y::Data[:refresh] elsif request==:refresh raise "This view cannot refresh." unless $browser_current.view.respond_to?(:reloadData) $browser_current.view.reloadData elsif request==:scroll raise "This view cannot scroll" unless A11y::Console.scrollable_view?($browser_current.view) below=CGRect.new([0, $browser_current.view.size.height], $browser_current.view.size) $browser_current.view.scrollRectToVisible(below, animated: false) elsif request.kind_of?(Fixnum)||request.kind_of?(String) A11y::Console.init unless $browser_tree $browser_current=$browser_tree unless $browser_current found=$browser_current.find(request) if found if found.subviews.empty? $browser_cursor=found return A11y.inspect found.view end A11y::Console.init unless A11y::Data[:refresh] $browser_current=found $browser_path<<found $browser_last=request end elsif request.respond_to?(:view)&&request.respond_to?(:subviews) A11y::Console.init(request) $browser_current=$browser_tree else puts "Unknown request: #{request.inspect}" end $browser_cursor=$browser_current A11y::Console.display_views nil end |
.display_views ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/project/motion-accessibility-console/browser.rb', line 34 def self.display_views $browser_current=$browser_tree unless $browser_current puts "Browsing "+$browser_current.display_view $browser_current.browsable_nodes.each_with_index do |node, index| next if node.nil? output=node.display_view( index) puts output unless output.nil? end end |
.init(view = nil) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/project/motion-accessibility-console/browser.rb', line 27 def self.init(view=nil) view=UIApplication.sharedApplication.keyWindow if view.nil? $browser_tree=A11y::Console::Tree.build(view) $browser_path<<$browser_tree if $browser_path.empty? nil end |
.refresh ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/project/motion-accessibility-console/browser.rb', line 98 def self.refresh A11y::Console.init $before=$browser_tree.copy unless $before unless $browser_tree==$before puts "The screen has changed." A11y::Console.browse :top puts "(Main)> " end $before=$browser_tree.copy end |
.scrollable_view?(view) ⇒ Boolean
19 20 21 22 23 24 25 |
# File 'lib/project/motion-accessibility-console/browser.rb', line 19 def self.scrollable_view?(view) control=view.class until control==UIScrollView||control.nil? control=control.superclass end control==UIScrollView end |
.start_refreshing ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/project/motion-accessibility-console/browser.rb', line 44 def self.start_refreshing if !A11y::Data[:refresh]&&RUBYMOTION_ENV!='test' NSTimer.scheduledTimerWithTimeInterval(Update_Delay, target: self, selector: 'refresh', userInfo: nil, repeats: true) A11y::Data[:refresh]=true A11y::Console.init end end |
.touch(request, arg = nil, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/project/motion-accessibility-console/touch.rb', line 4 def self.touch(request, arg=nil, ={}) self.start_refreshing $browser_current=$browser_tree unless $browser_current view=nil unless RUBYMOTION_ENV=='test' found=$browser_current.find(request) raise "Could not find the view" unless found view=found.view else view=request end control=A11y::Console.touchable_type(view) raise "I don't know how to touch a #{view.class}" if control.nil? if found sv=[:superview]||found.superview.view else sv=[:superview] end case control.to_s when "UIButton" arg||=UIControlEventTouchUpInside view.sendActionsForControlEvents(arg) when "UITabBarButton" arg||=UIControlEventTouchUpInside view.sendActionsForControlEvents(arg) when "UITextField" view.text=arg when "UIPickerView" self.touch_pickerview(view, arg) when "UIDatePicker" view.date=arg when "UISegmentedControl" self.touch_segmented(view, arg) when "UISlider" view.value=arg when "UIStepper" view.value=arg when "UISwitch" arg||=!view.arg view.on=arg when "UITableViewCell" raise "You cannot touch cells in this table." unless sv.delegate.respond_to?("tableView:didSelectRowAtIndexPath") raise "Could not get the UITableView" unless sv.kind_of?(UITableView) if sv.respond_to?(:numberOfSections) sections=sv.numberOfSections else sections=1 end if sections>1 index=[:index]||NSIndexPath.indexPathForRow(request-1, inSection: $browser_last-1) else index=[:index]||NSIndexPath.indexPathForRow(request-1, inSection: 0) end raise "Could not get the index" unless index sv.delegate.tableView(sv.delegate, didSelectRowAtIndexPath: index) when "UITableViewCellAccessibilityElement" raise "You cannot touch cells in this table." unless view.container.delegate.respond_to?("tableView:didSelectRowAtIndexPath") if [:index] index=[:index] else raise "Invalid number" if request>view.container.delegate.accessibility_element_count index=view.container.indexPathForCell(view.tableViewCell) raise "Could not get the index" unless index end view.container.delegate.tableView(view.container, didSelectRowAtIndexPath: index) when "UINavigationItemButtonView" view.superview.delegate.popViewControllerAnimated(true) else raise "I don't know what to do with a #{control}" end self.browse unless RUBYMOTION_ENV=='test' end |
.touch_pickerview(view, arg) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/project/motion-accessibility-console/touch.rb', line 77 def self.touch_pickerview(view, arg) raise "You must pass a hash with the row and component keywords" unless arg.kind_of?(Hash)&&arg[:row]&&arg[:component] arg[:animated]||=false if arg[:row].kind_of?(String) results=[] view.numberOfRowsInComponent(arg[:component]).times do |row_index| title=view.delegate.pickerView(view, titleForRow: row_index, forComponent: arg[:component]) if title.casecmp(arg[:row])==0 results=[row_index] break end if title=~Regexp.new(arg[:row],true) results<<row_index end end raise "Unknown value" if results.empty? raise "That could refer to more than one value." if results.length>1 view.selectRow(results.first, inComponent: arg[:component], animated: false) elsif arg[:row].kind_of?(Fixnum) view.selectRow(arg[:row], inComponent: arg[:component], animated: arg[:animated]) else raise "Unknown row #{arg[:row]}" end end |
.touch_segmented(view, arg) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/project/motion-accessibility-console/touch.rb', line 102 def self.touch_segmented(view, arg) if arg.kind_of?(Fixnum) view.selectedSegmentIndex=arg elsif arg.kind_of?(String) results=[] view.numberOfSegments.times do |index| title=view.titleForSegmentAtIndex(index) if title.casecmp(arg)==0 results=[index] break end if title=~Regexp.new(arg,true) results<<index end end raise "Unknown segment" if results.empty? raise "That could refer to more than one segment" if results.length>1 view.selectedSegmentIndex=results.first else raise "Invalid segment" end end |
.touchable_type(view) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/project/motion-accessibility-console/browser.rb', line 8 def self.touchable_type(view) control=view.class until A11y::Touchable_Types.member?(control.to_s)||control.nil? control=control.superclass end if control.class==UITableViewCell control=nil unless controll.respond_to?("tableView:didSelectRowAtIndexPath") end control end |
.view(request = nil) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/project/motion-accessibility-console/browser.rb', line 109 def view(request=nil) A11y::Console.init unless A11y::Data[:refresh] $browser_current=$browser_tree unless $browser_current $browser_cursor=$browser_tree unless $browser_cursor result=nil if request result=$browser_current.find(request) raise "Unknown view" unless result $browser_cursor=result result=result.view else result=$browser_cursor.view result end if defined?(UITableViewCellAccessibilityElement)&&result.class==UITableViewCellAccessibilityElement result=result.tableViewCell end result end |