diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-01-23 16:23:23 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-01-23 16:23:23 +0100 |
commit | 0569a1e7698141262e3f8443be26b5cb053954b8 (patch) | |
tree | 09730b1d8419338270077fa415e7ea846f083fdf /src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java | |
parent | 39fdf4a333378affcca360886701851d84dd9e0b (diff) |
introduced boolean form field wrapper
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java index a0ed371a3..f2560ef51 100644 --- a/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java +++ b/src/main/java/eu/siacs/conversations/ui/forms/FormFieldWrapper.java @@ -1,11 +1,15 @@ package eu.siacs.conversations.ui.forms; import android.content.Context; +import android.text.SpannableString; +import android.text.style.ForegroundColorSpan; +import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import java.util.List; +import eu.siacs.conversations.R; import eu.siacs.conversations.xmpp.forms.Field; public abstract class FormFieldWrapper { @@ -26,11 +30,11 @@ public abstract class FormFieldWrapper { setLabel(label, field.isRequired()); } - public void submit() { + public final void submit() { this.field.setValues(getValues()); } - public View getView() { + public final View getView() { return view; } @@ -42,6 +46,17 @@ public abstract class FormFieldWrapper { abstract protected int getLayoutResource(); + protected SpannableString createSpannableLabelString(String label, boolean required) { + 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); + } + return spannableString; + } + protected static <F extends FormFieldWrapper> FormFieldWrapper createFromField(Class<F> c, Context context, Field field) { try { return c.getDeclaredConstructor(Context.class, Field.class).newInstance(context,field); |