aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-07-05 23:30:09 -0700
committerAllan Wang <me@allanwang.ca>2017-07-05 23:30:09 -0700
commite803969433b56e7e6ef4b02ed01aaa2e410eb1f9 (patch)
tree50c42e4ecc58bef35f4407cdce42f5154b9b42a2 /core/src/main/kotlin/ca
parente3a12337d67802e79c9e7b20d96dff09118b8fc7 (diff)
downloadkau-e803969433b56e7e6ef4b02ed01aaa2e410eb1f9.tar.gz
kau-e803969433b56e7e6ef4b02ed01aaa2e410eb1f9.tar.bz2
kau-e803969433b56e7e6ef4b02ed01aaa2e410eb1f9.zip
Allow for sensitivity config
Diffstat (limited to 'core/src/main/kotlin/ca')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt7
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt1
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java21
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelperExtras.java6
4 files changed, 35 insertions, 0 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
index 48d7188..4473e23 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
@@ -132,6 +132,12 @@ class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs: Attribu
dragHelper.maxVelocity = value
}
+ override var sensitivity: Float
+ get() = dragHelper.sensitivity
+ set(value) {
+ dragHelper.setSensitivity(context, value)
+ }
+
init {
dragHelper = ViewDragHelper.create(this, ViewDragCallback())
val density = resources.displayMetrics.density
@@ -141,6 +147,7 @@ class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs: Attribu
minVelocity = minVel
// maxVelocity = 2.5f * minVel
edgeFlag = edgeFlag
+ sensitivity = 0.3f
addListener(chromeFadeListener)
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt
index c4e637b..cb28342 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt
@@ -59,6 +59,7 @@ interface SwipeBackContract {
var disallowIntercept: Boolean
var minVelocity: Float
var maxVelocity: Float
+ var sensitivity:Float
fun setEdgeSizePercent(swipeEdgePercent: Float)
fun addListener(listener: SwipeListener)
fun removeListener(listener: SwipeListener)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java b/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java
index 6b34af3..c6ff116 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java
@@ -385,6 +385,27 @@ public class ViewDragHelper implements ViewDragHelperExtras {
}
/**
+ * Sets the sensitivity of the dragger.
+ *
+ * @param context The application context.
+ * @param sensitivity value between 0 and 1, the final value for touchSlop =
+ * ViewConfiguration.getScaledTouchSlop * (1 / s);
+ * 1 is the default
+ */
+ @Override
+ public void setSensitivity(Context context, float sensitivity) {
+ float s = Math.max(0f, Math.min(1.0f, sensitivity));
+ ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
+ mTouchSlop = (int) (viewConfiguration.getScaledTouchSlop() * (1 / s));
+ }
+
+ @Override
+ public float getSensitivity() {
+ return mTouchSlop;
+ }
+
+
+ /**
* Set the minimum velocity that will be detected as having a magnitude greater than zero
* in pixels per second. Callback methods accepting a velocity will be clamped appropriately.
*
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelperExtras.java b/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelperExtras.java
index 2ee7ea3..a99310f 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelperExtras.java
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelperExtras.java
@@ -1,5 +1,7 @@
package ca.allanwang.kau.swipe;
+import android.content.Context;
+
/**
* Created by Allan Wang on 2017-07-05.
* <p>
@@ -20,4 +22,8 @@ interface ViewDragHelperExtras {
float getMaxVelocity();
+ void setSensitivity(Context context, float sensitivity);
+
+ float getSensitivity();
+
}