allow opening App info by long pressing an app icon
This commit is contained in:
parent
7ca977349b
commit
e2a99984f3
8 changed files with 64 additions and 9 deletions
|
@ -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) {
|
||||
|
|
|
@ -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<AppLauncher>,
|
||||
val fastScroller: RecyclerViewFastScroller,
|
||||
val allAppsListener: AllAppsListener,
|
||||
val itemClick: (Any) -> Unit
|
||||
) : RecyclerView.Adapter<LaunchersAdapter.ViewHolder>(), 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) {
|
||||
|
|
|
@ -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<AppLauncher>) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package com.simplemobiletools.launcher.interfaces
|
||||
|
||||
interface AllAppsListener {
|
||||
fun onIconLongPressed(x: Float, y: Float, packageName: String)
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
android:visibility="gone" />
|
||||
|
||||
<View
|
||||
android:id="@+id/popup_menu_anchor"
|
||||
android:id="@+id/home_screen_popup_menu_anchor"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="1dp"
|
||||
android:visibility="gone" />
|
||||
|
|
|
@ -22,4 +22,11 @@
|
|||
app:spanCount="@integer/portrait_column_count" />
|
||||
|
||||
</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>
|
||||
|
|
9
app/src/main/res/menu/menu_app_icon.xml
Normal file
9
app/src/main/res/menu/menu_app_icon.xml
Normal 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>
|
|
@ -1,6 +1,7 @@
|
|||
<resources>
|
||||
<string name="app_name">Simple 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>
|
||||
<!--
|
||||
Haven't found some strings? There's more at
|
||||
|
|
Loading…
Reference in a new issue