class RemoteDroid::Control

Public Class Methods

disable() click to toggle source
# File lib/remotedroid/control.rb, line 21
def self.disable()
  http_exec 'set-airplane-mode', {state: 1}
end
enable() click to toggle source
# File lib/remotedroid/control.rb, line 13
def self.enable()
  http_exec 'set-airplane-mode', {state: 0}
end
new(dev=nil, deviceid: dev, remote_url: nil, debug: false) click to toggle source
# 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
off() click to toggle source
# File lib/remotedroid/control.rb, line 25
def self.off()
  self.disable
end
on() click to toggle source
# File lib/remotedroid/control.rb, line 17
def self.on()
  self.enable
end
toggle() click to toggle source
# File lib/remotedroid/control.rb, line 29
def self.toggle()
  http_exec 'set-airplane-mode', {state: 2}
end

Public Instance Methods

airplane_mode() click to toggle source
# 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={}) click to toggle source
# File lib/remotedroid/control.rb, line 36
def ask_alexa(options={})
  http_exec 'ask-alexa', options
end
autorotate() click to toggle source
# 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() click to toggle source
# 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={}) click to toggle source
# File lib/remotedroid/control.rb, line 90
def camera_flash_light(options={})
  http_exec 'camera-flash-light', options
end
click(options={content: ''}) click to toggle source
# File lib/remotedroid/control.rb, line 94
def click(options={content: ''})
  http_exec 'click-text-content', options
end
control_media(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 98
def control_media(options={})      
  http_exec 'media-' + options[:option].downcase.gsub(/\W/,'-')
end
disable_airplane_mode() click to toggle source
# File lib/remotedroid/control.rb, line 102
def disable_airplane_mode()
  http_exec 'set-airplane-mode', {state: 1}
end
disable_bluetooth() click to toggle source
# File lib/remotedroid/control.rb, line 106
def disable_bluetooth()
  http_exec 'set-bluetooth', {state: 1}
end
disable_macro(macro) click to toggle source
# File lib/remotedroid/control.rb, line 110
def disable_macro(macro)
  http_exec 'disable-macro', {name: macro}
end
disable_wifi() click to toggle source
# File lib/remotedroid/control.rb, line 114
def disable_wifi()
  http_exec 'set-wifi', {state: 1}
end
enable_airplane_mode() click to toggle source
# File lib/remotedroid/control.rb, line 118
def enable_airplane_mode()
  http_exec 'set-airplane-mode', {state: 0}
end
enable_bluetooth() click to toggle source
# File lib/remotedroid/control.rb, line 122
def enable_bluetooth()
  http_exec 'set-bluetooth', {state: 0}
end
enable_macro(macro) click to toggle source
# File lib/remotedroid/control.rb, line 126
def enable_macro(macro)
  http_exec 'enable-macro', {name: macro}
end
enable_wifi() click to toggle source
# File lib/remotedroid/control.rb, line 130
def enable_wifi()
  http_exec 'set-wifi', {state: 0}
end
export(s)
Alias for: write
fill_clipboard(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 134
def fill_clipboard(options={})
  http_exec 'fill-clipboard', options
end
force_macro_run(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 138
def force_macro_run(options={})
  http_exec option[:macro_name].downcase.gsub(/ /,'-')
end
goto(options={url: ''})
Alias for: open_web_page
hotspot(state=nil) click to toggle source
# 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={}) click to toggle source
# File lib/remotedroid/control.rb, line 169
def http_exec(command, options={})
  
  url = "https://trigger.macrodroid.com/%s/%s" % [@deviceid, command]
  
  if options and options.any? then
    h = options
    url += '?' + \
        URI.escape(h.map {|key,value| "%s=%s" % [key, value]}.join('&'))
  end
  
  s = open(url).read
  
end
launch_activity(options={app: ''}) click to toggle source
# File lib/remotedroid/control.rb, line 183
def launch_activity(options={app: ''})
  
  return if options[:app].empty?
  
  app = options[: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'}) click to toggle source
# File lib/remotedroid/control.rb, line 200
def launch_package(options={package: 'com.google.android.chrome'})
  http_exec 'launch-by-package', options
end
location(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 204
def location(options={})
  http_exec 'location'
end
method_missing2(method_name, *args) click to toggle source
# 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: ''}) click to toggle source
# File lib/remotedroid/control.rb, line 208
def open_web_page(options={url: ''})
  http_exec 'open-web-page', options
end
Also aliased as: open_website, goto, visit
open_website(options={url: ''})
Alias for: open_web_page
say(obj)
Alias for: speak_text
say_current_time(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 216
def say_current_time(options={})
  http_exec 'say-current-time'
end
Also aliased as: say_time
say_time(options={})
Alias for: say_current_time
screen(state=nil) click to toggle source
# 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) click to toggle source
# 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={}) click to toggle source
# File lib/remotedroid/control.rb, line 264
def share_location(options={})
  http_exec 'share-location'
end
speak_text(obj) click to toggle source
# File lib/remotedroid/control.rb, line 268
def speak_text(obj)
  
  options = case obj
  when String
    {text: obj}
  when Hash
    obj
  end

  http_exec 'speak-text', options
end
Also aliased as: say
stay_awake(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 282
def stay_awake(options={})
  http_exec 'stay-awake', options
end
stay_awake_off(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 286
def stay_awake_off(options={})
  http_exec 'stay-awake-off', options
end
take_photo(options={})
Alias for: take_picture
take_picture(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 290
def take_picture(options={})
  http_exec 'take-picture', options
end
Also aliased as: take_photo
take_screenshot(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 296
def take_screenshot(options={})
  http_exec 'take-screenshot', options
end
toast(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 300
def toast(options={})
  http_exec :toast, options
end
torch(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 304
def torch(options={})
  http_exec :torch 
end
vibrate(options={}) click to toggle source
# File lib/remotedroid/control.rb, line 308
def vibrate(options={})
  http_exec :vibrate
end
visit(options={url: ''})
Alias for: open_web_page
wifi() click to toggle source
# 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) click to toggle source
# 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
Also aliased as: export