package jp.ac.titech.sharp4k.cuten;
-import javax.xml.datatype.Duration;
-
-import jp.ac.titech.sharp4k.cuten.sampletask.*;
-import android.R;
+import jp.ac.titech.sharp4k.cuten.sampletask.QATask;
import android.app.Activity;
import android.os.Bundle;
-import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
-public class QAActivity extends Activity implements ResultSender,OnClickListener {
+public class QAActivity extends Activity implements ResultSender,
+ OnClickListener {
private static String TAG = "QA";
private BaseApp taskApp;
layout.addView(taskApp.createView(this, this.getResources()));
setContentView(layout);
}
+
@Override
public void onClick(View v) {
taskApp.onClose();
}
+
@Override
public void send(int[] results) {
String str = "";
private RadioGroup[] choices;
private int num;
private Resources res;
+
@Override
protected View createView(Context ctx, Resources res) {
this.ctx = ctx;
this.res = res;
- ScrollView root=new ScrollView(ctx);
- HorizontalScrollView rootChild=new HorizontalScrollView(ctx);
+ ScrollView root = new ScrollView(ctx);
+ HorizontalScrollView rootChild = new HorizontalScrollView(ctx);
root.addView(rootChild);
LinearLayout body = new LinearLayout(ctx);
body.setOrientation(LinearLayout.VERTICAL);
rootChild.addView(body);
-
+
TextView tv = new TextView(ctx);
String message = res.getString(R.string.first);
tv.setText(message);
//
String[] questions = res.getStringArray(R.array.questions);
TypedArray typedArray = res.obtainTypedArray(R.array.choices);
- num=(questions.length<typedArray.length())?questions.length:typedArray.length();
- choices=new RadioGroup[num];
- for (int n = 0; n <num ; n++) {
+ num = (questions.length < typedArray.length()) ? questions.length
+ : typedArray.length();
+ choices = new RadioGroup[num];
+ for (int n = 0; n < num; n++) {
TextView text = new TextView(ctx);
text.setText(questions[n]);
RadioGroup radioGroup = new RadioGroup(ctx);
- choices[n]=radioGroup;
+ choices[n] = radioGroup;
radioGroup.setOrientation(LinearLayout.HORIZONTAL);
int id = typedArray.getResourceId(n, 0);
String[] names = res.getStringArray(id);
body.addView(radioGroup);
}
//
-
+
return root;
}
+
@Override
protected void onClose() {
- int[] choicesId =new int [num];
- for(int i=0;i<num;i++){
- choicesId[i]=choices[i].getCheckedRadioButtonId();
+ int[] choicesId = new int[num];
+ for (int i = 0; i < num; i++) {
+ choicesId[i] = choices[i].getCheckedRadioButtonId();
}
int[] answers = res.getIntArray(R.array.answers);
- num=(answers.length < num)?answers.length:num;
- int correctCount=0;
- for(int i=0;i<num;i++){
- if(answers[i]==choicesId[i]){
+ num = (answers.length < num) ? answers.length : num;
+ int correctCount = 0;
+ for (int i = 0; i < num; i++) {
+ if (answers[i] == choicesId[i]) {
correctCount++;
}
}
- int res=correctCount*100/num;
- int[] result={res};
+ int res = correctCount * 100 / num;
+ int[] result = { res };
sendResult(result);
super.onClose();
}