Clean up setTestResultAndFinish
Remove (hide) the static setTestResultAndFinish method since it had a
lot of duplication which can be pulled into the base class. Also
update the callers to use the simpler API.
Change-Id: I76fd85b2cd680b99c9c02844f6a341643af3af09
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java b/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
index ef80b5d..57ea127 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
@@ -86,6 +86,13 @@
/** @return null or details about the test run. */
String getTestDetails();
+
+ /**
+ * Set the result of the test and finish the activity.
+ *
+ * @param passed Whether or not the test passed.
+ */
+ void setTestResultAndFinish(boolean passed);
}
public static class Activity extends android.app.Activity implements PassFailActivity {
@@ -138,6 +145,12 @@
public String getTestDetails() {
return null;
}
+
+ @Override
+ public void setTestResultAndFinish(boolean passed) {
+ PassFailButtons.setTestResultAndFinishHelper(this, getTestId(), getTestDetails(),
+ passed);
+ }
}
public static class ListActivity extends android.app.ListActivity implements PassFailActivity {
@@ -171,6 +184,12 @@
public String getTestDetails() {
return null;
}
+
+ @Override
+ public void setTestResultAndFinish(boolean passed) {
+ PassFailButtons.setTestResultAndFinishHelper(this, getTestId(), getTestDetails(),
+ passed);
+ }
}
public static class TestListActivity extends AbstractTestListActivity
@@ -205,6 +224,12 @@
public String getTestDetails() {
return null;
}
+
+ @Override
+ public void setTestResultAndFinish(boolean passed) {
+ PassFailButtons.setTestResultAndFinishHelper(this, getTestId(), getTestDetails(),
+ passed);
+ }
}
private static <T extends android.app.Activity & PassFailActivity>
@@ -328,11 +353,11 @@
default:
throw new IllegalArgumentException("Unknown id: " + target.getId());
}
- setTestResultAndFinish(activity, testId, testDetails, passed);
+ setTestResultAndFinishHelper(activity, testId, testDetails, passed);
}
/** Set the test result and finish the activity. */
- public static void setTestResultAndFinish(android.app.Activity activity, String testId,
+ private static void setTestResultAndFinishHelper(android.app.Activity activity, String testId,
String testDetails, boolean passed) {
if (passed) {
TestResult.setPassedResult(activity, testId, testDetails);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java
index f93723c..2ae921c 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java
@@ -734,10 +734,7 @@
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
- PassFailButtons.setTestResultAndFinish(CameraVideoActivity.this,
- CameraVideoActivity.this.getTestId(),
- CameraVideoActivity.this.getTestDetails(),
- /* passed */false);
+ setTestResultAndFinish(/* passed */false);
break;
case DialogInterface.BUTTON_NEGATIVE:
break;
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/projection/offscreen/ProjectionOffscreenActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/projection/offscreen/ProjectionOffscreenActivity.java
index 500ebf7..5f32cfd 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/projection/offscreen/ProjectionOffscreenActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/projection/offscreen/ProjectionOffscreenActivity.java
@@ -169,7 +169,7 @@
protected void onPause() {
super.onPause();
if (mTestStatus == TestStatus.FAILED) {
- PassFailButtons.setTestResultAndFinish(this, getTestId(), getTestDetails(), false);
+ setTestResultAndFinish(false);
}
}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/HeartRateMonitorTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/HeartRateMonitorTestActivity.java
index 3a48e3c..b6a1c47 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/HeartRateMonitorTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/HeartRateMonitorTestActivity.java
@@ -61,7 +61,7 @@
if (!mSensorManager.registerListener(mSensorListener, mSensor,
SensorManager.SENSOR_DELAY_UI)) {
showNoHeartRateWarningDialog();
- PassFailButtons.setTestResultAndFinish(this, getTestId(), getTestDetails(), true);
+ setTestResultAndFinish(true);
}
}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/PlayVideoActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/PlayVideoActivity.java
index 369d32c..b8d8c30 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/PlayVideoActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/PlayVideoActivity.java
@@ -118,8 +118,7 @@
.setNegativeButton("Close", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- PassFailButtons.setTestResultAndFinish(PlayVideoActivity.this,
- getTestId(), null, false);
+ setTestResultAndFinish(false);
}
})
.show();
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/StreamingVideoActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/StreamingVideoActivity.java
index 6d12747..fa233e8 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/StreamingVideoActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/streamquality/StreamingVideoActivity.java
@@ -169,8 +169,7 @@
.setNegativeButton("Close", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- PassFailButtons.setTestResultAndFinish(StreamingVideoActivity.this,
- getTestId(), null, false);
+ setTestResultAndFinish(false);
}
}).show();
default: