From 3cb5b132308558b6caef233feaf6d1977c1b77d9 Mon Sep 17 00:00:00 2001 From: AlexII Date: Sun, 25 Dec 2016 01:02:18 +0300 Subject: [PATCH 1/4] changes: add few wrappers for itemView.getResources and ContextCompat.get... --- .../adapters/BindableViewHolder.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java b/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java index 62901f4..efa27db 100644 --- a/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java +++ b/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java @@ -19,8 +19,15 @@ package ru.touchin.roboswag.components.adapters; +import android.content.res.ColorStateList; +import android.graphics.drawable.Drawable; +import android.support.annotation.ColorInt; +import android.support.annotation.ColorRes; +import android.support.annotation.DrawableRes; import android.support.annotation.IdRes; import android.support.annotation.NonNull; +import android.support.annotation.StringRes; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.view.View; @@ -61,6 +68,31 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec return viewById; } + @NonNull + public String getString(@StringRes final int resId) { + return itemView.getResources().getString(resId); + } + + @NonNull + public String getString(@StringRes final int resId, final Object... formatArgs) { + return itemView.getResources().getString(resId, formatArgs); + } + + @ColorInt + public int getColor(@ColorRes final int resId) { + return ContextCompat.getColor(itemView.getContext(), resId); + } + + @NonNull + public Drawable getDrawable(@DrawableRes final int resId) { + return ContextCompat.getDrawable(itemView.getContext(), resId); + } + + @NonNull + public ColorStateList getColorStateList(@ColorRes final int resId) { + return ContextCompat.getColorStateList(itemView.getContext(), resId); + } + @NonNull @Override public Subscription bind(@NonNull final Observable observable, @NonNull final Action1 onNextAction) { From 74257aad0df73f4ad03892854898adefac754f15 Mon Sep 17 00:00:00 2001 From: AlexII Date: Wed, 28 Dec 2016 02:25:41 +0300 Subject: [PATCH 2/4] changes: add comments --- .../adapters/BindableViewHolder.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java b/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java index efa27db..66318f8 100644 --- a/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java +++ b/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java @@ -20,6 +20,7 @@ package ru.touchin.roboswag.components.adapters; import android.content.res.ColorStateList; +import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.annotation.ColorRes; @@ -68,26 +69,68 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec return viewById; } + /** + * Return the string value associated with a particular resource ID. It + * will be stripped of any styled text information. + * + * @param resId The resource id to search for data; + * @return String The string data associated with the resource. + * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist. + */ @NonNull public String getString(@StringRes final int resId) { return itemView.getResources().getString(resId); } + /** + * Return the string value associated with a particular resource ID. It + * will be stripped of any styled text information. + * + * @param resId The resource id to search for data; + * @param formatArgs The format arguments that will be used for substitution. + * @return String The string data associated with the resource. + * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist. + */ @NonNull public String getString(@StringRes final int resId, final Object... formatArgs) { return itemView.getResources().getString(resId, formatArgs); } + /** + * Return the color value associated with a particular resource ID. + * Starting in {@link android.os.Build.VERSION_CODES#M}, the returned + * color will be styled for the specified Context's theme. + * + * @param resId The resource id to search for data; + * @return int A single color value in the form 0xAARRGGBB. + * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist. + */ @ColorInt public int getColor(@ColorRes final int resId) { return ContextCompat.getColor(itemView.getContext(), resId); } + /** + * Returns a color state list object associated with a particular resource ID. + * Starting in {@link android.os.Build.VERSION_CODES#LOLLIPOP}, the + * returned drawable will be styled for the specified Context's theme. + * + * @param resId The resource id to search for data; + * @return Drawable An object that can be used to draw this resource. + */ @NonNull public Drawable getDrawable(@DrawableRes final int resId) { return ContextCompat.getDrawable(itemView.getContext(), resId); } + /** + * Returns a drawable object associated with a particular resource ID. + * Starting in {@link android.os.Build.VERSION_CODES#LOLLIPOP}, the + * returned drawable will be styled for the specified Context's theme. + * + * @param resId The resource id to search for data; + * @return A color state list, or {@code null} if the resource could not be resolved. + */ @NonNull public ColorStateList getColorStateList(@ColorRes final int resId) { return ContextCompat.getColorStateList(itemView.getContext(), resId); From aaae3884a496d7be22c3276be643bdcba534c998 Mon Sep 17 00:00:00 2001 From: Alexander Bubnov Date: Wed, 28 Dec 2016 10:24:55 +0300 Subject: [PATCH 3/4] changes:small comments fix --- .../roboswag/components/adapters/BindableViewHolder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java b/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java index 66318f8..bcd25fb 100644 --- a/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java +++ b/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java @@ -111,7 +111,7 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec } /** - * Returns a color state list object associated with a particular resource ID. + * Returns a drawable object associated with a particular resource ID. * Starting in {@link android.os.Build.VERSION_CODES#LOLLIPOP}, the * returned drawable will be styled for the specified Context's theme. * @@ -124,7 +124,7 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec } /** - * Returns a drawable object associated with a particular resource ID. + * Returns a color state list object associated with a particular resource ID. * Starting in {@link android.os.Build.VERSION_CODES#LOLLIPOP}, the * returned drawable will be styled for the specified Context's theme. * From a078685edf430401967fa28a9f9b8c24bf65118f Mon Sep 17 00:00:00 2001 From: Alexander Bubnov Date: Wed, 28 Dec 2016 12:04:23 +0300 Subject: [PATCH 4/4] changes: fix comments --- .../adapters/BindableViewHolder.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java b/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java index bcd25fb..f417c3b 100644 --- a/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java +++ b/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java @@ -19,8 +19,6 @@ package ru.touchin.roboswag.components.adapters; -import android.content.res.ColorStateList; -import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.annotation.ColorRes; @@ -75,7 +73,6 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec * * @param resId The resource id to search for data; * @return String The string data associated with the resource. - * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist. */ @NonNull public String getString(@StringRes final int resId) { @@ -89,7 +86,6 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec * @param resId The resource id to search for data; * @param formatArgs The format arguments that will be used for substitution. * @return String The string data associated with the resource. - * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist. */ @NonNull public String getString(@StringRes final int resId, final Object... formatArgs) { @@ -103,7 +99,6 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec * * @param resId The resource id to search for data; * @return int A single color value in the form 0xAARRGGBB. - * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist. */ @ColorInt public int getColor(@ColorRes final int resId) { @@ -123,19 +118,6 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec return ContextCompat.getDrawable(itemView.getContext(), resId); } - /** - * Returns a color state list object associated with a particular resource ID. - * Starting in {@link android.os.Build.VERSION_CODES#LOLLIPOP}, the - * returned drawable will be styled for the specified Context's theme. - * - * @param resId The resource id to search for data; - * @return A color state list, or {@code null} if the resource could not be resolved. - */ - @NonNull - public ColorStateList getColorStateList(@ColorRes final int resId) { - return ContextCompat.getColorStateList(itemView.getContext(), resId); - } - @NonNull @Override public Subscription bind(@NonNull final Observable observable, @NonNull final Action1 onNextAction) {