-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTimeLatencyTest.java
More file actions
67 lines (54 loc) · 2.26 KB
/
TimeLatencyTest.java
File metadata and controls
67 lines (54 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.aware.tests;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.widget.Toast;
import com.aware.TimeLatency;
public class TestTimeLatency {
private TimeLatency timeLatency = new TimeLatency();
private int questionId = 1;
public void test(final Activity activity) {
// Call startTime() when question appears
timeLatency.startTime(questionId);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("Question " + questionId);
builder.setMessage("What is 2 + 2?");
builder.setCancelable(false);
builder.setPositiveButton("4", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showResult(activity, "4");
}
});
builder.setNegativeButton("5", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showResult(activity, "5");
}
});
builder.show();
}
private void showResult(final Activity activity, String answer) {
// Call questionAnswered() when user responds
ContentValues result = timeLatency.questionAnswered(questionId);
if (result == null) {
Toast.makeText(activity, "Error: Question not found", Toast.LENGTH_SHORT).show();
return;
}
long timeTaken = result.getAsLong("time_taken");
String message = String.format("Answer: %s\nTime: %.2f seconds", answer, timeTaken / 1000.0);
AlertDialog.Builder resultBuilder = new AlertDialog.Builder(activity);
resultBuilder.setTitle("Result");
resultBuilder.setMessage(message);
resultBuilder.setPositiveButton("Next", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
questionId++;
test(activity);
}
});
resultBuilder.setNegativeButton("Done", null);
resultBuilder.show();
}
}