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