Class: MotionAsyncTask
- Inherits:
-
Android::Os::AsyncTask
- Object
- Android::Os::AsyncTask
- MotionAsyncTask
- Defined in:
- lib/motion-async/motion_async_task.rb
Instance Attribute Summary collapse
-
#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
#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
5 6 7 8 9 10 |
# File 'lib/motion-async/motion_async_task.rb', line 5 def self.create(={}, &block) MotionAsyncTask.new.tap do |task| [:background] = block if block task.callbacks.merge!() end end |
Instance Method Details
#cancelled? ⇒ Boolean
39 40 41 |
# File 'lib/motion-async/motion_async_task.rb', line 39 def cancelled? isCancelled end |
#doInBackground(params) ⇒ Object
54 55 56 |
# File 'lib/motion-async/motion_async_task.rb', line 54 def doInBackground(params) @result = call_if_defined :background, self end |
#finished? ⇒ Boolean
35 36 37 |
# File 'lib/motion-async/motion_async_task.rb', line 35 def finished? status == Android::Os::AsyncTask::Status::FINISHED end |
#on(callback, &block) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/motion-async/motion_async_task.rb', line 12 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
63 64 65 |
# File 'lib/motion-async/motion_async_task.rb', line 63 def onCancelled(result) call_if_defined :cancelled, result end |
#onPostExecute(result) ⇒ Object
50 51 52 |
# File 'lib/motion-async/motion_async_task.rb', line 50 def onPostExecute(result) call_if_defined :completion, result end |
#onPreExecute ⇒ Object
AsyncTask event methods
46 47 48 |
# File 'lib/motion-async/motion_async_task.rb', line 46 def onPreExecute call_if_defined :pre_execute, self end |
#onProgressUpdate(progress) ⇒ Object
58 59 60 61 |
# File 'lib/motion-async/motion_async_task.rb', line 58 def onProgressUpdate(progress) progress = progress.first if progress.size == 1 call_if_defined :progress, progress end |
#pending? ⇒ Boolean
27 28 29 |
# File 'lib/motion-async/motion_async_task.rb', line 27 def pending? status == Android::Os::AsyncTask::Status::PENDING end |
#progress(progress) ⇒ Object
publishProgress must be passed an Array - we can make that easier
22 23 24 25 |
# File 'lib/motion-async/motion_async_task.rb', line 22 def progress(progress) progress = [progress] unless progress.respond_to?(:[]) publishProgress(progress) end |
#running? ⇒ Boolean
31 32 33 |
# File 'lib/motion-async/motion_async_task.rb', line 31 def running? status == Android::Os::AsyncTask::Status::RUNNING end |