Skip to content
Permalink
Browse files

Merge pull request #26 from ema987/customShimmerColor

added option to choose default/darker shimmer colors
  • Loading branch information...
elye committed Aug 13, 2018
2 parents 5b22919 + 69f3bec commit 1d87aabad5d9f6bd621104845beb2e06f1c28906
@@ -57,9 +57,17 @@ Provide both TextView and ImageView the ability to show shimmer (animation loade

7. Setting the Text Style as BOLD would darken the loading shimmer

8. Other feature of TextView and ImageView is still applicable.
8. Use a custom shimmer color (note: if set, point 7 will not apply, your color will be used even if the Text Style is BOLD)
```xml
<com.elyeproj.loaderviewlibrary.LoaderTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:custom_color="@android:color/holo_green_dark" />
```

9. Other feature of TextView and ImageView is still applicable.

9. Reset and show shimmer (animation loader) again by calling the below API
10. Reset and show shimmer (animation loader) again by calling the below API
```java
myLoaderTextView.resetLoader();
myLoaderImageView.resetLoader();
@@ -77,7 +77,8 @@
android:textSize="@dimen/standard_font_size"
app:height_weight="0.8"
app:width_weight="0.9"
app:corners="8" />
app:corners="8"
app:custom_color="@android:color/holo_green_dark"/>

</LinearLayout>

@@ -19,8 +19,6 @@
*/

class LoaderConstant {
public final static int COLOR_DEFAULT_GREY = Color.rgb(215, 215, 215);
public final static int COLOR_DARKER_GREY = Color.rgb(180, 180, 180);
public final static int COLOR_DEFAULT_GRADIENT = Color.rgb(245, 245, 245);
public final static float MIN_WEIGHT = 0.0f;
public final static float MAX_WEIGHT = 1.0f;
@@ -23,12 +23,14 @@
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;

public class LoaderImageView extends AppCompatImageView implements LoaderView {

private LoaderController loaderController;
private int defaultColorResource;

public LoaderImageView(Context context) {
super(context);
@@ -50,6 +52,7 @@ private void init(AttributeSet attrs) {
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.loader_view, 0, 0);
loaderController.setUseGradient(typedArray.getBoolean(R.styleable.loader_view_use_gradient, LoaderConstant.USE_GRADIENT_DEFAULT));
loaderController.setCorners(typedArray.getInt(R.styleable.loader_view_corners, LoaderConstant.CORNER_DEFAULT));
defaultColorResource = typedArray.getColor(R.styleable.loader_view_custom_color, ContextCompat.getColor(getContext(), R.color.default_color));
typedArray.recycle();
}

@@ -74,7 +77,7 @@ protected void onDraw(Canvas canvas) {

@Override
public void setRectColor(Paint rectPaint) {
rectPaint.setColor(LoaderConstant.COLOR_DEFAULT_GREY);
rectPaint.setColor(defaultColorResource);
}

@Override
@@ -21,13 +21,16 @@
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.util.AttributeSet;

public class LoaderTextView extends AppCompatTextView implements LoaderView {

private LoaderController loaderController;
private int defaultColorResource;
private int darkerColorResource;

public LoaderTextView(Context context) {
super(context);
@@ -51,6 +54,8 @@ private void init(AttributeSet attrs) {
loaderController.setHeightWeight(typedArray.getFloat(R.styleable.loader_view_height_weight, LoaderConstant.MAX_WEIGHT));
loaderController.setUseGradient(typedArray.getBoolean(R.styleable.loader_view_use_gradient, LoaderConstant.USE_GRADIENT_DEFAULT));
loaderController.setCorners(typedArray.getInt(R.styleable.loader_view_corners, LoaderConstant.CORNER_DEFAULT));
defaultColorResource = typedArray.getColor(R.styleable.loader_view_custom_color, ContextCompat.getColor(getContext(), R.color.default_color));
darkerColorResource = typedArray.getColor(R.styleable.loader_view_custom_color, ContextCompat.getColor(getContext(), R.color.darker_color));
typedArray.recycle();
}

@@ -88,9 +93,9 @@ public void setText(CharSequence text, BufferType type) {
public void setRectColor(Paint rectPaint) {
final Typeface typeface = getTypeface();
if (typeface != null && typeface.getStyle()== Typeface.BOLD ) {
rectPaint.setColor(LoaderConstant.COLOR_DARKER_GREY);
rectPaint.setColor(darkerColorResource);
} else {
rectPaint.setColor(LoaderConstant.COLOR_DEFAULT_GREY);
rectPaint.setColor(defaultColorResource);
}
}

@@ -5,5 +5,6 @@
<attr name="height_weight" format="float" />
<attr name="use_gradient" format="boolean" />
<attr name="corners" format="integer" />
<attr name="custom_color" format="color"/>
</declare-styleable>
</resources>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="default_color">#D7D7D7</color>
<color name="darker_color">#B4B4B4</color>
</resources>

0 comments on commit 1d87aab

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.