Skip to content

Commit 9451f73

Browse files
committed
Auto format code
1 parent 82323b9 commit 9451f73

File tree

7 files changed

+57
-36
lines changed

7 files changed

+57
-36
lines changed

library/src/main/kotlin/me/thanel/swipeactionview/MultiSwipeActionView.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class MultiSwipeActionView : LinearLayout {
88
constructor(context: Context?) : super(context)
99
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
1010
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
11-
context,
12-
attrs,
13-
defStyleAttr
11+
context, attrs, defStyleAttr
1412
)
1513
}

library/src/main/kotlin/me/thanel/swipeactionview/SwipeActionView.kt

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import android.os.Build
2828
import android.os.Handler
2929
import android.os.Message
3030
import android.util.AttributeSet
31-
import android.util.Log
3231
import android.view.*
3332
import android.view.animation.DecelerateInterpolator
3433
import android.widget.FrameLayout
@@ -42,6 +41,7 @@ import me.thanel.swipeactionview.utils.marginStart
4241
import me.thanel.swipeactionview.utils.radius
4342
import me.thanel.swipeactionview.utils.setBoundsFrom
4443
import me.thanel.swipeactionview.utils.totalWidth
44+
import kotlin.math.abs
4545
import kotlin.math.absoluteValue
4646

4747

