Skip to content

Instantly share code, notes, and snippets.

@bumi
Last active November 15, 2015 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumi/03f4507b0765442efbae to your computer and use it in GitHub Desktop.
Save bumi/03f4507b0765442efbae to your computer and use it in GitHub Desktop.
example on how to expose an http interface to execute command on an android phone using adb
require 'sinatra/base'
# wrapper to easily translate tap coordinates to readable methods
class Calculate
PAD = {
'1' => [100, 1200],
'2' => [400, 1200],
'3' => [700, 1200],
'4' => [100, 1350],
'5' => [400, 1350],
'6' => [700, 1350],
'7' => [100, 1500],
'8' => [400, 1500],
'9' => [700, 1500],
'0' => [400, 1650]
}
def sum(a, b)
a.to_s.split('').each do |num|
tap(PAD[num], 0)
end
tap([900, 1650])
b.to_s.split('').each do |num|
tap(PAD[num], 0)
end
tap([700, 1650])
end
# you use X and Y screen coordindates for the tap
def tap(x_y, delay = 1.0)
puts "tapping #{x_y.join(' ')}"
# TODO: use open3
`adb shell input tap #{x_y.join(' ')}`
sleep(delay) if delay.to_f > 0.0
end
end
# accepts post requests to /sum and calls the Calculator#sum method
post '/sum' do
Calculator.new.sum(params[:a], params[:b])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment