Class: Animator
- Inherits:
-
Object
show all
- Defined in:
- lib/droiuby/wrappers/animation.rb
Overview
Wrap the android animation API
Instance Method Summary
collapse
Constructor Details
#initialize(target) ⇒ Animator
Returns a new instance of Animator.
36
37
38
39
40
41
42
|
# File 'lib/droiuby/wrappers/animation.rb', line 36
def initialize(target)
@animator_set = Java::android.animation.AnimatorSet.new
@mode = :together
@animators = []
@target = target
@done = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/droiuby/wrappers/animation.rb', line 56
def method_missing(name, *args, &block)
anim = Java::android.animation.ObjectAnimator.ofFloat(@target.native, name.to_s.camelize(:lower), args[0], args[1]);
if args[2] && args[2].kind_of?(Hash)
duration = args[2][:duration]
anim.setDuration(duration)
end
@animators << anim
anim
end
|
Instance Method Details
#after(animation) ⇒ Object
82
83
84
85
86
|
# File 'lib/droiuby/wrappers/animation.rb', line 82
def after(animation)
s = Java::android.animation.AnimatorSet.new.tap { |s|
s.play(to_animator(animation)).after(self.animator_set)
} if @done
end
|
#animator_set ⇒ Object
44
45
46
|
# File 'lib/droiuby/wrappers/animation.rb', line 44
def animator_set
@animator_set
end
|
#animators ⇒ Object
48
49
50
|
# File 'lib/droiuby/wrappers/animation.rb', line 48
def animators
@animators
end
|
#before(animation) ⇒ Object
76
77
78
79
80
|
# File 'lib/droiuby/wrappers/animation.rb', line 76
def before(animation)
Java::android.animation.AnimatorSet.new.tap { |s|
s.play(to_animator(animation)).before(self.animator_set)
} if @done
end
|
108
109
110
111
112
113
114
115
116
|
# File 'lib/droiuby/wrappers/animation.rb', line 108
def done
@done = true
case @mode
when :together
@animator_set.playTogether(*@animators)
when :one_after_the_other
@animator_set.playSequentially(*@animators)
end
end
|
52
53
54
|
# File 'lib/droiuby/wrappers/animation.rb', line 52
def native
@animator_set
end
|
#on(event, &block) ⇒ Object
123
124
125
126
127
128
129
130
|
# File 'lib/droiuby/wrappers/animation.rb', line 123
def on(event, &block)
@animation_listener = @animation_listener || AnimatorListenerWrapper.new
if [:cancel, :start, :end, :repeat ].include?(event)
@animation_listener.set_block(event, Proc.new { |v| block.call(wrap_native_view(v))})
self.native.addListener(@animation_listener.to_native)
end
self
end
|
#one_after_the_other ⇒ Object
104
105
106
|
# File 'lib/droiuby/wrappers/animation.rb', line 104
def one_after_the_other
@mode = :one_after_the_other
end
|
#sequentially ⇒ Object
66
67
68
69
|
# File 'lib/droiuby/wrappers/animation.rb', line 66
def sequentially
@mode = :one_after_the_other
self
end
|
118
119
120
121
|
# File 'lib/droiuby/wrappers/animation.rb', line 118
def start
@animator_set.start
self
end
|
71
72
73
74
|
# File 'lib/droiuby/wrappers/animation.rb', line 71
def together
@mode = :together
self
end
|
#wait(milliseconds) ⇒ Object
88
89
90
91
92
|
# File 'lib/droiuby/wrappers/animation.rb', line 88
def wait(milliseconds)
Java::android.animation.AnimatorSet.new.tap { |s|
s.play(self.animator_set).after(milliseconds.to_i)
} if @done
end
|
#with(animation) ⇒ Object
94
95
96
97
98
|
# File 'lib/droiuby/wrappers/animation.rb', line 94
def with(animation)
Java::android.animation.AnimatorSet.new.tap { |s|
s.play(to_animator(animation)).with(self.animator_set)
} if @done
end
|