Added the randomiztaion of the answesr

android-scanner
VladimirEliTokarev 2016-10-18 11:55:31 +03:00
parent c474bc5ffb
commit 37f8893224
2 changed files with 20 additions and 4 deletions

View File

@ -19,6 +19,7 @@ import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@ -57,7 +58,12 @@ class PicturesAnswersUpdater implements EventHandler{
*/
void UpdateAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) {
this.RemoveAllAnswers();
for (ByteString bytesAnswer : question.getAnswers().getAnswers().getAnswersList()) {
List<ByteString> answers = new ArrayList<>(question.getAnswers().getAnswers().getAnswersList());
if (question.getRandomizeListOrder()) {
Collections.shuffle(answers);
}
for (ByteString bytesAnswer : answers){
try {
this.allAvailableAnswers.add(bytesAnswer);
this.AddAnswer(bytesAnswer);

View File

@ -10,6 +10,9 @@ import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import meerkat.protobuf.BallotQuestionUIElementOuterClass;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@ -91,11 +94,18 @@ class StringsAnswersUpdater implements javafx.event.EventHandler{
/**
* Gets all the answers from the ballot ui question and puts them into the answers container
* @param question
* Checks if the answers should be randomized, if they are then randomize them
* @param question the questions that have all the information to be reporesneted
*/
void UpdateAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) {
this.RemoveAllAnswers();
for (ByteString bytesAnswer : question.getAnswers().getAnswers().getAnswersList()){
List<ByteString> answers = new ArrayList<>(question.getAnswers().getAnswers().getAnswersList());
if (question.getRandomizeListOrder()){
Collections.shuffle(answers);
}
for (ByteString bytesAnswer : answers){
this.AddAnswer(bytesAnswer.toStringUtf8());
}
this.currentStage.show();
@ -103,7 +113,7 @@ class StringsAnswersUpdater implements javafx.event.EventHandler{
/**
* Unchecks all the check boxes that are not target box
* @param target
* @param target the check box which wont be unchecked
*/
private void uncheckBoxes(CheckBox target){
GridPane answersContainer = this.GetAnswersContainer();