diff --git a/example/build.gradle b/example/build.gradle
index de3cb274..f55cfd77 100644
--- a/example/build.gradle
+++ b/example/build.gradle
@@ -20,6 +20,9 @@ android {
lintOptions {
abortOnError false
}
+ buildFeatures {
+ dataBinding true
+ }
}
dependencies {
diff --git a/example/src/main/java/com/ncorti/slidetoact/example/MainActivity.java b/example/src/main/java/com/ncorti/slidetoact/example/MainActivity.java
index 357a418f..4839ce6b 100644
--- a/example/src/main/java/com/ncorti/slidetoact/example/MainActivity.java
+++ b/example/src/main/java/com/ncorti/slidetoact/example/MainActivity.java
@@ -34,6 +34,7 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.button_reversed_slider).setOnClickListener(this);
findViewById(R.id.button_animation_duration).setOnClickListener(this);
findViewById(R.id.button_bump_vibration).setOnClickListener(this);
+ findViewById(R.id.button_bound).setOnClickListener(this);
}
public boolean onCreateOptionsMenu(Menu menu) {
diff --git a/example/src/main/java/com/ncorti/slidetoact/example/SampleActivity.java b/example/src/main/java/com/ncorti/slidetoact/example/SampleActivity.java
index 71f03c24..13ee3cd3 100644
--- a/example/src/main/java/com/ncorti/slidetoact/example/SampleActivity.java
+++ b/example/src/main/java/com/ncorti/slidetoact/example/SampleActivity.java
@@ -1,5 +1,7 @@
package com.ncorti.slidetoact.example;
+import android.annotation.SuppressLint;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
@@ -9,8 +11,10 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.databinding.DataBindingUtil;
import com.ncorti.slidetoact.SlideToActView;
+import com.ncorti.slidetoact.example.databinding.ContentBoundBinding;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -97,6 +101,15 @@ public void onClick(final View v) {
case R.id.button_bump_vibration:
setContentView(R.layout.content_bumb_vibration);
break;
+ case R.id.button_bound:
+ ContentBoundBinding binding = DataBindingUtil.setContentView(this, R.layout.content_bound);
+ @SuppressLint("UseCompatLoadingForDrawables")
+ SliderData fullData = new SliderData("Bound SlideToAct View",
+ getResources().getDrawable(R.drawable.ic_android),
+ getResources().getDrawable(R.drawable.ic_cloud));
+ binding.setFullData(fullData);
+ binding.setPlay(true);
+ break;
default:
finish();
break;
@@ -184,4 +197,16 @@ public void onSlideResetAnimationEnded(@NonNull SlideToActView view) {
private String getTime() {
return dateFormat.format(new Date());
}
+
+ public class SliderData {
+ public String text;
+ public Drawable sliderIcon;
+ public Drawable completeIcon;
+
+ public SliderData(String text, Drawable sliderIcon, Drawable completeIcon) {
+ this.text = text;
+ this.sliderIcon = sliderIcon;
+ this.completeIcon = completeIcon;
+ }
+ }
}
diff --git a/example/src/main/res/drawable/ic_pause.xml b/example/src/main/res/drawable/ic_pause.xml
new file mode 100644
index 00000000..906295eb
--- /dev/null
+++ b/example/src/main/res/drawable/ic_pause.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
diff --git a/example/src/main/res/drawable/ic_play.xml b/example/src/main/res/drawable/ic_play.xml
new file mode 100644
index 00000000..e6bafc8a
--- /dev/null
+++ b/example/src/main/res/drawable/ic_play.xml
@@ -0,0 +1,12 @@
+
+
+
+
diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml
index 49155bbd..1c0da8d2 100644
--- a/example/src/main/res/layout/activity_main.xml
+++ b/example/src/main/res/layout/activity_main.xml
@@ -112,5 +112,11 @@
android:layout_height="wrap_content"
android:text="@string/bump_vibration" />
+
+
diff --git a/example/src/main/res/layout/content_bound.xml b/example/src/main/res/layout/content_bound.xml
new file mode 100644
index 00000000..addd81e9
--- /dev/null
+++ b/example/src/main/res/layout/content_bound.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/example/src/main/res/values/strings.xml b/example/src/main/res/values/strings.xml
index 5eb45ca2..a16ade84 100644
--- a/example/src/main/res/values/strings.xml
+++ b/example/src/main/res/values/strings.xml
@@ -14,6 +14,7 @@
Reversed Slider
Animation duration
Bump Vibration
+ Bound
Event Log
Press the following buttons to checkout different SlideToActView and understand each parameter. You can reset the sliders pressing the Reset button in the Toolbar. Enjoy :)
Use Android icon
diff --git a/slidetoact/build.gradle b/slidetoact/build.gradle
index 55addf17..39f8c8f3 100644
--- a/slidetoact/build.gradle
+++ b/slidetoact/build.gradle
@@ -3,6 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'org.jlleitschuh.gradle.ktlint'
+apply plugin: 'kotlin-kapt'
version = "0.9.0"
@@ -25,6 +26,9 @@ android {
lintOptions {
abortOnError false
}
+ buildFeatures {
+ dataBinding true
+ }
}
dependencies {
diff --git a/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt b/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt
index e3507278..a0d72dc1 100644
--- a/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt
+++ b/slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt
@@ -27,13 +27,13 @@ import android.view.animation.AnticipateOvershootInterpolator
import android.view.animation.OvershootInterpolator
import android.widget.TextView
import androidx.annotation.ColorInt
-import androidx.annotation.DrawableRes
import androidx.annotation.RequiresApi
import androidx.annotation.StyleRes
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.widget.TextViewCompat
+import androidx.databinding.BindingAdapter
import com.ncorti.slidetoact.SlideToActIconUtil.createIconAnimator
import com.ncorti.slidetoact.SlideToActIconUtil.loadIconCompat
import com.ncorti.slidetoact.SlideToActIconUtil.stopIconAnimation
@@ -149,17 +149,34 @@ class SlideToActView @JvmOverloads constructor(
}
/** Custom Slider Icon */
- @DrawableRes
- var sliderIcon: Int = R.drawable.slidetoact_ic_arrow
+ var sliderIcon: Any = R.drawable.slidetoact_ic_arrow
set(value) {
field = value
- if (field != 0) {
- ResourcesCompat.getDrawable(context.resources, value, context.theme)?.let {
- mDrawableArrow = it
- DrawableCompat.setTint(it, iconColor)
+ when (value) {
+ is Int -> {
+ if (field != 0) {
+ ResourcesCompat.getDrawable(context.resources, value, context.theme)?.let {
+ mDrawableArrow = it
+ DrawableCompat.setTint(it, iconColor)
+ }
+ }
+ }
+ is Drawable -> {
+ mDrawableArrow = value
+ DrawableCompat.setTint(value, iconColor)
+ }
+ else -> {
+ ResourcesCompat.getDrawable(
+ context.resources,
+ R.drawable.slidetoact_ic_arrow,
+ context.theme
+ )?.let {
+ mDrawableArrow = it
+ DrawableCompat.setTint(it, iconColor)
+ }
}
- invalidate()
}
+ invalidate()
}
/** Slider cursor position (between 0 and (`mAreaWidth - mAreaHeight)) */
@@ -217,14 +234,21 @@ class SlideToActView @JvmOverloads constructor(
private var mDrawableTick: Drawable
private var mFlagDrawTick: Boolean = false
- @DrawableRes
- var completeIcon: Int = 0
+ var completeIcon: Any = 0
set(value) {
field = value
- if (field != 0) {
- mDrawableTick = loadIconCompat(context, value)
- invalidate()
+ when (value) {
+ is Int -> {
+ if (field != 0) {
+ mDrawableTick = loadIconCompat(context, value)
+ }
+ }
+ is Drawable -> {
+ mDrawableTick = value
+ }
+ else -> loadIconCompat(context, R.drawable.slidetoact_ic_check)
}
+ invalidate()
}
/* -------------------- PAINT & DRAW -------------------- */
@@ -987,3 +1011,13 @@ class SlideToActView @JvmOverloads constructor(
}
}
}
+
+@BindingAdapter("slider_icon")
+fun loadSliderIcon(view: SlideToActView, sliderIcon: Drawable) {
+ view.sliderIcon = sliderIcon
+}
+
+@BindingAdapter("complete_icon")
+fun loadCompleteIcon(view: SlideToActView, completeIcon: Drawable) {
+ view.completeIcon = completeIcon
+}