handle long pressing icons at the desktop too

This commit is contained in:
tibbi
2022-09-18 20:58:38 +02:00
parent cc38bb4af4
commit 155e21188d
4 changed files with 68 additions and 41 deletions

View File

@ -1,7 +1,16 @@
package com.simplemobiletools.launcher.extensions
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.launcher.R
fun Activity.launchApp(packageName: String) {
val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
@ -11,3 +20,26 @@ fun Activity.launchApp(packageName: String) {
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()
}
}