adding 2 new fields to HomeScreenGridItem for shortcuts

This commit is contained in:
tibbi 2022-10-08 22:29:00 +02:00
parent 9ed0e55c15
commit 593b0d575e
6 changed files with 34 additions and 7 deletions

View File

@ -521,7 +521,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, 0, ROW_COUNT - 1, defaultDialerPackage, title, ITEM_TYPE_ICON, "", -1)
val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 0, ROW_COUNT - 1, defaultDialerPackage, title, ITEM_TYPE_ICON, "", -1, "", null)
homeScreenGridItems.add(dialerIcon)
}
} catch (e: Exception) {
@ -531,7 +531,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, 1, ROW_COUNT - 1, defaultSMSMessengerPackage, title, ITEM_TYPE_ICON, "", -1)
HomeScreenGridItem(null, 1, ROW_COUNT - 1, 1, ROW_COUNT - 1, defaultSMSMessengerPackage, title, ITEM_TYPE_ICON, "", -1, "", null)
homeScreenGridItems.add(SMSMessengerIcon)
}
} catch (e: Exception) {
@ -543,7 +543,7 @@ class MainActivity : SimpleActivity(), FlingListener {
val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName
appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply {
val browserIcon =
HomeScreenGridItem(null, 2, ROW_COUNT - 1, 2, ROW_COUNT - 1, defaultBrowserPackage, title, ITEM_TYPE_ICON, "", -1)
HomeScreenGridItem(null, 2, ROW_COUNT - 1, 2, ROW_COUNT - 1, defaultBrowserPackage, title, ITEM_TYPE_ICON, "", -1, "", null)
homeScreenGridItems.add(browserIcon)
}
} catch (e: Exception) {
@ -554,7 +554,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, 3, ROW_COUNT - 1, storePackage, title, ITEM_TYPE_ICON, "", -1)
val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 3, ROW_COUNT - 1, storePackage, title, ITEM_TYPE_ICON, "", -1, "", null)
homeScreenGridItems.add(storeIcon)
}
}
@ -566,7 +566,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, 4, ROW_COUNT - 1, defaultCameraPackage, title, ITEM_TYPE_ICON, "", -1)
val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 4, ROW_COUNT - 1, defaultCameraPackage, title, ITEM_TYPE_ICON, "", -1, "", null)
homeScreenGridItems.add(cameraIcon)
}
} catch (e: Exception) {

View File

@ -141,7 +141,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
val gridItem =
HomeScreenGridItem(null, -1, -1, -1, -1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, "", -1, appLauncher.drawable)
HomeScreenGridItem(null, -1, -1, -1, -1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, "", -1, "", null, appLauncher.drawable)
activity?.showHomeIconMenu(x, y, gridItem, true)
ignoreTouches = true
}

View File

@ -240,6 +240,8 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
type,
appWidget.className,
-1,
"",
null,
appWidget.widgetPreviewImage,
appWidget.providerInfo,
appWidget.activityInfo,

View File

@ -0,0 +1,20 @@
package com.simplemobiletools.launcher.helpers
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.room.TypeConverter
import java.io.ByteArrayOutputStream
class Converters {
@TypeConverter
fun toBitmap(bytes: ByteArray): Bitmap? {
return BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
}
@TypeConverter
fun fromBitmap(bmp: Bitmap?): ByteArray {
val outputStream = ByteArrayOutputStream()
bmp?.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
return outputStream.toByteArray()
}
}

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.launcher.models
import android.appwidget.AppWidgetProviderInfo
import android.content.ComponentName
import android.content.pm.ActivityInfo
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.room.*
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON
@ -20,6 +21,8 @@ data class HomeScreenGridItem(
@ColumnInfo(name = "type") var type: Int,
@ColumnInfo(name = "class_name") var className: String,
@ColumnInfo(name = "widget_id") var widgetId: Int,
@ColumnInfo(name = "intent") var intent: String, // used at shortcuts on click
@ColumnInfo(name = "icon") var icon: Bitmap?, // store only images of shortcuts, those cannot be retrieved anytime
@Ignore var drawable: Drawable? = null,
@Ignore var providerInfo: AppWidgetProviderInfo? = null, // used at widgets
@ -27,7 +30,7 @@ data class HomeScreenGridItem(
@Ignore var widthCells: Int = 1,
@Ignore var heightCells: Int = 1
) {
constructor() : this(null, -1, -1, -1, -1, "", "", ITEM_TYPE_ICON, "", -1, null, null, null, 1, 1)
constructor() : this(null, -1, -1, -1, -1, "", "", ITEM_TYPE_ICON, "", -1, "", null, null, null, null, 1, 1)
fun getWidthInCells() = if (right == -1 || left == -1) {
widthCells

View File

@ -273,6 +273,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
draggedItem!!.type,
"",
-1,
"",
draggedItem!!.icon,
draggedItem!!.drawable,
draggedItem!!.providerInfo,
draggedItem!!.activityInfo