This repository has been archived by the owner on Mar 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
128 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/src/androidTest/java/com/ebanx/swipebutton/utils/CenterSwipeAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ebanx.com.ego.utils | ||
|
||
import android.support.test.espresso.PerformException | ||
import android.support.test.espresso.UiController | ||
import android.support.test.espresso.ViewAction | ||
import android.support.test.espresso.action.CoordinatesProvider | ||
import android.support.test.espresso.action.PrecisionDescriber | ||
import android.support.test.espresso.action.Swiper | ||
import android.support.test.espresso.matcher.ViewMatchers | ||
import android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility | ||
import android.support.test.espresso.util.HumanReadables | ||
import android.view.View | ||
import android.view.ViewConfiguration | ||
import org.hamcrest.Matcher | ||
|
||
class CenterSwipeAction(private val swiper: Swiper, | ||
private val startCoordProvide: CoordinatesProvider, | ||
private val endCoordProvide: CoordinatesProvider, | ||
private val precDesc: PrecisionDescriber) : ViewAction { | ||
|
||
override fun getConstraints(): Matcher<View> { | ||
return withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE) | ||
} | ||
|
||
override fun getDescription(): String { | ||
return "swipe from middle of screen" | ||
} | ||
|
||
@Suppress("CatchRuntimeException") | ||
override fun perform(uiController: UiController, view: View) { | ||
val startCoord = startCoordProvide.calculateCoordinates(view) | ||
val finalCoord = endCoordProvide.calculateCoordinates(view) | ||
val precision = precDesc.describePrecision() | ||
|
||
// you could try this for several times until Swiper.Status is achieved or try count is reached | ||
try { | ||
swiper.sendSwipe(uiController, startCoord, finalCoord, precision) | ||
} catch (re: RuntimeException) { | ||
throw PerformException.Builder() | ||
.withActionDescription(this.description) | ||
.withViewDescription(HumanReadables.describe(view)) | ||
.withCause(re) | ||
.build() | ||
} | ||
|
||
// ensures that the swipe has been run. | ||
uiController.loopMainThreadForAtLeast(ViewConfiguration.getPressedStateDuration().toLong()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
swipe-button/src/main/java/com/ebanx/swipebtn/TouchUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.ebanx.swipebtn; | ||
|
||
import android.view.MotionEvent; | ||
import android.view.View; | ||
|
||
final class TouchUtils { | ||
private TouchUtils() { | ||
} | ||
|
||
static boolean isTouchOutsideInitialPosition(MotionEvent event, View view) { | ||
return event.getX() > view.getX() + view.getWidth(); | ||
} | ||
} |