Class: Animator
  
  
  
  
  
    - Inherits:
- 
      Object
      
        
        show all
      
    
    - Defined in:
- lib/droiuby/wrappers/animator.rb
 
  
    
      Instance Method Summary
      collapse
    
    
  
  Constructor Details
  
    
  
  
    #initialize(target)  ⇒ Animator 
  
  
  
  
    
Returns a new instance of Animator.
   
 
  
  
    | 
3
4
5
6
7
8
9 | # File 'lib/droiuby/wrappers/animator.rb', line 3
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 
  
  
  
  
    | 
23
24
25
26
27
28
29
30
31 | # File 'lib/droiuby/wrappers/animator.rb', line 23
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 
  
  
  
  
    | 
49
50
51
52
53 | # File 'lib/droiuby/wrappers/animator.rb', line 49
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 
  
  
  
  
    | 
11
12
13 | # File 'lib/droiuby/wrappers/animator.rb', line 11
def animator_set
  @animator_set
end
 | 
 
    
      
  
  
    #animators  ⇒ Object 
  
  
  
  
    | 
15
16
17 | # File 'lib/droiuby/wrappers/animator.rb', line 15
def animators
  @animators
end
 | 
 
    
      
  
  
    #before(animation)  ⇒ Object 
  
  
  
  
    | 
43
44
45
46
47 | # File 'lib/droiuby/wrappers/animator.rb', line 43
def before(animation)
  Java::android.animation.AnimatorSet.new.tap { |s|
    s.play(to_animator(animation)).before(self.animator_set)
  } if @done
end
 | 
 
    
      
  
  
    | 
75
76
77
78
79
80
81
82
83 | # File 'lib/droiuby/wrappers/animator.rb', line 75
def done
  @done = true
  case @mode
  when :together
    @animator_set.playTogether(*@animators)
  when :one_after_the_other
    @animator_set.playSequentially(*@animators)
  end
end
 | 
 
    
      
  
  
    | 
19
20
21 | # File 'lib/droiuby/wrappers/animator.rb', line 19
def native
  @animator_set
end
 | 
 
    
      
  
  
    #on(event, &block)  ⇒ Object 
  
  
  
  
    | 
90
91
92
93
94
95
96
97 | # File 'lib/droiuby/wrappers/animator.rb', line 90
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 
  
  
  
  
    | 
71
72
73 | # File 'lib/droiuby/wrappers/animator.rb', line 71
def one_after_the_other
  @mode = :one_after_the_other
end
 | 
 
    
      
  
  
    #sequentially  ⇒ Object 
  
  
  
  
    | 
33
34
35
36 | # File 'lib/droiuby/wrappers/animator.rb', line 33
def sequentially
  @mode = :one_after_the_other
  self
end
 | 
 
    
      
  
  
    | 
85
86
87
88 | # File 'lib/droiuby/wrappers/animator.rb', line 85
def start
  @animator_set.start
  self
end
 | 
 
    
      
  
  
    | 
38
39
40
41 | # File 'lib/droiuby/wrappers/animator.rb', line 38
def together
  @mode = :together
  self
end
 | 
 
    
      
  
  
    #wait(milliseconds)  ⇒ Object 
  
  
  
  
    | 
55
56
57
58
59 | # File 'lib/droiuby/wrappers/animator.rb', line 55
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 
  
  
  
  
    | 
61
62
63
64
65 | # File 'lib/droiuby/wrappers/animator.rb', line 61
def with(animation)
  Java::android.animation.AnimatorSet.new.tap { |s|
    s.play(to_animator(animation)).with(self.animator_set)
  } if @done
end
 |