Class: RemoteDroid::Control
- Inherits:
-
Object
- Object
- RemoteDroid::Control
- Defined in:
- lib/remotedroid/control.rb
Class Method Summary collapse
Instance Method Summary collapse
- #airplane_mode ⇒ Object
- #ask_alexa(options = {}) ⇒ Object
- #autorotate ⇒ Object
- #bluetooth ⇒ Object
- #camera_flash_light(options = {}) ⇒ Object
- #click(options = {content: ''}) ⇒ Object
- #control_media(options = {}) ⇒ Object
- #disable_airplane_mode ⇒ Object
- #disable_bluetooth ⇒ Object
- #disable_macro(macro) ⇒ Object
- #disable_wifi ⇒ Object
- #enable_airplane_mode ⇒ Object
- #enable_bluetooth ⇒ Object
- #enable_macro(macro) ⇒ Object
- #enable_wifi ⇒ Object
- #fill_clipboard(options = {}) ⇒ Object
- #force_macro_run(options = {}) ⇒ Object
- #hotspot(state = nil) ⇒ Object
- #http_exec(command, options = {}) ⇒ Object
-
#initialize(dev = nil, deviceid: dev, remote_url: nil, debug: false) ⇒ Control
constructor
A new instance of Control.
- #launch_activity(options = {app: ''}) ⇒ Object
- #launch_package(options = {package: 'com.google.android.chrome'}) ⇒ Object
- #location(options = {}) ⇒ Object
- #method_missing2(method_name, *args) ⇒ Object
- #open_web_page(options = {url: ''}) ⇒ Object (also: #open_website, #goto, #visit)
- #say_current_time(options = {}) ⇒ Object (also: #say_time)
- #screen(state = nil) ⇒ Object
- #set_auto_rotate(state = nil) ⇒ Object
- #share_location(options = {}) ⇒ Object
- #speak_text(obj) ⇒ Object (also: #say)
- #stay_awake(options = {}) ⇒ Object
- #stay_awake_off(options = {}) ⇒ Object
- #take_picture(options = {}) ⇒ Object (also: #take_photo)
- #take_screenshot(options = {}) ⇒ Object
- #toast(options = {}) ⇒ Object
- #torch(options = {}) ⇒ Object
- #vibrate(options = {}) ⇒ Object
- #voice_search(options = {}) ⇒ Object
- #wifi ⇒ Object
- #write(s) ⇒ Object (also: #export)
Constructor Details
#initialize(dev = nil, deviceid: dev, remote_url: nil, debug: false) ⇒ Control
Returns a new instance of Control.
5 6 7 8 9 |
# File 'lib/remotedroid/control.rb', line 5 def initialize(dev=nil, deviceid: dev, remote_url: nil, debug: false) @deviceid, @remote_url, @debug = deviceid, remote_url, debug end |
Class Method Details
.disable ⇒ Object
21 22 23 |
# File 'lib/remotedroid/control.rb', line 21 def self.disable() http_exec 'set-airplane-mode', {state: 1} end |
.enable ⇒ Object
13 14 15 |
# File 'lib/remotedroid/control.rb', line 13 def self.enable() http_exec 'set-airplane-mode', {state: 0} end |
.off ⇒ Object
25 26 27 |
# File 'lib/remotedroid/control.rb', line 25 def self.off() self.disable end |
.on ⇒ Object
17 18 19 |
# File 'lib/remotedroid/control.rb', line 17 def self.on() self.enable end |
.toggle ⇒ Object
29 30 31 |
# File 'lib/remotedroid/control.rb', line 29 def self.toggle() http_exec 'set-airplane-mode', {state: 2} end |
Instance Method Details
#airplane_mode ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/remotedroid/control.rb', line 11 def airplane_mode() def self.enable() http_exec 'set-airplane-mode', {state: 0} end def self.on() self.enable end def self.disable() http_exec 'set-airplane-mode', {state: 1} end def self.off() self.disable end def self.toggle() http_exec 'set-airplane-mode', {state: 2} end self end |
#ask_alexa(options = {}) ⇒ Object
36 37 38 |
# File 'lib/remotedroid/control.rb', line 36 def ask_alexa(={}) http_exec 'ask-alexa', end |
#autorotate ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/remotedroid/control.rb', line 40 def autorotate() def self.enable() http_exec 'set-auto-rotate', {state: 0} end def self.on() self.enable end def self.disable() http_exec 'set-auto-rotate', {state: 1} end def self.off() self.disable end def self.toggle() http_exec 'set-auto-rotate', {state: 2} end self end |
#bluetooth ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/remotedroid/control.rb', line 65 def bluetooth() def self.enable() http_exec 'set-bluetooth', {state: 0} end def self.on() self.enable end def self.disable() http_exec 'set-bluetooth', {state: 1} end def self.off() self.disable end def self.toggle() http_exec 'set-bluetooth', {state: 2} end self end |
#camera_flash_light(options = {}) ⇒ Object
90 91 92 |
# File 'lib/remotedroid/control.rb', line 90 def camera_flash_light(={}) http_exec 'camera-flash-light', end |
#click(options = {content: ''}) ⇒ Object
94 95 96 |
# File 'lib/remotedroid/control.rb', line 94 def click(={content: ''}) http_exec 'click-text-content', end |
#control_media(options = {}) ⇒ Object
98 99 100 |
# File 'lib/remotedroid/control.rb', line 98 def control_media(={}) http_exec 'media-' + [:option].downcase.gsub(/\W/,'-') end |
#disable_airplane_mode ⇒ Object
102 103 104 |
# File 'lib/remotedroid/control.rb', line 102 def disable_airplane_mode() http_exec 'set-airplane-mode', {state: 1} end |
#disable_bluetooth ⇒ Object
106 107 108 |
# File 'lib/remotedroid/control.rb', line 106 def disable_bluetooth() http_exec 'set-bluetooth', {state: 1} end |
#disable_macro(macro) ⇒ Object
110 111 112 |
# File 'lib/remotedroid/control.rb', line 110 def disable_macro(macro) http_exec 'disable-macro', {name: macro} end |
#disable_wifi ⇒ Object
114 115 116 |
# File 'lib/remotedroid/control.rb', line 114 def disable_wifi() http_exec 'set-wifi', {state: 1} end |
#enable_airplane_mode ⇒ Object
118 119 120 |
# File 'lib/remotedroid/control.rb', line 118 def enable_airplane_mode() http_exec 'set-airplane-mode', {state: 0} end |
#enable_bluetooth ⇒ Object
122 123 124 |
# File 'lib/remotedroid/control.rb', line 122 def enable_bluetooth() http_exec 'set-bluetooth', {state: 0} end |
#enable_macro(macro) ⇒ Object
126 127 128 |
# File 'lib/remotedroid/control.rb', line 126 def enable_macro(macro) http_exec 'enable-macro', {name: macro} end |
#enable_wifi ⇒ Object
130 131 132 |
# File 'lib/remotedroid/control.rb', line 130 def enable_wifi() http_exec 'set-wifi', {state: 0} end |
#fill_clipboard(options = {}) ⇒ Object
134 135 136 |
# File 'lib/remotedroid/control.rb', line 134 def fill_clipboard(={}) http_exec 'fill-clipboard', end |
#force_macro_run(options = {}) ⇒ Object
138 139 140 |
# File 'lib/remotedroid/control.rb', line 138 def force_macro_run(={}) http_exec option[:macro_name].downcase.gsub(/ /,'-') end |
#hotspot(state = nil) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/remotedroid/control.rb', line 142 def hotspot(state=nil) if state then http_exec 'hotspot', {enable: state == :enable} else def self.enable() http_exec 'hotspot', {enable: true} end def self.on() self.enable end def self.disable() http_exec 'hotspot', {enable: false} end def self.off() self.disable end self end end |
#http_exec(command, options = {}) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/remotedroid/control.rb', line 169 def http_exec(command, ={}) url = "https://trigger.macrodroid.com/%s/%s" % [@deviceid, command] if and .any? then h = url += '?' + \ URI.escape(h.map {|key,value| "%s=%s" % [key, value]}.join('&')) end s = open(url).read end |
#launch_activity(options = {app: ''}) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/remotedroid/control.rb', line 183 def launch_activity(={app: ''}) return if [:app].empty? app = [:app] package = APPS[app] if package then launch_package package: package else r = APPS.find {|k,v| k =~ /#{app}/i} launch_package(package: r[1]) if r end end |
#launch_package(options = {package: 'com.google.android.chrome'}) ⇒ Object
200 201 202 |
# File 'lib/remotedroid/control.rb', line 200 def launch_package(={package: 'com.google.android.chrome'}) http_exec 'launch-by-package', end |
#location(options = {}) ⇒ Object
204 205 206 |
# File 'lib/remotedroid/control.rb', line 204 def location(={}) http_exec 'location' end |
#method_missing2(method_name, *args) ⇒ Object
387 388 389 |
# File 'lib/remotedroid/control.rb', line 387 def method_missing2(method_name, *args) http_exec(method_name, args.first) end |
#open_web_page(options = {url: ''}) ⇒ Object Also known as: open_website, goto, visit
208 209 210 |
# File 'lib/remotedroid/control.rb', line 208 def open_web_page(={url: ''}) http_exec 'open-web-page', end |
#say_current_time(options = {}) ⇒ Object Also known as: say_time
216 217 218 |
# File 'lib/remotedroid/control.rb', line 216 def say_current_time(={}) http_exec 'say-current-time' end |
#screen(state = nil) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/remotedroid/control.rb', line 222 def screen(state=nil) if state then http_exec 'screen', {on: state == :on} else def self.on() http_exec 'screen', {on: true} end def self.off() http_exec 'screen', {on: false} end self end end |
#set_auto_rotate(state = nil) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/remotedroid/control.rb', line 241 def set_auto_rotate(state=nil) if state then http_exec 'set-auto-rotate', {state: state} else def self.on() http_exec 'set-auto-rotate', {state: 0} end def self.off() http_exec 'set-auto-rotate', {state: 1} end def self.toggle() http_exec 'set-auto-rotate', {state: 2} end self end end |
#share_location(options = {}) ⇒ Object
264 265 266 |
# File 'lib/remotedroid/control.rb', line 264 def share_location(={}) http_exec 'share-location' end |
#speak_text(obj) ⇒ Object Also known as: say
268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/remotedroid/control.rb', line 268 def speak_text(obj) = case obj when String {text: obj} when Hash obj end http_exec 'speak-text', end |
#stay_awake(options = {}) ⇒ Object
282 283 284 |
# File 'lib/remotedroid/control.rb', line 282 def stay_awake(={}) http_exec 'stay-awake', end |
#stay_awake_off(options = {}) ⇒ Object
286 287 288 |
# File 'lib/remotedroid/control.rb', line 286 def stay_awake_off(={}) http_exec 'stay-awake-off', end |
#take_picture(options = {}) ⇒ Object Also known as: take_photo
290 291 292 |
# File 'lib/remotedroid/control.rb', line 290 def take_picture(={}) http_exec 'take-picture', end |
#take_screenshot(options = {}) ⇒ Object
296 297 298 |
# File 'lib/remotedroid/control.rb', line 296 def take_screenshot(={}) http_exec 'take-screenshot', end |
#toast(options = {}) ⇒ Object
300 301 302 |
# File 'lib/remotedroid/control.rb', line 300 def toast(={}) http_exec :toast, end |
#torch(options = {}) ⇒ Object
304 305 306 |
# File 'lib/remotedroid/control.rb', line 304 def torch(={}) http_exec :torch end |
#vibrate(options = {}) ⇒ Object
308 309 310 |
# File 'lib/remotedroid/control.rb', line 308 def vibrate(={}) http_exec :vibrate end |
#voice_search(options = {}) ⇒ Object
312 313 314 |
# File 'lib/remotedroid/control.rb', line 312 def voice_search(={}) http_exec 'voice-search' end |
#wifi ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/remotedroid/control.rb', line 316 def wifi() def self.enable() http_exec 'set-wifi', {state: 0} end def self.on() self.enable end def self.disable() http_exec 'set-wifi', {state: 1} end def self.off() self.disable end def self.toggle() http_exec 'set-wifi', {state: 2} end self end |
#write(s) ⇒ Object Also known as: export
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/remotedroid/control.rb', line 341 def write(s) d = MacroDroid.new(RD_MACROS, deviceid: @deviceid, remote_url: @remote_url, debug: false) a = d.macros.select do |macro| macro.triggers.find {|trigger| trigger.is_a? WebHookTrigger }.nil? end puts 'a: ' + a.length.inspect aux_macros = %w(Disable Enable).map do |state| rows = a[1..-1].map do |macro| " Else If name = #{macro.title} #{state} macro #{macro.title}" end " m: #{state} macro v: name t: webhook a: If name = #{a[0].title} #{state} macro #{a[0].title} #{rows.join("\n")} End If " end puts aux_macros.join d.import aux_macros.join # disable the non-webhook triggers by default a.each(&:disable) d.export s puts 'exported to ' + s end |