Modifier and Type | Field and Description |
---|---|
private int |
currentExercise
|
private static int |
EXERCISE_CONTINUE
State in which an exercise has been correctly answered and a click on the ButtonGrid or
Play button will load the next exercise.
|
private static int |
EXERCISE_READY
State in which an exercise is prepared and has been played at least once, the buttons in the
ButtonGrid are enabled.
|
private static int |
EXERCISE_READY_NOTPLAYED
State in which an exercise is prepared but has not been played, the buttons in the ButtonGrid
are disabled as we do not want the user to (inadvertently) give an answer before listening to the
exercise.
|
private int |
exerciseState
The current state.
|
private boolean |
isEmpty
Set to true if we are currently hiding the UI
The UI is hidden when there is no
Module selected. |
private Activity |
mCtx |
private Module |
mod
The
Module we are currently doing exercises from. |
private int |
modId
ID of the
Module we are currently doing exercises from. |
private int |
modIndex
Index of the
Module in Main.mModules |
private static java.lang.String |
PREFERENCES_CURRENTEXERCISE |
private static java.lang.String |
PREFERENCES_EXERCISESTATE |
private static java.lang.String |
PREFERENCES_ISEMPTY |
(package private) static java.lang.String |
PREFERENCES_ISFRESHINTENT |
private static java.lang.String |
PREFERENCES_MODID |
private static java.lang.String |
PREFERENCES_MODINDEX |
Constructor and Description |
---|
ExerciseFragment() |
Modifier and Type | Method and Description |
---|---|
private void |
fadeButton(int position)
Fade out the Button in
ButtonGridFragment at the given position |
int |
getModuleIndex() |
void |
onActivityCreated(Bundle savedInstanceState)
Initializes or restores the Fragment's state.
|
void |
onAnswerSelected(int position)
Handler for click events in the ButtonGridFragment
|
void |
onClickPlay(View view)
On receiving a click event on the Play button, relay it to the MediaFragment and:
If the current state is
EXERCISE_READY_NOTPLAYED , move the state to EXERCISE_READY
If the current state is EXERCISE_CONTINUE , prepare an exercise and request the MediaFragment
to play it as soon as it is ready, and set the state to EXERCISE_READY |
View |
onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) |
void |
onPause()
Save complete state.
|
void |
onResume() |
private void |
prepareExercise()
Prepare an exercise for this activity.
|
(package private) void |
setEmpty()
Hide the main UI of the fragment and display a single TextView instead.
|
private void |
setFeedbackText(java.lang.String text)
Set the feedback text in
FeedbackBarFragment |
void |
setModule(int position)
Display the Module at position in
Main.getModuleList() |
(package private) void |
setNotEmpty()
Unhide the main UI, does the exact opposite of setEmpty().
|
void |
updateFeedbackStatistics()
Update
FeedbackBarFragment statistics |
private static final int EXERCISE_READY
private static final int EXERCISE_CONTINUE
private static final int EXERCISE_READY_NOTPLAYED
private static final java.lang.String PREFERENCES_ISEMPTY
private static final java.lang.String PREFERENCES_MODINDEX
private static final java.lang.String PREFERENCES_MODID
private static final java.lang.String PREFERENCES_CURRENTEXERCISE
private static final java.lang.String PREFERENCES_EXERCISESTATE
static final java.lang.String PREFERENCES_ISFRESHINTENT
private int exerciseState
private int modIndex
Module
in Main.mModules
private int modId
Module
we are currently doing exercises from.private int currentExercise
private boolean isEmpty
Module
selected.private Activity mCtx
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
public void onActivityCreated(Bundle savedInstanceState)
android.content.Intent
, set up the UI
from the given position value, otherwise restore the state the fragment was left in.void setEmpty()
Module
selected, instead of showing an empty layout
we show this TextView saying 'No Module Selected'void setNotEmpty()
public void setModule(int position)
Main.getModuleList()
If position is out of bounds set the UI to 'empty', otherwise load the selected Module, set up the UI and prepare an exercise.
position
- The position of the Module in Main.getModuleList()
to displaypublic int getModuleIndex()
public void onPause()
public void onResume()
private void prepareExercise()
This function will receive an Exercise index from the loaded Module and use that to:
- Set up the ButtonGrid with the answers
- Start the MediaFragment to prepare and load the required WAV file
- Set up the FeedbackBarFragment to reflect the current state.
public void onClickPlay(View view)
EXERCISE_READY_NOTPLAYED
, move the state to EXERCISE_READY
If the current state is EXERCISE_CONTINUE
, prepare an exercise and request the MediaFragment
to play it as soon as it is ready, and set the state to EXERCISE_READY
view
- The parent view where the click event was received.public void onAnswerSelected(int position)
Depending on the state of the Activity, handle user input, see code for details.
position
- The position of the Button in the ButtonGridFragment that was clicked.private void setFeedbackText(java.lang.String text)
FeedbackBarFragment
text
- The text to set in the FeedbackBarFragment text field.public void updateFeedbackStatistics()
FeedbackBarFragment
statisticsprivate void fadeButton(int position)
ButtonGridFragment
at the given positionposition
- The position of the Button in ButtonGridFragment
to fade out.