Skip to content

Commit e0bb106

Browse files
committed
Added DPI calculation for GestureManager distance variables. DPI values are stored with Constants.
1 parent d6c730f commit e0bb106

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

app/src/main/java/com/github/droidworksstudio/mlauncher/data/Constants.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ object Constants {
6161
const val MAX_THRESHOLD = 100 // pixels
6262
var SHORT_SWIPE_THRESHOLD = 0f // pixels
6363
var LONG_SWIPE_THRESHOLD = 0f // pixels
64+
var USR_DPIX = 0
65+
var USR_DPIY = 0
6466

6567

6668
// Update MAX_HOME_PAGES dynamically based on MAX_HOME_APPS
@@ -94,8 +96,11 @@ object Constants {
9496
val prefs = Prefs(context)
9597
val metrics = context.resources.displayMetrics
9698

97-
val screenWidthInches = metrics.widthPixels / metrics.xdpi
98-
val screenHeightInches = metrics.heightPixels / metrics.ydpi
99+
USR_DPIX = metrics.xdpi
100+
USR_DPIY = metrics.ydpi
101+
102+
val screenWidthInches = metrics.widthPixels / USR_DPIX
103+
val screenHeightInches = metrics.heightPixels / USR_DPIY
99104

100105
if (direction.equals("left", true) || direction.equals("right", true)) {
101106
LONG_SWIPE_THRESHOLD = screenWidthInches * prefs.longSwipeThreshold

app/src/main/java/com/github/droidworksstudio/mlauncher/listener/GestureManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class GestureManager(
134134
val longThreshold = Constants.LONG_SWIPE_THRESHOLD
135135
val velocityThreshold = Constants.SWIPE_VELOCITY_THRESHOLD
136136

137-
val distance = if (isHorizontalSwipe) abs(diffX) else abs(diffY)
137+
val distance = if (isHorizontalSwipe) (abs(diffX)/Constants.USR_DPIX) else (abs(diffY)/Constants.USR_DPIY)
138138
val isLongSwipe = distance > longThreshold
139139
val isShortSwipe = distance in (shortThreshold + 1)..longThreshold
140140

0 commit comments

Comments
 (0)