@@ -400,6 +400,7 @@ class SwipeActionView : FrameLayout {
400400
SwipeDirection.LEFT -> leftSwipeView?.let {
401401
container.translationX = -maxLeftSwipeDistance
402402
}
403+
403404
SwipeDirection.RIGHT -> rightSwipeView?.let {
404405
container.translationX = maxRightSwipeDistance
405406
}
@@ -620,6 +621,7 @@ class SwipeActionView : FrameLayout {
620621
leftSwipeRipple.draw(canvas)
621622
}
622623
}
624+
623625
SwipeDirection.RIGHT -> {
624626
if (rightSwipeRipple.hasColor) {
625627
rightSwipeRipple.draw(canvas)
@@ -727,13 +729,13 @@ class SwipeActionView : FrameLayout {
727729
*
728730
* @return Whether the user has moved their finger vertically.
729731
*/
730-
private fun hasMovedVertically(e: MotionEvent) = Math.abs(e.rawY - initialRawY) >= touchSlop
732+
private fun hasMovedVertically(e: MotionEvent) = abs(e.rawY - initialRawY) >= touchSlop
731733

732734
/**
733735
* Tells whether the drag can be started by the user based on provided motion event.
734736
*/
735737
private fun canStartDrag(e: MotionEvent): Boolean {
736-
val movedFarEnough = Math.abs(e.rawX - initialRawX) > touchSlop
738+
val movedFarEnough = abs(e.rawX - initialRawX) > touchSlop
737739
return movedFarEnough && isTouchValid
738740
}
739741

@@ -783,18 +785,18 @@ class SwipeActionView : FrameLayout {
783785

784786
val normalizedTranslation = swipeDistance.absoluteValue
785787
//swiping right
786-
if(swipeDistance>0){
788+
if (swipeDistance > 0) {
787789
if (rightSwipeView is MultiSwipeActionView) {
788790
val halfway = (rightSwipeView as MultiSwipeActionView).getChildAt(0)?.width ?: 0
789-
if(halfway-distanceFromCenterpoint < normalizedTranslation) {
791+
if (halfway - distanceFromCenterpoint < normalizedTranslation) {
790792
return true
791793
}
792794
}
793795
} else {
794796
if (leftSwipeView is MultiSwipeActionView) {
795797
val vg = (leftSwipeView as MultiSwipeActionView)
796-
val halfway = vg.getChildAt(vg.childCount-1)?.width ?: 0
797-
if(halfway-distanceFromCenterpoint < normalizedTranslation) {
798+
val halfway = vg.getChildAt(vg.childCount - 1)?.width ?: 0
799+
if (halfway - distanceFromCenterpoint < normalizedTranslation) {
798800
return true
799801
}
800802
}
@@ -815,21 +817,23 @@ class SwipeActionView : FrameLayout {
815817
val resistanceMulitplier = 4
816818

817819
//swiping right
818-
if(container.translationX>0){
820+
if (container.translationX > 0) {
819821
if (rightSwipeView is MultiSwipeActionView) {
820822
val halfway = (rightSwipeView as MultiSwipeActionView).getChildAt(0)?.width ?: 0
821-
if(halfway+distanceFromCenterpoint > normalizedTranslation &&
822-
normalizedTranslation > halfway-distanceFromCenterpoint) {
823-
resistance *=resistanceMulitplier
823+
if (halfway + distanceFromCenterpoint > normalizedTranslation &&
824+
normalizedTranslation > halfway - distanceFromCenterpoint
825+
) {
826+
resistance *= resistanceMulitplier
824827
}
825828
}
826829
} else {
827830
if (leftSwipeView is MultiSwipeActionView) {
828831
val vg = (leftSwipeView as MultiSwipeActionView)
829-
val halfway = vg.getChildAt(vg.childCount-1)?.width ?: 0
830-
if(halfway+distanceFromCenterpoint > normalizedTranslation &&
831-
normalizedTranslation > halfway-distanceFromCenterpoint) {
832-
resistance *=resistanceMulitplier
832+
val halfway = vg.getChildAt(vg.childCount - 1)?.width ?: 0
833+
if (halfway + distanceFromCenterpoint > normalizedTranslation &&
834+
normalizedTranslation > halfway - distanceFromCenterpoint
835+
) {
836+
resistance *= resistanceMulitplier
833837
}
834838
}
835839
}
@@ -869,7 +873,7 @@ class SwipeActionView : FrameLayout {
869873
cancelDrag(false)
870874
velocityTracker.computeCurrentVelocity(100)
871875

872-
val swipedFastEnough = Math.abs(velocityTracker.xVelocity) > minActivationSpeed
876+
val swipedFastEnough = abs(velocityTracker.xVelocity) > minActivationSpeed
873877

874878
if (swipedFastEnough && !isValidDelta(velocityTracker.xVelocity)) {
875879
animateToOriginalPosition()
@@ -921,15 +925,18 @@ class SwipeActionView : FrameLayout {
921925
leftSwipeRipple.restart()
922926
}
923927

924-
animateContainer(getTargetTranslationX(swipedRight, isHalfwaySwipe), swipeAnimationDuration) {
928+
animateContainer(
929+
getTargetTranslationX(swipedRight, isHalfwaySwipe),
930+
swipeAnimationDuration
931+
) {
925932
val shouldFinish = if (swipedRight) {
926-
if(isHalfwaySwipe) {
933+
if (isHalfwaySwipe) {
927934
swipeGestureListener?.onSwipedHalfwayRight(this)
928935
} else {
929936
swipeGestureListener?.onSwipedRight(this)
930937
}
931938
} else {
932-
if(isHalfwaySwipe) {
939+
if (isHalfwaySwipe) {
933940
swipeGestureListener?.onSwipedHalfwayLeft(this)
934941
} else {
935942
swipeGestureListener?.onSwipedLeft(this)
@@ -1006,16 +1013,18 @@ class SwipeActionView : FrameLayout {
10061013
swipeView = leftSwipeView
10071014
animator = leftSwipeAnimator
10081015
}
1016+
10091017
swipeDistance > 0 -> {
10101018
swipeView = rightSwipeView
10111019
animator = rightSwipeAnimator
10121020
}
1021+
10131022
else -> return
10141023
}
10151024

10161025
if (swipeView == null || animator == null) return
10171026

1018-
val absTranslationX = Math.abs(swipeDistance)
1027+
val absTranslationX = abs(swipeDistance)
10191028
val maxSwipeDistance = getMaxSwipeDistance(swipeDistance)
10201029

10211030
val progress = absTranslationX / maxSwipeDistance
@@ -1046,11 +1055,13 @@ class SwipeActionView : FrameLayout {
10461055
* @return Translation Value
10471056
*/
10481057
private fun getTargetTranslationX(swipedRight: Boolean, isHalfwaySwipe: Boolean): Float {
1049-
return if(isHalfwaySwipe) {
1058+
return if (isHalfwaySwipe) {
10501059
return if (swipedRight) {
1051-
((rightSwipeView as MultiSwipeActionView).getChildAt(0)?.width ?: maxRightSwipeDistance).toFloat()
1060+
((rightSwipeView as MultiSwipeActionView).getChildAt(0)?.width
1061+
?: maxRightSwipeDistance).toFloat()
10521062
} else {
1053-
-((leftSwipeView as MultiSwipeActionView).getChildAt(0)?.width ?: maxLeftSwipeDistance).toFloat()
1063+
-((leftSwipeView as MultiSwipeActionView).getChildAt(0)?.width
1064+
?: maxLeftSwipeDistance).toFloat()
10541065
}
10551066
} else {
10561067
if (swipedRight) maxRightSwipeDistance else -maxLeftSwipeDistance
@@ -1085,6 +1096,7 @@ class SwipeActionView : FrameLayout {
10851096
swipeActionView.inLongPress = true
10861097
swipeActionView.performLongClick()
10871098
}
1099+
10881100
TAP -> {
10891101
swipeActionView.startPress(x, y)
10901102
}

library/src/main/kotlin/me/thanel/swipeactionview/SwipeGestureListener.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ interface SwipeGestureListener {
3333
* should manually call `reset` method to return to default position.
3434
* @see SwipeActionView
3535
*/
36-
fun onSwipedLeft(swipeActionView: SwipeActionView): Boolean {return true}
36+
fun onSwipedLeft(swipeActionView: SwipeActionView): Boolean {
37+
return true
38+
}
3739

3840
/**
3941
* Callback method to be invoked when user swipes the [SwipeActionView] to the
@@ -45,7 +47,9 @@ interface SwipeGestureListener {
4547
* should manually call `reset` method to return to default position.
4648
* @see SwipeActionView
4749
*/
48-
fun onSwipedRight(swipeActionView: SwipeActionView): Boolean {return true}
50+
fun onSwipedRight(swipeActionView: SwipeActionView): Boolean {
51+
return true
52+
}
4953

5054
/**
5155
* Callback method to be invoked when user swipes the [SwipeActionView] to the
@@ -57,7 +61,9 @@ interface SwipeGestureListener {
5761
* should manually call `reset` method to return to default position.
5862
* @see SwipeActionView
5963
*/
60-
fun onSwipedHalfwayLeft(swipeActionView: SwipeActionView): Boolean {return true}
64+
fun onSwipedHalfwayLeft(swipeActionView: SwipeActionView): Boolean {
65+
return true
66+
}
6167

6268
/**
6369
* Callback method to be invoked when user swipes the [SwipeActionView] to the
@@ -69,7 +75,9 @@ interface SwipeGestureListener {
6975
* should manually call `reset` method to return to default position.
7076
* @see SwipeActionView
7177
*/
72-
fun onSwipedHalfwayRight(swipeActionView: SwipeActionView): Boolean {return true}
78+
fun onSwipedHalfwayRight(swipeActionView: SwipeActionView): Boolean {
79+
return true
80+
}
7381

7482
/**
7583
* Callback method to be invoked when the left swipe is complete.
@@ -78,6 +86,7 @@ interface SwipeGestureListener {
7886
* @param swipeActionView The [SwipeActionView] from which this method was invoked.
7987
*/
8088
fun onSwipeLeftComplete(swipeActionView: SwipeActionView) {}
89+
8190
/**
8291
* Callback method to be invoked when the right swipe is complete.
8392
* A swipe is considered complete once the view returns back to its original position.

library/src/main/kotlin/me/thanel/swipeactionview/SwipeRippleDrawable.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ internal class SwipeRippleDrawable : Drawable(), Animatable {
100100
drawBounds.set(bounds)
101101
}
102102

103+
@Deprecated("Deprecated in Java",
104+
ReplaceWith("PixelFormat.OPAQUE", "android.graphics.PixelFormat")
105+
)
103106
override fun getOpacity() = PixelFormat.OPAQUE
104107

105108
override fun setColorFilter(colorFilter: ColorFilter?) {

library/src/main/kotlin/me/thanel/swipeactionview/animation/ScalableIconAnimator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ package me.thanel.swipeactionview.animation
1818

1919
import android.view.View
2020
import me.thanel.swipeactionview.utils.setScale
21+
import kotlin.math.min
2122

2223
class ScalableIconAnimator : SwipeActionViewAnimator {
2324
override fun onUpdateSwipeProgress(view: View, progress: Float, minActivationProgress: Float) {
2425
var scale = 0.65f
2526

2627
if (progress > minActivationProgress) {
2728
val xOverActivation = progress - minActivationProgress
28-
scale += Math.min(xOverActivation / 0.4f, 1f - scale)
29+
scale += min(xOverActivation / 0.4f, 1f - scale)
2930
}
3031

3132
view.setScale(scale)

library/src/main/kotlin/me/thanel/swipeactionview/utils/ViewUtils.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ internal fun View.isRightAligned(): Boolean {
4848
val absGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection)
4949
if (absGravity <= 0) return false
5050

51-
return absGravity and Gravity.END == Gravity.END ||
52-
absGravity and Gravity.RIGHT == Gravity.RIGHT
51+
return absGravity and Gravity.END == Gravity.END || absGravity and Gravity.RIGHT == Gravity.RIGHT
5352
}
5453

5554
/**

sample/src/main/java/me/thanel/swipeactionview/sample/MainActivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ public boolean onSwipedRight(@NonNull SwipeActionView swipeActionView) {
129129
swipeCustomLayout.setSwipeGestureListener(swipeGestureListener);
130130

131131

132-
133132
SwipeGestureListener completeGestureListener = new SwipeGestureListener() {
134133
@Override
135134
public boolean onSwipedHalfwayLeft(@NonNull SwipeActionView swipeActionView) {
@@ -171,8 +170,8 @@ public boolean onSwipedRight(@NonNull SwipeActionView swipeActionView) {
171170
private void showToast(Boolean swipedRight, Boolean wasHalfway) {
172171
int resId = swipedRight ? R.string.swiped_right : R.string.swiped_left;
173172
String text = getString(resId);
174-
if(wasHalfway) {
175-
text+= getString(R.string.swiped_halfway);
173+
if (wasHalfway) {
174+
text += getString(R.string.swiped_halfway);
176175
}
177176

178177
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();

0 commit comments

Comments
 (0)