Class: ControlMediaAction

Inherits:
MediaAction show all
Defined in:
lib/ruby-macrodroid/actions.rb

Overview

note: to find a package id from an App name, try searching for the name on

the Google Play Store and the id will be returned in the URL once the 
correct app has been clicked. e.g.
https://play.google.com/store/apps/details?id=com.google.android.music

Instance Attribute Summary

Attributes inherited from Action

#constraints

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from Action

#invoke

Methods included from ObjectX

#action_to_object, #object_create, #varify

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(obj = nil) ⇒ ControlMediaAction

Returns a new instance of ControlMediaAction.



2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
# File 'lib/ruby-macrodroid/actions.rb', line 2058

def initialize(obj=nil)

  h = if obj.is_a? Hash then
    obj
  elsif obj.is_a? Array
    
    e, macro = obj      
    s = e.text('item/description').to_s
    app = s[/Simulate Media Button \(([^\)]+)/,1]
    
    if app then        
      
      {
        application_name: app,  package_name: APPS[app], 
        simulate_media_button: true
      }
      
    else
      {}
    end
  end 
  
  options = {
    application_name: "Google Play Music", option: "Play/Pause", 
    package_name: "com.google.android.music", 
    send_media_player_commands: false, 
    simulate_media_button: true,
  }

  super(options.merge h)

end

Instance Method Details

#to_s(colour: false, indent: 0) ⇒ Object Also known as: to_summary



2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
# File 'lib/ruby-macrodroid/actions.rb', line 2091

def to_s(colour: false, indent: 0)
  
  @s = 'Media ' + @h[:option] #+ @h.inspect
  
  if @h[:simulate_media_button] then
    @s +=  "\nSimulate Media Button (%s)" % @h[:application_name]
  end
  
  super()
end