From e2a99984f37aa41652d662e36d4e8727cdff2cb3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 16 Sep 2022 20:10:46 +0200 Subject: [PATCH] allow opening App info by long pressing an app icon --- .../launcher/activities/MainActivity.kt | 6 +-- .../launcher/adapters/LaunchersAdapter.kt | 6 +++ .../launcher/fragments/AllAppsFragment.kt | 37 ++++++++++++++++--- .../launcher/interfaces/AllAppsListener.kt | 5 +++ app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/all_apps_fragment.xml | 7 ++++ app/src/main/res/menu/menu_app_icon.xml | 9 +++++ app/src/main/res/values/strings.xml | 1 + 8 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AllAppsListener.kt create mode 100644 app/src/main/res/menu/menu_app_icon.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt index 63fb0f4..00355bd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -123,10 +123,10 @@ class MainActivity : SimpleActivity(), FlingListener { fun homeScreenLongPressed(x: Float, y: Float) { main_holder.performHapticFeedback() - popup_menu_anchor.x = x - popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_offset_y) + home_screen_popup_menu_anchor.x = x + home_screen_popup_menu_anchor.y = y - resources.getDimension(R.dimen.long_press_anchor_offset_y) 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) setOnMenuItemClickListener { item -> when (item.itemId) { diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/LaunchersAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/LaunchersAdapter.kt index f022646..6673293 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/LaunchersAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/adapters/LaunchersAdapter.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.commons.extensions.realScreenSize import com.simplemobiletools.launcher.R import com.simplemobiletools.launcher.activities.SimpleActivity import com.simplemobiletools.launcher.extensions.getColumnCount +import com.simplemobiletools.launcher.interfaces.AllAppsListener import com.simplemobiletools.launcher.models.AppLauncher import kotlinx.android.synthetic.main.item_launcher_label.view.* @@ -19,6 +20,7 @@ class LaunchersAdapter( val activity: SimpleActivity, val launchers: ArrayList, val fastScroller: RecyclerViewFastScroller, + val allAppsListener: AllAppsListener, val itemClick: (Any) -> Unit ) : RecyclerView.Adapter(), RecyclerViewFastScroller.OnPopupTextUpdate { @@ -60,6 +62,10 @@ class LaunchersAdapter( launcher_icon.setImageDrawable(launcher.drawable!!) launcher_icon.setPadding(iconPadding, iconPadding, iconPadding, 0) setOnClickListener { itemClick(launcher) } + setOnLongClickListener { view -> + allAppsListener.onIconLongPressed(view.x, view.y, launcher.packageName) + true + } } if (!wasManualScrollPositionSet) { diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt index f849b13..ff9c29c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt @@ -6,11 +6,12 @@ import android.content.Intent import android.content.pm.LauncherApps import android.content.pm.PackageManager import android.graphics.drawable.Drawable +import android.net.Uri import android.os.Process +import android.provider.Settings import android.util.AttributeSet -import android.view.MotionEvent -import android.view.Surface -import android.view.WindowManager +import android.view.* +import android.widget.PopupMenu import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.ensureBackgroundThread 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.adapters.LaunchersAdapter import com.simplemobiletools.launcher.extensions.getColumnCount +import com.simplemobiletools.launcher.interfaces.AllAppsListener import com.simplemobiletools.launcher.models.AppLauncher 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 @SuppressLint("ClickableViewAccessibility") @@ -114,7 +116,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment private fun setupAdapter(launchers: ArrayList) { activity?.runOnUiThread { - LaunchersAdapter(activity!!, launchers, all_apps_fastscroller) { + LaunchersAdapter(activity!!, launchers, all_apps_fastscroller, this) { val launchIntent = context.packageManager.getLaunchIntentForPackage((it as AppLauncher).packageName) try { 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_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) + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AllAppsListener.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AllAppsListener.kt new file mode 100644 index 0000000..b0ab92e --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/AllAppsListener.kt @@ -0,0 +1,5 @@ +package com.simplemobiletools.launcher.interfaces + +interface AllAppsListener { + fun onIconLongPressed(x: Float, y: Float, packageName: String) +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4162f63..47b1947 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -15,7 +15,7 @@ android:visibility="gone" /> diff --git a/app/src/main/res/layout/all_apps_fragment.xml b/app/src/main/res/layout/all_apps_fragment.xml index 1967d18..bdb35be 100644 --- a/app/src/main/res/layout/all_apps_fragment.xml +++ b/app/src/main/res/layout/all_apps_fragment.xml @@ -22,4 +22,11 @@ app:spanCount="@integer/portrait_column_count" /> + + + diff --git a/app/src/main/res/menu/menu_app_icon.xml b/app/src/main/res/menu/menu_app_icon.xml new file mode 100644 index 0000000..65c7ae8 --- /dev/null +++ b/app/src/main/res/menu/menu_app_icon.xml @@ -0,0 +1,9 @@ + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b949e17..b8a2599 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ Simple Launcher Launcher + App info Long press the widget and drag it on your home screen