adding some swiping improvements
This commit is contained in:
parent
23e0bccabf
commit
1b42712776
|
@ -1,9 +1,11 @@
|
|||
package com.simplemobiletools.launcher.activities
|
||||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.MotionEvent
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import android.widget.FrameLayout
|
||||
import com.simplemobiletools.commons.extensions.appLaunched
|
||||
import com.simplemobiletools.commons.extensions.realScreenSize
|
||||
|
@ -14,9 +16,9 @@ import com.simplemobiletools.launcher.fragments.AllAppsFragment
|
|||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
private var mTouchDownY = 0
|
||||
var mTouchDownY = -1
|
||||
var mCurrentFragmentY = 0
|
||||
private var mScreenHeight = 0
|
||||
private var mCurrentFragmentY = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
useDynamicTheme = false
|
||||
|
@ -52,12 +54,27 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val diffY = mTouchDownY - event.y
|
||||
val newY = mCurrentFragmentY - diffY
|
||||
all_apps_fragment.y = Math.min(Math.max(0f, newY), mScreenHeight.toFloat())
|
||||
if (mTouchDownY != -1) {
|
||||
val diffY = mTouchDownY - event.y
|
||||
val newY = mCurrentFragmentY - diffY
|
||||
all_apps_fragment.y = Math.min(Math.max(0f, newY), mScreenHeight.toFloat())
|
||||
}
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_CANCEL,
|
||||
MotionEvent.ACTION_UP -> {
|
||||
mTouchDownY = -1
|
||||
showAllAppsFragment()
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun showAllAppsFragment() {
|
||||
ObjectAnimator.ofFloat(all_apps_fragment, "y", 0f).apply {
|
||||
interpolator = DecelerateInterpolator()
|
||||
start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.content.pm.PackageManager
|
|||
import android.graphics.drawable.Drawable
|
||||
import android.os.Process
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.Surface
|
||||
import android.view.WindowManager
|
||||
import android.widget.RelativeLayout
|
||||
|
@ -16,19 +17,29 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
|||
import com.simplemobiletools.commons.helpers.isRPlus
|
||||
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
||||
import com.simplemobiletools.launcher.R
|
||||
import com.simplemobiletools.launcher.activities.SimpleActivity
|
||||
import com.simplemobiletools.launcher.activities.MainActivity
|
||||
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
|
||||
import com.simplemobiletools.launcher.extensions.getColumnCount
|
||||
import com.simplemobiletools.launcher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.all_apps_fragment.view.*
|
||||
|
||||
class AllAppsFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
||||
private var activity: SimpleActivity? = null
|
||||
private var touchDownY = -1
|
||||
private var activity: MainActivity? = null
|
||||
|
||||
fun setupFragment(activity: SimpleActivity) {
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
fun setupFragment(activity: MainActivity) {
|
||||
this.activity = activity
|
||||
getLaunchers()
|
||||
setBackgroundColor(activity.getProperBackgroundColor())
|
||||
|
||||
all_apps_grid.setOnTouchListener { v, event ->
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
|
||||
touchDownY = -1
|
||||
}
|
||||
|
||||
return@setOnTouchListener false
|
||||
}
|
||||
}
|
||||
|
||||
fun onConfigurationChanged() {
|
||||
|
@ -42,6 +53,22 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : RelativeLa
|
|||
setupAdapter(launchers)
|
||||
}
|
||||
|
||||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
||||
var shouldIntercept = false
|
||||
if (touchDownY != -1) {
|
||||
shouldIntercept = touchDownY - event.y < 0 && all_apps_grid.computeVerticalScrollOffset() == 0
|
||||
if (shouldIntercept) {
|
||||
activity?.mTouchDownY = touchDownY
|
||||
activity?.mCurrentFragmentY = y.toInt()
|
||||
touchDownY = -1
|
||||
}
|
||||
} else {
|
||||
touchDownY = event.y.toInt()
|
||||
}
|
||||
|
||||
return shouldIntercept
|
||||
}
|
||||
|
||||
@SuppressLint("WrongConstant")
|
||||
private fun getLaunchers() {
|
||||
val allApps = ArrayList<AppLauncher>()
|
||||
|
|
Loading…
Reference in New Issue