droiuby 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/droiuby.rb +1 -1
- data/lib/droiuby/android.rb +59 -0
- data/lib/droiuby/application.rb +30 -0
- data/lib/droiuby/bootstrap.rb +263 -0
- data/lib/droiuby/droiuby.rb +47 -0
- data/lib/droiuby/loader.rb +36 -0
- data/lib/droiuby/plugins/plugins.rb +25 -0
- data/lib/droiuby/preload.rb +29 -0
- data/lib/droiuby/{project.rb → scripts/project.rb} +15 -6
- data/lib/droiuby/scripts/templates/ruby/Gemfile.erb +3 -0
- data/lib/droiuby/{templates → scripts/templates}/ruby/application.css.erb +0 -0
- data/lib/droiuby/{templates → scripts/templates}/ruby/config.droiuby.erb +0 -0
- data/lib/droiuby/{templates → scripts/templates}/ruby/gitignore.erb +0 -0
- data/lib/droiuby/{templates → scripts/templates}/ruby/index.rb.erb +0 -0
- data/lib/droiuby/{templates → scripts/templates}/ruby/index.xml.erb +0 -0
- data/lib/droiuby/support/asset.rb +47 -0
- data/lib/droiuby/support/autoload.rb +22 -0
- data/lib/droiuby/support/fixnum.rb +11 -0
- data/lib/droiuby/support/object.rb +11 -0
- data/lib/droiuby/support/string.rb +38 -0
- data/lib/droiuby/support/system.rb +14 -0
- data/lib/droiuby/support/thread.rb +17 -0
- data/lib/droiuby/support/to_query.rb +28 -0
- data/lib/droiuby/support/utils.rb +10 -0
- data/lib/droiuby/wrappers/accelerometer.rb +17 -0
- data/lib/droiuby/wrappers/activity.rb +64 -0
- data/lib/droiuby/wrappers/animation.rb +141 -0
- data/lib/droiuby/wrappers/async.rb +33 -0
- data/lib/droiuby/wrappers/button.rb +2 -0
- data/lib/droiuby/wrappers/canvas.rb +147 -0
- data/lib/droiuby/wrappers/collection/view_array.rb +21 -0
- data/lib/droiuby/wrappers/compound_button_wrapper.rb +25 -0
- data/lib/droiuby/wrappers/edit_text.rb +22 -0
- data/lib/droiuby/wrappers/image_button.rb +8 -0
- data/lib/droiuby/wrappers/intent.rb +24 -0
- data/lib/droiuby/wrappers/java_helpers/java_method_helper.rb +42 -0
- data/lib/droiuby/wrappers/java_helpers/view_helper.rb +84 -0
- data/lib/droiuby/wrappers/linear_layout.rb +15 -0
- data/lib/droiuby/wrappers/list_adapter_wrapper.rb +61 -0
- data/lib/droiuby/wrappers/list_view.rb +10 -0
- data/lib/droiuby/wrappers/listeners/auto_wrap.rb +72 -0
- data/lib/droiuby/wrappers/listeners/on_click_listener.rb +21 -0
- data/lib/droiuby/wrappers/listeners/on_web_console_ready_listener.rb +23 -0
- data/lib/droiuby/wrappers/motion_events.rb +34 -0
- data/lib/droiuby/wrappers/preferences.rb +59 -0
- data/lib/droiuby/wrappers/proxy_builder/interface_builder.rb +25 -0
- data/lib/droiuby/wrappers/runnable_wrapper.rb +16 -0
- data/lib/droiuby/wrappers/surface_view_wrapper.rb +59 -0
- data/lib/droiuby/wrappers/text_view.rb +28 -0
- data/lib/droiuby/wrappers/thread_pool.rb +18 -0
- data/lib/droiuby/wrappers/view_group_wrapper.rb +87 -0
- data/lib/droiuby/wrappers/view_wrapper.rb +221 -0
- data/lib/droiuby/wrappers/web_view.rb +16 -0
- data/lib/droiuby/wrappers/wrappers.rb +5 -0
- metadata +77 -51
@@ -0,0 +1,25 @@
|
|
1
|
+
module Droiuby
|
2
|
+
class Plugins
|
3
|
+
|
4
|
+
def self.descendants
|
5
|
+
@descendants ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.inherited(descendant)
|
9
|
+
descendants << descendant
|
10
|
+
end
|
11
|
+
|
12
|
+
#ran after all classes are initialized and before executing the MainActivity on_create method
|
13
|
+
def after_bootstrap
|
14
|
+
end
|
15
|
+
|
16
|
+
#after a partial is rendered
|
17
|
+
def after_partial_setup(view)
|
18
|
+
end
|
19
|
+
|
20
|
+
#after a complete view is rendered
|
21
|
+
def after_view_setup
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#trigger pre load
|
2
|
+
def start_droiuby_plugins
|
3
|
+
puts "starting plugins"
|
4
|
+
$droiuby_plugins = []
|
5
|
+
puts "loading plugins"
|
6
|
+
Droiuby::Plugins.descendants.each { |klass|
|
7
|
+
puts "plugin -> #{klass.to_s}"
|
8
|
+
$droiuby_plugins << klass.new
|
9
|
+
}
|
10
|
+
|
11
|
+
$droiuby_plugins.each do |plugin|
|
12
|
+
puts "plugin attach #{plugin.class.to_s}"
|
13
|
+
plugin.after_bootstrap
|
14
|
+
end unless $droiuby_plugins.blank?
|
15
|
+
end
|
16
|
+
|
17
|
+
def after_view_setup
|
18
|
+
$droiuby_plugins.each do |plugin|
|
19
|
+
puts "plugin attach #{plugin.class.to_s}"
|
20
|
+
plugin.after_view_setup
|
21
|
+
end unless $droiuby_plugins.blank?
|
22
|
+
end
|
23
|
+
|
24
|
+
def after_partial_setup(view_group)
|
25
|
+
$droiuby_plugins.each do |plugin|
|
26
|
+
puts "plugin attach #{plugin.class.to_s}"
|
27
|
+
plugin.after_partial_setup(view_group)
|
28
|
+
end unless $droiuby_plugins.blank?
|
29
|
+
end
|
@@ -132,12 +132,17 @@ class Project < Thor
|
|
132
132
|
end
|
133
133
|
|
134
134
|
dest_folder = File.join(output_dir,"#{name}")
|
135
|
+
template File.join('ruby','Gemfile.erb'), File.join(dest_folder,"Gemfile")
|
135
136
|
template File.join('ruby','config.droiuby.erb'), File.join(dest_folder,"config.droiuby")
|
136
137
|
template File.join('ruby','gitignore.erb'), File.join(dest_folder,".gitignore")
|
137
138
|
template File.join('ruby','index.xml.erb'), File.join(dest_folder,"index.xml")
|
138
139
|
template File.join('ruby','application.css.erb'), File.join(dest_folder,"application.css")
|
139
140
|
template File.join('ruby','index.rb.erb'), File.join(dest_folder,"index.rb")
|
140
141
|
empty_directory File.join(dest_folder,"lib")
|
142
|
+
say "running bundle install"
|
143
|
+
Dir.chdir dest_folder
|
144
|
+
`bundle install`
|
145
|
+
bundle
|
141
146
|
end
|
142
147
|
|
143
148
|
desc "package NAME [WORKSPACE_DIR] [true|false]","package a project"
|
@@ -177,8 +182,11 @@ class Project < Thor
|
|
177
182
|
Thread.new do
|
178
183
|
while !ready
|
179
184
|
end
|
180
|
-
|
181
|
-
|
185
|
+
begin
|
186
|
+
launch(device_ip, "http://#{host_name_args}:#{port}/config.droiuby")
|
187
|
+
rescue Exception=>e
|
188
|
+
`adb shell am start -W -S --activity-clear-top --activity-brought-to-front -n com.droiuby.application/.DroiubyActivity`
|
189
|
+
end
|
182
190
|
end
|
183
191
|
|
184
192
|
puts "Starting server: http://#{host_name_args}:#{port}"
|
@@ -264,9 +272,7 @@ class Project < Thor
|
|
264
272
|
end
|
265
273
|
|
266
274
|
desc "execute NAME DEVICE_IP [WORKSPACE_DIR]","package and execute a droiuby application to target device running droiuby client"
|
267
|
-
|
268
275
|
def execute(name, device_ip, source_dir = 'projects')
|
269
|
-
`adb shell am start -W -S --activity-clear-top --activity-brought-to-front -n com.droiuby.application/.CanvasActivity`
|
270
276
|
package name, source_dir, "true"
|
271
277
|
upload name, device_ip, source_dir
|
272
278
|
end
|
@@ -312,9 +318,12 @@ class Project < Thor
|
|
312
318
|
FileUtils.rm archive, :force=>true
|
313
319
|
|
314
320
|
Zip::File.open(archive, Zip::File::CREATE) do |zipfile|
|
315
|
-
Dir
|
321
|
+
Dir.glob("**{,/*/**}/*.*").reject{ |f| f==archive || f.match(/^build/) }.uniq.each do |file|
|
316
322
|
say_status 'adding', file
|
317
|
-
|
323
|
+
begin
|
324
|
+
zipfile.add(file, file)
|
325
|
+
rescue Zip::ZipEntryExistsError=>e
|
326
|
+
end
|
318
327
|
end
|
319
328
|
end
|
320
329
|
say_status 'create', archive
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class BitmapDrawableWrapper
|
2
|
+
def initialize(drawable)
|
3
|
+
@native = drawable
|
4
|
+
end
|
5
|
+
|
6
|
+
def native
|
7
|
+
@native
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_bitmap
|
11
|
+
@native.getBitmap
|
12
|
+
end
|
13
|
+
|
14
|
+
def height
|
15
|
+
@native.getIntrinsicHeight
|
16
|
+
end
|
17
|
+
|
18
|
+
def width
|
19
|
+
@native.getIntrinsicWidth
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class AssetHandler
|
24
|
+
|
25
|
+
def initialize(url)
|
26
|
+
@url = url
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.download(url)
|
30
|
+
AssetHandler.new(url)
|
31
|
+
end
|
32
|
+
|
33
|
+
def start
|
34
|
+
async.perform {
|
35
|
+
result = BitmapDrawableWrapper.new(Java::com.droiuby.client.core.utils.Utils.loadAppAssetRuby(_execution_bundle, _current_app, _current_activity,
|
36
|
+
@url, Java::com.droiuby.client.core.utils.Utils::ASSET_TYPE_IMAGE, Java::com.droiuby.client.core.utils.Utils::HTTP_GET))
|
37
|
+
result
|
38
|
+
}.done { |result|
|
39
|
+
@block.call(result)
|
40
|
+
}.start
|
41
|
+
end
|
42
|
+
|
43
|
+
def done(&block)
|
44
|
+
@block = block
|
45
|
+
self
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
class Object
|
3
|
+
class << self
|
4
|
+
alias :const_missing_old :const_missing
|
5
|
+
def const_missing(name)
|
6
|
+
puts "constant missing #{name}"
|
7
|
+
@looked_for ||= {}
|
8
|
+
str_name = name.to_s
|
9
|
+
raise "Class not found: #{name}" if @looked_for[str_name]
|
10
|
+
@looked_for[str_name] = 1
|
11
|
+
|
12
|
+
name_parts = name.to_s.split('::').collect { |n| n.underscore }
|
13
|
+
require_path = File.join(*name_parts)
|
14
|
+
|
15
|
+
puts "autoloading #{require_path}"
|
16
|
+
require require_path
|
17
|
+
klass = const_get(name)
|
18
|
+
return klass if klass
|
19
|
+
raise "Class not found: #{name}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Fixnum
|
2
|
+
|
3
|
+
def dip
|
4
|
+
Java::com.droiuby.client.core.builder.ActivityBuilder.toDeviceIndependentPixels(_current_activity, self)
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_px
|
8
|
+
Java::com.droiuby.client.core.builder.ActivityBuilder.toPixelsFromDip(_current_activity, self)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
def camelize(first_letter_in_uppercase = true)
|
4
|
+
if first_letter_in_uppercase
|
5
|
+
self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
6
|
+
else
|
7
|
+
self.first + camelize(self)[1..-1]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_pixels
|
12
|
+
Java::com.droiuby.client.core.builder.ActivityBuilder.toPixels(_current_activity, self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_color
|
16
|
+
Java::android.graphics.Color.parseColor(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def underscore
|
20
|
+
self.gsub(/::/, '/').
|
21
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
22
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
23
|
+
tr("-", "_").
|
24
|
+
downcase
|
25
|
+
end
|
26
|
+
|
27
|
+
def constantize
|
28
|
+
names = self.split('::')
|
29
|
+
names.shift if names.empty? || names.first.empty?
|
30
|
+
|
31
|
+
constant = Object
|
32
|
+
names.each do |name|
|
33
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
34
|
+
end
|
35
|
+
constant
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Droiuby
|
2
|
+
class SystemWrapper
|
3
|
+
|
4
|
+
include JavaMethodHelper
|
5
|
+
|
6
|
+
java_native_singleton Java::java.lang.System, :nanoTime, []
|
7
|
+
java_native_singleton Java::java.lang.System, :currentTimeMillis, []
|
8
|
+
java_native_singleton Java::java.lang.System, :currentTimeMillis, []
|
9
|
+
java_native_singleton Java::java.lang.Thread, :sleep, [Java::long]
|
10
|
+
java_native_singleton Java::java.lang.System, :gc, []
|
11
|
+
java_native_singleton Java::android.util.Log, :d, [Java::java.lang.String, Java::java.lang.String]
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Object
|
2
|
+
def with_large_stack(stack_size_kb = 64, &block)
|
3
|
+
result = nil
|
4
|
+
t = Thread.with_large_stack(&proc{result = block.call})
|
5
|
+
t.join
|
6
|
+
result
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Thread
|
11
|
+
def self.with_large_stack(stack_size_kb = 128, &block)
|
12
|
+
runnable = RunnableWrapper.new(block).to_native
|
13
|
+
t = Java::java.lang.Thread.new(nil, runnable, "block with large stack", stack_size_kb * 1024)
|
14
|
+
t.start
|
15
|
+
t
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/core_ext/object/to_param'
|
2
|
+
|
3
|
+
class Object
|
4
|
+
# Converts an object into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
|
5
|
+
# param name.
|
6
|
+
#
|
7
|
+
# Note: This method is defined as a default implementation for all Objects for Hash#to_query to work.
|
8
|
+
def to_query(key)
|
9
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
10
|
+
"#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class Array
|
16
|
+
# Converts an array into a string suitable for use as a URL query string,
|
17
|
+
# using the given +key+ as the param name.
|
18
|
+
#
|
19
|
+
# ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
|
20
|
+
def to_query(key)
|
21
|
+
prefix = "#{key}[]"
|
22
|
+
collect { |value| value.to_query(prefix) }.join '&'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Hash
|
27
|
+
alias_method :to_query, :to_param
|
28
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Droiuby
|
2
|
+
class Utils
|
3
|
+
|
4
|
+
def self.start_web_console(&block)
|
5
|
+
listener = Droiuby::Wrappers::Listeners::OnWebConsoleReadyListener.new(_execution_bundle,block)
|
6
|
+
Java::com.droiuby.client.core.DroiubyLauncher.setupConsole(_execution_bundle, listener.to_native)
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Accelerometer
|
2
|
+
|
3
|
+
attr_accessor :sensor, :rate
|
4
|
+
include Droiuby::Wrappers::Listeners
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@native = _execution_bundle.getSensor(Java::Sensor.TYPE_ACCELEROMETER)
|
8
|
+
end
|
9
|
+
|
10
|
+
def on(event, &block)
|
11
|
+
unless @listener
|
12
|
+
@listener = Droiuby::Wrappers::Listeners::AutoWrapMultiple.new(_execution_bundle)
|
13
|
+
@native.registerListener(@listener.to_native('SensorEventListener'), @sensor, @rate)
|
14
|
+
end
|
15
|
+
@listener.impl(event, &block)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class Activity
|
2
|
+
|
3
|
+
@@before_content_blocks = []
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
def me
|
9
|
+
_current_activity
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def on_click(name, &block)
|
15
|
+
view = V(name).tap { |v|
|
16
|
+
v.native.setOnClickListener(Java::com.droiuby.client.core.OnClickListenerBridge.new(_execution_bundle, v.id))
|
17
|
+
}
|
18
|
+
define_method("on_click_listener_for_#{view.id.to_s}".to_sym) do |n_view|
|
19
|
+
_current_activity.instance_exec(wrap_native_view(n_view),&block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def portrait_mode_only
|
24
|
+
add_before_content_task { _current_activity.setRequestedOrientation(ActivityInfo::SCREEN_ORIENTATION_PORTRAIT) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def landscape_mode_only
|
28
|
+
add_before_content_task { _current_activity.setRequestedOrientation(ActivityInfo::SCREEN_ORIENTATION_LANDSCAPE) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def no_action_bar
|
32
|
+
add_before_content_task { _current_activity.requestWindowFeature(Java::android.view.Window::FEATURE_NO_TITLE) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_theme(theme, namespace = nil)
|
36
|
+
namespace = "#{namespace}." unless namespace.nil?
|
37
|
+
|
38
|
+
add_before_content_task do
|
39
|
+
_current_activity.setTheme(_R("#{namespace}R.style.#{theme}"))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def add_before_content_task(&block)
|
46
|
+
@@before_content_blocks = @@before_content_blocks || []
|
47
|
+
@@before_content_blocks << block
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def on_activity_result(request_code, result_code, intent)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def before_content_render
|
57
|
+
@@before_content_blocks.each { |block| block.call }
|
58
|
+
_current_activity.setContentView(_R('R.layout.canvas'))
|
59
|
+
end
|
60
|
+
|
61
|
+
def on_activity_reload
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
class AnimatorListenerWrapper
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@native = Java::com.droiuby.wrappers::AnimatorListenerRubyWrapper.new(_execution_bundle, self)
|
5
|
+
@blocks = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def set_block(sym, &block)
|
9
|
+
@blocks[sym.to_sym] = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def onAnimationStart
|
13
|
+
@block[:start].call if @block.has_key? :start
|
14
|
+
end
|
15
|
+
|
16
|
+
def onAnimationEnd
|
17
|
+
@block[:end].call if @block.has_key? :end
|
18
|
+
end
|
19
|
+
|
20
|
+
def onAnimationCancel
|
21
|
+
@block[:cancel].call if @block.has_key? :cancel
|
22
|
+
end
|
23
|
+
|
24
|
+
def onAnimationRepeat
|
25
|
+
@block[:repeat].call if @block.has_key? :repeat
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_native
|
29
|
+
@native
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
#Wrap the android animation API
|
35
|
+
class Animator
|
36
|
+
def initialize(target)
|
37
|
+
@animator_set = Java::android.animation.AnimatorSet.new
|
38
|
+
@mode = :together
|
39
|
+
@animators = []
|
40
|
+
@target = target
|
41
|
+
@done = false
|
42
|
+
end
|
43
|
+
|
44
|
+
def animator_set
|
45
|
+
@animator_set
|
46
|
+
end
|
47
|
+
|
48
|
+
def animators
|
49
|
+
@animators
|
50
|
+
end
|
51
|
+
|
52
|
+
def native
|
53
|
+
@animator_set
|
54
|
+
end
|
55
|
+
|
56
|
+
def method_missing(name, *args, &block)
|
57
|
+
anim = Java::android.animation.ObjectAnimator.ofFloat(@target.native, name.to_s.camelize(:lower), args[0], args[1]);
|
58
|
+
if args[2] && args[2].kind_of?(Hash)
|
59
|
+
duration = args[2][:duration]
|
60
|
+
anim.setDuration(duration)
|
61
|
+
end
|
62
|
+
@animators << anim
|
63
|
+
anim
|
64
|
+
end
|
65
|
+
|
66
|
+
def sequentially
|
67
|
+
@mode = :one_after_the_other
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
def together
|
72
|
+
@mode = :together
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def before(animation)
|
77
|
+
Java::android.animation.AnimatorSet.new.tap { |s|
|
78
|
+
s.play(to_animator(animation)).before(self.animator_set)
|
79
|
+
} if @done
|
80
|
+
end
|
81
|
+
|
82
|
+
def after(animation)
|
83
|
+
s = Java::android.animation.AnimatorSet.new.tap { |s|
|
84
|
+
s.play(to_animator(animation)).after(self.animator_set)
|
85
|
+
} if @done
|
86
|
+
end
|
87
|
+
|
88
|
+
def wait(milliseconds)
|
89
|
+
Java::android.animation.AnimatorSet.new.tap { |s|
|
90
|
+
s.play(self.animator_set).after(milliseconds.to_i)
|
91
|
+
} if @done
|
92
|
+
end
|
93
|
+
|
94
|
+
def with(animation)
|
95
|
+
Java::android.animation.AnimatorSet.new.tap { |s|
|
96
|
+
s.play(to_animator(animation)).with(self.animator_set)
|
97
|
+
} if @done
|
98
|
+
end
|
99
|
+
|
100
|
+
def together
|
101
|
+
@mode = :together
|
102
|
+
end
|
103
|
+
|
104
|
+
def one_after_the_other
|
105
|
+
@mode = :one_after_the_other
|
106
|
+
end
|
107
|
+
|
108
|
+
def done
|
109
|
+
@done = true
|
110
|
+
case @mode
|
111
|
+
when :together
|
112
|
+
@animator_set.playTogether(*@animators)
|
113
|
+
when :one_after_the_other
|
114
|
+
@animator_set.playSequentially(*@animators)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def start
|
119
|
+
@animator_set.start
|
120
|
+
self
|
121
|
+
end
|
122
|
+
|
123
|
+
def on(event, &block)
|
124
|
+
@animation_listener = @animation_listener || AnimatorListenerWrapper.new
|
125
|
+
if [:cancel, :start, :end, :repeat ].include?(event)
|
126
|
+
@animation_listener.set_block(event, Proc.new { |v| block.call(wrap_native_view(v))})
|
127
|
+
self.native.addListener(@animation_listener.to_native)
|
128
|
+
end
|
129
|
+
self
|
130
|
+
end
|
131
|
+
|
132
|
+
protected
|
133
|
+
|
134
|
+
def to_animator(animation)
|
135
|
+
animator = animation
|
136
|
+
if animation.kind_of? Animator
|
137
|
+
animator = animation.animator_set
|
138
|
+
end
|
139
|
+
animator
|
140
|
+
end
|
141
|
+
end
|