Class: MotionAsyncTask
- Inherits:
-
Android::Os::AsyncTask
- Object
- Android::Os::AsyncTask
- MotionAsyncTask
- Defined in:
- lib/motion-async/motion_async_task.rb
Instance Attribute Summary collapse
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
-
.create(options = {}, &block) ⇒ Object
Java is super picky about constructors, so we’ll use a factory method.
Instance Method Summary collapse
- #cancelled? ⇒ Boolean
- #doInBackground(params) ⇒ Object
- #finished? ⇒ Boolean
- #on(callback, &block) ⇒ Object
- #onCancelled(result) ⇒ Object
- #onPostExecute(result) ⇒ Object
-
#onPreExecute ⇒ Object
AsyncTask event methods.
- #onProgressUpdate(progress) ⇒ Object
- #pending? ⇒ Boolean
-
#progress(progress) ⇒ Object
publishProgress must be passed an Array - we can make that easier.
- #running? ⇒ Boolean
Instance Attribute Details
#delay ⇒ Object
Returns the value of attribute delay.
3 4 5 |
# File 'lib/motion-async/motion_async_task.rb', line 3 def delay @delay end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
2 3 4 |
# File 'lib/motion-async/motion_async_task.rb', line 2 def result @result end |
Class Method Details
.create(options = {}, &block) ⇒ Object
Java is super picky about constructors, so we’ll use a factory method
6 7 8 9 10 11 12 |
# File 'lib/motion-async/motion_async_task.rb', line 6 def self.create(={}, &block) MotionAsyncTask.new.tap do |task| [:background] = block if block task.delay = .delete(:delay) task.callbacks.merge!() end end |
Instance Method Details
#cancelled? ⇒ Boolean
41 42 43 |
# File 'lib/motion-async/motion_async_task.rb', line 41 def cancelled? isCancelled end |
#doInBackground(params) ⇒ Object
56 57 58 59 |
# File 'lib/motion-async/motion_async_task.rb', line 56 def doInBackground(params) sleep self.delay if self.delay @result = call_if_defined :background, self end |
#finished? ⇒ Boolean
37 38 39 |
# File 'lib/motion-async/motion_async_task.rb', line 37 def finished? status == Android::Os::AsyncTask::Status::FINISHED end |
#on(callback, &block) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/motion-async/motion_async_task.rb', line 14 def on(callback, &block) callbacks[callback] = block if callback == :completion && finished? # task already ran, but we'll call the completion block anyway block.call @result end self end |
#onCancelled(result) ⇒ Object
66 67 68 |
# File 'lib/motion-async/motion_async_task.rb', line 66 def onCancelled(result) call_if_defined :cancelled, result end |
#onPostExecute(result) ⇒ Object
52 53 54 |
# File 'lib/motion-async/motion_async_task.rb', line 52 def onPostExecute(result) call_if_defined :completion, result end |
#onPreExecute ⇒ Object
AsyncTask event methods
48 49 50 |
# File 'lib/motion-async/motion_async_task.rb', line 48 def onPreExecute call_if_defined :pre_execute, self end |
#onProgressUpdate(progress) ⇒ Object
61 62 63 64 |
# File 'lib/motion-async/motion_async_task.rb', line 61 def onProgressUpdate(progress) progress = progress.first if progress.size == 1 call_if_defined :progress, progress end |
#pending? ⇒ Boolean
29 30 31 |
# File 'lib/motion-async/motion_async_task.rb', line 29 def pending? status == Android::Os::AsyncTask::Status::PENDING end |
#progress(progress) ⇒ Object
publishProgress must be passed an Array - we can make that easier
24 25 26 27 |
# File 'lib/motion-async/motion_async_task.rb', line 24 def progress(progress) progress = [progress] unless progress.respond_to?(:[]) publishProgress(progress) end |
#running? ⇒ Boolean
33 34 35 |
# File 'lib/motion-async/motion_async_task.rb', line 33 def running? status == Android::Os::AsyncTask::Status::RUNNING end |