From e71800fff69014443aa24cbfceff6d2f386bc16b Mon Sep 17 00:00:00 2001 From: Dionysis Date: Sun, 4 Dec 2016 22:31:36 +0100 Subject: [PATCH] Add up/down directions capacity --- example/build.gradle | 6 +- .../lorentzos/swipecards/AsyncActivity.java | 37 +++-- .../swipecards/SingleViewActivity.java | 2 +- example/src/main/res/layout/buttons.xml | 30 +++- example/src/main/res/values/dimens.xml | 2 +- library/build.gradle | 2 +- .../flingswipe/OnScrollListener.java | 4 +- .../flingswipe/SwipeAdapterView.java | 19 ++- .../internal/CardEventListener.java | 2 +- .../flingswipe/internal/Direction.java | 5 +- .../flingswipe/internal/ExitPosition.java | 2 +- .../flingswipe/internal/FrameData.java | 143 ++++++++++++++---- .../flingswipe/internal/FrameResult.java | 24 +-- .../flingswipe/internal/OnSwipeListener.java | 9 +- .../flingswipe/internal/ScrollProgress.java | 18 +++ .../flingswipe/internal/SwipeEvent.java | 10 +- .../flingswipe/internal/SwipeOperator.java | 8 +- .../flingswipe/internal/TouchEvent.java | 30 ++-- .../flingswipe/internal/UpdatePosition.java | 8 +- .../internal/BottomTouchEventTest.java | 36 ++--- .../internal/ExitTouchEventTest.java | 52 ++++--- .../flingswipe/internal/MockViewFactory.java | 2 + .../internal/SwipeOperatorTouchTest.java | 6 + .../internal/TestCardEventListener.java | 2 +- .../internal/TopTouchEventTest.java | 36 ++--- .../flingswipe/internal/TouchEventTest.java | 9 +- 26 files changed, 340 insertions(+), 164 deletions(-) create mode 100644 library/src/main/java/com/lorentzos/flingswipe/internal/ScrollProgress.java diff --git a/example/build.gradle b/example/build.gradle index f8bf9637d6..d4053ce008 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -23,9 +23,9 @@ android { dependencies { compile project(':library') - compile 'com.android.support:appcompat-v7:25.0.0' - compile 'com.android.support:design:25.0.0' - compile 'com.android.support:support-v4:25.0.0' + compile 'com.android.support:appcompat-v7:25.0.1' + compile 'com.android.support:design:25.0.1' + compile 'com.android.support:support-v4:25.0.1' compile 'com.squareup.moshi:moshi:1.3.1' compile 'com.squareup.okio:okio:1.11.0' diff --git a/example/src/main/java/com/lorentzos/swipecards/AsyncActivity.java b/example/src/main/java/com/lorentzos/swipecards/AsyncActivity.java index 1c47aec4c9..e95bd85f72 100644 --- a/example/src/main/java/com/lorentzos/swipecards/AsyncActivity.java +++ b/example/src/main/java/com/lorentzos/swipecards/AsyncActivity.java @@ -29,8 +29,8 @@ import static io.reactivex.schedulers.Schedulers.newThread; /** - * Activity with example of a network call to obtain the data and load the avatars - * in the image views. + * Activity with example of a network call to obtain the data and load the avatars in the image + * views. */ public class AsyncActivity extends AppCompatActivity { @@ -87,8 +87,8 @@ public void onItemClick(AdapterView parent, View view, int position, long id) // Optionally add an onScrollListener flingContainer.setOnScrollListener(new OnScrollListener() { @Override - public void onScroll(View view, float scrollProgressPercent) { - Log.i("MyActivity", "onScroll " + scrollProgressPercent); + public void onScroll(View view, float scrollProgressPercent, int direction) { + Log.i("MyActivity", "onScroll " + direction + ": " + scrollProgressPercent); } }); @@ -116,14 +116,14 @@ protected void onDestroy() { super.onDestroy(); } - @OnClick(R.id.right) - public void swipeRight() { + @OnClick(R.id.up) + public void swipeTop() { if (memberAdapter.isEmpty()) { - Snackbar.make(coordinatorLayout, "Cannot swipe right. Adapter is empty.", Snackbar.LENGTH_SHORT).show(); + Snackbar.make(coordinatorLayout, "Cannot swipe up. Adapter is empty.", Snackbar.LENGTH_SHORT).show(); return; } - //Trigger the right event manually. - flingContainer.swipeRight(); + //Trigger the up event manually. + flingContainer.swipeUp(); } @OnClick(R.id.left) @@ -136,4 +136,23 @@ public void swipeLeft() { flingContainer.swipeLeft(); } + @OnClick(R.id.right) + public void swipeRight() { + if (memberAdapter.isEmpty()) { + Snackbar.make(coordinatorLayout, "Cannot swipe right. Adapter is empty.", Snackbar.LENGTH_SHORT).show(); + return; + } + //Trigger the right event manually. + flingContainer.swipeRight(); + } + + @OnClick(R.id.down) + public void swipeDown() { + if (memberAdapter.isEmpty()) { + Snackbar.make(coordinatorLayout, "Cannot swipe down. Adapter is empty.", Snackbar.LENGTH_SHORT).show(); + return; + } + //Trigger the down event manually. + flingContainer.swipeDown(); + } } diff --git a/example/src/main/java/com/lorentzos/swipecards/SingleViewActivity.java b/example/src/main/java/com/lorentzos/swipecards/SingleViewActivity.java index d2ad992ff9..922ff2342d 100644 --- a/example/src/main/java/com/lorentzos/swipecards/SingleViewActivity.java +++ b/example/src/main/java/com/lorentzos/swipecards/SingleViewActivity.java @@ -24,7 +24,7 @@ public void onCardExited(View view, @Direction int direction) { } @Override - public void onScroll(View view, float scrollProgressPercent) { + public void onScroll(View view, float scrollProgressPercent, @Direction int direction) { } diff --git a/example/src/main/res/layout/buttons.xml b/example/src/main/res/layout/buttons.xml index 669d0213e4..9b1657c306 100644 --- a/example/src/main/res/layout/buttons.xml +++ b/example/src/main/res/layout/buttons.xml @@ -1,6 +1,6 @@ - +