mirror of
				https://github.com/SimpleMobileTools/Simple-Launcher.git
				synced 2025-06-05 21:59:15 +02:00 
			
		
		
		
	close home screen popup menu on move event
This commit is contained in:
		| @@ -43,6 +43,8 @@ class MainActivity : SimpleActivity(), FlingListener { | |||||||
|     private var mScreenHeight = 0 |     private var mScreenHeight = 0 | ||||||
|     private var mIgnoreUpEvent = false |     private var mIgnoreUpEvent = false | ||||||
|     private var mIgnoreMoveEvents = false |     private var mIgnoreMoveEvents = false | ||||||
|  |     private var mIsIconLongPressed = false | ||||||
|  |     private var mOpenPopupMenu: PopupMenu? = null | ||||||
|     private var mCachedLaunchers = ArrayList<AppLauncher>() |     private var mCachedLaunchers = ArrayList<AppLauncher>() | ||||||
|  |  | ||||||
|     private lateinit var mDetector: GestureDetectorCompat |     private lateinit var mDetector: GestureDetectorCompat | ||||||
| @@ -131,6 +133,11 @@ class MainActivity : SimpleActivity(), FlingListener { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             MotionEvent.ACTION_MOVE -> { |             MotionEvent.ACTION_MOVE -> { | ||||||
|  |                 if (mIsIconLongPressed && mOpenPopupMenu != null) { | ||||||
|  |                     mOpenPopupMenu?.dismiss() | ||||||
|  |                     mOpenPopupMenu = null | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 if (mTouchDownY != -1 && !mIgnoreMoveEvents) { |                 if (mTouchDownY != -1 && !mIgnoreMoveEvents) { | ||||||
|                     val diffY = mTouchDownY - event.y |                     val diffY = mTouchDownY - event.y | ||||||
|                     val newY = mCurrentFragmentY - diffY |                     val newY = mCurrentFragmentY - diffY | ||||||
| @@ -142,6 +149,7 @@ class MainActivity : SimpleActivity(), FlingListener { | |||||||
|             MotionEvent.ACTION_UP -> { |             MotionEvent.ACTION_UP -> { | ||||||
|                 mTouchDownY = -1 |                 mTouchDownY = -1 | ||||||
|                 mIgnoreMoveEvents = false |                 mIgnoreMoveEvents = false | ||||||
|  |                 mIsIconLongPressed = false | ||||||
|                 if (!mIgnoreUpEvent) { |                 if (!mIgnoreUpEvent) { | ||||||
|                     if (all_apps_fragment.y < mScreenHeight * 0.7) { |                     if (all_apps_fragment.y < mScreenHeight * 0.7) { | ||||||
|                         showFragment(all_apps_fragment) |                         showFragment(all_apps_fragment) | ||||||
| @@ -221,8 +229,9 @@ class MainActivity : SimpleActivity(), FlingListener { | |||||||
|  |  | ||||||
|         mIgnoreMoveEvents = true |         mIgnoreMoveEvents = true | ||||||
|         main_holder.performHapticFeedback() |         main_holder.performHapticFeedback() | ||||||
|         val clickedPackageName = home_screen_grid.gridClicked(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop) |         val clickedPackageName = home_screen_grid.isClickingIcon(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop) | ||||||
|         if (clickedPackageName.isNotEmpty()) { |         if (clickedPackageName.isNotEmpty()) { | ||||||
|  |             mIsIconLongPressed = true | ||||||
|             showHomeIconMenu(x, y, clickedPackageName) |             showHomeIconMenu(x, y, clickedPackageName) | ||||||
|             return |             return | ||||||
|         } |         } | ||||||
| @@ -232,7 +241,7 @@ class MainActivity : SimpleActivity(), FlingListener { | |||||||
|  |  | ||||||
|     fun homeScreenClicked(x: Float, y: Float) { |     fun homeScreenClicked(x: Float, y: Float) { | ||||||
|         if (x >= home_screen_grid.left && x <= home_screen_grid.right && y >= home_screen_grid.top && y <= home_screen_grid.bottom) { |         if (x >= home_screen_grid.left && x <= home_screen_grid.right && y >= home_screen_grid.top && y <= home_screen_grid.bottom) { | ||||||
|             val clickedPackageName = home_screen_grid.gridClicked(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop) |             val clickedPackageName = home_screen_grid.isClickingIcon(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop) | ||||||
|             if (clickedPackageName.isNotEmpty()) { |             if (clickedPackageName.isNotEmpty()) { | ||||||
|                 launchApp(clickedPackageName) |                 launchApp(clickedPackageName) | ||||||
|             } |             } | ||||||
| @@ -242,7 +251,7 @@ class MainActivity : SimpleActivity(), FlingListener { | |||||||
|     private fun showHomeIconMenu(x: Float, y: Float, clickedPackageName: String) { |     private fun showHomeIconMenu(x: Float, y: Float, clickedPackageName: String) { | ||||||
|         home_screen_popup_menu_anchor.x = x |         home_screen_popup_menu_anchor.x = x | ||||||
|         home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_offset_y) |         home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_offset_y) | ||||||
|         handleAppIconPopupMenu(home_screen_popup_menu_anchor, clickedPackageName) |         mOpenPopupMenu = handleAppIconPopupMenu(home_screen_popup_menu_anchor, clickedPackageName) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun showMainLongPressMenu(x: Float, y: Float) { |     private fun showMainLongPressMenu(x: Float, y: Float) { | ||||||
|   | |||||||
| @@ -36,9 +36,9 @@ fun Activity.uninstallApp(packageName: String) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| fun Activity.handleAppIconPopupMenu(anchorView: View, appPackageName: String) { | fun Activity.handleAppIconPopupMenu(anchorView: View, appPackageName: String): PopupMenu { | ||||||
|     val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme()) |     val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme()) | ||||||
|     PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply { |     return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply { | ||||||
|         inflate(R.menu.menu_app_icon) |         inflate(R.menu.menu_app_icon) | ||||||
|         setOnMenuItemClickListener { item -> |         setOnMenuItemClickListener { item -> | ||||||
|             when (item.itemId) { |             when (item.itemId) { | ||||||
|   | |||||||
| @@ -110,7 +110,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun gridClicked(x: Float, y: Float): String { |     fun isClickingIcon(x: Float, y: Float): String { | ||||||
|         for (appIcon in appIcons) { |         for (appIcon in appIcons) { | ||||||
|             if (x >= appIcon.left * rowWidth && x <= appIcon.right * rowWidth && y >= appIcon.top * rowHeight && y <= appIcon.bottom * rowHeight) { |             if (x >= appIcon.left * rowWidth && x <= appIcon.right * rowWidth && y >= appIcon.top * rowHeight && y <= appIcon.bottom * rowHeight) { | ||||||
|                 return appIcon.packageName |                 return appIcon.packageName | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user