Skip to content

Commit f8d0034

Browse files
committed
fix #24, add support for apps creating multiple icons, not just launcher
1 parent a61e2b0 commit f8d0034

File tree

7 files changed

+57
-25
lines changed

7 files changed

+57
-25
lines changed

app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class MainActivity : SimpleActivity(), FlingListener {
107107
rect.right,
108108
rect.bottom,
109109
item.shortcutInfo!!.`package`,
110+
"",
110111
label,
111112
ITEM_TYPE_SHORTCUT,
112113
"",
@@ -396,7 +397,7 @@ class MainActivity : SimpleActivity(), FlingListener {
396397
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
397398
if (clickedGridItem != null) {
398399
if (clickedGridItem.type == ITEM_TYPE_ICON) {
399-
launchApp(clickedGridItem.packageName)
400+
launchApp(clickedGridItem.packageName, clickedGridItem.activityName)
400401
} else if (clickedGridItem.type == ITEM_TYPE_SHORTCUT) {
401402
if (clickedGridItem.intent.isNotEmpty()) {
402403
launchShortcutIntent(clickedGridItem)
@@ -567,7 +568,6 @@ class MainActivity : SimpleActivity(), FlingListener {
567568
@SuppressLint("WrongConstant")
568569
fun getAllAppLaunchers(): ArrayList<AppLauncher> {
569570
val allApps = ArrayList<AppLauncher>()
570-
val allPackageNames = ArrayList<String>()
571571
val intent = Intent(Intent.ACTION_MAIN, null)
572572
intent.addCategory(Intent.CATEGORY_LAUNCHER)
573573

@@ -576,36 +576,33 @@ class MainActivity : SimpleActivity(), FlingListener {
576576
val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
577577
for (info in list) {
578578
val componentInfo = info.activityInfo.applicationInfo
579-
val packageName = componentInfo.packageName
579+
var packageName = componentInfo.packageName
580580
if (packageName == simpleLauncher || packageName == microG) {
581581
continue
582582
}
583583

584584
val label = info.loadLabel(packageManager).toString()
585-
val drawable = getDrawableForPackageName(packageName) ?: continue
585+
val drawable = info.loadIcon(packageManager) ?: getDrawableForPackageName(packageName) ?: continue
586586
val placeholderColor = calculateAverageColor(drawable.toBitmap())
587-
588-
allPackageNames.add(packageName)
589-
allApps.add(AppLauncher(null, label, packageName, 0, placeholderColor, drawable))
587+
val activityName = info.activityInfo.name
588+
allApps.add(AppLauncher(null, label, packageName, activityName, 0, placeholderColor, drawable))
590589
}
591590

592591
// add Simple Launchers settings as an app
593592
val drawable = getDrawableForPackageName(packageName)
594593
val placeholderColor = calculateAverageColor(drawable!!.toBitmap())
595-
val launcherSettings = AppLauncher(null, getString(R.string.launcher_settings), packageName, 0, placeholderColor, drawable)
594+
val launcherSettings = AppLauncher(null, getString(R.string.launcher_settings), packageName, "", 0, placeholderColor, drawable)
596595
allApps.add(launcherSettings)
597-
598-
val launchers = allApps.distinctBy { it.packageName } as ArrayList<AppLauncher>
599-
launchersDB.insertAll(launchers)
600-
return launchers
596+
launchersDB.insertAll(allApps)
597+
return allApps
601598
}
602599

603600
private fun getDefaultAppPackages(appLaunchers: ArrayList<AppLauncher>) {
604601
val homeScreenGridItems = ArrayList<HomeScreenGridItem>()
605602
try {
606603
val defaultDialerPackage = (getSystemService(Context.TELECOM_SERVICE) as TelecomManager).defaultDialerPackage
607604
appLaunchers.firstOrNull { it.packageName == defaultDialerPackage }?.apply {
608-
val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 0, ROW_COUNT - 1, defaultDialerPackage, title, ITEM_TYPE_ICON, "", -1, "", "", null)
605+
val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 0, ROW_COUNT - 1, defaultDialerPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null)
609606
homeScreenGridItems.add(dialerIcon)
610607
}
611608
} catch (e: Exception) {
@@ -615,7 +612,7 @@ class MainActivity : SimpleActivity(), FlingListener {
615612
val defaultSMSMessengerPackage = Telephony.Sms.getDefaultSmsPackage(this)
616613
appLaunchers.firstOrNull { it.packageName == defaultSMSMessengerPackage }?.apply {
617614
val SMSMessengerIcon =
618-
HomeScreenGridItem(null, 1, ROW_COUNT - 1, 1, ROW_COUNT - 1, defaultSMSMessengerPackage, title, ITEM_TYPE_ICON, "", -1, "", "", null)
615+
HomeScreenGridItem(null, 1, ROW_COUNT - 1, 1, ROW_COUNT - 1, defaultSMSMessengerPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null)
619616
homeScreenGridItems.add(SMSMessengerIcon)
620617
}
621618
} catch (e: Exception) {
@@ -627,7 +624,7 @@ class MainActivity : SimpleActivity(), FlingListener {
627624
val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName
628625
appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply {
629626
val browserIcon =
630-
HomeScreenGridItem(null, 2, ROW_COUNT - 1, 2, ROW_COUNT - 1, defaultBrowserPackage, title, ITEM_TYPE_ICON, "", -1, "", "", null)
627+
HomeScreenGridItem(null, 2, ROW_COUNT - 1, 2, ROW_COUNT - 1, defaultBrowserPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null)
631628
homeScreenGridItems.add(browserIcon)
632629
}
633630
} catch (e: Exception) {
@@ -638,7 +635,7 @@ class MainActivity : SimpleActivity(), FlingListener {
638635
val storePackage = potentialStores.firstOrNull { isPackageInstalled(it) && appLaunchers.map { it.packageName }.contains(it) }
639636
if (storePackage != null) {
640637
appLaunchers.firstOrNull { it.packageName == storePackage }?.apply {
641-
val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 3, ROW_COUNT - 1, storePackage, title, ITEM_TYPE_ICON, "", -1, "", "", null)
638+
val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 3, ROW_COUNT - 1, storePackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null)
642639
homeScreenGridItems.add(storeIcon)
643640
}
644641
}
@@ -650,7 +647,7 @@ class MainActivity : SimpleActivity(), FlingListener {
650647
val resolveInfo = packageManager.resolveActivity(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY)
651648
val defaultCameraPackage = resolveInfo!!.activityInfo.packageName
652649
appLaunchers.firstOrNull { it.packageName == defaultCameraPackage }?.apply {
653-
val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 4, ROW_COUNT - 1, defaultCameraPackage, title, ITEM_TYPE_ICON, "", -1, "", "", null)
650+
val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 4, ROW_COUNT - 1, defaultCameraPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null)
654651
homeScreenGridItems.add(cameraIcon)
655652
}
656653
} catch (e: Exception) {

app/src/main/kotlin/com/simplemobiletools/launcher/databases/AppsDatabase.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.simplemobiletools.launcher.interfaces.HomeScreenGridItemsDao
1313
import com.simplemobiletools.launcher.models.AppLauncher
1414
import com.simplemobiletools.launcher.models.HomeScreenGridItem
1515

16-
@Database(entities = [AppLauncher::class, HomeScreenGridItem::class], version = 2)
16+
@Database(entities = [AppLauncher::class, HomeScreenGridItem::class], version = 3)
1717
@TypeConverters(Converters::class)
1818
abstract class AppsDatabase : RoomDatabase() {
1919

@@ -30,6 +30,7 @@ abstract class AppsDatabase : RoomDatabase() {
3030
if (db == null) {
3131
db = Room.databaseBuilder(context.applicationContext, AppsDatabase::class.java, "apps.db")
3232
.addMigrations(MIGRATION_1_2)
33+
.addMigrations(MIGRATION_2_3)
3334
.build()
3435
}
3536
}
@@ -44,5 +45,12 @@ abstract class AppsDatabase : RoomDatabase() {
4445
database.execSQL("ALTER TABLE home_screen_grid_items ADD COLUMN icon BLOB")
4546
}
4647
}
48+
49+
private val MIGRATION_2_3 = object : Migration(2, 3) {
50+
override fun migrate(database: SupportSQLiteDatabase) {
51+
database.execSQL("ALTER TABLE apps ADD COLUMN activity_name TEXT default '' NOT NULL")
52+
database.execSQL("ALTER TABLE home_screen_grid_items ADD COLUMN activity_name TEXT default '' NOT NULL")
53+
}
54+
}
4755
}
4856
}

app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Activity.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.simplemobiletools.launcher.extensions
22

33
import android.app.Activity
4+
import android.content.ActivityNotFoundException
5+
import android.content.ComponentName
46
import android.content.Intent
57
import android.net.Uri
68
import android.provider.Settings
@@ -9,16 +11,22 @@ import com.simplemobiletools.launcher.activities.SettingsActivity
911
import com.simplemobiletools.launcher.helpers.UNINSTALL_APP_REQUEST_CODE
1012
import com.simplemobiletools.launcher.models.HomeScreenGridItem
1113

12-
fun Activity.launchApp(packageName: String) {
14+
fun Activity.launchApp(packageName: String, activityName: String) {
1315
// if this is true, launch the app settings
1416
if (packageName == this.packageName) {
1517
startActivity(Intent(applicationContext, SettingsActivity::class.java))
1618
return
1719
}
1820

19-
val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
2021
try {
21-
startActivity(launchIntent)
22+
Intent(Intent.ACTION_MAIN).apply {
23+
addCategory(Intent.CATEGORY_LAUNCHER)
24+
`package` = packageName
25+
component = ComponentName.unflattenFromString("$packageName/$activityName")
26+
startActivity(this)
27+
}
28+
} catch (e: ActivityNotFoundException) {
29+
showErrorToast(e)
2230
} catch (e: Exception) {
2331
showErrorToast(e)
2432
}

app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
9898
val currAdapter = all_apps_grid.adapter
9999
if (currAdapter == null) {
100100
LaunchersAdapter(activity!!, launchers, this) {
101-
activity?.launchApp((it as AppLauncher).packageName)
101+
activity?.launchApp((it as AppLauncher).packageName, it.activityName)
102102
}.apply {
103103
all_apps_grid.adapter = this
104104
}
@@ -151,7 +151,23 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
151151

152152
override fun onAppLauncherLongPressed(x: Float, y: Float, appLauncher: AppLauncher) {
153153
val gridItem =
154-
HomeScreenGridItem(null, -1, -1, -1, -1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, "", -1, "", "", null, appLauncher.drawable)
154+
HomeScreenGridItem(
155+
null,
156+
-1,
157+
-1,
158+
-1,
159+
-1,
160+
appLauncher.packageName,
161+
appLauncher.activityName,
162+
appLauncher.title,
163+
ITEM_TYPE_ICON,
164+
"",
165+
-1,
166+
"",
167+
"",
168+
null,
169+
appLauncher.drawable
170+
)
155171
activity?.showHomeIconMenu(x, y, gridItem, true)
156172
ignoreTouches = true
157173
}

app/src/main/kotlin/com/simplemobiletools/launcher/models/AppLauncher.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ data class AppLauncher(
1111
@PrimaryKey(autoGenerate = true) var id: Long?,
1212
@ColumnInfo(name = "title") var title: String,
1313
@ColumnInfo(name = "package_name") var packageName: String,
14+
@ColumnInfo(name = "activity_name") var activityName: String, // some apps create multiple icons, this is needed at clicking them
1415
@ColumnInfo(name = "order") var order: Int,
1516
@ColumnInfo(name = "thumbnail_color") var thumbnailColor: Int,
1617

1718
@Ignore var drawable: Drawable?
1819
) : Comparable<AppLauncher> {
1920

20-
constructor() : this(null, "", "", 0, 0, null)
21+
constructor() : this(null, "", "", "", 0, 0, null)
2122

2223
companion object {
2324
var sorting = 0

app/src/main/kotlin/com/simplemobiletools/launcher/models/HomeScreenGridItem.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ data class HomeScreenGridItem(
1616
@ColumnInfo(name = "right") var right: Int,
1717
@ColumnInfo(name = "bottom") var bottom: Int,
1818
@ColumnInfo(name = "package_name") var packageName: String,
19+
@ColumnInfo(name = "activity_name") var activityName: String, // needed at apps that create multiple icons at install, not just the launcher
1920
@ColumnInfo(name = "title") var title: String,
2021
@ColumnInfo(name = "type") var type: Int,
2122
@ColumnInfo(name = "class_name") var className: String,
@@ -30,7 +31,7 @@ data class HomeScreenGridItem(
3031
@Ignore var widthCells: Int = 1,
3132
@Ignore var heightCells: Int = 1
3233
) {
33-
constructor() : this(null, -1, -1, -1, -1, "", "", ITEM_TYPE_ICON, "", -1, "", "", null, null, null, null, 1, 1)
34+
constructor() : this(null, -1, -1, -1, -1, "", "", "", ITEM_TYPE_ICON, "", -1, "", "", null, null, null, null, 1, 1)
3435

3536
fun getWidthInCells() = if (right == -1 || left == -1) {
3637
widthCells

app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
278278
xIndex,
279279
yIndex,
280280
draggedItem!!.packageName,
281+
draggedItem!!.activityName,
281282
draggedItem!!.title,
282283
draggedItem!!.type,
283284
"",

0 commit comments

Comments
 (0)