{"action":"created","comment":{"url":"https://api.github.com/repos/calabash/calabash-android/pulls/comments/37895534","id":37895534,"diff_hunk":"@@ -0,0 +1,91 @@\n+require 'calabash-android/env'\n+\n+module Calabash\n+  module Android\n+    module MonkeyHelpers\n+      include Calabash::Android::EnvironmentHelpers\n+\n+      MAX_RETRIES = 10\n+      @@monkey_port = nil\n+      @@monkey_pid = nil\n+\n+      def monkey_move_from(from_x, from_y, to_x, to_y, args={})\n+        @@monkey_port = start_monkey\n+        monkey_touch(:down, from_x, from_y)\n+        sleep(args.fetch(:hold_time))\n+\n+        x_delta = to_x - from_x\n+        y_delta = to_y - from_y\n+        steps = args.fetch(:steps)\n+\n+        steps.times do |i|\n+          move_x = (from_x + ((i+1) * (x_delta.to_f / steps))).to_i\n+          move_y = (from_y + ((i+1) * (y_delta.to_f / steps))).to_i\n+          monkey_touch(:move, move_x, move_y)\n+        end\n+\n+        sleep(args.fetch(:hang_time))\n+        monkey_touch(:up, to_x, to_y)\n+      end\n+\n+      def start_monkey\n+        unless xamarin_test_cloud? #monkey processes are automatically killed in XTC\n+          kill_existing_monkey_processes\n+        end\n+\n+        MAX_RETRIES.times do\n+          port = rand((1024..65535))\n+\n+          monkey_starter_thread = Thread.new do\n+            Thread.current[:output]= `#{adb_command} shell monkey --port #{port}`\n+          end\n+          sleep(4)\n+\n+          output = monkey_starter_thread[:output]\n+          unless output && output.include?('Error binding to network socket.')\n+            return port\n+          end\n+        end\n+        raise 'Unable to start com.android.commands.monkey'\n+      end\n+\n+      def existing_monkey_pids\n+        procs = `#{adb_command} shell ps`\n+        procs.scan(/.+?\\s(?<pid>[0-9]+).+?com.android.commands.monkey\\r?\\n?/).flatten\n+      end\n+\n+      def kill_existing_monkey_processes\n+        existing_monkey_pids.each do |pid|\n+          `#{adb_command} shell kill -9 #{pid}`\n+        end\n+      end\n+\n+      def monkey_tap(x, y, should_start_monkey=true)\n+        start_monkey if should_start_monkey\n+        monkey_touch(:down, x, y)\n+        monkey_touch(:up, x, y)\n+      end\n+\n+      def monkey_touch(touch_type, x, y)\n+        case touch_type\n+          when :move\n+            perform_action('send_tcp', @@monkey_port, \"touch move #{x} #{y}\", true)\n+          when :down\n+            perform_action('send_tcp', @@monkey_port, \"touch down #{x} #{y}\", true)\n+          when :up\n+            perform_action('send_tcp', @@monkey_port, \"touch up #{x} #{y}\", true)\n+          else\n+            raise \"touch_type #{touch_type} is invalid\"\n+        end\n+      end\n+\n+      def adb_command","path":"ruby-gem/lib/calabash-android/monkey_helpers.rb","position":82,"original_position":82,"commit_id":"dbb6bbce8770d89d8840dabe2b226d1d5d9dcbe9","original_commit_id":"dbb6bbce8770d89d8840dabe2b226d1d5d9dcbe9","user":{"login":"sapieneptus","id":3009852,"avatar_url":"https://avatars.githubusercontent.com/u/3009852?v=3","gravatar_id":"","url":"https://api.github.com/users/sapieneptus","html_url":"https://github.com/sapieneptus","followers_url":"https://api.github.com/users/sapieneptus/followers","following_url":"https://api.github.com/users/sapieneptus/following{/other_user}","gists_url":"https://api.github.com/users/sapieneptus/gists{/gist_id}","starred_url":"https://api.github.com/users/sapieneptus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sapieneptus/subscriptions","organizations_url":"https://api.github.com/users/sapieneptus/orgs","repos_url":"https://api.github.com/users/sapieneptus/repos","events_url":"https://api.github.com/users/sapieneptus/events{/privacy}","received_events_url":"https://api.github.com/users/sapieneptus/received_events","type":"User","site_admin":false},"body":"Why would it need to do that? `send_tcp` goes to the server, which is already a supported action (this is ported from UITest)","created_at":"2015-08-25T17:44:16Z","updated_at":"2015-08-25T17:44:16Z","html_url":"https://github.com/calabash/calabash-android/pull/601#discussion_r37895534","pull_request_url":"https://api.github.com/repos/calabash/calabash-android/pulls/601","_links":{"self":{"href":"https://api.github.com/repos/calabash/calabash-android/pulls/comments/37895534"},"html":{"href":"https://github.com/calabash/calabash-android/pull/601#discussion_r37895534"},"pull_request":{"href":"https://api.github.com/repos/calabash/calabash-android/pulls/601"}}},"pull_request":{"url":"https://api.github.com/repos/calabash/calabash-android/pulls/601","id":39972884,"html_url":"https://github.com/calabash/calabash-android/pull/601","diff_url":"https://github.com/calabash/calabash-android/pull/601.diff","patch_url":"https://github.com/calabash/calabash-android/pull/601.patch","issue_url":"https://api.github.com/repos/calabash/calabash-android/issues/601","number":601,"state":"open","locked":false,"title":"drag_helpers: basic implementation of monkey drag","user":{"login":"sapieneptus","id":3009852,"avatar_url":"https://avatars.githubusercontent.com/u/3009852?v=3","gravatar_id":"","url":"https://api.github.com/users/sapieneptus","html_url":"https://github.com/sapieneptus","followers_url":"https://api.github.com/users/sapieneptus/followers","following_url":"https://api.github.com/users/sapieneptus/following{/other_user}","gists_url":"https://api.github.com/users/sapieneptus/gists{/gist_id}","starred_url":"https://api.github.com/users/sapieneptus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sapieneptus/subscriptions","organizations_url":"https://api.github.com/users/sapieneptus/orgs","repos_url":"https://api.github.com/users/sapieneptus/repos","events_url":"https://api.github.com/users/sapieneptus/events{/privacy}","received_events_url":"https://api.github.com/users/sapieneptus/received_events","type":"User","site_admin":false},"body":"Lazily instantiates monkey, then uses `send_tcp` action to send touch/drag commands.\r\n\r\n","created_at":"2015-07-14T23:06:05Z","updated_at":"2015-08-25T17:44:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ce0ba4e38e8f7d30b1b637283c9cf7bee492f7ef","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/calabash/calabash-android/pulls/601/commits","review_comments_url":"https://api.github.com/repos/calabash/calabash-android/pulls/601/comments","review_comment_url":"https://api.github.com/repos/calabash/calabash-android/pulls/comments{/number}","comments_url":"https://api.github.com/repos/calabash/calabash-android/issues/601/comments","statuses_url":"https://api.github.com/repos/calabash/calabash-android/statuses/dbb6bbce8770d89d8840dabe2b226d1d5d9dcbe9","head":{"label":"calabash:feature/monkey-api","ref":"feature/monkey-api","sha":"dbb6bbce8770d89d8840dabe2b226d1d5d9dcbe9","user":{"login":"calabash","id":1325677,"avatar_url":"https://avatars.githubusercontent.com/u/1325677?v=3","gravatar_id":"","url":"https://api.github.com/users/calabash","html_url":"https://github.com/calabash","followers_url":"https://api.github.com/users/calabash/followers","following_url":"https://api.github.com/users/calabash/following{/other_user}","gists_url":"https://api.github.com/users/calabash/gists{/gist_id}","starred_url":"https://api.github.com/users/calabash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calabash/subscriptions","organizations_url":"https://api.github.com/users/calabash/orgs","repos_url":"https://api.github.com/users/calabash/repos","events_url":"https://api.github.com/users/calabash/events{/privacy}","received_events_url":"https://api.github.com/users/calabash/received_events","type":"Organization","site_admin":false},"repo":{"id":3362065,"name":"calabash-android","full_name":"calabash/calabash-android","owner":{"login":"calabash","id":1325677,"avatar_url":"https://avatars.githubusercontent.com/u/1325677?v=3","gravatar_id":"","url":"https://api.github.com/users/calabash","html_url":"https://github.com/calabash","followers_url":"https://api.github.com/users/calabash/followers","following_url":"https://api.github.com/users/calabash/following{/other_user}","gists_url":"https://api.github.com/users/calabash/gists{/gist_id}","starred_url":"https://api.github.com/users/calabash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calabash/subscriptions","organizations_url":"https://api.github.com/users/calabash/orgs","repos_url":"https://api.github.com/users/calabash/repos","events_url":"https://api.github.com/users/calabash/events{/privacy}","received_events_url":"https://api.github.com/users/calabash/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/calabash/calabash-android","description":"Automated Functional testing for Android based on cucumber","fork":false,"url":"https://api.github.com/repos/calabash/calabash-android","forks_url":"https://api.github.com/repos/calabash/calabash-android/forks","keys_url":"https://api.github.com/repos/calabash/calabash-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/calabash/calabash-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/calabash/calabash-android/teams","hooks_url":"https://api.github.com/repos/calabash/calabash-android/hooks","issue_events_url":"https://api.github.com/repos/calabash/calabash-android/issues/events{/number}","events_url":"https://api.github.com/repos/calabash/calabash-android/events","assignees_url":"https://api.github.com/repos/calabash/calabash-android/assignees{/user}","branches_url":"https://api.github.com/repos/calabash/calabash-android/branches{/branch}","tags_url":"https://api.github.com/repos/calabash/calabash-android/tags","blobs_url":"https://api.github.com/repos/calabash/calabash-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/calabash/calabash-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/calabash/calabash-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/calabash/calabash-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/calabash/calabash-android/statuses/{sha}","languages_url":"https://api.github.com/repos/calabash/calabash-android/languages","stargazers_url":"https://api.github.com/repos/calabash/calabash-android/stargazers","contributors_url":"https://api.github.com/repos/calabash/calabash-android/contributors","subscribers_url":"https://api.github.com/repos/calabash/calabash-android/subscribers","subscription_url":"https://api.github.com/repos/calabash/calabash-android/subscription","commits_url":"https://api.github.com/repos/calabash/calabash-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/calabash/calabash-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/calabash/calabash-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/calabash/calabash-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/calabash/calabash-android/contents/{+path}","compare_url":"https://api.github.com/repos/calabash/calabash-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/calabash/calabash-android/merges","archive_url":"https://api.github.com/repos/calabash/calabash-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/calabash/calabash-android/downloads","issues_url":"https://api.github.com/repos/calabash/calabash-android/issues{/number}","pulls_url":"https://api.github.com/repos/calabash/calabash-android/pulls{/number}","milestones_url":"https://api.github.com/repos/calabash/calabash-android/milestones{/number}","notifications_url":"https://api.github.com/repos/calabash/calabash-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/calabash/calabash-android/labels{/name}","releases_url":"https://api.github.com/repos/calabash/calabash-android/releases{/id}","created_at":"2012-02-05T20:48:08Z","updated_at":"2015-08-23T14:59:07Z","pushed_at":"2015-08-25T17:43:20Z","git_url":"git://github.com/calabash/calabash-android.git","ssh_url":"git@github.com:calabash/calabash-android.git","clone_url":"https://github.com/calabash/calabash-android.git","svn_url":"https://github.com/calabash/calabash-android","homepage":"calaba.sh","size":51340,"stargazers_count":953,"watchers_count":953,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":446,"mirror_url":null,"open_issues_count":87,"forks":446,"open_issues":87,"watchers":953,"default_branch":"master"}},"base":{"label":"calabash:master","ref":"master","sha":"904d389cf1f5af896f3a59238aaba521845737da","user":{"login":"calabash","id":1325677,"avatar_url":"https://avatars.githubusercontent.com/u/1325677?v=3","gravatar_id":"","url":"https://api.github.com/users/calabash","html_url":"https://github.com/calabash","followers_url":"https://api.github.com/users/calabash/followers","following_url":"https://api.github.com/users/calabash/following{/other_user}","gists_url":"https://api.github.com/users/calabash/gists{/gist_id}","starred_url":"https://api.github.com/users/calabash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calabash/subscriptions","organizations_url":"https://api.github.com/users/calabash/orgs","repos_url":"https://api.github.com/users/calabash/repos","events_url":"https://api.github.com/users/calabash/events{/privacy}","received_events_url":"https://api.github.com/users/calabash/received_events","type":"Organization","site_admin":false},"repo":{"id":3362065,"name":"calabash-android","full_name":"calabash/calabash-android","owner":{"login":"calabash","id":1325677,"avatar_url":"https://avatars.githubusercontent.com/u/1325677?v=3","gravatar_id":"","url":"https://api.github.com/users/calabash","html_url":"https://github.com/calabash","followers_url":"https://api.github.com/users/calabash/followers","following_url":"https://api.github.com/users/calabash/following{/other_user}","gists_url":"https://api.github.com/users/calabash/gists{/gist_id}","starred_url":"https://api.github.com/users/calabash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calabash/subscriptions","organizations_url":"https://api.github.com/users/calabash/orgs","repos_url":"https://api.github.com/users/calabash/repos","events_url":"https://api.github.com/users/calabash/events{/privacy}","received_events_url":"https://api.github.com/users/calabash/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/calabash/calabash-android","description":"Automated Functional testing for Android based on cucumber","fork":false,"url":"https://api.github.com/repos/calabash/calabash-android","forks_url":"https://api.github.com/repos/calabash/calabash-android/forks","keys_url":"https://api.github.com/repos/calabash/calabash-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/calabash/calabash-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/calabash/calabash-android/teams","hooks_url":"https://api.github.com/repos/calabash/calabash-android/hooks","issue_events_url":"https://api.github.com/repos/calabash/calabash-android/issues/events{/number}","events_url":"https://api.github.com/repos/calabash/calabash-android/events","assignees_url":"https://api.github.com/repos/calabash/calabash-android/assignees{/user}","branches_url":"https://api.github.com/repos/calabash/calabash-android/branches{/branch}","tags_url":"https://api.github.com/repos/calabash/calabash-android/tags","blobs_url":"https://api.github.com/repos/calabash/calabash-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/calabash/calabash-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/calabash/calabash-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/calabash/calabash-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/calabash/calabash-android/statuses/{sha}","languages_url":"https://api.github.com/repos/calabash/calabash-android/languages","stargazers_url":"https://api.github.com/repos/calabash/calabash-android/stargazers","contributors_url":"https://api.github.com/repos/calabash/calabash-android/contributors","subscribers_url":"https://api.github.com/repos/calabash/calabash-android/subscribers","subscription_url":"https://api.github.com/repos/calabash/calabash-android/subscription","commits_url":"https://api.github.com/repos/calabash/calabash-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/calabash/calabash-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/calabash/calabash-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/calabash/calabash-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/calabash/calabash-android/contents/{+path}","compare_url":"https://api.github.com/repos/calabash/calabash-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/calabash/calabash-android/merges","archive_url":"https://api.github.com/repos/calabash/calabash-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/calabash/calabash-android/downloads","issues_url":"https://api.github.com/repos/calabash/calabash-android/issues{/number}","pulls_url":"https://api.github.com/repos/calabash/calabash-android/pulls{/number}","milestones_url":"https://api.github.com/repos/calabash/calabash-android/milestones{/number}","notifications_url":"https://api.github.com/repos/calabash/calabash-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/calabash/calabash-android/labels{/name}","releases_url":"https://api.github.com/repos/calabash/calabash-android/releases{/id}","created_at":"2012-02-05T20:48:08Z","updated_at":"2015-08-23T14:59:07Z","pushed_at":"2015-08-25T17:43:20Z","git_url":"git://github.com/calabash/calabash-android.git","ssh_url":"git@github.com:calabash/calabash-android.git","clone_url":"https://github.com/calabash/calabash-android.git","svn_url":"https://github.com/calabash/calabash-android","homepage":"calaba.sh","size":51340,"stargazers_count":953,"watchers_count":953,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":446,"mirror_url":null,"open_issues_count":87,"forks":446,"open_issues":87,"watchers":953,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/calabash/calabash-android/pulls/601"},"html":{"href":"https://github.com/calabash/calabash-android/pull/601"},"issue":{"href":"https://api.github.com/repos/calabash/calabash-android/issues/601"},"comments":{"href":"https://api.github.com/repos/calabash/calabash-android/issues/601/comments"},"review_comments":{"href":"https://api.github.com/repos/calabash/calabash-android/pulls/601/comments"},"review_comment":{"href":"https://api.github.com/repos/calabash/calabash-android/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/calabash/calabash-android/pulls/601/commits"},"statuses":{"href":"https://api.github.com/repos/calabash/calabash-android/statuses/dbb6bbce8770d89d8840dabe2b226d1d5d9dcbe9"}}}}