mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-05-23 22:04:17 +02:00
add a new menu button for removing icons from the home screen
This commit is contained in:
parent
06738b595c
commit
3441a84d02
@ -177,7 +177,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
if (!launchers.map { it.packageName }.contains(packageName)) {
|
if (!launchers.map { it.packageName }.contains(packageName)) {
|
||||||
hasDeletedAnything = true
|
hasDeletedAnything = true
|
||||||
launchersDB.deleteApp(packageName)
|
launchersDB.deleteApp(packageName)
|
||||||
homeScreenGridItemsDB.deleteItem(packageName)
|
homeScreenGridItemsDB.deleteByPackageName(packageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,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)
|
showHomeIconMenu(x, y - resources.getDimension(R.dimen.icon_long_press_anchor_offset_y), clickedGridItem, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,15 +251,15 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getGridTouchedX(x: Float) = Math.min(Math.max(x.toInt() - home_screen_grid.marginLeft, 0), home_screen_grid.width).toInt()
|
private fun getGridTouchedX(x: Float) = Math.min(Math.max(x.toInt() - home_screen_grid.marginLeft, 0), home_screen_grid.width)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
fun showHomeIconMenu(x: Float, y: Float, gridItem: HomeScreenGridItem) {
|
fun showHomeIconMenu(x: Float, y: Float, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean) {
|
||||||
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
|
||||||
mOpenPopupMenu = handleGridItemPopupMenu(home_screen_popup_menu_anchor, gridItem.packageName)
|
mOpenPopupMenu = handleGridItemPopupMenu(home_screen_popup_menu_anchor, gridItem, isOnAllAppsFragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showMainLongPressMenu(x: Float, y: Float) {
|
private fun showMainLongPressMenu(x: Float, y: Float) {
|
||||||
@ -278,15 +278,17 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleGridItemPopupMenu(anchorView: View, appPackageName: String): PopupMenu {
|
private fun handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean): PopupMenu {
|
||||||
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||||
return 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)
|
||||||
|
menu.findItem(R.id.remove).isVisible = !isOnAllAppsFragment
|
||||||
setOnMenuItemClickListener { item ->
|
setOnMenuItemClickListener { item ->
|
||||||
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.app_info -> launchAppInfo(appPackageName)
|
R.id.app_info -> launchAppInfo(gridItem.packageName)
|
||||||
R.id.uninstall -> uninstallApp(appPackageName)
|
R.id.remove -> home_screen_grid.removeAppIcon(gridItem.id!!)
|
||||||
|
R.id.uninstall -> uninstallApp(gridItem.packageName)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -128,7 +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)
|
activity?.showHomeIconMenu(x, y, gridItem, true)
|
||||||
ignoreTouches = true
|
ignoreTouches = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,9 @@ interface HomeScreenGridItemsDao {
|
|||||||
@Query("UPDATE home_screen_grid_items SET `left` = :left, `top` = :top, `right` = :right, `bottom` = :bottom WHERE id = :id")
|
@Query("UPDATE home_screen_grid_items SET `left` = :left, `top` = :top, `right` = :right, `bottom` = :bottom WHERE id = :id")
|
||||||
fun updateAppPosition(left: Int, top: Int, right: Int, bottom: Int, id: Long)
|
fun updateAppPosition(left: Int, top: Int, right: Int, bottom: Int, id: Long)
|
||||||
|
|
||||||
|
@Query("DELETE FROM home_screen_grid_items WHERE id = :id")
|
||||||
|
fun deleteById(id: Long)
|
||||||
|
|
||||||
@Query("DELETE FROM home_screen_grid_items WHERE package_name = :packageName")
|
@Query("DELETE FROM home_screen_grid_items WHERE package_name = :packageName")
|
||||||
fun deleteItem(packageName: String)
|
fun deleteByPackageName(packageName: String)
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,14 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun removeAppIcon(iconId: Long) {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
context.homeScreenGridItemsDB.deleteById(iconId)
|
||||||
|
gridItems.removeIf { it.id == iconId }
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun itemDraggingStarted(draggedGridItem: HomeScreenGridItem) {
|
fun itemDraggingStarted(draggedGridItem: HomeScreenGridItem) {
|
||||||
draggedItem = draggedGridItem
|
draggedItem = draggedGridItem
|
||||||
invalidate()
|
invalidate()
|
||||||
|
@ -6,6 +6,11 @@
|
|||||||
android:icon="@drawable/ic_info_vector"
|
android:icon="@drawable/ic_info_vector"
|
||||||
android:title="@string/app_info"
|
android:title="@string/app_info"
|
||||||
app:showAsAction="always" />
|
app:showAsAction="always" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/remove"
|
||||||
|
android:icon="@drawable/ic_cross_vector"
|
||||||
|
android:title="@string/remove"
|
||||||
|
app:showAsAction="always" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/uninstall"
|
android:id="@+id/uninstall"
|
||||||
android:icon="@drawable/ic_delete_vector"
|
android:icon="@drawable/ic_delete_vector"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="launcher_icon_size">55dp</dimen>
|
<dimen name="launcher_icon_size">55dp</dimen>
|
||||||
<dimen name="icon_long_press_anchor_offset_y">100dp</dimen>
|
<dimen name="icon_long_press_anchor_offset_y">150dp</dimen>
|
||||||
<dimen name="home_long_press_anchor_offset_y">50dp</dimen>
|
<dimen name="home_long_press_anchor_offset_y">50dp</dimen>
|
||||||
<dimen name="widget_preview_size">140dp</dimen>
|
<dimen name="widget_preview_size">140dp</dimen>
|
||||||
<dimen name="icon_side_margin">10dp</dimen>
|
<dimen name="icon_side_margin">10dp</dimen>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user