From a4dbd7ccb513d74785dc0fd363ce5d8553e16946 Mon Sep 17 00:00:00 2001 From: Taylor Sloan Date: Sat, 21 Feb 2015 06:25:14 -0800 Subject: [PATCH 1/3] Added ability to change text color of title and subtitle programmatically and in xml. --- .../main/java/tr/xip/errorview/ErrorView.java | 27 +++++++++++++++++++ library/src/main/res/values/attrs.xml | 2 ++ 2 files changed, 29 insertions(+) diff --git a/library/src/main/java/tr/xip/errorview/ErrorView.java b/library/src/main/java/tr/xip/errorview/ErrorView.java index a7f65d4..6a9adca 100644 --- a/library/src/main/java/tr/xip/errorview/ErrorView.java +++ b/library/src/main/java/tr/xip/errorview/ErrorView.java @@ -51,7 +51,10 @@ public class ErrorView extends LinearLayout { private int errorImageRes; private String errorTitle; + private int errorTitleTextColor; + private String errorSubtitle; + private int errorSubtitleTextColor; private boolean showTitle; private boolean showSubtitle; @@ -84,7 +87,11 @@ private void init() { try { errorImageRes = a.getResourceId(R.styleable.ErrorView_ev_errorImage, R.drawable.error_view_cloud); errorTitle = a.getString(R.styleable.ErrorView_ev_errorTitle); + errorTitleTextColor = a.getColor(R.styleable.ErrorView_ev_errorTitleTextColor, + getResources().getColor(R.color.error_view_text)); errorSubtitle = a.getString(R.styleable.ErrorView_ev_errorSubtitle); + errorSubtitleTextColor = a.getColor(R.styleable.ErrorView_ev_errorSubtitleTextColor, + getResources().getColor(R.color.error_view_text_light)); showTitle = a.getBoolean(R.styleable.ErrorView_ev_showTitle, true); showSubtitle = a.getBoolean(R.styleable.ErrorView_ev_showSubtitle, true); showRetryButton = a.getBoolean(R.styleable.ErrorView_ev_showRetryButton, true); @@ -111,6 +118,9 @@ private void init() { if (!showRetryButton) mRetryButton.setVisibility(GONE); + mErrorTitle.setTextColor(errorTitleTextColor); + mErrorSubtitle.setTextColor(errorSubtitleTextColor); + mRetryButton.setTextColor(retryButtonTextColor); mRetryButton.setBackgroundResource(retryButtonBackground); } finally { @@ -191,6 +201,15 @@ public void setErrorTitle(int res) { mErrorTitle.setText(res); } + /** + * Sets the error title text to a given color. + * + * @param res color resource to use for error title text. + */ + public void setErrorTitleTextColor(int res){ + mErrorTitle.setTextColor(res); + } + /** * Sets the error subtitle to a given {@link java.lang.String}. * @@ -209,6 +228,14 @@ public void setErrorSubtitle(int res) { mErrorSubtitle.setText(res); } + /** + * Sets the error subtitle text to a given color + * @param res color resource to use for error subtitle text. + */ + public void setErrorSubtitleTextColor(int res){ + mErrorSubtitle.setTextColor(res); + } + /** * Sets the retry button's text to a given {@link java.lang.String}. * diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 5b07163..c5649da 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -2,7 +2,9 @@ + + From 01d79d841577281cc938cf25e7704c80b8d1ee96 Mon Sep 17 00:00:00 2001 From: Taylor Sloan Date: Sat, 21 Feb 2015 10:05:31 -0800 Subject: [PATCH 2/3] Changed method names: setErrorTitleTextColor->setErrorTitleColor setErrorSubtitleTextColor ->setErrorSubtitleColor Changed view attributes: ev_errorTitleTextColor->ev_errorTitleColor ev_errorSubtitleTextColor->ev_errorSubtitleColor Added context.getResources().getColor(int res) to each setColor() method Updated sample --- .../main/java/tr/xip/errorview/ErrorView.java | 20 +++++++++---------- library/src/main/res/values/attrs.xml | 4 ++-- .../tr/xip/errorview/sample/MainActivity.java | 2 ++ sample/src/main/res/layout/activity_main.xml | 2 ++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/library/src/main/java/tr/xip/errorview/ErrorView.java b/library/src/main/java/tr/xip/errorview/ErrorView.java index 6a9adca..bc8c0d5 100644 --- a/library/src/main/java/tr/xip/errorview/ErrorView.java +++ b/library/src/main/java/tr/xip/errorview/ErrorView.java @@ -51,10 +51,10 @@ public class ErrorView extends LinearLayout { private int errorImageRes; private String errorTitle; - private int errorTitleTextColor; + private int errorTitleColor; private String errorSubtitle; - private int errorSubtitleTextColor; + private int errorSubtitleColor; private boolean showTitle; private boolean showSubtitle; @@ -87,10 +87,10 @@ private void init() { try { errorImageRes = a.getResourceId(R.styleable.ErrorView_ev_errorImage, R.drawable.error_view_cloud); errorTitle = a.getString(R.styleable.ErrorView_ev_errorTitle); - errorTitleTextColor = a.getColor(R.styleable.ErrorView_ev_errorTitleTextColor, + errorTitleColor = a.getColor(R.styleable.ErrorView_ev_errorTitleColor, getResources().getColor(R.color.error_view_text)); errorSubtitle = a.getString(R.styleable.ErrorView_ev_errorSubtitle); - errorSubtitleTextColor = a.getColor(R.styleable.ErrorView_ev_errorSubtitleTextColor, + errorSubtitleColor = a.getColor(R.styleable.ErrorView_ev_errorSubtitleColor, getResources().getColor(R.color.error_view_text_light)); showTitle = a.getBoolean(R.styleable.ErrorView_ev_showTitle, true); showSubtitle = a.getBoolean(R.styleable.ErrorView_ev_showSubtitle, true); @@ -118,8 +118,8 @@ private void init() { if (!showRetryButton) mRetryButton.setVisibility(GONE); - mErrorTitle.setTextColor(errorTitleTextColor); - mErrorSubtitle.setTextColor(errorSubtitleTextColor); + mErrorTitle.setTextColor(errorTitleColor); + mErrorSubtitle.setTextColor(errorSubtitleColor); mRetryButton.setTextColor(retryButtonTextColor); mRetryButton.setBackgroundResource(retryButtonBackground); @@ -206,8 +206,8 @@ public void setErrorTitle(int res) { * * @param res color resource to use for error title text. */ - public void setErrorTitleTextColor(int res){ - mErrorTitle.setTextColor(res); + public void setErrorTitleColor(int res){ + mErrorTitle.setTextColor(context.getResources().getColor(res)); } /** @@ -232,8 +232,8 @@ public void setErrorSubtitle(int res) { * Sets the error subtitle text to a given color * @param res color resource to use for error subtitle text. */ - public void setErrorSubtitleTextColor(int res){ - mErrorSubtitle.setTextColor(res); + public void setErrorSubtitleColor(int res){ + mErrorSubtitle.setTextColor(context.getResources().getColor(res)); } /** diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index c5649da..c181a86 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -2,9 +2,9 @@ - + - + diff --git a/sample/src/main/java/tr/xip/errorview/sample/MainActivity.java b/sample/src/main/java/tr/xip/errorview/sample/MainActivity.java index b03753b..ecd468f 100644 --- a/sample/src/main/java/tr/xip/errorview/sample/MainActivity.java +++ b/sample/src/main/java/tr/xip/errorview/sample/MainActivity.java @@ -31,6 +31,8 @@ public void onRetry() { mErrorView.setError(ErrorViewStatusCodes.CODE_408); mErrorView.setErrorTitle(R.string.error_title_damn); + mErrorView.setErrorTitleColor(android.R.color.holo_orange_dark); + mErrorView.setErrorSubtitleColor(android.R.color.holo_green_dark); } }); } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 2750147..3d3e2e3 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -15,5 +15,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" app:ev_errorSubtitle="@string/error_subtitle_failed_one_more_time" + app:ev_errorTitleColor="@android:color/holo_blue_dark" + app:ev_errorSubtitleColor="@android:color/holo_blue_bright" app:ev_retryButtonTextColor="@color/apptheme_accent" /> \ No newline at end of file From 4520fb672cc63b3300cc73f6c82278a10e96d5b5 Mon Sep 17 00:00:00 2001 From: Taylor Sloan Date: Sat, 21 Feb 2015 11:46:07 -0800 Subject: [PATCH 3/3] Removed context.getResources().getColor(int res) to each setColor() method Updated sample --- library/src/main/java/tr/xip/errorview/ErrorView.java | 4 ++-- .../src/main/java/tr/xip/errorview/sample/MainActivity.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/tr/xip/errorview/ErrorView.java b/library/src/main/java/tr/xip/errorview/ErrorView.java index bc8c0d5..c6a8045 100644 --- a/library/src/main/java/tr/xip/errorview/ErrorView.java +++ b/library/src/main/java/tr/xip/errorview/ErrorView.java @@ -207,7 +207,7 @@ public void setErrorTitle(int res) { * @param res color resource to use for error title text. */ public void setErrorTitleColor(int res){ - mErrorTitle.setTextColor(context.getResources().getColor(res)); + mErrorTitle.setTextColor(res); } /** @@ -233,7 +233,7 @@ public void setErrorSubtitle(int res) { * @param res color resource to use for error subtitle text. */ public void setErrorSubtitleColor(int res){ - mErrorSubtitle.setTextColor(context.getResources().getColor(res)); + mErrorSubtitle.setTextColor(res); } /** diff --git a/sample/src/main/java/tr/xip/errorview/sample/MainActivity.java b/sample/src/main/java/tr/xip/errorview/sample/MainActivity.java index ecd468f..06c5200 100644 --- a/sample/src/main/java/tr/xip/errorview/sample/MainActivity.java +++ b/sample/src/main/java/tr/xip/errorview/sample/MainActivity.java @@ -31,8 +31,8 @@ public void onRetry() { mErrorView.setError(ErrorViewStatusCodes.CODE_408); mErrorView.setErrorTitle(R.string.error_title_damn); - mErrorView.setErrorTitleColor(android.R.color.holo_orange_dark); - mErrorView.setErrorSubtitleColor(android.R.color.holo_green_dark); + mErrorView.setErrorTitleColor(getResources().getColor(android.R.color.holo_orange_dark)); + mErrorView.setErrorSubtitleColor(getResources().getColor(android.R.color.holo_green_dark)); } }); }