pass the provider info at resizing too
This commit is contained in:
parent
80adadd0e8
commit
a159465361
|
@ -487,7 +487,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
try {
|
||||
val defaultDialerPackage = (getSystemService(Context.TELECOM_SERVICE) as TelecomManager).defaultDialerPackage
|
||||
appLaunchers.firstOrNull { it.packageName == defaultDialerPackage }?.apply {
|
||||
val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 1, ROW_COUNT, 1, 1, defaultDialerPackage, title, ITEM_TYPE_ICON, "", -1, null)
|
||||
val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 1, ROW_COUNT, 1, 1, defaultDialerPackage, title, ITEM_TYPE_ICON, "", -1, null, null)
|
||||
homeScreenGridItems.add(dialerIcon)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
@ -497,7 +497,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
val defaultSMSMessengerPackage = Telephony.Sms.getDefaultSmsPackage(this)
|
||||
appLaunchers.firstOrNull { it.packageName == defaultSMSMessengerPackage }?.apply {
|
||||
val SMSMessengerIcon =
|
||||
HomeScreenGridItem(null, 1, ROW_COUNT - 1, 2, ROW_COUNT, 1, 1, defaultSMSMessengerPackage, title, ITEM_TYPE_ICON, "", -1, null)
|
||||
HomeScreenGridItem(null, 1, ROW_COUNT - 1, 2, ROW_COUNT, 1, 1, defaultSMSMessengerPackage, title, ITEM_TYPE_ICON, "", -1, null, null)
|
||||
homeScreenGridItems.add(SMSMessengerIcon)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
@ -508,7 +508,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
val resolveInfo = packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||
val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName
|
||||
appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply {
|
||||
val browserIcon = HomeScreenGridItem(null, 2, ROW_COUNT - 1, 3, ROW_COUNT, 1, 1, defaultBrowserPackage, title, ITEM_TYPE_ICON, "", -1, null)
|
||||
val browserIcon = HomeScreenGridItem(null, 2, ROW_COUNT - 1, 3, ROW_COUNT, 1, 1, defaultBrowserPackage, title, ITEM_TYPE_ICON, "", -1, null, null)
|
||||
homeScreenGridItems.add(browserIcon)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
@ -519,7 +519,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
val storePackage = potentialStores.firstOrNull { isPackageInstalled(it) && appLaunchers.map { it.packageName }.contains(it) }
|
||||
if (storePackage != null) {
|
||||
appLaunchers.firstOrNull { it.packageName == storePackage }?.apply {
|
||||
val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 4, ROW_COUNT, 1, 1, storePackage, title, ITEM_TYPE_ICON, "", -1, null)
|
||||
val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 4, ROW_COUNT, 1, 1, storePackage, title, ITEM_TYPE_ICON, "", -1, null, null)
|
||||
homeScreenGridItems.add(storeIcon)
|
||||
}
|
||||
}
|
||||
|
@ -531,7 +531,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
val resolveInfo = packageManager.resolveActivity(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||
val defaultCameraPackage = resolveInfo!!.activityInfo.packageName
|
||||
appLaunchers.firstOrNull { it.packageName == defaultCameraPackage }?.apply {
|
||||
val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 5, ROW_COUNT, 1, 1, defaultCameraPackage, title, ITEM_TYPE_ICON, "", -1, null)
|
||||
val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 5, ROW_COUNT, 1, 1, defaultCameraPackage, title, ITEM_TYPE_ICON, "", -1, null, null)
|
||||
homeScreenGridItems.add(cameraIcon)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -136,7 +136,8 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
}
|
||||
|
||||
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
|
||||
val gridItem = HomeScreenGridItem(null, -1, -1, -1, -1, 1, 1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, "", -1, appLauncher.drawable)
|
||||
val gridItem =
|
||||
HomeScreenGridItem(null, -1, -1, -1, -1, 1, 1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, "", -1, appLauncher.drawable, null)
|
||||
activity?.showHomeIconMenu(x, y, gridItem, true)
|
||||
ignoreTouches = true
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
val widthCells = Math.min(COLUMN_COUNT, getTileCount(info.minWidth))
|
||||
val heightCells = Math.min(ROW_COUNT, getTileCount(info.minHeight))
|
||||
val className = info.provider.className
|
||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthCells, heightCells, false, className)
|
||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, widthCells, heightCells, false, className, info)
|
||||
appWidgets.add(widget)
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ 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, "")
|
||||
val widget = AppWidget(appPackageName, appTitle, appIcon, widgetTitle, widgetPreviewImage, 0, 0, true, "", null)
|
||||
appWidgets.add(widget)
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,8 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
type,
|
||||
appWidget.className,
|
||||
-1,
|
||||
appWidget.widgetPreviewImage
|
||||
appWidget.widgetPreviewImage,
|
||||
appWidget.providerInfo
|
||||
)
|
||||
|
||||
activity?.widgetLongPressedOnList(gridItem)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.launcher.models
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
data class AppWidget(
|
||||
|
@ -11,7 +12,8 @@ data class AppWidget(
|
|||
var widthCells: Int,
|
||||
val heightCells: Int,
|
||||
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?
|
||||
) : WidgetsListItem() {
|
||||
override fun getHashToCompare() = getStringToCompare().hashCode()
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.launcher.models
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.room.*
|
||||
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON
|
||||
|
@ -20,7 +21,8 @@ data class HomeScreenGridItem(
|
|||
@ColumnInfo(name = "class_name") var className: String,
|
||||
@ColumnInfo(name = "widget_id") var widgetId: Int,
|
||||
|
||||
@Ignore var drawable: Drawable?
|
||||
@Ignore var drawable: Drawable?,
|
||||
@Ignore var providerInfo: AppWidgetProviderInfo?
|
||||
) {
|
||||
constructor() : this(null, -1, -1, -1, -1, 1, 1, "", "", ITEM_TYPE_ICON, "", -1, null)
|
||||
constructor() : this(null, -1, -1, -1, -1, 1, 1, "", "", ITEM_TYPE_ICON, "", -1, null, null)
|
||||
}
|
||||
|
|
|
@ -81,11 +81,14 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||
|
||||
fun fetchGridItems() {
|
||||
ensureBackgroundThread {
|
||||
val providers = appWidgetManager.installedProviders
|
||||
gridItems = context.homeScreenGridItemsDB.getAllItems() as ArrayList<HomeScreenGridItem>
|
||||
gridItems.forEach { item ->
|
||||
if (item.type == ITEM_TYPE_ICON) {
|
||||
item.drawable = context.getDrawableForPackageName(item.packageName)
|
||||
}
|
||||
|
||||
item.providerInfo = providers.firstOrNull { it.provider.className == item.className }
|
||||
}
|
||||
|
||||
redrawGrid()
|
||||
|
@ -174,10 +177,11 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||
val widgetView = widgetViews.firstOrNull { it.tag == resizedWidget!!.widgetId }
|
||||
resize_frame.beGone()
|
||||
if (widgetView != null) {
|
||||
val appWidgetProviderInfo = item.providerInfo ?: appWidgetManager!!.installedProviders.firstOrNull { it.provider.className == item.className }
|
||||
val viewX = widgetView.x.toInt()
|
||||
val viewY = widgetView.y.toInt()
|
||||
val frameRect = Rect(viewX, viewY, viewX + widgetView.width, viewY + widgetView.height)
|
||||
resize_frame.updateFrameCoords(frameRect, rowWidth, rowHeight, sideMargins)
|
||||
resize_frame.updateFrameCoords(frameRect, rowWidth, rowHeight, sideMargins, appWidgetProviderInfo)
|
||||
resize_frame.beVisible()
|
||||
resize_frame.z = 1f // make sure the frame isnt behind the widget itself
|
||||
resize_frame.onClickListener = {
|
||||
|
@ -263,7 +267,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||
draggedItem!!.type,
|
||||
"",
|
||||
-1,
|
||||
draggedItem!!.drawable
|
||||
draggedItem!!.drawable,
|
||||
draggedItem!!.providerInfo
|
||||
)
|
||||
|
||||
ensureBackgroundThread {
|
||||
|
@ -368,8 +373,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||
|
||||
private fun bindWidget(item: HomeScreenGridItem, isInitialDrawAfterLaunch: Boolean) {
|
||||
val activity = context as MainActivity
|
||||
val infoList = appWidgetManager!!.installedProviders
|
||||
val appWidgetProviderInfo = infoList.firstOrNull { it.provider.className == item.className }
|
||||
val appWidgetProviderInfo = item.providerInfo ?: appWidgetManager!!.installedProviders.firstOrNull { it.provider.className == item.className }
|
||||
if (appWidgetProviderInfo != null) {
|
||||
val appWidgetId = appWidgetHost.allocateAppWidgetId()
|
||||
activity.handleWidgetBinding(appWidgetManager, appWidgetId, appWidgetProviderInfo) { canBind ->
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simplemobiletools.launcher.views
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
|
@ -21,6 +22,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
|||
private var frameRect = Rect(0, 0, 0, 0)
|
||||
private var rowWidth = 0
|
||||
private var rowHeight = 0
|
||||
private var providerInfo: AppWidgetProviderInfo? = null
|
||||
private var sideMargins = Rect()
|
||||
private val lineDotRadius = context.resources.getDimension(R.dimen.resize_frame_dot_radius)
|
||||
private val MAX_TOUCH_LINE_DISTANCE = lineDotRadius * 5 // how close we have to be to the widgets side to drag it
|
||||
|
@ -47,11 +49,12 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
|||
}
|
||||
}
|
||||
|
||||
fun updateFrameCoords(coords: Rect, rowWidth: Int, rowHeight: Int, sideMargins: Rect) {
|
||||
fun updateFrameCoords(coords: Rect, rowWidth: Int, rowHeight: Int, sideMargins: Rect, providerInfo: AppWidgetProviderInfo?) {
|
||||
frameRect = coords
|
||||
this.rowWidth = rowWidth
|
||||
this.rowHeight = rowHeight
|
||||
this.sideMargins = sideMargins
|
||||
this.providerInfo = providerInfo
|
||||
redrawFrame()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue