allow opening App info by long pressing an app icon

This commit is contained in:
tibbi 2022-09-16 20:10:46 +02:00
parent 7ca977349b
commit e2a99984f3
8 changed files with 64 additions and 9 deletions

View File

@ -123,10 +123,10 @@ class MainActivity : SimpleActivity(), FlingListener {
fun homeScreenLongPressed(x: Float, y: Float) { fun homeScreenLongPressed(x: Float, y: Float) {
main_holder.performHapticFeedback() main_holder.performHapticFeedback()
popup_menu_anchor.x = x home_screen_popup_menu_anchor.x = x
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())
PopupMenu(contextTheme, popup_menu_anchor, Gravity.TOP or Gravity.END).apply { PopupMenu(contextTheme, home_screen_popup_menu_anchor, Gravity.TOP or Gravity.END).apply {
inflate(R.menu.menu_home_screen) inflate(R.menu.menu_home_screen)
setOnMenuItemClickListener { item -> setOnMenuItemClickListener { item ->
when (item.itemId) { when (item.itemId) {

View File

@ -12,6 +12,7 @@ import com.simplemobiletools.commons.extensions.realScreenSize
import com.simplemobiletools.launcher.R import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.activities.SimpleActivity import com.simplemobiletools.launcher.activities.SimpleActivity
import com.simplemobiletools.launcher.extensions.getColumnCount import com.simplemobiletools.launcher.extensions.getColumnCount
import com.simplemobiletools.launcher.interfaces.AllAppsListener
import com.simplemobiletools.launcher.models.AppLauncher import com.simplemobiletools.launcher.models.AppLauncher
import kotlinx.android.synthetic.main.item_launcher_label.view.* import kotlinx.android.synthetic.main.item_launcher_label.view.*
@ -19,6 +20,7 @@ class LaunchersAdapter(
val activity: SimpleActivity, val activity: SimpleActivity,
val launchers: ArrayList<AppLauncher>, val launchers: ArrayList<AppLauncher>,
val fastScroller: RecyclerViewFastScroller, val fastScroller: RecyclerViewFastScroller,
val allAppsListener: AllAppsListener,
val itemClick: (Any) -> Unit val itemClick: (Any) -> Unit
) : RecyclerView.Adapter<LaunchersAdapter.ViewHolder>(), RecyclerViewFastScroller.OnPopupTextUpdate { ) : RecyclerView.Adapter<LaunchersAdapter.ViewHolder>(), RecyclerViewFastScroller.OnPopupTextUpdate {
@ -60,6 +62,10 @@ class LaunchersAdapter(
launcher_icon.setImageDrawable(launcher.drawable!!) launcher_icon.setImageDrawable(launcher.drawable!!)
launcher_icon.setPadding(iconPadding, iconPadding, iconPadding, 0) launcher_icon.setPadding(iconPadding, iconPadding, iconPadding, 0)
setOnClickListener { itemClick(launcher) } setOnClickListener { itemClick(launcher) }
setOnLongClickListener { view ->
allAppsListener.onIconLongPressed(view.x, view.y, launcher.packageName)
true
}
} }
if (!wasManualScrollPositionSet) { if (!wasManualScrollPositionSet) {

View File

@ -6,11 +6,12 @@ import android.content.Intent
import android.content.pm.LauncherApps import android.content.pm.LauncherApps
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Process import android.os.Process
import android.provider.Settings
import android.util.AttributeSet import android.util.AttributeSet
import android.view.MotionEvent import android.view.*
import android.view.Surface import android.widget.PopupMenu
import android.view.WindowManager
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isRPlus import com.simplemobiletools.commons.helpers.isRPlus
@ -19,10 +20,11 @@ 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.getColumnCount
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.*
class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet) { class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), AllAppsListener {
private var touchDownY = -1 private var touchDownY = -1
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@ -114,7 +116,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
private fun setupAdapter(launchers: ArrayList<AppLauncher>) { private fun setupAdapter(launchers: ArrayList<AppLauncher>) {
activity?.runOnUiThread { activity?.runOnUiThread {
LaunchersAdapter(activity!!, launchers, all_apps_fastscroller) { LaunchersAdapter(activity!!, launchers, all_apps_fastscroller, this) {
val launchIntent = context.packageManager.getLaunchIntentForPackage((it as AppLauncher).packageName) val launchIntent = context.packageManager.getLaunchIntentForPackage((it as AppLauncher).packageName)
try { try {
activity!!.startActivity(launchIntent) activity!!.startActivity(launchIntent)
@ -161,4 +163,29 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
all_apps_grid.setPadding(0, 0, resources.getDimension(R.dimen.medium_margin).toInt(), bottomListPadding) all_apps_grid.setPadding(0, 0, resources.getDimension(R.dimen.medium_margin).toInt(), bottomListPadding)
all_apps_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0) all_apps_fastscroller.setPadding(leftListPadding, 0, rightListPadding, 0)
} }
override fun onIconLongPressed(x: Float, y: Float, packageName: String) {
all_apps_popup_menu_anchor.x = x
all_apps_popup_menu_anchor.y = y
val contextTheme = ContextThemeWrapper(activity, activity!!.getPopupMenuTheme())
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)
}
}
} }

View File

@ -0,0 +1,5 @@
package com.simplemobiletools.launcher.interfaces
interface AllAppsListener {
fun onIconLongPressed(x: Float, y: Float, packageName: String)
}

View File

@ -15,7 +15,7 @@
android:visibility="gone" /> android:visibility="gone" />
<View <View
android:id="@+id/popup_menu_anchor" android:id="@+id/home_screen_popup_menu_anchor"
android:layout_width="1dp" android:layout_width="1dp"
android:layout_height="1dp" android:layout_height="1dp"
android:visibility="gone" /> android:visibility="gone" />

View File

@ -22,4 +22,11 @@
app:spanCount="@integer/portrait_column_count" /> app:spanCount="@integer/portrait_column_count" />
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller> </com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
<View
android:id="@+id/all_apps_popup_menu_anchor"
android:layout_width="1dp"
android:layout_height="1dp"
android:visibility="gone" />
</com.simplemobiletools.launcher.fragments.AllAppsFragment> </com.simplemobiletools.launcher.fragments.AllAppsFragment>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/app_info"
android:icon="@drawable/ic_info_vector"
android:title="@string/app_info"
app:showAsAction="always" />
</menu>

View File

@ -1,6 +1,7 @@
<resources> <resources>
<string name="app_name">Simple Launcher</string> <string name="app_name">Simple Launcher</string>
<string name="app_launcher_name">Launcher</string> <string name="app_launcher_name">Launcher</string>
<string name="app_info">App info</string>
<string name="touch_hold_widget">Long press the widget and drag it on your home screen</string> <string name="touch_hold_widget">Long press the widget and drag it on your home screen</string>
<!-- <!--
Haven't found some strings? There's more at Haven't found some strings? There's more at