@@ -22,28 +22,28 @@ public class QuestionList {
2222 Context context ;
2323 int orientation ;
2424
25- public QuestionList (ArrayList <Question > questions , QuestionListSettings settings , Context context ){
25+ public QuestionList (ArrayList <Question > questions , QuestionListSettings settings , Context context ) {
2626 choiceQuestions = questions ;
2727 this .settings = settings ;
2828 this .context = context ;
2929 this .orientation = settings .getCheckBoxOrientation ();
3030 linearLayout = new LinearLayout (context );
3131 }
3232
33- public QuestionList (String [] questions , QuestionListSettings settings , Context context ){
33+ public QuestionList (String [] questions , QuestionListSettings settings , Context context ) {
3434 this .questions = questions ;
3535 this .settings = settings ;
3636 this .orientation = settings .getCheckBoxOrientation ();
3737 this .context = context ;
3838 linearLayout = new LinearLayout (context );
3939 }
4040
41- public void createQuestionViews (){
41+ public void createQuestionViews () {
4242 int i = 1 ;
4343 linearLayout = new LinearLayout (context );
4444 linearLayout .setOrientation (LinearLayout .VERTICAL );
45- if (questions == null ){
46- for (Question q : choiceQuestions ){
45+ if (questions == null ) {
46+ for (Question q : choiceQuestions ) {
4747 switch (q .type ) {
4848 case Question .MULTIPLE_CHOICE_QUESTION :
4949 Log .d ("TAG" , "createQuestionViews: " + Arrays .toString (q .options ));
@@ -77,7 +77,7 @@ public void createQuestionViews(){
7777
7878 }
7979
80- public void setLayoutOrientation (int orientation ){
80+ public void setLayoutOrientation (int orientation ) {
8181 this .orientation = orientation ;
8282 for (int i = 0 ; i < linearLayout .getChildCount (); i ++) {
8383 YesOrNoQuestion yesOrNoQuestion ;
@@ -108,7 +108,7 @@ public void setLayoutOrientation(int orientation){
108108 createQuestionViews ();
109109 }
110110
111- public float getPercentageOfCorrectAnswers (){
111+ public float getPercentageOfCorrectAnswers () {
112112 int correctAnswers = 0 ;
113113 int allAnswers = linearLayout .getChildCount ();
114114 for (int i = 0 ; i < linearLayout .getChildCount (); i ++) {
@@ -122,9 +122,9 @@ public float getPercentageOfCorrectAnswers(){
122122 Log .d ("TAG" , "answer: " + answer );
123123 int correctAnswer = choiceQuestions .get (i ).correctAnswer ;
124124 Log .d ("TAG" , "correct answer: " + correctAnswer );
125- if (correctAnswer == 0 ){
125+ if (correctAnswer == 0 ) {
126126 allAnswers --;
127- } else if (answer == correctAnswer ){
127+ } else if (answer == correctAnswer ) {
128128 correctAnswers ++;
129129 }
130130 } catch (ClassCastException ignored ) {
@@ -137,9 +137,9 @@ public float getPercentageOfCorrectAnswers(){
137137 Log .d ("TAG" , "answer: " + answer );
138138 int correctAnswer = choiceQuestions .get (i ).correctAnswer ;
139139 Log .d ("TAG" , "correct answer: " + correctAnswer );
140- if (correctAnswer == 0 ){
140+ if (correctAnswer == 0 ) {
141141 allAnswers --;
142- } else if (answer == correctAnswer ){
142+ } else if (answer == correctAnswer ) {
143143 correctAnswers ++;
144144 }
145145 } catch (Exception ignored ) {
@@ -154,9 +154,9 @@ public float getPercentageOfCorrectAnswers(){
154154 ArrayList <Integer > correctAnswer = choiceQuestions .get (i ).multipleCorrectAnswer ;
155155 Collections .sort (correctAnswer );
156156 Log .d ("TAG" , "correct answer: " + correctAnswer );
157- if (correctAnswer .size () == 0 || correctAnswer == null ){
157+ if (correctAnswer .size () == 0 || correctAnswer == null ) {
158158 allAnswers --;
159- } else if (answer .equals (correctAnswer )){
159+ } else if (answer .equals (correctAnswer )) {
160160 correctAnswers ++;
161161 }
162162 } catch (ClassCastException ignored ) {
@@ -165,10 +165,10 @@ public float getPercentageOfCorrectAnswers(){
165165 }
166166 Log .d ("TAG" , "getPercentageOfCorrectAnswers: " + correctAnswers );
167167 Log .d ("TAG" , "getPercentageOfCorrectAnswers: " + allAnswers );
168- return (float ) correctAnswers / allAnswers ;
168+ return (float ) correctAnswers / allAnswers ;
169169 }
170170
171- public ArrayList <Object > getAnswers (){
171+ public ArrayList <Object > getAnswers () {
172172 ArrayList <Object > answers = new ArrayList <>();
173173 Log .d ("answers" , "list size: " + linearLayout .getChildCount ());
174174 for (int i = 0 ; i < linearLayout .getChildCount (); i ++) {
@@ -200,7 +200,7 @@ public ArrayList<Object> getAnswers(){
200200 return answers ;
201201 }
202202
203- public boolean areAllQuestionsAnswered (){
203+ public boolean areAllQuestionsAnswered () {
204204 Log .d ("answers" , "list size: " + linearLayout .getChildCount ());
205205 for (int i = 0 ; i < linearLayout .getChildCount (); i ++) {
206206 YesOrNoQuestion yesOrNoQuestion ;
@@ -209,15 +209,15 @@ public boolean areAllQuestionsAnswered(){
209209
210210 try {
211211 yesOrNoQuestion = (YesOrNoQuestion ) getQuestion (i );
212- if (yesOrNoQuestion .getAnswer () == 0 ){
212+ if (yesOrNoQuestion .getAnswer () == 0 ) {
213213 return false ;
214214 }
215215 } catch (ClassCastException ignored ) {
216216
217217 }
218218 try {
219219 multipleChoiceQuestion = (MultipleChoiceQuestion ) getQuestion (i );
220- if (multipleChoiceQuestion .getAnswer () == 0 ){
220+ if (multipleChoiceQuestion .getAnswer () == 0 ) {
221221 return false ;
222222 }
223223 } catch (Exception ignored ) {
@@ -226,7 +226,7 @@ public boolean areAllQuestionsAnswered(){
226226
227227 try {
228228 multipleAnswerQuestion = (MultipleAnswerQuestion ) getQuestion (i );
229- if (multipleAnswerQuestion .getAnswer ().size () == 0 ){
229+ if (multipleAnswerQuestion .getAnswer ().size () == 0 ) {
230230 return false ;
231231 }
232232 } catch (Exception ignored ) {
@@ -236,7 +236,7 @@ public boolean areAllQuestionsAnswered(){
236236 return true ;
237237 }
238238
239- public View getQuestion (int index ){
239+ public View getQuestion (int index ) {
240240 YesOrNoQuestion yesOrNoQuestion = null ;
241241 MultipleChoiceQuestion multipleChoiceQuestion = null ;
242242 MultipleAnswerQuestion multipleAnswerQuestion = null ;
@@ -259,27 +259,38 @@ public View getQuestion(int index){
259259
260260 }
261261
262- if (yesOrNoQuestion != null ){
262+ if (yesOrNoQuestion != null ) {
263263 return yesOrNoQuestion ;
264- }else if (multipleChoiceQuestion != null ){
264+ } else if (multipleChoiceQuestion != null ) {
265265 return multipleChoiceQuestion ;
266- } else if (multipleAnswerQuestion != null ){
266+ } else if (multipleAnswerQuestion != null ) {
267267 return multipleAnswerQuestion ;
268- }else {
268+ } else {
269269 return null ;
270270 }
271271 }
272272
273- public void addOnValueChangedRunnable (int index , Runnable r ){
273+ public void addOnAnswerChangedListener (int index , OnAnswerChangedListener r ) {
274274 try {
275- ((MultipleChoiceQuestion ) getQuestion (index )).doOnValueChanged (r );
276- } catch (Exception e ) {
277- YesOrNoQuestion yesOrNoQuestion = (YesOrNoQuestion ) getQuestion (index );
278- //Todo: add do on value changed
275+ ((MultipleChoiceQuestion ) getQuestion (index )).addOnAnswerChangedListener (r );
276+ } catch (Exception ignored ) {
277+
278+ }
279+
280+ try {
281+ ((MultipleAnswerQuestion ) getQuestion (index )).addOnAnswerChangedListener (r );
282+ } catch (Exception ignored ) {
283+
284+ }
285+
286+ try {
287+ ((YesOrNoQuestion ) getQuestion (index )).addOnAnswerChangedListener (r );
288+ } catch (Exception ignored ) {
289+
279290 }
280291 }
281292
282- public LinearLayout getQuestionViews (){
293+ public LinearLayout getQuestionViews () {
283294 return linearLayout ;
284295 }
285296}
0 commit comments