public class OrderedTask extends Task implements java.io.Serializable
Task
protocol and represents a
task that assumes a fixed order for its steps.
In the ResearchStack framework, any simple sequential task, such as a survey or an active task, can be represented as an ordered task.
If you want further custom conditional behaviors in a task, it can be easier to subclass
OrderedTask or NavigableOrderedTask and override particular Task
methods than it
is to implement a new Task subclass directly. Override the methods getStepAfterStep(org.researchstack.backbone.step.Step, org.researchstack.backbone.result.TaskResult)
and
getStepBeforeStep(org.researchstack.backbone.step.Step, org.researchstack.backbone.result.TaskResult)
, and call super for all other methods.
Task.InvalidTaskException, Task.TaskProgress, Task.ViewChangeType
Constructor and Description |
---|
OrderedTask(java.lang.String identifier,
java.util.List<Step> steps)
Returns an initialized ordered task using the specified identifier and array of steps.
|
OrderedTask(java.lang.String identifier,
Step... steps)
Returns an initialized ordered task using the specified identifier and array of steps.
|
Modifier and Type | Method and Description |
---|---|
Task.TaskProgress |
getProgressOfCurrentStep(Step step,
TaskResult result)
Returns the progress of the current step.
|
Step |
getStepAfterStep(Step step,
TaskResult result)
Returns the next step immediately after the passed in step in the list of steps, or null
|
Step |
getStepBeforeStep(Step step,
TaskResult result)
Returns the next step immediately before the passed in step in the list of steps, or null
|
java.util.List<Step> |
getSteps()
Returns a copy of the list of steps.
|
Step |
getStepWithIdentifier(java.lang.String identifier)
Returns the step that matches the specified identifier, if there is one.
|
java.lang.String |
getTitleForStep(android.content.Context context,
Step step)
Returns
Step.getStepTitle() if it exists, otherwise returns string showing progress. |
void |
validateParameters()
Validates that there are no duplicate identifiers in the list of steps
|
getIdentifier, onViewChange
protected java.util.List<Step> steps
public OrderedTask(java.lang.String identifier, java.util.List<Step> steps)
identifier
- The unique identifier for the task.steps
- An array of Step
objects in the order in which they should be
presented.public Step getStepAfterStep(Step step, TaskResult result)
getStepAfterStep
in class Task
step
- The reference step. Pass null to specify the first step.result
- A snapshot of the current set of results.steps
after the passed in step, or null if at the endpublic Step getStepBeforeStep(Step step, TaskResult result)
getStepBeforeStep
in class Task
step
- The reference step.result
- A snapshot of the current set of results.steps
before the passed in step, or null if at the
startpublic Step getStepWithIdentifier(java.lang.String identifier)
Task
getStepWithIdentifier
in class Task
identifier
- The identifier of the step to retrieve.public Task.TaskProgress getProgressOfCurrentStep(Step step, TaskResult result)
Task
During a task, the ViewTaskActivity
can display the
progress (that is, the current step number out of the total number of steps) in the
navigation bar. Implement this method to control what is displayed; if you don't implement
this method, the progress label does not appear.
If the returned Task.TaskProgress
object has a count of 0, the progress is not displayed.
getProgressOfCurrentStep
in class Task
step
- The current step.result
- A snapshot of the current set of results.public java.lang.String getTitleForStep(android.content.Context context, Step step)
Step.getStepTitle()
if it exists, otherwise returns string showing progress.getTitleForStep
in class Task
context
- for fetching resourcesstep
- the current steppublic void validateParameters()
validateParameters
in class Task
Task.InvalidTaskException
public java.util.List<Step> getSteps()