Fix: Fixed the swiping gestures.
This commit is contained in:
@@ -67,6 +67,37 @@ internal open class OnSwipeTouchListener(c: Context?) : OnTouchListener {
|
||||
super.onLongPress(e)
|
||||
}
|
||||
|
||||
// Detecting swipe or drag movement
|
||||
override fun onScroll(
|
||||
event1: MotionEvent?,
|
||||
event2: MotionEvent,
|
||||
distanceX: Float,
|
||||
distanceY: Float
|
||||
): Boolean {
|
||||
try {
|
||||
if (event1 == null) return false
|
||||
|
||||
val diffX = event2.x - event1.x
|
||||
val diffY = event2.y - event1.y
|
||||
|
||||
// Horizontal swipe
|
||||
if (abs(diffX) > abs(diffY)) {
|
||||
if (abs(diffX) > swipeThreshold && abs(distanceX) > swipeVelocityThreshold) {
|
||||
if (diffX > 0) onSwipeRight() else onSwipeLeft()
|
||||
}
|
||||
}
|
||||
// Vertical swipe
|
||||
else {
|
||||
if (abs(diffY) > swipeThreshold && abs(distanceY) > swipeVelocityThreshold) {
|
||||
if (diffY > 0) onSwipeDown() else onSwipeUp()
|
||||
}
|
||||
}
|
||||
} catch (_: NullPointerException) {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onFling(
|
||||
event1: MotionEvent?,
|
||||
event2: MotionEvent,
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.github.droidworksstudio.launcher.listener
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.GestureDetector
|
||||
import android.view.GestureDetector.SimpleOnGestureListener
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.View.OnTouchListener
|
||||
import kotlin.math.abs
|
||||
|
||||
internal open class ViewSwipeTouchListener(c: Context?, v: View) : OnTouchListener {
|
||||
private val gestureDetector: GestureDetector = GestureDetector(c, GestureListener(v))
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
|
||||
when (motionEvent.action) {
|
||||
MotionEvent.ACTION_DOWN -> view.isPressed = true
|
||||
MotionEvent.ACTION_UP -> view.isPressed = false
|
||||
}
|
||||
return gestureDetector.onTouchEvent(motionEvent)
|
||||
}
|
||||
|
||||
private inner class GestureListener(private val view: View) : SimpleOnGestureListener() {
|
||||
private val swipeThreshold: Int = 100
|
||||
private val swipeVelocityThreshold: Int = 100
|
||||
|
||||
override fun onDown(e: MotionEvent): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
||||
onClick(view)
|
||||
return super.onSingleTapUp(e)
|
||||
}
|
||||
|
||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||
onDoubleClick()
|
||||
return super.onDoubleTap(e)
|
||||
}
|
||||
|
||||
override fun onLongPress(e: MotionEvent) {
|
||||
onLongClick(view)
|
||||
super.onLongPress(e)
|
||||
}
|
||||
|
||||
override fun onFling(
|
||||
event1: MotionEvent?,
|
||||
event2: MotionEvent,
|
||||
velocityX: Float,
|
||||
velocityY: Float
|
||||
): Boolean {
|
||||
try {
|
||||
val diffY = event2.y - event1!!.y
|
||||
val diffX = event2.x - event1.x
|
||||
if (abs(diffX) > abs(diffY)) {
|
||||
if (abs(diffX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold) {
|
||||
if (diffX > 0) onSwipeRight() else onSwipeLeft()
|
||||
}
|
||||
} else {
|
||||
if (abs(diffY) > swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
|
||||
if (diffY < 0) onSwipeUp() else onSwipeDown()
|
||||
}
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
open fun onSwipeRight() {}
|
||||
open fun onSwipeLeft() {}
|
||||
open fun onSwipeUp() {}
|
||||
open fun onSwipeDown() {}
|
||||
open fun onLongClick(view: View) {}
|
||||
open fun onDoubleClick() {}
|
||||
open fun onClick(view: View) {}
|
||||
}
|
||||
@@ -20,9 +20,7 @@ import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.appcompat.widget.LinearLayoutCompat
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
@@ -48,7 +46,6 @@ import com.github.droidworksstudio.launcher.helper.PreferenceHelper
|
||||
import com.github.droidworksstudio.launcher.listener.OnItemClickedListener
|
||||
import com.github.droidworksstudio.launcher.listener.OnSwipeTouchListener
|
||||
import com.github.droidworksstudio.launcher.listener.ScrollEventListener
|
||||
import com.github.droidworksstudio.launcher.listener.ViewSwipeTouchListener
|
||||
import com.github.droidworksstudio.launcher.ui.bottomsheetdialog.AppInfoBottomSheetFragment
|
||||
import com.github.droidworksstudio.launcher.utils.Constants
|
||||
import com.github.droidworksstudio.launcher.viewmodel.AppViewModel
|
||||
@@ -234,16 +231,6 @@ class HomeFragment : Fragment(),
|
||||
clock.setOnClickListener { context.launchClock() }
|
||||
date.setOnClickListener { context.launchCalendar() }
|
||||
battery.setOnClickListener { context.openBatteryManager() }
|
||||
|
||||
val appListViews =
|
||||
layoutInflater.inflate(R.layout.item_home, null) as ConstraintLayout
|
||||
appListViews.apply {
|
||||
// Find the TextView by its ID
|
||||
val appLayout = findViewById<LinearLayoutCompat>(R.id.linear_layout)
|
||||
|
||||
// Set the OnTouchListener on the TextView
|
||||
appLayout.setOnTouchListener(getHomeAppsGestureListener(context, this))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,46 +365,6 @@ class HomeFragment : Fragment(),
|
||||
}
|
||||
}
|
||||
|
||||
private fun getHomeAppsGestureListener(context: Context, view: View): View.OnTouchListener {
|
||||
return object : ViewSwipeTouchListener(context, view) {
|
||||
override fun onLongClick(view: View) {
|
||||
super.onLongClick(view)
|
||||
trySettings()
|
||||
return
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onDoubleClick() {
|
||||
super.onDoubleClick()
|
||||
handleOtherAction(preferenceHelper.doubleTapAction, Constants.Swipe.DoubleTap)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onSwipeUp() {
|
||||
super.onSwipeUp()
|
||||
handleOtherAction(preferenceHelper.swipeUpAction, Constants.Swipe.Up)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onSwipeDown() {
|
||||
super.onSwipeDown()
|
||||
handleOtherAction(preferenceHelper.swipeDownAction, Constants.Swipe.Down)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onSwipeLeft() {
|
||||
super.onSwipeLeft()
|
||||
handleOtherAction(preferenceHelper.swipeLeftAction, Constants.Swipe.Left)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onSwipeRight() {
|
||||
super.onSwipeRight()
|
||||
handleOtherAction(preferenceHelper.swipeRightAction, Constants.Swipe.Right)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun openApp(packageName: String) {
|
||||
val context = binding.root.context
|
||||
val pm: PackageManager = context.packageManager
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:id="@+id/blockView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
|
||||
Reference in New Issue
Block a user