mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-06-05 21:59:15 +02:00
hide the menu at long pressing an item and moving gesture
This commit is contained in:
@ -137,6 +137,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
mOpenPopupMenu?.dismiss()
|
mOpenPopupMenu?.dismiss()
|
||||||
mOpenPopupMenu = null
|
mOpenPopupMenu = null
|
||||||
home_screen_grid.itemDraggingStarted(mLongPressedIcon!!)
|
home_screen_grid.itemDraggingStarted(mLongPressedIcon!!)
|
||||||
|
hideFragment(all_apps_fragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mTouchDownY != -1 && !mIgnoreMoveEvents) {
|
if (mTouchDownY != -1 && !mIgnoreMoveEvents) {
|
||||||
@ -151,6 +152,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
mTouchDownY = -1
|
mTouchDownY = -1
|
||||||
mIgnoreMoveEvents = false
|
mIgnoreMoveEvents = false
|
||||||
mLongPressedIcon = null
|
mLongPressedIcon = null
|
||||||
|
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
||||||
home_screen_grid.itemDraggingStopped(getGridTouchedX(event.x), getGridTouchedY(event.y))
|
home_screen_grid.itemDraggingStopped(getGridTouchedX(event.x), getGridTouchedY(event.y))
|
||||||
if (!mIgnoreUpEvent) {
|
if (!mIgnoreUpEvent) {
|
||||||
if (all_apps_fragment.y < mScreenHeight * 0.7) {
|
if (all_apps_fragment.y < mScreenHeight * 0.7) {
|
||||||
@ -233,7 +235,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
main_holder.performHapticFeedback()
|
main_holder.performHapticFeedback()
|
||||||
val clickedGridItem = home_screen_grid.isClickingGridItem(getGridTouchedX(x), getGridTouchedY(y))
|
val clickedGridItem = home_screen_grid.isClickingGridItem(getGridTouchedX(x), getGridTouchedY(y))
|
||||||
if (clickedGridItem != null) {
|
if (clickedGridItem != null) {
|
||||||
showHomeIconMenu(x, y - resources.getDimension(R.dimen.icon_long_press_anchor_offset_y), clickedGridItem, false)
|
showHomeIconMenu(x, y - resources.getDimension(R.dimen.icon_long_press_anchor_offset_y), clickedGridItem)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,11 +255,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
|
|
||||||
private fun getGridTouchedY(y: Float) = Math.min(Math.max(y.toInt() - home_screen_grid.marginTop, 0), home_screen_grid.height).toInt()
|
private fun getGridTouchedY(y: Float) = Math.min(Math.max(y.toInt() - home_screen_grid.marginTop, 0), home_screen_grid.height).toInt()
|
||||||
|
|
||||||
fun showHomeIconMenu(x: Float, y: Float, gridItem: HomeScreenGridItem, isFromAllAppsFragment: Boolean) {
|
fun showHomeIconMenu(x: Float, y: Float, gridItem: HomeScreenGridItem) {
|
||||||
if (isFromAllAppsFragment) {
|
|
||||||
hideFragment(all_apps_fragment)
|
|
||||||
}
|
|
||||||
|
|
||||||
mLongPressedIcon = gridItem
|
mLongPressedIcon = gridItem
|
||||||
home_screen_popup_menu_anchor.x = x
|
home_screen_popup_menu_anchor.x = x
|
||||||
home_screen_popup_menu_anchor.y = y
|
home_screen_popup_menu_anchor.y = y
|
||||||
@ -280,6 +278,27 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleGridItemPopupMenu(anchorView: View, appPackageName: String): PopupMenu {
|
||||||
|
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||||
|
return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply {
|
||||||
|
inflate(R.menu.menu_app_icon)
|
||||||
|
setOnMenuItemClickListener { item ->
|
||||||
|
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
||||||
|
when (item.itemId) {
|
||||||
|
R.id.app_info -> launchAppInfo(appPackageName)
|
||||||
|
R.id.uninstall -> uninstallApp(appPackageName)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
setOnDismissListener {
|
||||||
|
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
||||||
|
}
|
||||||
|
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun showWidgetsFragment() {
|
private fun showWidgetsFragment() {
|
||||||
showFragment(widgets_fragment)
|
showFragment(widgets_fragment)
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,7 @@ import android.app.Activity
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.view.ContextThemeWrapper
|
|
||||||
import android.view.Gravity
|
|
||||||
import android.view.View
|
|
||||||
import android.widget.PopupMenu
|
|
||||||
import com.simplemobiletools.commons.extensions.getPopupMenuTheme
|
|
||||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
import com.simplemobiletools.launcher.R
|
|
||||||
import com.simplemobiletools.launcher.helpers.UNINSTALL_APP_REQUEST_CODE
|
import com.simplemobiletools.launcher.helpers.UNINSTALL_APP_REQUEST_CODE
|
||||||
|
|
||||||
fun Activity.launchApp(packageName: String) {
|
fun Activity.launchApp(packageName: String) {
|
||||||
@ -35,18 +29,3 @@ fun Activity.uninstallApp(packageName: String) {
|
|||||||
startActivityForResult(this, UNINSTALL_APP_REQUEST_CODE)
|
startActivityForResult(this, UNINSTALL_APP_REQUEST_CODE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.handleGridItemPopupMenu(anchorView: View, appPackageName: String): PopupMenu {
|
|
||||||
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
|
||||||
return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply {
|
|
||||||
inflate(R.menu.menu_app_icon)
|
|
||||||
setOnMenuItemClickListener { item ->
|
|
||||||
when (item.itemId) {
|
|
||||||
R.id.app_info -> launchAppInfo(appPackageName)
|
|
||||||
R.id.uninstall -> uninstallApp(appPackageName)
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -21,6 +21,7 @@ import kotlinx.android.synthetic.main.all_apps_fragment.view.*
|
|||||||
|
|
||||||
class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), AllAppsListener {
|
class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), AllAppsListener {
|
||||||
private var touchDownY = -1
|
private var touchDownY = -1
|
||||||
|
var ignoreTouches = false
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun setupFragment(activity: MainActivity) {
|
override fun setupFragment(activity: MainActivity) {
|
||||||
@ -49,6 +50,10 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
||||||
|
if (ignoreTouches) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
var shouldIntercept = false
|
var shouldIntercept = false
|
||||||
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
|
||||||
@ -123,6 +128,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||||||
|
|
||||||
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
|
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
|
||||||
val gridItem = HomeScreenGridItem(null, -1, -1, -1, 1, appLauncher.packageName, appLauncher.title)
|
val gridItem = HomeScreenGridItem(null, -1, -1, -1, 1, appLauncher.packageName, appLauncher.title)
|
||||||
activity?.showHomeIconMenu(x, y, gridItem, true)
|
activity?.showHomeIconMenu(x, y, gridItem)
|
||||||
|
ignoreTouches = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user