Format the instruction strings with the action button label

Refactor the instructions details from Test.Details to SimpleTest.SimpleDetails as they are not used by regular tests.

Change-Id: I650bb4a34645fc0264897c65a051717278719256
diff --git a/app/src/main/java/com/fairphone/checkup/tests/InformationTest.java b/app/src/main/java/com/fairphone/checkup/tests/InformationTest.java
index 7d78d86..1856c24 100644
--- a/app/src/main/java/com/fairphone/checkup/tests/InformationTest.java
+++ b/app/src/main/java/com/fairphone/checkup/tests/InformationTest.java
@@ -13,7 +13,7 @@
 /**
  * An information test automatically begins when the {@link android.app.Fragment} starts.
  */
-public abstract class InformationTest<InstanceInformation extends Information> extends Test {
+public abstract class InformationTest<InstanceInformation extends Information> extends Test<Test.Details> {
 
     protected InstanceInformation mInstanceInformation;
 
diff --git a/app/src/main/java/com/fairphone/checkup/tests/SimpleTest.java b/app/src/main/java/com/fairphone/checkup/tests/SimpleTest.java
index 3880476..56835d3 100644
--- a/app/src/main/java/com/fairphone/checkup/tests/SimpleTest.java
+++ b/app/src/main/java/com/fairphone/checkup/tests/SimpleTest.java
@@ -1,5 +1,6 @@
 package com.fairphone.checkup.tests;
 
+import android.content.Context;
 import android.content.res.ColorStateList;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
@@ -17,7 +18,36 @@
  * <p>If the test is cancellable, the action button will display a cancel label while the test is running.
  * If not cancellable, the action button will remain inactive until completion of the test.</p>
  */
-public abstract class SimpleTest extends Test {
+public abstract class SimpleTest extends Test<SimpleTest.SimpleDetails> {
+
+    public static abstract class SimpleDetails extends Test.Details {
+
+        protected final int mInstructionsId;
+
+        /**
+         * @param titleId        The title string resource id.
+         * @param summaryId      The summary string resource id.
+         * @param descriptionId  The description string resource id.
+         * @param instructionsId The instructions string resource id.
+         */
+        protected SimpleDetails(int titleId, int summaryId, int descriptionId, int instructionsId) {
+            super(titleId, summaryId, descriptionId);
+
+            mInstructionsId = instructionsId;
+        }
+
+        /**
+         * The instructions are a multiline description of what the user has to do.
+         * <p>It is *not* the general description of the test but explains what is going to happen and what the user needs to do.</p>
+         * <p>The instructions string is parametrised with the action button label.</p>
+         * <p>Override this method to further format the instructions string.</p>
+         *
+         * @return The instructions string.
+         */
+        public String getInstructions(Context context, CharSequence actionButtonLabel) {
+            return String.format(context.getString(mInstructionsId), actionButtonLabel);
+        }
+    }
 
     private Button mActionButton;
     private final View.OnClickListener mActionClickLister = new View.OnClickListener() {
@@ -48,7 +78,7 @@
         mActionButton = (Button) root.findViewById(R.id.test_action);
 
         descriptionView.setText(getDetails().getDescription(getActivity()));
-        instructionsView.setText(getDetails().getInstructions(getActivity()));
+        instructionsView.setText(getDetails().getInstructions(getActivity(), mActionButton.getText()));
         mActionButton.setOnClickListener(mActionClickLister);
 
         mContainer = container;
diff --git a/app/src/main/java/com/fairphone/checkup/tests/Test.java b/app/src/main/java/com/fairphone/checkup/tests/Test.java
index a063888..c4fa641 100644
--- a/app/src/main/java/com/fairphone/checkup/tests/Test.java
+++ b/app/src/main/java/com/fairphone/checkup/tests/Test.java
@@ -26,7 +26,7 @@
  * <p><strong>The call to the parent method </strong>(<code>super.onBeginTest()</code> for instance)<strong> must be included in each overridden method.</strong></p>
  * <p>The {@link #beginTest()}, {@link #cancelTest()}, and {@link #finishTest(boolean)} methods should <strong>not</strong> be overridden.
  * They are the public interface to a test with the status methods ({@link #isFresh()}, {@link #isRunning()}, {@link #isCancelled()}, {@link #isCompleted()}, {@link #hasPassed()}, {@link #hasFailed()}).</p>
- * <p>To define a test details (title, summary, description, and instructions), a concrete test should instantiate a {@link Details} sub-class.<br>
+ * <p>To define a test details (title, summary, and description), a concrete test should instantiate a {@link Details} sub-class.<br>
  * The default behaviour is to retrieve the strings as-is from the resource files.
  * To format them in a different way, do override:
  * <ul>
@@ -37,37 +37,23 @@
  * </p>
  * TODO properly document the state machine (w.r.t Fragment)
  */
-public abstract class Test extends Fragment {
+public abstract class Test<TestDetails extends Test.Details> extends Fragment {
 
     public static abstract class Details implements Serializable {
 
         protected final int mTitleId;
         protected final int mSummaryId;
         protected final int mDescriptionId;
-        protected final int mInstructionsId;
 
         /**
          * @param titleId        The title string resource id.
          * @param summaryId      The summary string resource id.
          * @param descriptionId  The description string resource id.
-         * @param instructionsId The instructions string resource id, or -1 if none.
          */
-        protected Details(int titleId, int summaryId, int descriptionId, int instructionsId) {
+        protected Details(int titleId, int summaryId, int descriptionId) {
             this.mTitleId = titleId;
             this.mSummaryId = summaryId;
             this.mDescriptionId = descriptionId;
-            this.mInstructionsId = instructionsId;
-        }
-
-        /**
-         * Call to {@link Details(int, int, int, int)} with -1 as the instructions string resource id.
-         *
-         * @param titleId       The title string resource id.
-         * @param summaryId     The summary string resource id.
-         * @param descriptionId The description string resource id.
-         */
-        protected Details(int titleId, int summaryId, int descriptionId) {
-            this(titleId, summaryId, descriptionId, -1);
         }
 
         /**
@@ -106,25 +92,6 @@
             return context.getString(mDescriptionId);
         }
 
-        public boolean hasInstructions() {
-            return mInstructionsId != -1;
-        }
-
-        /**
-         * The instructions are a multiline description of what the user has to do.
-         * <p>It is *not* the general description of the test but explains what is going to happen and what the user needs to do.</p>
-         * <p>Override this method to format the instructions string.</p>
-         *
-         * @return The instructions string or <code>null</code> if none.
-         */
-        public String getInstructions(Context context) {
-            if (hasInstructions()) {
-                return context.getString(mInstructionsId);
-            } else {
-                return null;
-            }
-        }
-
         public abstract Fragment getFragment();
     }
 
@@ -147,7 +114,7 @@
         mIsCancellable = isCancellable;
     }
 
-    protected abstract Details getDetails();
+    protected abstract TestDetails getDetails();
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
diff --git a/app/src/main/java/com/fairphone/checkup/tests/freedraw/FreeDrawTest.java b/app/src/main/java/com/fairphone/checkup/tests/freedraw/FreeDrawTest.java
index 5e41fca..34660bf 100644
--- a/app/src/main/java/com/fairphone/checkup/tests/freedraw/FreeDrawTest.java
+++ b/app/src/main/java/com/fairphone/checkup/tests/freedraw/FreeDrawTest.java
@@ -5,12 +5,11 @@
 import android.widget.ViewFlipper;
 
 import com.fairphone.checkup.R;
-import com.fairphone.checkup.tests.Test;
 import com.fairphone.checkup.tests.SimpleTest;
 
 public class FreeDrawTest extends SimpleTest {
 
-    public static final Details DETAILS = new Test.Details(R.string.freedraw_test_title, R.string.freedraw_test_summary, R.string.freedraw_test_description, R.string.freedraw_test_instructions) {
+    public static final SimpleDetails DETAILS = new SimpleTest.SimpleDetails(R.string.freedraw_test_title, R.string.freedraw_test_summary, R.string.freedraw_test_description, R.string.freedraw_test_instructions) {
         @Override
         public Fragment getFragment() {
             return new FreeDrawTest();
@@ -29,7 +28,7 @@
     }
 
     @Override
-    protected Details getDetails() {
+    protected SimpleDetails getDetails() {
         return DETAILS;
     }
 
diff --git a/app/src/main/java/com/fairphone/checkup/tests/lcd/LcdTest.java b/app/src/main/java/com/fairphone/checkup/tests/lcd/LcdTest.java
index 5d9e21c..d5808a6 100644
--- a/app/src/main/java/com/fairphone/checkup/tests/lcd/LcdTest.java
+++ b/app/src/main/java/com/fairphone/checkup/tests/lcd/LcdTest.java
@@ -7,13 +7,12 @@
 import android.widget.ViewFlipper;
 
 import com.fairphone.checkup.R;
-import com.fairphone.checkup.tests.Test;
 import com.fairphone.checkup.tests.SimpleTest;
 
 
 public class LcdTest extends SimpleTest {
 
-    public static final Details DETAILS = new Test.Details(R.string.lcd_test_title, R.string.lcd_test_summary, R.string.lcd_test_description, R.string.lcd_test_instructions) {
+    public static final SimpleDetails DETAILS = new SimpleTest.SimpleDetails(R.string.lcd_test_title, R.string.lcd_test_summary, R.string.lcd_test_description, R.string.lcd_test_instructions) {
         @Override
         public Fragment getFragment() {
             return new LcdTest();
@@ -32,7 +31,7 @@
     }
 
     @Override
-    protected Details getDetails() {
+    protected SimpleDetails getDetails() {
         return DETAILS;
     }
 
diff --git a/app/src/main/java/com/fairphone/checkup/tests/loopback/PrimaryMicLoopbackTest.java b/app/src/main/java/com/fairphone/checkup/tests/loopback/PrimaryMicLoopbackTest.java
index e633740..3efb12d 100644
--- a/app/src/main/java/com/fairphone/checkup/tests/loopback/PrimaryMicLoopbackTest.java
+++ b/app/src/main/java/com/fairphone/checkup/tests/loopback/PrimaryMicLoopbackTest.java
@@ -3,11 +3,11 @@
 import android.app.Fragment;
 
 import com.fairphone.checkup.R;
-import com.fairphone.checkup.tests.Test;
+import com.fairphone.checkup.tests.SimpleTest;
 
 public class PrimaryMicLoopbackTest extends MicLoopbackTest {
 
-    public static final Details DETAILS = new Test.Details(R.string.primary_mic_loopback_test_title, R.string.primary_mic_loopback_test_summary, R.string.primary_mic_loopback_test_description, R.string.primary_mic_loopback_test_instructions) {
+    public static final SimpleDetails DETAILS = new SimpleTest.SimpleDetails(R.string.primary_mic_loopback_test_title, R.string.primary_mic_loopback_test_summary, R.string.primary_mic_loopback_test_description, R.string.primary_mic_loopback_test_instructions) {
         @Override
         public Fragment getFragment() {
             return new PrimaryMicLoopbackTest();
@@ -19,7 +19,7 @@
     }
 
     @Override
-    protected Details getDetails() {
+    protected SimpleDetails getDetails() {
         return DETAILS;
     }
 }
diff --git a/app/src/main/java/com/fairphone/checkup/tests/loopback/SecondaryMicLoopbackTest.java b/app/src/main/java/com/fairphone/checkup/tests/loopback/SecondaryMicLoopbackTest.java
index fcca54d..b638ece 100644
--- a/app/src/main/java/com/fairphone/checkup/tests/loopback/SecondaryMicLoopbackTest.java
+++ b/app/src/main/java/com/fairphone/checkup/tests/loopback/SecondaryMicLoopbackTest.java
@@ -3,10 +3,11 @@
 import android.app.Fragment;
 
 import com.fairphone.checkup.R;
+import com.fairphone.checkup.tests.SimpleTest;
 
 public class SecondaryMicLoopbackTest extends MicLoopbackTest {
 
-    public static final Details DETAILS = new Details(R.string.secondary_mic_loopback_test_title, R.string.secondary_mic_loopback_test_summary, R.string.secondary_mic_loopback_test_description, R.string.secondary_mic_loopback_test_instructions) {
+    public static final SimpleDetails DETAILS = new SimpleTest.SimpleDetails(R.string.secondary_mic_loopback_test_title, R.string.secondary_mic_loopback_test_summary, R.string.secondary_mic_loopback_test_description, R.string.secondary_mic_loopback_test_instructions) {
         @Override
         public Fragment getFragment() {
             return new SecondaryMicLoopbackTest();
@@ -18,7 +19,7 @@
     }
 
     @Override
-    protected Details getDetails() {
+    protected SimpleDetails getDetails() {
         return DETAILS;
     }
 }
diff --git a/app/src/main/java/com/fairphone/checkup/tests/speaker/EarSpeakerTest.java b/app/src/main/java/com/fairphone/checkup/tests/speaker/EarSpeakerTest.java
index eaa0f8c..4234491 100644
--- a/app/src/main/java/com/fairphone/checkup/tests/speaker/EarSpeakerTest.java
+++ b/app/src/main/java/com/fairphone/checkup/tests/speaker/EarSpeakerTest.java
@@ -3,11 +3,11 @@
 import android.app.Fragment;
 
 import com.fairphone.checkup.R;
-import com.fairphone.checkup.tests.Test;
+import com.fairphone.checkup.tests.SimpleTest;
 
 public class EarSpeakerTest extends SpeakerTest {
 
-    public static final Details DETAILS = new Test.Details(R.string.ear_speaker_test_title, R.string.ear_speaker_test_summary, R.string.ear_speaker_test_description, R.string.ear_speaker_test_instructions) {
+    public static final SimpleDetails DETAILS = new SimpleTest.SimpleDetails(R.string.ear_speaker_test_title, R.string.ear_speaker_test_summary, R.string.ear_speaker_test_description, R.string.ear_speaker_test_instructions) {
         @Override
         public Fragment getFragment() {
             return new EarSpeakerTest();
@@ -19,7 +19,7 @@
     }
 
     @Override
-    protected Details getDetails() {
+    protected SimpleDetails getDetails() {
         return DETAILS;
     }
 
diff --git a/app/src/main/java/com/fairphone/checkup/tests/speaker/LoudSpeakerTest.java b/app/src/main/java/com/fairphone/checkup/tests/speaker/LoudSpeakerTest.java
index a5cd641..edec36a 100644
--- a/app/src/main/java/com/fairphone/checkup/tests/speaker/LoudSpeakerTest.java
+++ b/app/src/main/java/com/fairphone/checkup/tests/speaker/LoudSpeakerTest.java
@@ -3,10 +3,11 @@
 import android.app.Fragment;
 
 import com.fairphone.checkup.R;
+import com.fairphone.checkup.tests.SimpleTest;
 
 public class LoudSpeakerTest extends SpeakerTest {
 
-    public static final Details DETAILS = new Details(R.string.loud_speaker_test_title, R.string.loud_speaker_test_summary, R.string.loud_speaker_test_description, R.string.loud_speaker_test_instructions) {
+    public static final SimpleDetails DETAILS = new SimpleTest.SimpleDetails(R.string.loud_speaker_test_title, R.string.loud_speaker_test_summary, R.string.loud_speaker_test_description, R.string.loud_speaker_test_instructions) {
         @Override
         public Fragment getFragment() {
             return new LoudSpeakerTest();
@@ -18,7 +19,7 @@
     }
 
     @Override
-    protected Details getDetails() {
+    protected SimpleDetails getDetails() {
         return DETAILS;
     }
 
diff --git a/app/src/main/java/com/fairphone/checkup/tests/vibrator/VibratorTest.java b/app/src/main/java/com/fairphone/checkup/tests/vibrator/VibratorTest.java
index 9275850..d6dad56 100644
--- a/app/src/main/java/com/fairphone/checkup/tests/vibrator/VibratorTest.java
+++ b/app/src/main/java/com/fairphone/checkup/tests/vibrator/VibratorTest.java
@@ -8,22 +8,21 @@
 import android.util.Log;
 
 import com.fairphone.checkup.R;
-import com.fairphone.checkup.tests.Test;
 import com.fairphone.checkup.tests.SimpleTest;
 
 public class VibratorTest extends SimpleTest {
 
     private static final long VIBRATION_DURATION_MS = 2000;
 
-    public static final Details DETAILS = new Test.Details(R.string.vibrator_test_title, R.string.vibrator_test_summary, R.string.vibrator_test_description, R.string.vibrator_test_instructions) {
+    public static final SimpleDetails DETAILS = new SimpleTest.SimpleDetails(R.string.vibrator_test_title, R.string.vibrator_test_summary, R.string.vibrator_test_description, R.string.vibrator_test_instructions) {
         @Override
         public Fragment getFragment() {
             return new VibratorTest();
         }
 
         @Override
-        public String getInstructions(Context context) {
-            return String.format(context.getString(mInstructionsId), Math.round(VIBRATION_DURATION_MS / 1000));
+        public String getInstructions(Context context, CharSequence actionButtonLabel) {
+            return String.format(context.getString(mInstructionsId), actionButtonLabel, Math.round(VIBRATION_DURATION_MS / 1000));
         }
     };
 
@@ -38,7 +37,7 @@
     }
 
     @Override
-    protected Details getDetails() {
+    protected SimpleDetails getDetails() {
         return DETAILS;
     }
 
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 3815cbb..23bba6e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -13,25 +13,29 @@
     <string name="freedraw_test_title">Free drawing</string>
     <string name="freedraw_test_summary">Draw freely on the screen.</string>
     <string name="freedraw_test_description">Draw freely on the screen</string>
-    <string name="freedraw_test_instructions">Press \'start test\' and use your finger to draw freely on the screen. Look specifically for any screen abnormalities, i.e. blank spots, etc. To go back, swipe from the bottom of the screen towards the top to make the navigation buttons appear.</string>
+    <!-- Arguments: <action button label> -->
+    <string name="freedraw_test_instructions">Press \'%1$s\' and use your finger to draw freely on the screen. Look specifically for any screen abnormalities, i.e. blank spots, etc. To go back, swipe from the bottom of the screen towards the top to make the navigation buttons appear.</string>
 
     <!-- LCD -->
     <string name="lcd_test_title">Screen (LCD)</string>
     <string name="lcd_test_summary">The LCD screen displays all the content of your Fairphone.</string>
     <string name="lcd_test_description">The LCD screen displays all the content of your Fairphone</string>
-    <string name="lcd_test_instructions">Press \'start test\' and tap the screen to cycle through various colors.</string>
+    <!-- Arguments: <action button label> -->
+    <string name="lcd_test_instructions">Press \'%1$s\' and tap the screen to cycle through various colors.</string>
 
     <!-- Primary microphone loopback -->
     <string name="primary_mic_loopback_test_title">Primary microphone</string>
     <string name="primary_mic_loopback_test_summary">The microphone that is used for phone calls.</string>
     <string name="primary_mic_loopback_test_description">The microphone that is used for phone calls</string>
-    <string name="primary_mic_loopback_test_instructions">Press \'start test\' and pretend you are making a phone call by holding the phone against your ear. If you can hear yourself talk, no worries, that means the microphone is working correctly!</string>
+    <!-- Arguments: <action button label> -->
+    <string name="primary_mic_loopback_test_instructions">Press \'%1$s\' and pretend you are making a phone call by holding the phone against your ear. If you can hear yourself talk, no worries, that means the microphone is working correctly!</string>
 
     <!-- Secondary microphone loopback -->
     <string name="secondary_mic_loopback_test_title">Secondary microphone</string>
     <string name="secondary_mic_loopback_test_summary">The microphone to reduce ambient noise.</string>
     <string name="secondary_mic_loopback_test_description">The microphone to reduce ambient noise</string>
-    <string name="secondary_mic_loopback_test_instructions">Press \'start test\' and pretend you are making a phone call, but hold your phone upside down. Can you hear yourself?</string>
+    <!-- Arguments: <action button label> -->
+    <string name="secondary_mic_loopback_test_instructions">Press \'%1$s\' and pretend you are making a phone call, but hold your phone upside down. Can you hear yourself?</string>
 
     <!-- Modem -->
     <string name="modem_test_title">Mobile connectivity</string>
@@ -73,20 +77,22 @@
     <string name="ear_speaker_test_title">Ear speaker</string>
     <string name="ear_speaker_test_summary">The ear speaker is used to hear the other person during phone calls.</string>
     <string name="ear_speaker_test_description">The ear speaker is used to hear the other person during phone calls</string>
-    <string name="ear_speaker_test_instructions">Press \'start test\' and pretend you are making a phone call. If you hear the music through the ear speaker, that means it is working correctly.</string>
+    <!-- Arguments: <action button label> -->
+    <string name="ear_speaker_test_instructions">Press \'%1$s\' and pretend you are making a phone call. If you hear the music through the ear speaker, that means it is working correctly.</string>
 
     <!-- Loud speaker -->
     <string name="loud_speaker_test_title">Loud (rear) speaker</string>
     <string name="loud_speaker_test_summary">The loud (rear) speaker is used for listening to music and for hands-free phone calls.</string>
     <string name="loud_speaker_test_description">The loud (rear) speaker is used for listening to music and for hands-free phone calls</string>
-    <string name="loud_speaker_test_instructions">Press \'start test\' and use the physical volume buttons to lower or raise the sound level. You should hear your favorite Fairphone tune playing!</string>
+    <!-- Arguments: <action button label> -->
+    <string name="loud_speaker_test_instructions">Press \'%1$s\' and use the physical volume buttons to lower or raise the sound level. You should hear your favorite Fairphone tune playing!</string>
 
     <!-- Vibration motor -->
     <string name="vibrator_test_title">Vibration motor</string>
     <string name="vibrator_test_summary">This is what makes your Fairphone vibrate.</string>
     <string name="vibrator_test_description">This is what makes your Fairphone vibrate</string>
-    <!-- Arguments: <vibration duration in seconds (integer)> -->
-    <string name="vibrator_test_instructions">Press \'start test\' to make your phone vibrate for %d seconds.</string>
+    <!-- Arguments: <action button label> <vibration duration in seconds (integer)> -->
+    <string name="vibrator_test_instructions">Press \'%1$s\' to make your phone vibrate for %2$d seconds.</string>
 
     <!-- Wifi -->
     <string name="wifi_test_title">Wi-Fi</string>