Class: TakePictureAction

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

Overview

Category: Camera/Photo

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) ⇒ TakePictureAction

Returns a new instance of TakePictureAction.



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/ruby-macrodroid/actions.rb', line 287

def initialize(obj=nil)

  
  h = if obj.is_a? Hash then

    macro = obj[:macro]    
    obj.delete :macro
    obj

    
  elsif obj.is_a? Array
    
    e, macro = obj
    
    puts 'e: ' + e.xml.inspect

    a = e.xpath('item/*')
    
    if a.any? then
      
      h2 = a.map {|node| [node.name.to_sym, node.text.to_s.strip]}.to_h
      
      desc = ''
      
      if h2[:description] then

        desc = h2[:description]
        h2.delete :description
        puts 'desc: ' + desc.inspect
        
        if desc.length > 1 then
          
          flash = case desc
          when /Flash On/i
            1
          when /Flash Auto/i
            2
          else
            0
          end
          

        end          
        
      end
      
      {
        use_front_camera: (desc =~ /Front Facing/ ? true : false),
        flash_option: flash
      }.merge(h2)          
      
    
    end
  end
  
  options = {
    new_path: macro.picture_path,
    path: macro.picture_path,
    show_icon: true,
    use_front_camera: true,
    flash_option: 0
  }

  super(options.merge h)

end

Instance Method Details

#to_pcObject



354
355
356
357
# File 'lib/ruby-macrodroid/actions.rb', line 354

def to_pc()
  camera = @h[:use_front_camera] ? :front : :back
  'take_photo :' + camera.to_s
end

#to_s(colour: false, indent: 0) ⇒ Object



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/ruby-macrodroid/actions.rb', line 359

def to_s(colour: false, indent: 0)
  
  flash = case @h[:flash_option]
  when 0
    ''
  when 1
    'Flash On'
  when 2
    'Flash Auto'
  end
  
  @s = 'Take Picture'# + @h.inspect
  a = [@h[:use_front_camera] ? 'Front Facing' : 'Rear Facing']
  a << flash if flash.length > 0
  @s += "\n" + a.join(', ')
  super()
  
end