<commit_before>/*
 * QUe
 * 
 * Copyright (c) 2014 Quality and Usability Lab,
 * Telekom Innvation Laboratories, TU Berlin. All rights reserved.
 * https://github.com/QULab/QUe-Android
 * 
 * This file is part of QUe.
 * 
 * QUe is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * QUe is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with QUe. If not, see <http://www.gnu.org/licenses/>.
 */
package de.tel.questionnaire.builder;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import de.tel.questionnaire.entities.BasisQuestionEntity;
import de.tel.questionnaire.entities.RadioOption;
import de.tel.questionnaire.entities.RadioQuestionEntity;
import de.tel.questionnaire.util.AnswerLogging;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class RadioLayoutBuilder extends QuestionLayoutBuilder {

  
  public static final String QUESTION_TYPE_RADIO = "radio";

  public RadioLayoutBuilder(Context context, AnswerLogging logging) {
    super(context, logging);
  }
  
  @Override
  public LinearLayout addQuestionLayout(LinearLayout ll,
                                        BasisQuestionEntity basis,
                                        final Button next) {
      
    if (!basis.getType().equals(QUESTION_TYPE_RADIO))
      return ll;
    
    final RadioQuestionEntity radioQuestion = (RadioQuestionEntity) basis;
    RadioGroup grp = new RadioGroup(context);
   
    String orientation = radioQuestion.getOrientation();
    
    if (orientation.equals(RadioQuestionEntity.HORIZONTAL))
      grp.setOrientation(RadioGroup.HORIZONTAL);
    
    RadioOption[] options = radioQuestion.getOptions();
    for (RadioOption option : options) {
      RadioButton radioBtn = new RadioButton(context);
      radioBtn.setText(option.getValue());
//      radioBtn.setChecked(option.getOpDefault()); // set default 
      grp.addView(radioBtn);
    }
    
    grp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

      public void onCheckedChanged(RadioGroup arg0, int arg1) {
        int radioButtonID = arg0.getCheckedRadioButtonId();
        RadioButton v = (RadioButton) arg0.findViewById(radioButtonID);
        String text = v.getText().toString();
        Log.d(RadioLayoutBuilder.class.getName(), text);
        logging.addAnswer(radioQuestion.getQuestion(), text);
        next.setVisibility(View.VISIBLE);
      }
    });
    
    ll.addView(grp);
    return ll;
  }

  @Override
  public String getType() {
    return QUESTION_TYPE_RADIO;<commit_msg>changed answer logging for radio layout from the radio button text to the indices<commit_after>/*
 * QUe
 * 
 * Copyright (c) 2014 Quality and Usability Lab,
 * Telekom Innvation Laboratories, TU Berlin. All rights reserved.
 * https://github.com/QULab/QUe-Android
 * 
 * This file is part of QUe.
 * 
 * QUe is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * QUe is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with QUe. If not, see <http://www.gnu.org/licenses/>.
 */
package de.tel.questionnaire.builder;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import de.tel.questionnaire.entities.BasisQuestionEntity;
import de.tel.questionnaire.entities.RadioOption;
import de.tel.questionnaire.entities.RadioQuestionEntity;
import de.tel.questionnaire.util.AnswerLogging;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class RadioLayoutBuilder extends QuestionLayoutBuilder {

  
  public static final String QUESTION_TYPE_RADIO = "radio";

  public RadioLayoutBuilder(Context context, AnswerLogging logging) {
    super(context, logging);
  }
  
  @Override
  public LinearLayout addQuestionLayout(LinearLayout ll,
                                        BasisQuestionEntity basis,
                                        final Button next) {
      
    if (!basis.getType().equals(QUESTION_TYPE_RADIO))
      return ll;
    
    final RadioQuestionEntity radioQuestion = (RadioQuestionEntity) basis;
    RadioGroup grp = new RadioGroup(context);
   
    String orientation = radioQuestion.getOrientation();
    
    if (orientation.equals(RadioQuestionEntity.HORIZONTAL))
      grp.setOrientation(RadioGroup.HORIZONTAL);
    
    RadioOption[] options = radioQuestion.getOptions();
    for (RadioOption option : options) {
      RadioButton radioBtn = new RadioButton(context);
      radioBtn.setText(option.getValue());
//      radioBtn.setChecked(option.getOpDefault()); // set default 
      grp.addView(radioBtn);
    }
    
    grp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

      public void onCheckedChanged(RadioGroup arg0, int arg1) {
        int radioButtonID = arg0.getCheckedRadioButtonId();
        RadioButton v = (RadioButton) arg0.findViewById(radioButtonID);
        String idx = Integer.toString(arg0.indexOfChild(v));
        Log.d(RadioLayoutBuilder.class.getName(), idx);
        logging.addAnswer(radioQuestion.getQuestion(), idx);
        next.setVisibility(View.VISIBLE);
      }
    });
    
    ll.addView(grp);
    return ll;
  }

  @Override
  public String getType() {
    return QUESTION_TYPE_RADIO;
{'fraction_non_alphanumeric': 0.09013473749419235, 'fraction_numerical': 0.002942542976614527, 'mean_word_length': 3.4661134163208853, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1567170', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1736, 'n_words': 508}