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 {
implementation 'com.github.SimpleMobileTools:Simple-Commons:02ac8df059'
implementation 'com.github.SimpleMobileTools:Simple-Commons:2e9ca234a7'
kapt "androidx.room:room-compiler: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.appwidget.AppWidgetManager
import android.content.Context
import android.content.Intent
import android.content.pm.LauncherApps
import android.content.pm.PackageManager
import android.os.Process
import android.util.AttributeSet
import android.view.MotionEvent
@ -21,6 +23,7 @@ import com.simplemobiletools.launcher.interfaces.WidgetsFragmentListener
import com.simplemobiletools.launcher.models.*
import kotlinx.android.synthetic.main.widgets_fragment.view.*
class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), WidgetsFragmentListener {
private var touchDownY = -1
private var lastTouchCoords = Pair(0f, 0f)
@ -98,12 +101,13 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
val widthCells = cellSize.width
val heightCells = cellSize.height
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)
}
// 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)
for (info in list) {
val componentInfo = info.activityInfo.applicationInfo
@ -113,9 +117,9 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
val appIcon = appMetadata.appIcon
val widgetTitle = info.loadLabel(packageManager).toString()
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 = appWidgets.sortedWith(compareBy({ it.appTitle }, { it.appPackageName }, { it.widgetTitle })).toMutableList() as ArrayList<AppWidget>
splitWidgetsByApps(appWidgets)
@ -238,6 +242,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
-1,
appWidget.widgetPreviewImage,
appWidget.providerInfo,
appWidget.activityInfo,
appWidget.widthCells,
appWidget.heightCells
)

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.launcher.models
import android.appwidget.AppWidgetProviderInfo
import android.content.pm.ActivityInfo
import android.graphics.drawable.Drawable
data class AppWidget(
@ -13,7 +14,8 @@ data class AppWidget(
val heightCells: Int,
val isShortcut: Boolean,
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() {
override fun getHashToCompare() = getStringToCompare().hashCode()

View file

@ -1,6 +1,8 @@
package com.simplemobiletools.launcher.models
import android.appwidget.AppWidgetProviderInfo
import android.content.ComponentName
import android.content.pm.ActivityInfo
import android.graphics.drawable.Drawable
import androidx.room.*
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON
@ -20,11 +22,12 @@ data class HomeScreenGridItem(
@ColumnInfo(name = "widget_id") var widgetId: Int,
@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 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) {
widthCells
@ -37,4 +40,6 @@ data class HomeScreenGridItem(
} else {
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,
draggedItem!!.drawable,
draggedItem!!.providerInfo
draggedItem!!.providerInfo,
draggedItem!!.activityInfo
)
ensureBackgroundThread {