31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/fusuma/plugin/detectors/touch_detector.rb', line 31
def detect(buffers)
events = []
timer_buffer = buffers.find { |b| b.type == 'timer' }
touch_buffer = buffers.find { |b| b.type == 'touch' }
@touch_buffer = touch_buffer || @touch_buffer
if timer_buffer &&
timer_buffer.events.any? &&
@last_known_gesture &&
(timer_buffer.events.last.time - @last_known_gesture.time) > event_expire_time
events << create_event(record: @last_known_gesture.record.create_index_record(status: 'end', trigger: :repeat)) if @last_known_gesture.record.repeatable?
@last_known_gesture = nil
end
if timer_buffer
return events if @touch_buffer.nil? || @touch_buffer.empty?
else
return events if touch_buffer.nil? || touch_buffer.empty?
end
gesture_record = nil
if touch_buffer
@detectors.each do |detector|
gesture_record = detector.detect(@touch_buffer)
break if gesture_record
end
else
return events if @touch_buffer.empty?
gesture_record = @hold_detector.detect(@touch_buffer)
end
if gesture_record
if gesture_record.repeatable? && @last_known_gesture&.record == gesture_record
@last_known_gesture = create_event(record: gesture_record)
if touch_buffer.ended?
events << create_event(record: gesture_record.create_index_record(status: 'end', trigger: :repeat))
else
events << create_event(record: gesture_record.create_index_record(status: 'update', trigger: :repeat))
end
else
events << create_event(record: @last_known_gesture.record.create_index_record(status: 'end', trigger: :repeat)) if @last_known_gesture&.record&.repeatable?
@last_known_gesture = create_event(record: gesture_record)
events << create_event(record: gesture_record.create_index_record)
if gesture_record.repeatable?
events << create_event(record: gesture_record.create_index_record(status: 'begin', trigger: :repeat))
events << create_event(record: gesture_record.create_index_record(status: 'end', trigger: :repeat)) if touch_buffer.ended?
end
end
@touch_buffer.clear
elsif @touch_buffer&.ended? && @last_known_gesture
events << create_event(record: @last_known_gesture.record.create_index_record(status: 'end', trigger: :repeat)) if @last_known_gesture.record.repeatable?
@last_known_gesture = nil
end
events
end
|