package de.thedevstack.conversationsplus.utils.ui; import android.support.annotation.ColorRes; import android.support.annotation.StringRes; import android.view.View; import android.widget.TextView; import de.thedevstack.conversationsplus.ConversationsPlusColors; /** * */ public final class TextViewUtil extends ViewUtil { public static void setTextWithoutAutoLink(TextView tv, CharSequence text) { int oldAutoLinkMask = tv.getAutoLinkMask(); tv.setAutoLinkMask(0); tv.setText(text); tv.setAutoLinkMask(oldAutoLinkMask); } public static void setText(View parentView, int textViewId, CharSequence text) { TextView tv = (TextView) parentView.findViewById(textViewId); if (null != tv) { tv.setText(text); } } public static void setText(View parentView, int textViewId, int textResId) { TextView tv = (TextView) parentView.findViewById(textViewId); if (null != tv) { tv.setText(textResId); } } 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) { setColorByIdEnabledAndTextResId(tv, color, null, null); } private static void setColorByIdEnabledAndTextResId(TextView tv, @ColorRes Integer colorResId, Boolean enabled, @StringRes Integer resid) { Integer color = null; if (null != colorResId) { color = ConversationsPlusColors.byId(colorResId); } setColorEnabledAndTextResId(tv, color, enabled, resid); } 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 } }