mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-02-06 02:33:51 +01:00
add fling handling at showing/hiding all app icons
This commit is contained in:
parent
1b42712776
commit
5ef9c643c9
@ -4,21 +4,26 @@ import android.animation.ObjectAnimator
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.GestureDetector
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.animation.DecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import androidx.core.view.GestureDetectorCompat
|
||||||
import com.simplemobiletools.commons.extensions.appLaunched
|
import com.simplemobiletools.commons.extensions.appLaunched
|
||||||
import com.simplemobiletools.commons.extensions.realScreenSize
|
import com.simplemobiletools.commons.extensions.realScreenSize
|
||||||
import com.simplemobiletools.commons.extensions.statusBarHeight
|
import com.simplemobiletools.commons.extensions.statusBarHeight
|
||||||
import com.simplemobiletools.launcher.BuildConfig
|
import com.simplemobiletools.launcher.BuildConfig
|
||||||
import com.simplemobiletools.launcher.R
|
import com.simplemobiletools.launcher.R
|
||||||
import com.simplemobiletools.launcher.fragments.AllAppsFragment
|
import com.simplemobiletools.launcher.fragments.AllAppsFragment
|
||||||
|
import com.simplemobiletools.launcher.interfaces.FlingListener
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity() {
|
class MainActivity : SimpleActivity(), FlingListener {
|
||||||
var mTouchDownY = -1
|
private var mTouchDownY = -1
|
||||||
var mCurrentFragmentY = 0
|
private var mCurrentFragmentY = 0
|
||||||
private var mScreenHeight = 0
|
private var mScreenHeight = 0
|
||||||
|
private var mIgnoreUpEvent = false
|
||||||
|
private lateinit var mDetector: GestureDetectorCompat
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
useDynamicTheme = false
|
useDynamicTheme = false
|
||||||
@ -27,6 +32,8 @@ class MainActivity : SimpleActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
appLaunched(BuildConfig.APPLICATION_ID)
|
appLaunched(BuildConfig.APPLICATION_ID)
|
||||||
|
|
||||||
|
mDetector = GestureDetectorCompat(this, MyGestureListener(this))
|
||||||
window.setDecorFitsSystemWindows(false)
|
window.setDecorFitsSystemWindows(false)
|
||||||
(all_apps_fragment as AllAppsFragment).setupFragment(this)
|
(all_apps_fragment as AllAppsFragment).setupFragment(this)
|
||||||
mScreenHeight = realScreenSize.y
|
mScreenHeight = realScreenSize.y
|
||||||
@ -47,10 +54,12 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
|
mDetector.onTouchEvent(event)
|
||||||
when (event.actionMasked) {
|
when (event.actionMasked) {
|
||||||
MotionEvent.ACTION_DOWN -> {
|
MotionEvent.ACTION_DOWN -> {
|
||||||
mTouchDownY = event.y.toInt()
|
mTouchDownY = event.y.toInt()
|
||||||
mCurrentFragmentY = all_apps_fragment.y.toInt()
|
mCurrentFragmentY = all_apps_fragment.y.toInt()
|
||||||
|
mIgnoreUpEvent = false
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_MOVE -> {
|
MotionEvent.ACTION_MOVE -> {
|
||||||
@ -64,17 +73,57 @@ class MainActivity : SimpleActivity() {
|
|||||||
MotionEvent.ACTION_CANCEL,
|
MotionEvent.ACTION_CANCEL,
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
mTouchDownY = -1
|
mTouchDownY = -1
|
||||||
showAllAppsFragment()
|
if (!mIgnoreUpEvent) {
|
||||||
|
if (all_apps_fragment.y < mScreenHeight * 0.7) {
|
||||||
|
showAllAppsFragment()
|
||||||
|
} else {
|
||||||
|
hideAllAppsFragment()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun startHandlingTouches(touchDownY: Int) {
|
||||||
|
mTouchDownY = touchDownY
|
||||||
|
mCurrentFragmentY = all_apps_fragment.y.toInt()
|
||||||
|
mIgnoreUpEvent = false
|
||||||
|
}
|
||||||
|
|
||||||
private fun showAllAppsFragment() {
|
private fun showAllAppsFragment() {
|
||||||
ObjectAnimator.ofFloat(all_apps_fragment, "y", 0f).apply {
|
ObjectAnimator.ofFloat(all_apps_fragment, "y", 0f).apply {
|
||||||
interpolator = DecelerateInterpolator()
|
interpolator = DecelerateInterpolator()
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun hideAllAppsFragment() {
|
||||||
|
ObjectAnimator.ofFloat(all_apps_fragment, "y", mScreenHeight.toFloat()).apply {
|
||||||
|
interpolator = DecelerateInterpolator()
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MyGestureListener(private val flingListener: FlingListener) : GestureDetector.SimpleOnGestureListener() {
|
||||||
|
override fun onFling(event1: MotionEvent, event2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
|
||||||
|
if (velocityY > 0) {
|
||||||
|
flingListener.onFlingDown()
|
||||||
|
} else {
|
||||||
|
flingListener.onFlingUp()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFlingUp() {
|
||||||
|
mIgnoreUpEvent = true
|
||||||
|
showAllAppsFragment()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFlingDown() {
|
||||||
|
mIgnoreUpEvent = true
|
||||||
|
hideAllAppsFragment()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : RelativeLa
|
|||||||
if (touchDownY != -1) {
|
if (touchDownY != -1) {
|
||||||
shouldIntercept = touchDownY - event.y < 0 && all_apps_grid.computeVerticalScrollOffset() == 0
|
shouldIntercept = touchDownY - event.y < 0 && all_apps_grid.computeVerticalScrollOffset() == 0
|
||||||
if (shouldIntercept) {
|
if (shouldIntercept) {
|
||||||
activity?.mTouchDownY = touchDownY
|
activity?.startHandlingTouches(touchDownY)
|
||||||
activity?.mCurrentFragmentY = y.toInt()
|
|
||||||
touchDownY = -1
|
touchDownY = -1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.simplemobiletools.launcher.interfaces
|
||||||
|
|
||||||
|
interface FlingListener {
|
||||||
|
fun onFlingUp()
|
||||||
|
|
||||||
|
fun onFlingDown()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user