Commit 664a6fa5 authored by fpeterfalvi's avatar fpeterfalvi
Browse files

"Show correct answer to client" is added to server

parent a360c8c9
......@@ -89,7 +89,7 @@ public class GameActivity extends AppCompatActivity implements MultipleChoiceFra
@Override
public void run() {
String[] params = msg.split("##");
if (params.length == 5) {
if (params.length == 8) {
replaceFragment(params);
}
}
......@@ -98,7 +98,9 @@ public class GameActivity extends AppCompatActivity implements MultipleChoiceFra
private void replaceFragment(String[] strings) {
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
MultipleChoiceFragment frag = MultipleChoiceFragment.newInstance(strings[0], strings[1], strings[2], strings[3], strings[4]);
MultipleChoiceFragment frag = MultipleChoiceFragment.newInstance(
strings[0], strings[1], strings[2], strings[3], strings[4],
Integer.parseInt(strings[5]), Integer.parseInt(strings[6]), Integer.parseInt(strings[7]));
fragmentTransaction.replace(R.id.FragmentContainer, frag);
fragmentTransaction.commit();
}
......
......@@ -3,6 +3,7 @@ package onlab.kvizclient;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
......@@ -11,6 +12,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MultipleChoiceFragment extends Fragment {
......@@ -20,9 +22,15 @@ public class MultipleChoiceFragment extends Fragment {
private static final String ANSWER2 = "ANSWER2";
private static final String ANSWER3 = "ANSWER3";
private static final String ANSWER4 = "ANSWER4";
private static final String OWN_ANSWER = "OWN_ANSWER";
private static final String OPPONENT_ANSWER = "OPPONENT_ANSWER";
private static final String CORRECT_ANSWER = "CORRECT_ANSWER";
private String question;
private String[] answers = new String[4];
private int own_answer;
private int opponent_answer;
private int correct_answer;
private TextView questionTextTextView;
private Button[] answerButtons = new Button[4];
......@@ -33,7 +41,9 @@ public class MultipleChoiceFragment extends Fragment {
// Required empty public constructor
}
public static MultipleChoiceFragment newInstance(String question, String answer1, String answer2, String answer3, String answer4) {
public static MultipleChoiceFragment newInstance(String question, String answer1, String answer2,
String answer3, String answer4, int own_answer,
int opponent_answer, int correct_answer) {
MultipleChoiceFragment fragment = new MultipleChoiceFragment();
Bundle args = new Bundle();
args.putString(QUESTION, question);
......@@ -41,6 +51,9 @@ public class MultipleChoiceFragment extends Fragment {
args.putString(ANSWER2, answer2);
args.putString(ANSWER3, answer3);
args.putString(ANSWER4, answer4);
args.putInt(OWN_ANSWER, own_answer);
args.putInt(OPPONENT_ANSWER, opponent_answer);
args.putInt(CORRECT_ANSWER, correct_answer);
fragment.setArguments(args);
return fragment;
}
......@@ -54,6 +67,9 @@ public class MultipleChoiceFragment extends Fragment {
answers[1] = getArguments().getString(ANSWER2);
answers[2] = getArguments().getString(ANSWER3);
answers[3] = getArguments().getString(ANSWER4);
own_answer = getArguments().getInt(OWN_ANSWER);
opponent_answer = getArguments().getInt(OPPONENT_ANSWER);
correct_answer = getArguments().getInt(CORRECT_ANSWER);
}
}
......@@ -77,10 +93,43 @@ public class MultipleChoiceFragment extends Fragment {
answerButtons[2] = (Button) getView().findViewById(R.id.Answer3Button);
answerButtons[3] = (Button) getView().findViewById(R.id.Answer4Button);
ImageView[] leftImageViews = new ImageView[4];
leftImageViews[0] = (ImageView) getView().findViewById(R.id.LeftImageView1);
leftImageViews[1] = (ImageView) getView().findViewById(R.id.LeftImageView2);
leftImageViews[2] = (ImageView) getView().findViewById(R.id.LeftImageView3);
leftImageViews[3] = (ImageView) getView().findViewById(R.id.LeftImageView4);
ImageView[] rightImageViews = new ImageView[4];
rightImageViews[0] = (ImageView) getView().findViewById(R.id.RightImageView1);
rightImageViews[1] = (ImageView) getView().findViewById(R.id.RightImageView2);
rightImageViews[2] = (ImageView) getView().findViewById(R.id.RightImageView3);
rightImageViews[3] = (ImageView) getView().findViewById(R.id.RightImageView4);
for (int i=0;i<4;i++) {
answerButtons[i].setOnClickListener(new MyOnClickListener(i));
answerButtons[i].setText(answers[i]);
}
if (correct_answer != -1) {
answerButtons[correct_answer].setBackgroundColor(Color.GREEN);
}
if (own_answer != correct_answer && own_answer != -1) {
answerButtons[own_answer].setBackgroundColor(Color.RED);
}
if (opponent_answer != correct_answer && opponent_answer != -1) {
answerButtons[opponent_answer].setBackgroundColor(Color.RED);
}
if (own_answer != -1) {
leftImageViews[own_answer].setImageResource(R.drawable.ic_keyboard_arrow_right_black_48dp);
}
if (opponent_answer != -1) {
rightImageViews[opponent_answer].setImageResource(R.drawable.ic_keyboard_arrow_left_black_48dp);
}
}
@Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment