OSDN Git Service

Merge remote-tracking branch 'origin/AppC'
authoreagletmt <eagletmt@gmail.com>
Wed, 21 Nov 2012 04:42:55 +0000 (13:42 +0900)
committereagletmt <eagletmt@gmail.com>
Wed, 21 Nov 2012 04:42:55 +0000 (13:42 +0900)
Circuit/res-tasks/res-HA/drawable/question.png [new file with mode: 0644]
Circuit/res-tasks/res-HA/values/array.xml [new file with mode: 0644]
Circuit/res-tasks/res-HA/values/strings.xml [new file with mode: 0644]
Circuit/res-tasks/res-SRFF/drawable/question.png [new file with mode: 0644]
Circuit/res-tasks/res-SRFF/values/array.xml [new file with mode: 0644]
Circuit/res-tasks/res-SRFF/values/strings.xml [new file with mode: 0644]
Circuit/res-tasks/res-tasuu/drawable/question.png [new file with mode: 0644]
Circuit/res-tasks/res-tasuu/values/array.xml [new file with mode: 0644]
Circuit/res-tasks/res-tasuu/values/strings.xml [new file with mode: 0644]
Circuit/res/values/array.xml [new file with mode: 0644]
Circuit/src/jp/ac/titech/sharp4k/cuten/app/CircuitTask.java

diff --git a/Circuit/res-tasks/res-HA/drawable/question.png b/Circuit/res-tasks/res-HA/drawable/question.png
new file mode 100644 (file)
index 0000000..8222d5c
Binary files /dev/null and b/Circuit/res-tasks/res-HA/drawable/question.png differ
diff --git a/Circuit/res-tasks/res-HA/values/array.xml b/Circuit/res-tasks/res-HA/values/array.xml
new file mode 100644 (file)
index 0000000..62de6ba
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+        <integer-array name="answer_array">
+        <item >1</item>
+        <item >0</item>
+        <item >2</item>
+        <item >0</item>
+    </integer-array>
+    
+</resources>
\ No newline at end of file
diff --git a/Circuit/res-tasks/res-HA/values/strings.xml b/Circuit/res-tasks/res-HA/values/strings.xml
new file mode 100644 (file)
index 0000000..7361273
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <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
diff --git a/Circuit/res-tasks/res-SRFF/drawable/question.png b/Circuit/res-tasks/res-SRFF/drawable/question.png
new file mode 100644 (file)
index 0000000..f10ce13
Binary files /dev/null and b/Circuit/res-tasks/res-SRFF/drawable/question.png differ
diff --git a/Circuit/res-tasks/res-SRFF/values/array.xml b/Circuit/res-tasks/res-SRFF/values/array.xml
new file mode 100644 (file)
index 0000000..066656d
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+        <integer-array name="answer_array">
+        <item >0</item>
+        <item >2</item>
+        <item >0</item>
+        <item >2</item>
+    </integer-array>
+    
+</resources>
\ No newline at end of file
diff --git a/Circuit/res-tasks/res-SRFF/values/strings.xml b/Circuit/res-tasks/res-SRFF/values/strings.xml
new file mode 100644 (file)
index 0000000..050ae0a
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="hello">Hello World, CircuitActivity!</string>
+    <string name="app_name">Circuit</string>
+    <string name="test_btn">Toast</string>
+    <string name="question">以下の空欄を埋め、SRフリップフロップを作りなさい。</string>
+
+</resources>
\ No newline at end of file
diff --git a/Circuit/res-tasks/res-tasuu/drawable/question.png b/Circuit/res-tasks/res-tasuu/drawable/question.png
new file mode 100644 (file)
index 0000000..b95d9ff
Binary files /dev/null and b/Circuit/res-tasks/res-tasuu/drawable/question.png differ
diff --git a/Circuit/res-tasks/res-tasuu/values/array.xml b/Circuit/res-tasks/res-tasuu/values/array.xml
new file mode 100644 (file)
index 0000000..1f56e96
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <integer-array name="answer_array">
+        <item >0</item>
+        <item >0</item>
+        <item >1</item>
+        <item >0</item>
+        <item >1</item>
+    </integer-array>
+    
+</resources>
\ No newline at end of file
diff --git a/Circuit/res-tasks/res-tasuu/values/strings.xml b/Circuit/res-tasks/res-tasuu/values/strings.xml
new file mode 100644 (file)
index 0000000..fd03d58
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="hello">Hello World, CircuitActivity!</string>
+    <string name="app_name">Circuit</string>
+    <string name="test_btn">Toast</string>
+    <string name="question">以下の空欄を埋め、3入力多数決回路を作りなさい。</string>
+
+</resources>
\ No newline at end of file
diff --git a/Circuit/res/values/array.xml b/Circuit/res/values/array.xml
new file mode 100644 (file)
index 0000000..62de6ba
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+        <integer-array name="answer_array">
+        <item >1</item>
+        <item >0</item>
+        <item >2</item>
+        <item >0</item>
+    </integer-array>
+    
+</resources>
\ No newline at end of file
index 75dd331..36ee8dd 100644 (file)
@@ -3,7 +3,11 @@ package jp.ac.titech.sharp4k.cuten.app;
 import jp.ac.titech.sharp4k.cuten.BaseApp;
 import jp.ac.titech.sharp4k.cuten.R;
 import android.content.Context;
