FormTextFieldWrapper.java

 1package eu.siacs.conversations.ui.forms;
 2
 3import android.content.Context;
 4import android.text.SpannableString;
 5import android.text.style.ForegroundColorSpan;
 6import android.text.style.StyleSpan;
 7import android.widget.EditText;
 8import android.widget.TextView;
 9
10import java.util.ArrayList;
11import java.util.List;
12
13import eu.siacs.conversations.R;
14import eu.siacs.conversations.xmpp.forms.Field;
15
16public class FormTextFieldWrapper extends FormFieldWrapper {
17
18	protected EditText editText;
19
20	protected FormTextFieldWrapper(Context context, Field field) {
21		super(context, field);
22		editText = (EditText) view.findViewById(R.id.field);
23		editText.setSingleLine("text-single".equals(field.getType()));
24	}
25
26	@Override
27	protected void setLabel(String label, boolean required) {
28		TextView textView = (TextView) view.findViewById(R.id.label);
29		SpannableString spannableString = new SpannableString(label + (required ? " *" : ""));
30		if (required) {
31			int start = label.length();
32			int end = label.length() + 2;
33			spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, end, 0);
34			spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.accent)), start, end, 0);
35		}
36		textView.setText(spannableString);
37	}
38
39	@Override
40	List<String> getValues() {
41		List<String> values = new ArrayList<>();
42		for (String line : editText.getText().toString().split("\\n")) {
43			values.add(line);
44		}
45		return values;
46	}
47
48	@Override
49	protected int getLayoutResource() {
50		return R.layout.form_text;
51	}
52}