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.



2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
# File 'lib/ruby-macrodroid/actions.rb', line 2208

def initialize(obj=nil)

  h = if obj.is_a? Hash then
    obj
  elsif obj.is_a? Array
    
    e, macro, h2 = 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
      }.merge h2
      
    else
      {}
    end
  end
  #puts 'h: ' + h.inspect
  
  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



2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
# File 'lib/ruby-macrodroid/actions.rb', line 2242

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