mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-04-23 06:17:20 +02:00
handle long pressing icons at the desktop too
This commit is contained in:
parent
cc38bb4af4
commit
155e21188d
@ -22,6 +22,7 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
|||||||
import com.simplemobiletools.launcher.BuildConfig
|
import com.simplemobiletools.launcher.BuildConfig
|
||||||
import com.simplemobiletools.launcher.R
|
import com.simplemobiletools.launcher.R
|
||||||
import com.simplemobiletools.launcher.extensions.config
|
import com.simplemobiletools.launcher.extensions.config
|
||||||
|
import com.simplemobiletools.launcher.extensions.handleAppIconPopupMenu
|
||||||
import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB
|
import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB
|
||||||
import com.simplemobiletools.launcher.extensions.launchApp
|
import com.simplemobiletools.launcher.extensions.launchApp
|
||||||
import com.simplemobiletools.launcher.fragments.AllAppsFragment
|
import com.simplemobiletools.launcher.fragments.AllAppsFragment
|
||||||
@ -159,7 +160,31 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main_holder.performHapticFeedback()
|
main_holder.performHapticFeedback()
|
||||||
|
val clickedPackageName = home_screen_grid.gridClicked(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop)
|
||||||
|
if (clickedPackageName.isNotEmpty()) {
|
||||||
|
showHomeIconMenu(x, y, clickedPackageName)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
showMainLongPressMenu(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
val clickedPackageName = home_screen_grid.gridClicked(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop)
|
||||||
|
if (clickedPackageName.isNotEmpty()) {
|
||||||
|
launchApp(clickedPackageName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showHomeIconMenu(x: Float, y: Float, clickedPackageName: String) {
|
||||||
|
home_screen_popup_menu_anchor.x = x
|
||||||
|
home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_offset_y)
|
||||||
|
handleAppIconPopupMenu(home_screen_popup_menu_anchor, clickedPackageName)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showMainLongPressMenu(x: Float, y: Float) {
|
||||||
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)
|
||||||
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||||
@ -177,14 +202,6 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
|
||||||
home_screen_grid.gridClicked(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop) { packageName ->
|
|
||||||
launchApp(packageName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showWidgetsFragment() {
|
private fun showWidgetsFragment() {
|
||||||
showFragment(widgets_fragment)
|
showFragment(widgets_fragment)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
package com.simplemobiletools.launcher.extensions
|
package com.simplemobiletools.launcher.extensions
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
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
|
||||||
|
|
||||||
fun Activity.launchApp(packageName: String) {
|
fun Activity.launchApp(packageName: String) {
|
||||||
val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
|
val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
|
||||||
@ -11,3 +20,26 @@ fun Activity.launchApp(packageName: String) {
|
|||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Activity.launchAppInfo(packageName: String) {
|
||||||
|
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
|
||||||
|
data = Uri.fromParts("package", packageName, null)
|
||||||
|
startActivity(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Activity.handleAppIconPopupMenu(anchorView: View, appPackageName: String) {
|
||||||
|
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,11 +6,10 @@ import android.content.Intent
|
|||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.net.Uri
|
|
||||||
import android.provider.Settings
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.*
|
import android.view.MotionEvent
|
||||||
import android.widget.PopupMenu
|
import android.view.Surface
|
||||||
|
import android.view.WindowManager
|
||||||
import androidx.core.graphics.drawable.toBitmap
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
@ -19,10 +18,7 @@ import com.simplemobiletools.commons.views.MyGridLayoutManager
|
|||||||
import com.simplemobiletools.launcher.R
|
import com.simplemobiletools.launcher.R
|
||||||
import com.simplemobiletools.launcher.activities.MainActivity
|
import com.simplemobiletools.launcher.activities.MainActivity
|
||||||
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
|
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
|
||||||
import com.simplemobiletools.launcher.extensions.getColumnCount
|
import com.simplemobiletools.launcher.extensions.*
|
||||||
import com.simplemobiletools.launcher.extensions.getDrawableForPackageName
|
|
||||||
import com.simplemobiletools.launcher.extensions.launchApp
|
|
||||||
import com.simplemobiletools.launcher.extensions.launchersDB
|
|
||||||
import com.simplemobiletools.launcher.interfaces.AllAppsListener
|
import com.simplemobiletools.launcher.interfaces.AllAppsListener
|
||||||
import com.simplemobiletools.launcher.models.AppLauncher
|
import com.simplemobiletools.launcher.models.AppLauncher
|
||||||
import kotlinx.android.synthetic.main.all_apps_fragment.view.*
|
import kotlinx.android.synthetic.main.all_apps_fragment.view.*
|
||||||
@ -163,26 +159,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||||||
override fun onIconLongPressed(x: Float, y: Float, packageName: String) {
|
override fun onIconLongPressed(x: Float, y: Float, packageName: String) {
|
||||||
all_apps_popup_menu_anchor.x = x
|
all_apps_popup_menu_anchor.x = x
|
||||||
all_apps_popup_menu_anchor.y = y
|
all_apps_popup_menu_anchor.y = y
|
||||||
val contextTheme = ContextThemeWrapper(activity, activity!!.getPopupMenuTheme())
|
activity?.handleAppIconPopupMenu(all_apps_popup_menu_anchor, packageName)
|
||||||
PopupMenu(contextTheme, all_apps_popup_menu_anchor, Gravity.TOP or Gravity.END).apply {
|
|
||||||
inflate(R.menu.menu_app_icon)
|
|
||||||
setOnMenuItemClickListener { item ->
|
|
||||||
when (item.itemId) {
|
|
||||||
R.id.app_info -> {
|
|
||||||
launchAppInfo(packageName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun launchAppInfo(packageName: String) {
|
|
||||||
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
|
|
||||||
data = Uri.fromParts("package", packageName, null)
|
|
||||||
activity?.startActivity(this)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// taken from https://gist.github.com/maxjvh/a6ab15cbba9c82a5065d
|
// taken from https://gist.github.com/maxjvh/a6ab15cbba9c82a5065d
|
||||||
|
@ -83,12 +83,13 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun gridClicked(x: Float, y: Float, callback: (packageName: String) -> Unit) {
|
fun gridClicked(x: Float, y: Float): String {
|
||||||
for (gridItem in appIcons) {
|
for (appIcon in appIcons) {
|
||||||
if (x >= gridItem.left * rowWidth && x <= gridItem.right * rowWidth && y >= gridItem.top * rowHeight && y <= gridItem.bottom * rowHeight) {
|
if (x >= appIcon.left * rowWidth && x <= appIcon.right * rowWidth && y >= appIcon.top * rowHeight && y <= appIcon.bottom * rowHeight) {
|
||||||
callback(gridItem.packageName)
|
return appIcon.packageName
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user