diff --git a/app/build.gradle b/app/build.gradle index c130596..66a4398 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt index d42f5be..59d11cd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt @@ -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 splitWidgetsByApps(appWidgets) @@ -238,6 +242,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment -1, appWidget.widgetPreviewImage, appWidget.providerInfo, + appWidget.activityInfo, appWidget.widthCells, appWidget.heightCells ) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/models/AppWidget.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/models/AppWidget.kt index 56c4734..6c7949e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/models/AppWidget.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/models/AppWidget.kt @@ -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() diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/models/HomeScreenGridItem.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/models/HomeScreenGridItem.kt index eec0b42..d4d1eda 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/models/HomeScreenGridItem.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/models/HomeScreenGridItem.kt @@ -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 ?: "") } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt index bd87504..59fca86 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt @@ -279,7 +279,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel "", -1, draggedItem!!.drawable, - draggedItem!!.providerInfo + draggedItem!!.providerInfo, + draggedItem!!.activityInfo ) ensureBackgroundThread {