From 9b8369e157a7b10e30724e94a363baa0637ff71f Mon Sep 17 00:00:00 2001 From: Wenbin Date: Tue, 30 Jun 2020 22:44:47 +0800 Subject: [PATCH] Added two samples --- .../chinalwb/slidetoconfirm/MainActivity.java | 57 ++++++++- .../drawable/ic_arrow_forward_black_60dp.xml | 5 + app/src/main/res/layout/activity_main.xml | 114 ++++++++++++++---- 3 files changed, 150 insertions(+), 26 deletions(-) create mode 100644 app/src/main/res/drawable/ic_arrow_forward_black_60dp.xml diff --git a/app/src/main/java/com/chinalwb/slidetoconfirm/MainActivity.java b/app/src/main/java/com/chinalwb/slidetoconfirm/MainActivity.java index 56235bb..a5490cc 100644 --- a/app/src/main/java/com/chinalwb/slidetoconfirm/MainActivity.java +++ b/app/src/main/java/com/chinalwb/slidetoconfirm/MainActivity.java @@ -10,12 +10,53 @@ public class MainActivity extends AppCompatActivity { + public static final String START_WORKING = "STEP #1"; + public static final String STOP_WORKING = "STEP #2"; + private String engageTextNow = START_WORKING; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - final SlideToConfirm slideToConfirm = findViewById(R.id.slide_to_confirm); + defaultSample(); + sampleForTwoSteps(); + } + + private void defaultSample() { + final SlideToConfirm slideToConfirm = findViewById(R.id.slide_to_confirm_1); + slideToConfirm.setSlideListener(new ISlideListener() { + @Override + public void onSlideStart() { + Log.w("XX", "on start !! "); + } + + @Override + public void onSlideMove(float percent) { + Log.w("XX", "on move !! == " + percent); + } + + @Override + public void onSlideCancel() { + Log.w("XX", "on cancel !! "); + } + + @Override + public void onSlideDone() { + Log.w("XX", "on Done!!"); + + slideToConfirm.postDelayed(new Runnable() { + @Override + public void run() { + slideToConfirm.reset(); + } + }, 500); + } + }); + } + + private void sampleForTwoSteps() { + final SlideToConfirm slideToConfirm = findViewById(R.id.slide_to_confirm_2); + slideToConfirm.setEngageText(engageTextNow); slideToConfirm.setSlideListener(new ISlideListener() { @Override public void onSlideStart() { @@ -35,12 +76,24 @@ public void onSlideCancel() { @Override public void onSlideDone() { Log.w("XX", "on Done!!"); + if (engageTextNow.equals(START_WORKING)) { + slideToConfirm.setCompletedText("Processing..."); + } else { + slideToConfirm.setCompletedText("Finishing..."); + } + slideToConfirm.postDelayed(new Runnable() { @Override public void run() { + if (engageTextNow.equals(START_WORKING)) { + engageTextNow = STOP_WORKING; + } else { + engageTextNow = START_WORKING; + } + slideToConfirm.setEngageText(engageTextNow); slideToConfirm.reset(); } - }, 1000 * 3); + }, 500); } }); } diff --git a/app/src/main/res/drawable/ic_arrow_forward_black_60dp.xml b/app/src/main/res/drawable/ic_arrow_forward_black_60dp.xml new file mode 100644 index 0000000..25fb386 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_forward_black_60dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4d4d225..57f9a9d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,33 +1,99 @@ - - app:border_radius="10dp" - app:border_width="1dp" - app:slider_background_color="@color/pact_purple" - app:slider_color="@color/colorAccent" - app:slider_lottie="lottie_x.json" - app:slider_image="@drawable/slider" - app:slider_width="60dp" - app:slider_reset_duration="300" - app:slider_vibration_duration="50" - app:slider_threshold="1dp" - app:engage_text="Your action text" - app:engage_text_size="17sp" - app:engage_text_color="@android:color/white" - app:engaged_text_font="@font/pro_solid" - app:completed_text="Unlocked!" - app:completed_text_color="@android:color/white" - app:completed_text_size="30sp" + + + + + + + + + + + + - tools:context=".MainActivity" > -