OSDN Git Service

create task view.
authorkato-sh4k <kato.t.an@m.titech.ac.jp>
Tue, 30 Oct 2012 02:48:02 +0000 (11:48 +0900)
committerkato-sh4k <kato.t.an@m.titech.ac.jp>
Tue, 30 Oct 2012 02:48:02 +0000 (11:48 +0900)
not testing on CUTEn.

Circuit/res/values/strings.xml
Circuit/src/jp/ac/titech/sharp4k/cuten/CircuitActivity.java
Circuit/src/jp/ac/titech/sharp4k/cuten/app/CircuitTask.java

index 977e9a1..7361273 100644 (file)
@@ -4,5 +4,6 @@
     <string name="hello">Hello World, CircuitActivity!</string>
     <string name="app_name">Circuit</string>
     <string name="test_btn">Toast</string>
+    <string name="question">以下の空欄を埋め、半加算器を作りなさい。</string>
 
 </resources>
\ No newline at end of file
index 4565bba..5271d99 100644 (file)
@@ -7,6 +7,7 @@ import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.LinearLayout;
+import android.widget.Toast;
 
 public class CircuitActivity extends Activity implements ResultSender,
                OnClickListener {
@@ -38,7 +39,11 @@ public class CircuitActivity extends Activity implements ResultSender,
        @Override
        public void send(int[] archieve) {
                // TODO 自動生成されたメソッド・スタブ
-
+               String str = "";
+               for (Integer i : archieve) {
+                       str += i.toString() + ",";
+               }
+               Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
        }
 
        @Override
index 8bd1bcc..069dd0e 100644 (file)
@@ -4,29 +4,40 @@ import jp.ac.titech.sharp4k.cuten.BaseApp;
 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) {
@@ -34,50 +45,121 @@ public class CircuitTask extends BaseApp implements OnClickListener{
                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();
                }
        }
-       
 }