import jp.ac.titech.sharp4k.cuten.R;
import android.content.Context;
import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Paint;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
+import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
+import android.widget.TextView;
import android.widget.Toast;
-public class CircuitTask extends BaseApp implements OnClickListener{
+public class CircuitTask extends BaseApp implements OnClickListener {
+ static final int QUESTION_SIZE = 4;
+
static final int FP = ViewGroup.LayoutParams.FILL_PARENT;
static final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
-
+
+ static final int AND = 0;
+ static final int OR = 1;
+ static final int NOT = 2;
+
+ static final float QUESTION_TEXT_SIZE = 30.0f;
+
private static final String TAG = CircuitTask.class.getSimpleName();
private Context cxt;
private Resources res;
private Button submitBtn;
- private Button[] selectBtnAllay;
+ private int[] correctAnswer = { OR, AND, NOT, AND };
+ private int[] userAnswer = new int[QUESTION_SIZE];
+ private ImageView[] answerView = new ImageView[QUESTION_SIZE];
+ private int[] ViewAllay = {R.drawable.and, R.drawable.or, R.drawable.not};
+ LinearLayout viewLayout;
+ private int count = 0;
@Override
protected View createView(final Context cxt, Resources res) {
this.cxt = cxt;
this.res = res;
- LinearLayout layout = new LinearLayout(cxt);
- layout.setLayoutParams(new LayoutParams(FP, WC));
- layout.setOrientation(LinearLayout.VERTICAL);
-
+ viewLayout = new LinearLayout(cxt);
+ viewLayout.setLayoutParams(new LayoutParams(FP, FP));
+ viewLayout.setOrientation(LinearLayout.VERTICAL);
+
+ LinearLayout questionLayout = new LinearLayout(cxt);
+ questionLayout.setLayoutParams(new LayoutParams(FP, WC));
+ questionLayout.setOrientation(LinearLayout.VERTICAL);
+
+ TextView textView = new TextView(cxt);
+ textView.setText(R.string.question);
+ textView.setTextSize(QUESTION_TEXT_SIZE);
+
ImageView imageView = new ImageView(cxt);
imageView.setImageResource(R.drawable.question);
-
+
LinearLayout selectBtnLayout = new LinearLayout(cxt);
selectBtnLayout.setOrientation(LinearLayout.HORIZONTAL);
selectBtnLayout.setLayoutParams(new LayoutParams(FP, FP));
- selectBtnAllay = new Button[3];
-
- for(Button btn : selectBtnAllay){
- btn = new Button(cxt);
- btn.setOnClickListener(this);
- btn.setWidth(FP);
- btn.setHeight(WC);
- selectBtnLayout.addView(btn);
- }
-
+ createBtnArray(selectBtnLayout);
+
submitBtn = new Button(cxt);
submitBtn.setText("Submit");
submitBtn.setOnClickListener(this);
- layout.addView(imageView);
- layout.addView(selectBtnLayout);
- layout.addView(submitBtn);
+ questionLayout.addView(textView);
+ questionLayout.addView(imageView);
+ questionLayout.addView(selectBtnLayout);
+ questionLayout.addView(submitBtn);
+
+ LinearLayout answerLayout = createAnswerLayout(cxt);
+
+ viewLayout.addView(questionLayout);
+ viewLayout.addView(answerLayout);
+
+ return viewLayout;
+ }
+
+ private void createBtnArray(LinearLayout selectBtnLayout) {
+ ImageButton[] btnArray = new ImageButton[3];
+
+ for (int i = 0; i < btnArray.length; i++) {
+ ImageButton btn = new ImageButton(cxt);
+ btn.setOnClickListener(this);
+ switch (i) {
+ case AND: {
+ btn.setImageResource(R.drawable.and);
+ btn.setId(AND);
+ break;
+ }
+ case OR: {
+ btn.setImageResource(R.drawable.or);
+ btn.setId(OR);
+ break;
+ }
+ case NOT: {
+ btn.setImageResource(R.drawable.not);
+ btn.setId(NOT);
+ break;
+ }
+ default: {
+ }
+ }
+
+ selectBtnLayout.addView(btn);
+ }
+
+ }
+
+ private LinearLayout createAnswerLayout(Context cxt) {
+ LinearLayout layout = new LinearLayout(cxt);
+ layout.setOrientation(LinearLayout.HORIZONTAL);
+
+ for (int i = 0; i < QUESTION_SIZE; i++) {
+ LinearLayout line = new LinearLayout(cxt);
+ TextView number = new TextView(cxt);
+ number.setText("Q" + (i+1) + " : ");
+ answerView[i] = new ImageView(cxt);
+
+ line.addView(number);
+ line.addView(answerView[i]);
+ layout.addView(line);
+ }
return layout;
}
@Override
protected void onClose() {
+
super.onClose();
}
@Override
public void onClick(View v) {
// TODO 自動生成されたメソッド・スタブ
- if(v.equals(submitBtn)){
+ if (v.equals(submitBtn)) {
+ int[] result = new int[QUESTION_SIZE];
+ for(int i = 0; i < result.length; i++){
+ if(correctAnswer[i] == userAnswer[i]){
+ result[i] = 10;
+ }else{
+ result[i] = 0;
+ }
+ }
+ sendResult(result);
Toast.makeText(cxt, "SUBMIT", Toast.LENGTH_LONG).show();
- }else{
- Toast.makeText(cxt, "なんか押した?", Toast.LENGTH_LONG).show();
+ close();
+
+ } else if (count < QUESTION_SIZE) {
+ userAnswer[count] = v.getId();
+ answerView[count].setImageResource(ViewAllay[v.getId()]);
+ viewLayout.invalidate();
+ count++;
+ } else{
+ Toast.makeText(cxt, "何を押してんだ?", Toast.LENGTH_LONG).show();
}
}
-
}