store activityInfo at shortcuts

This commit is contained in:
tibbi 2022-10-07 22:35:35 +02:00
parent b56bae67ca
commit 543371632a
5 changed files with 22 additions and 9 deletions

View File

@ -63,7 +63,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:02ac8df059' implementation 'com.github.SimpleMobileTools:Simple-Commons:2e9ca234a7'
kapt "androidx.room:room-compiler:2.4.3" kapt "androidx.room:room-compiler:2.4.3"
implementation "androidx.room:room-runtime:2.4.3" implementation "androidx.room:room-runtime:2.4.3"

View File

@ -3,7 +3,9 @@ package com.simplemobiletools.launcher.fragments
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetManager
import android.content.Context import android.content.Context
import android.content.Intent
import android.content.pm.LauncherApps import android.content.pm.LauncherApps
import android.content.pm.PackageManager
import android.os.Process import android.os.Process
import android.util.AttributeSet import android.util.AttributeSet
import android.view.MotionEvent import android.view.MotionEvent
@ -21,6 +23,7 @@ import com.simplemobiletools.launcher.interfaces.WidgetsFragmentListener
import com.simplemobiletools.launcher.models.* import com.simplemobiletools.launcher.models.*
import kotlinx.android.synthetic.main.widgets_fragment.view.* import kotlinx.android.synthetic.main.widgets_fragment.view.*
class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), WidgetsFragmentListener { class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), WidgetsFragmentListener {
private var touchDownY = -1 private var touchDownY = -1
private var lastTouchCoords = Pair(0f, 0f) private var lastTouchCoords = Pair(0f, 0f)
@ -98,12 +101,13 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
val widthCells = cellSize.width val widthCells = cellSize.width
val heightCells = cellSize.height val heightCells = cellSize.height
val className = info.provider.className val className = info.provider.className
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthCells, heightCells, false, className, info) val widget =
AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthCells, heightCells, false, className, info, null)
appWidgets.add(widget) appWidgets.add(widget)
} }
// show also the widgets that are technically shortcuts // show also the widgets that are technically shortcuts
/*val intent = Intent(Intent.ACTION_CREATE_SHORTCUT, null) val intent = Intent(Intent.ACTION_CREATE_SHORTCUT, null)
val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED) val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
for (info in list) { for (info in list) {
val componentInfo = info.activityInfo.applicationInfo val componentInfo = info.activityInfo.applicationInfo
@ -113,9 +117,9 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
val appIcon = appMetadata.appIcon val appIcon = appMetadata.appIcon
val widgetTitle = info.loadLabel(packageManager).toString() val widgetTitle = info.loadLabel(packageManager).toString()
val widgetPreviewImage = packageManager.getDrawable(componentInfo.packageName, info.iconResource, componentInfo) val widgetPreviewImage = packageManager.getDrawable(componentInfo.packageName, info.iconResource, componentInfo)
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0, true, "", null) val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0, true, "", null, info.activityInfo)
appWidgets.add(widget) appWidgets.add(widget)
}*/ }
appWidgets = appWidgets.sortedWith(compareBy({ it.appTitle }, { it.appPackageName }, { it.widgetTitle })).toMutableList() as ArrayList<AppWidget> appWidgets = appWidgets.sortedWith(compareBy({ it.appTitle }, { it.appPackageName }, { it.widgetTitle })).toMutableList() as ArrayList<AppWidget>
splitWidgetsByApps(appWidgets) splitWidgetsByApps(appWidgets)
@ -238,6 +242,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
-1, -1,
appWidget.widgetPreviewImage, appWidget.widgetPreviewImage,
appWidget.providerInfo, appWidget.providerInfo,
appWidget.activityInfo,
appWidget.widthCells, appWidget.widthCells,
appWidget.heightCells appWidget.heightCells
) )

View File

@ -1,6 +1,7 @@
package com.simplemobiletools.launcher.models package com.simplemobiletools.launcher.models
import android.appwidget.AppWidgetProviderInfo import android.appwidget.AppWidgetProviderInfo
import android.content.pm.ActivityInfo
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
data class AppWidget( data class AppWidget(
@ -13,7 +14,8 @@ data class AppWidget(
val heightCells: Int, val heightCells: Int,
val isShortcut: Boolean, val isShortcut: Boolean,
val className: String, // identifier to know which app widget are we using val className: String, // identifier to know which app widget are we using
val providerInfo: AppWidgetProviderInfo? val providerInfo: AppWidgetProviderInfo?, // used at widgets
val activityInfo: ActivityInfo? // used at shortcuts
) : WidgetsListItem() { ) : WidgetsListItem() {
override fun getHashToCompare() = getStringToCompare().hashCode() override fun getHashToCompare() = getStringToCompare().hashCode()

View File

@ -1,6 +1,8 @@
package com.simplemobiletools.launcher.models package com.simplemobiletools.launcher.models
import android.appwidget.AppWidgetProviderInfo import android.appwidget.AppWidgetProviderInfo
import android.content.ComponentName
import android.content.pm.ActivityInfo
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import androidx.room.* import androidx.room.*
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON
@ -20,11 +22,12 @@ data class HomeScreenGridItem(
@ColumnInfo(name = "widget_id") var widgetId: Int, @ColumnInfo(name = "widget_id") var widgetId: Int,
@Ignore var drawable: Drawable? = null, @Ignore var drawable: Drawable? = null,
@Ignore var providerInfo: AppWidgetProviderInfo? = null, @Ignore var providerInfo: AppWidgetProviderInfo? = null, // used at widgets
@Ignore var activityInfo: ActivityInfo? = null, // used at shortcuts
@Ignore var widthCells: Int = 1, @Ignore var widthCells: Int = 1,
@Ignore var heightCells: Int = 1 @Ignore var heightCells: Int = 1
) { ) {
constructor() : this(null, -1, -1, -1, -1, "", "", ITEM_TYPE_ICON, "", -1, null, null, 1, 1) constructor() : this(null, -1, -1, -1, -1, "", "", ITEM_TYPE_ICON, "", -1, null, null, null, 1, 1)
fun getWidthInCells() = if (right == -1 || left == -1) { fun getWidthInCells() = if (right == -1 || left == -1) {
widthCells widthCells
@ -37,4 +40,6 @@ data class HomeScreenGridItem(
} else { } else {
bottom - top + 1 bottom - top + 1
} }
fun getComponentName() = ComponentName(activityInfo?.packageName ?: "", activityInfo?.name ?: "")
} }

View File

@ -279,7 +279,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
"", "",
-1, -1,
draggedItem!!.drawable, draggedItem!!.drawable,
draggedItem!!.providerInfo draggedItem!!.providerInfo,
draggedItem!!.activityInfo
) )
ensureBackgroundThread { ensureBackgroundThread {