Class: UIInteractionAction

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

Overview

Category: Device Actions

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

Returns a new instance of UIInteractionAction.



1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
# File 'lib/ruby-macrodroid/actions.rb', line 1078

def initialize(obj=nil)

  if obj.is_a? Hash then
    h = obj
  elsif obj.is_a? Array
    
    e, macro = obj
    s = e.text('item/description').to_s
    
    r = s.match(/^(Click|Long Click) \[([^\]]+)/)

    # [Current focus] # Current focus
    # [0,0] # x,y location
    # [274,186] # Identify in app
    # [fooo] # Text content

    h = {
      ui_interaction_configuration: {}, :xy_point=>{:x=>0, :y=>0}, 
      :type=>"Click"
    }
    h2 = {}

    if r then

      h[:action] = 0

      click, detail = r.captures
      h2[:long_click] = false if click.downcase.to_sym == :click

      if detail == 'Current focus' then          
        h2[:click_option] = 1
      elsif detail =~ /\d+,\d+/
        # to-do   
      else
        # text content
        h2[:click_option] = 1
        h2[:text_content] = detail
      end
      
      h[:ui_interaction_configuration] = h2
    end

  end   
  
  options = {
    ui_interaction_configuration: {:type=>"Copy"},
    action: 2
  }


  super(options.merge h) 

end

Instance Method Details

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



1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
# File 'lib/ruby-macrodroid/actions.rb', line 1132

def to_s(colour: false, indent: 0)

  ui = @h[:ui_interaction_configuration]
  
  option = -> do
    detail = case ui[:click_option]
    when 0 # 'Current focus'
      'Current focus'
    when 1 # 'Text content'
      ui[:text_content]
    when 2 # 'X, Y location'
      "%s" % ui[:xy_point].values.join(',')
    when 3 # 'Identify in app'
      "id:%s" % ui[:view_id]
    end      
  end
  
  s = case @h[:action]
  when 0 # 'Click'      
    'Click' + " [%s]" % option.call
  when 1 # 'Long Click'
    'Long Click' + " [%s]" % option.call
  when 2 # 'Copy'
    'Copy'
  when 3 # 'Cut'
    'Cut'
  when 4 # 'Paste'
    "Paste [%s]" % (ui[:use_clipboard] ? 'Clipboard text' : ui[:text])
  when 5 # 'Clear selection'
    'Clear selection'
  when 6 # 'Gesture'
    detail = "%d ms: %d,%d -> %d,%d" % [ui[:duration_ms], ui[:start_x], 
        ui[:start_y], ui[:end_x], ui[:end_y]]
    "Gesture [%s]" % detail
  end
  
  'UI Interaction' + "\n  " + s + ' ' + @h.inspect
end