+import android.content.res.ColorStateList;
+import android.content.res.Configuration;
 import android.content.res.Resources;
+import android.graphics.Color;
+import android.view.Gravity;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
@@ -16,7 +20,7 @@ import android.widget.TextView;
 import android.widget.Toast;
 
 public class CircuitTask extends BaseApp implements OnClickListener {
-       static final int QUESTION_SIZE = 4;
+       private int questionSize;
 
        static final int FP = ViewGroup.LayoutParams.FILL_PARENT;
        static final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
@@ -24,61 +28,91 @@ public class CircuitTask extends BaseApp implements OnClickListener {
        static final int AND = 0;
        static final int OR = 1;
        static final int NOT = 2;
+       static final int COLOR_WHEN_SELECTED = Color.RED;
+       private int defaultBtnColor;
 
        static final float QUESTION_TEXT_SIZE = 30.0f;
+       static final float ANSWER_TEXT_SIZE = 25.0f;
 
        private static final String TAG = CircuitTask.class.getSimpleName();
        private Context cxt;
        private Resources res;
        private Button submitBtn;
-       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 };
+       private int[] correctAnswer;
+       private int[] userAnswer;
+       private ImageView[] answerView;
+
+       private ImageButton andBtn;
+       private ImageButton orBtn;
+       private ImageButton notBtn;
+
        LinearLayout viewLayout;
+       LinearLayout questionLayout;
+       LinearLayout answerLayout;
 
-       private int count = 0;
+       private Button solvingQuestionButton;
 
        @Override
        protected View createView(final Context cxt, Resources res) {
                // TODO 自動生成されたメソッド・スタブ
                this.cxt = cxt;
                this.res = res;
-
-               for (int i = 0; i < QUESTION_SIZE; i++) {
+               
+               correctAnswer = res.getIntArray(R.array.answer_array);
+               questionSize = correctAnswer.length;
+               userAnswer = new int[questionSize];
+               answerView = new ImageView[questionSize];
+               
+               for (int i = 0; i < questionSize; i++) {
                        userAnswer[i] = -1;
                }
+               
+
 
                viewLayout = new LinearLayout(cxt);
-               viewLayout.setLayoutParams(new LayoutParams(FP, FP));
-               viewLayout.setOrientation(LinearLayout.VERTICAL);
+               viewLayout.setLayoutParams(new LayoutParams(WC, WC));
+
+               if (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
+                       viewLayout.setOrientation(LinearLayout.VERTICAL);
+               } else if (res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
+                       viewLayout.setOrientation(LinearLayout.HORIZONTAL);
+               }
 
-               LinearLayout questionLayout = new LinearLayout(cxt);
-               questionLayout.setLayoutParams(new LayoutParams(FP, WC));
+               questionLayout = new LinearLayout(cxt);
+               questionLayout.setLayoutParams(new LayoutParams(WC, WC));
+               questionLayout.setHorizontalGravity(Gravity.CENTER);
                questionLayout.setOrientation(LinearLayout.VERTICAL);
 
                TextView textView = new TextView(cxt);
                textView.setText(res.getText(R.string.question));
+               textView.setLayoutParams(new LayoutParams(WC, WC));
                textView.setTextSize(QUESTION_TEXT_SIZE);
 
                ImageView imageView = new ImageView(cxt);
+               imageView.setLayoutParams(new LayoutParams(WC, WC));
                imageView.setImageDrawable(res.getDrawable(R.drawable.question));
 
                LinearLayout selectBtnLayout = new LinearLayout(cxt);
                selectBtnLayout.setOrientation(LinearLayout.HORIZONTAL);
-               selectBtnLayout.setLayoutParams(new LayoutParams(FP, FP));
+               selectBtnLayout.setLayoutParams(new LayoutParams(WC, FP));
                createBtnArray(selectBtnLayout);
 
                submitBtn = new Button(cxt);
                submitBtn.setText("Submit");
+               submitBtn.setLayoutParams(new LayoutParams(WC, WC));
                submitBtn.setOnClickListener(this);
+               
+               ColorStateList mList = submitBtn.getTextColors();
+               defaultBtnColor = mList.getDefaultColor();
 
                questionLayout.addView(textView);
                questionLayout.addView(imageView);
                questionLayout.addView(selectBtnLayout);
                questionLayout.addView(submitBtn);
 
-               LinearLayout answerLayout = createAnswerLayout(cxt);
+               answerLayout = createAnswerLayout(cxt);
+               answerLayout.setLayoutParams(new LayoutParams(WC, WC));
+               answerLayout.setOrientation(LinearLayout.VERTICAL);
 
                viewLayout.addView(questionLayout);
                viewLayout.addView(answerLayout);
@@ -87,47 +121,38 @@ public class CircuitTask extends BaseApp implements OnClickListener {
        }
 
        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.setImageDrawable(res.getDrawable(ViewAllay[AND]));
-                               btn.setId(AND);
-                               break;
-                       }
-                       case OR: {
-                               btn.setImageDrawable(res.getDrawable(ViewAllay[OR]));
-                               btn.setId(OR);
-                               break;
-                       }
-                       case NOT: {
-                               btn.setImageDrawable(res.getDrawable(ViewAllay[NOT]));
-                               btn.setId(NOT);
-                               break;
-                       }
-                       default: {
-                       }
-                       }
+               andBtn = new ImageButton(cxt);
+               andBtn.setOnClickListener(this);
+               andBtn.setImageDrawable(res.getDrawable(R.drawable.and));
 
-                       selectBtnLayout.addView(btn);
-               }
+               orBtn = new ImageButton(cxt);
+               orBtn.setOnClickListener(this);
+               orBtn.setImageDrawable(res.getDrawable(R.drawable.or));
+
+               notBtn = new ImageButton(cxt);
+               notBtn.setOnClickListener(this);
+               notBtn.setImageDrawable(res.getDrawable(R.drawable.not));
 
