Skip to content

Commit

Permalink
Added the ability to customise the icon color (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshHughes-Dev authored and cortinico committed Apr 29, 2019
1 parent b864f2e commit 8543fce
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ app:slider_icon="@drawable/custom_icon"

You can also disable the rotation by setting the ``rotate_icon`` attribute to false.

#### ``slider_icon_color``

You can set a custom color for the icon by setting the ``slider_icon_color`` attribute.

<p align="center">
<img src="assets/slider_icon_color.png" alt="custom_icon" width="40%"/>
</p>

This attribute defaults to the ``outer_color`` if set. If ``outer_color`` is not set, this attribute defaults to **colorAccent** from your theme.

#### ``android:elevation``

Use the ``android:elevation`` attribute to set the **elevation** of the widget. The widgets will take care of providing the proper ``ViewOutlineProvider`` during the whole animation (a.k.a. The shadow will be drawn properly).
Expand Down
Binary file added assets/slider_icon_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 21 additions & 3 deletions slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import android.support.annotation.RequiresApi
import android.support.graphics.drawable.AnimatedVectorDrawableCompat
import android.support.graphics.drawable.VectorDrawableCompat
import android.support.v4.content.ContextCompat
import android.support.v4.graphics.ColorUtils
import android.support.v4.widget.TextViewCompat
import android.util.AttributeSet
import android.util.TypedValue
Expand Down Expand Up @@ -90,12 +89,11 @@ class SlideToActView @JvmOverloads constructor (
}
}

/** Outer color used by the slider (primary) */
/** Outer color used by the slider (primary)*/
var outerColor: Int = 0
set(value) {
field = value
mOuterPaint.color = value
mDrawableArrow.setTint(value)
invalidate()
}

Expand All @@ -115,6 +113,14 @@ class SlideToActView @JvmOverloads constructor (
invalidate()
}

/** Custom Icon color */
var iconColor: Int = 0
set(value) {
field = value
mDrawableArrow.setTint(value)
invalidate()
}

/** Slider cursor position (between 0 and (`reaWidth - mAreaHeight)) */
private var mPosition: Int = 0
set(value) {
Expand Down Expand Up @@ -213,6 +219,7 @@ class SlideToActView @JvmOverloads constructor (
val actualOuterColor : Int
val actualInnerColor : Int
val actualTextColor : Int
val actualIconColor : Int

mTextView = TextView(context)
mTextPaint = mTextView.paint
Expand Down Expand Up @@ -258,6 +265,16 @@ class SlideToActView @JvmOverloads constructor (
mActualAreaMargin = mOriginAreaMargin

mIcon = layoutAttrs.getResourceId(R.styleable.SlideToActView_slider_icon, R.drawable.ic_arrow)

// For icon color. check if the `slide_icon_color` is set.
// if not check if the `outer_color` is set.
// if not, default to defaultOuter.
actualIconColor = when {
layoutAttrs.hasValue(R.styleable.SlideToActView_slider_icon_color) ->
layoutAttrs.getColor(R.styleable.SlideToActView_slider_icon_color, defaultOuter)
layoutAttrs.hasValue(R.styleable.SlideToActView_outer_color) -> actualOuterColor
else -> defaultOuter
}
} finally {
layoutAttrs.recycle()
}
Expand All @@ -281,6 +298,7 @@ class SlideToActView @JvmOverloads constructor (

outerColor = actualOuterColor
innerColor = actualInnerColor
iconColor = actualIconColor

mIconMargin = context.resources.getDimensionPixelSize(R.dimen.default_icon_margin)
mArrowMargin = mIconMargin
Expand Down
1 change: 1 addition & 0 deletions slidetoact/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<attr name="slider_height" format="dimension" />
<attr name="slider_locked" format="boolean" />
<attr name="slider_icon" format="reference" />
<attr name="slider_icon_color" format="color"/>
<attr name="rotate_icon" format="boolean" />
<attr name="animate_completion" format="boolean" />
<attr name="text_appearance" format="reference" />
Expand Down

0 comments on commit 8543fce

Please sign in to comment.