From 5db67c602d7c43f4a84dd45339a5f7de7a354e7a Mon Sep 17 00:00:00 2001 From: Tino Laomahei Date: Tue, 8 Sep 2020 20:57:14 +1200 Subject: [PATCH 1/7] add loadable state and callbacks --- .../slidetoact/example/MainActivity.java | 1 + .../slidetoact/example/SampleActivity.java | 26 +++++++ example/src/main/res/layout/activity_main.xml | 6 ++ .../res/layout/content_loadable_slider.xml | 22 ++++++ example/src/main/res/values/strings.xml | 1 + .../com/ncorti/slidetoact/SlideToActView.kt | 77 ++++++++++++++++++- .../drawable/slidetoact_ic_rotate_right.xml | 5 ++ slidetoact/src/main/res/values/attrs.xml | 2 + 8 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 example/src/main/res/layout/content_loadable_slider.xml create mode 100644 slidetoact/src/main/res/drawable/slidetoact_ic_rotate_right.xml 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..0c53883d 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_loadable_slider).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..923279d3 100644 --- a/example/src/main/java/com/ncorti/slidetoact/example/SampleActivity.java +++ b/example/src/main/java/com/ncorti/slidetoact/example/SampleActivity.java @@ -1,6 +1,7 @@ package com.ncorti.slidetoact.example; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -16,6 +17,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Random; public class SampleActivity extends AppCompatActivity { @@ -97,6 +99,30 @@ public void onClick(final View v) { case R.id.button_bump_vibration: setContentView(R.layout.content_bumb_vibration); break; + case R.id.button_loadable_slider: + setContentView(R.layout.content_loadable_slider); + final SlideToActView loadableSlider = findViewById(R.id.slide_loadable); + loadableSlider.setOnSlideLoadingStartedListener(new SlideToActView.OnSlideLoadingStartedListener() { + @Override + public void onSlideLoadingStarted(SlideToActView view) { + Random ran = new Random(); + // Simulate an indeterminate amount of time + int delay = ran.nextInt(3000); + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + if (loadableSlider.isLoadable()) { + if (loadableSlider.isAnimateCompletion()) { + loadableSlider.completeSlider(); + } else { + loadableSlider.resetSlider(); + } + } + } + }, delay); + } + }); + break; default: finish(); break; diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml index 49155bbd..d7d94357 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" /> +