From 1d5d94080a6bffaf5fa7c358af76a3cfae0a8ade Mon Sep 17 00:00:00 2001 From: steckbrief Date: Tue, 29 Mar 2016 22:28:19 +0200 Subject: Introduction of a TextViewUtil to easily set attributes for TextViews --- .../conversationsplus/utils/ui/TextViewUtil.java | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java (limited to 'src/main/java/de/thedevstack/conversationsplus/utils') diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java new file mode 100644 index 00000000..bb08014b --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java @@ -0,0 +1,75 @@ +package de.thedevstack.conversationsplus.utils.ui; + +import android.support.annotation.StringRes; +import android.widget.TextView; + +/** + * Created by steckbrief on 29.03.2016. + */ +public final class TextViewUtil { + public static void enable(TextView tv) { + setColorEnabledAndTextResId(tv, null, true, null); + } + + public static void enable(TextView tv, String text) { + setColorEnabledAndText(tv, null, true, text); + } + + public static void enable(TextView tv, Integer color) { + setColorEnabledAndTextResId(tv, color, true, null); + } + + public static void enable(TextView tv, Integer color, @StringRes Integer resid) { + setColorEnabledAndTextResId(tv, color, true, resid); + } + + public static void disable(TextView tv) { + setColorEnabledAndTextResId(tv, null, false, null); + } + + public static void disable(TextView tv, String text) { + setColorEnabledAndText(tv, null, false, text); + } + + public static void disable(TextView tv, Integer color) { + setColorEnabledAndTextResId(tv, color, false, null); + } + + public static void disable(TextView tv, Integer color, @StringRes Integer resid) { + setColorEnabledAndTextResId(tv, color, false, resid); + } + + public static void setColor(TextView tv, Integer color) { + setColorEnabledAndTextResId(tv, color, null, null); + } + + public static void setColorEnabledAndTextResId(TextView tv, Integer color, Boolean enabled, @StringRes Integer resid) { + if (null != color) { + tv.setTextColor(color); + } + + if (enabled != null) { + tv.setEnabled(enabled); + } + if (resid != null) { + tv.setText(resid); + } + } + + public static void setColorEnabledAndText(TextView tv, Integer color, Boolean enabled, String text) { + if (null != color) { + tv.setTextColor(color); + } + + if (enabled != null) { + tv.setEnabled(enabled); + } + if (text != null) { + tv.setText(text); + } + } + + private TextViewUtil() { + // avoid instantiation - helper class + } +} -- cgit v1.2.3