+               selectBtnLayout.addView(andBtn);
+               selectBtnLayout.addView(orBtn);
+               selectBtnLayout.addView(notBtn);
        }
 
        private LinearLayout createAnswerLayout(Context cxt) {
                LinearLayout layout = new LinearLayout(cxt);
                layout.setOrientation(LinearLayout.HORIZONTAL);
 
-               for (int i = 0; i < QUESTION_SIZE; i++) {
+               for (int i = 0; i < questionSize; i++) {
                        LinearLayout line = new LinearLayout(cxt);
-                       TextView number = new TextView(cxt);
-                       number.setText("Q" + (i + 1) + " : ");
+                       line.setVerticalGravity(Gravity.CENTER);
+                       Button questionBtn = new Button(cxt);
+                       questionBtn.setText("Q" + (i + 1) + " : ");
+                       questionBtn.setTextSize(ANSWER_TEXT_SIZE);
+                       questionBtn.setOnClickListener(this);
+                       questionBtn.setId(i);
                        answerView[i] = new ImageView(cxt);
 
-                       line.addView(number);
+                       line.addView(questionBtn);
                        line.addView(answerView[i]);
                        layout.addView(line);
                }
@@ -145,7 +170,7 @@ public class CircuitTask extends BaseApp implements OnClickListener {
        public void onClick(View v) {
                // TODO 自動生成されたメソッド・スタブ
                if (v.equals(submitBtn)) {
-                       int[] result = new int[QUESTION_SIZE];
+                       int[] result = new int[questionSize];
                        for (int i = 0; i < result.length; i++) {
                                if (correctAnswer[i] == userAnswer[i]) {
                                        result[i] = 10;
@@ -154,17 +179,56 @@ public class CircuitTask extends BaseApp implements OnClickListener {
                                }
                        }
                        sendResult(result);
-                       Toast.makeText(cxt, "SUBMIT", Toast.LENGTH_LONG).show();
                        close();
 
-               } else if (count < QUESTION_SIZE) {
-                       userAnswer[count] = v.getId();
-                       answerView[count].setImageDrawable(res.getDrawable(ViewAllay[v
-                                       .getId()]));
-                       viewLayout.invalidate();
-                       count++;
+               } else if (solvingQuestionButton != null) {
+                       if (v.equals(andBtn)) {
+                               userAnswer[solvingQuestionButton.getId()] = AND;
+                               answerView[solvingQuestionButton.getId()].setImageDrawable(res
+                                               .getDrawable(R.drawable.and));
+                               solvingQuestionButton.setTextColor(defaultBtnColor);
+                               solvingQuestionButton = null;
+
+                       } else if (v.equals(orBtn)) {
+                               userAnswer[solvingQuestionButton.getId()] = OR;
+                               answerView[solvingQuestionButton.getId()].setImageDrawable(res
+                                               .getDrawable(R.drawable.or));
+                               solvingQuestionButton.setTextColor(defaultBtnColor);
+                               solvingQuestionButton = null;
+
+                       } else if (v.equals(notBtn)) {
+                               userAnswer[solvingQuestionButton.getId()] = NOT;
+                               answerView[solvingQuestionButton.getId()].setImageDrawable(res
+                                               .getDrawable(R.drawable.not));
+                               solvingQuestionButton.setTextColor(defaultBtnColor);
+                               solvingQuestionButton = null;
+
+                       } else {
+                               solvingQuestionButton.setTextColor(defaultBtnColor);
+                               setSolvingQustion(v);
+                       }
                } else {
-                       Toast.makeText(cxt, "何を押してんだ?", Toast.LENGTH_LONG).show();
+                       if (v.equals(andBtn) || v.equals(orBtn) || v.equals(notBtn))
+                               Toast.makeText(cxt, "問題を選びましょう(Q1の部分をタップ)", Toast.LENGTH_LONG)
+                                               .show();
+                       else {
+                               setSolvingQustion(v);
+                       }
+               }
+       }
+
+       private void setSolvingQustion(View v) {
+               if (v.getClass().equals(Button.class)) {
+                       solvingQuestionButton = (Button) v;
+                       solvingQuestionButton.setTextColor(COLOR_WHEN_SELECTED);
+               }
+       }
+
+       protected void onConfigurationChanged(Configuration newConfig) {
+               if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
+                       viewLayout.setOrientation(LinearLayout.VERTICAL);
+               } else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
+                       viewLayout.setOrientation(LinearLayout.HORIZONTAL);
                }
        }
 }