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