/*
 * Copyright (c) 2013, Apptentive, Inc. All Rights Reserved.
 * Please refer to the LICENSE file for the terms and conditions
 * under which redistribution and use of this file is permitted.
 */

package com.apptentive.android.sdk.module.survey;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import com.apptentive.android.sdk.R;
import com.apptentive.android.sdk.SurveyModule;
import com.apptentive.android.sdk.util.Constants;

import java.util.ArrayList;
import java.util.Set;


/**
 * @author Sky Kelsey.
 */
public class TextSurveyQuestionView extends SurveyItemView<BaseQuestion> {


	protected EditText answerText;

	public TextSurveyQuestionView(Context context, BaseQuestion question) {
		super(context, question);
	}

	@Override
	protected void initView() {
		super.initView();
		instructionsTextView.setText(question.isRequired() ? appContext.getString(R.string.apptentive_survey_required) : appContext.getString(R.string.apptentive_survey_optional));

		addSeparator();
		answerText = new EditText(appContext);
		answerText.setLayoutParams(Constants.ROW_LAYOUT);
		answerText.setBackgroundDrawable(null); // No crappy looking border.
		Set<String> answers = SurveyModule.getInstance().getSurveyState().getAnswers(question.getId());
		if(answers.size() > 0) {
			answerText.setText(new ArrayList<String>(answers).get(0));
		}
		answerText.addTextChangedListener(new TextWatcher() {
			public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
			}

			public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
			}

			public void afterTextChanged(Editable editable) {
				String questionId = question.getId();
				SurveyState state = SurveyModule.getInstance().getSurveyState();
				state.clearAnswers(questionId);
				state.addAnswer(questionId, editable.toString());
				updateInstructionsColor();
				fireListener();
			}
		});
		questionView.addView(answerText);
	}
}

@@ -648,19 +648,25 @@
 temView%3C
-Bas
+Singlelin
 eQuestio
@@ -757,11 +757,17 @@
 xt, 
-Bas
+Singlelin
 eQue
@@ -1975,16 +1975,186 @@
 %7D%0A%09%09%7D);%0A
+%0A%09%09if (question.isMultiLine()) %7B%0A%09%09%09answerText.setMinLines(5);%0A%09%09%09answerText.setMaxLines(12);%0A%09%09%7D else %7B%0A%09%09%09answerText.setMinLines(1);%0A%09%09%09answerText.setMaxLines(5);%0A%09%09%7D%0A%0A
 %09%09questi
@@ -2181,13 +2181,14 @@
 rText);%0A
+%0A
 %09%7D%0A%7D%0A

Add ability to have multi or single line text questions in surveys.