mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-02-19 21:10:36 +01:00
fix #24, add support for apps creating multiple icons, not just launcher
This commit is contained in:
parent
a61e2b0dae
commit
f8d0034222
@ -107,6 +107,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
rect.right,
|
rect.right,
|
||||||
rect.bottom,
|
rect.bottom,
|
||||||
item.shortcutInfo!!.`package`,
|
item.shortcutInfo!!.`package`,
|
||||||
|
"",
|
||||||
label,
|
label,
|
||||||
ITEM_TYPE_SHORTCUT,
|
ITEM_TYPE_SHORTCUT,
|
||||||
"",
|
"",
|
||||||
@ -396,7 +397,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
val clickedGridItem = home_screen_grid.isClickingGridItem(x.toInt(), y.toInt())
|
||||||
if (clickedGridItem != null) {
|
if (clickedGridItem != null) {
|
||||||
if (clickedGridItem.type == ITEM_TYPE_ICON) {
|
if (clickedGridItem.type == ITEM_TYPE_ICON) {
|
||||||
launchApp(clickedGridItem.packageName)
|
launchApp(clickedGridItem.packageName, clickedGridItem.activityName)
|
||||||
} else if (clickedGridItem.type == ITEM_TYPE_SHORTCUT) {
|
} else if (clickedGridItem.type == ITEM_TYPE_SHORTCUT) {
|
||||||
if (clickedGridItem.intent.isNotEmpty()) {
|
if (clickedGridItem.intent.isNotEmpty()) {
|
||||||
launchShortcutIntent(clickedGridItem)
|
launchShortcutIntent(clickedGridItem)
|
||||||
@ -567,7 +568,6 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
@SuppressLint("WrongConstant")
|
@SuppressLint("WrongConstant")
|
||||||
fun getAllAppLaunchers(): ArrayList<AppLauncher> {
|
fun getAllAppLaunchers(): ArrayList<AppLauncher> {
|
||||||
val allApps = ArrayList<AppLauncher>()
|
val allApps = ArrayList<AppLauncher>()
|
||||||
val allPackageNames = ArrayList<String>()
|
|
||||||
val intent = Intent(Intent.ACTION_MAIN, null)
|
val intent = Intent(Intent.ACTION_MAIN, null)
|
||||||
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
|
||||||
@ -576,28 +576,25 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
||||||
for (info in list) {
|
for (info in list) {
|
||||||
val componentInfo = info.activityInfo.applicationInfo
|
val componentInfo = info.activityInfo.applicationInfo
|
||||||
val packageName = componentInfo.packageName
|
var packageName = componentInfo.packageName
|
||||||
if (packageName == simpleLauncher || packageName == microG) {
|
if (packageName == simpleLauncher || packageName == microG) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val label = info.loadLabel(packageManager).toString()
|
val label = info.loadLabel(packageManager).toString()
|
||||||
val drawable = getDrawableForPackageName(packageName) ?: continue
|
val drawable = info.loadIcon(packageManager) ?: getDrawableForPackageName(packageName) ?: continue
|
||||||
val placeholderColor = calculateAverageColor(drawable.toBitmap())
|
val placeholderColor = calculateAverageColor(drawable.toBitmap())
|
||||||
|
val activityName = info.activityInfo.name
|
||||||
allPackageNames.add(packageName)
|
allApps.add(AppLauncher(null, label, packageName, activityName, 0, placeholderColor, drawable))
|
||||||
allApps.add(AppLauncher(null, label, packageName, 0, placeholderColor, drawable))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add Simple Launchers settings as an app
|
// add Simple Launchers settings as an app
|
||||||
val drawable = getDrawableForPackageName(packageName)
|
val drawable = getDrawableForPackageName(packageName)
|
||||||
val placeholderColor = calculateAverageColor(drawable!!.toBitmap())
|
val placeholderColor = calculateAverageColor(drawable!!.toBitmap())
|
||||||
val launcherSettings = AppLauncher(null, getString(R.string.launcher_settings), packageName, 0, placeholderColor, drawable)
|
val launcherSettings = AppLauncher(null, getString(R.string.launcher_settings), packageName, "", 0, placeholderColor, drawable)
|
||||||
allApps.add(launcherSettings)
|
allApps.add(launcherSettings)
|
||||||
|
launchersDB.insertAll(allApps)
|
||||||
val launchers = allApps.distinctBy { it.packageName } as ArrayList<AppLauncher>
|
return allApps
|
||||||
launchersDB.insertAll(launchers)
|
|
||||||
return launchers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDefaultAppPackages(appLaunchers: ArrayList<AppLauncher>) {
|
private fun getDefaultAppPackages(appLaunchers: ArrayList<AppLauncher>) {
|
||||||
@ -605,7 +602,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, 0, ROW_COUNT - 1, defaultDialerPackage, title, ITEM_TYPE_ICON, "", -1, "", "", null)
|
val dialerIcon = HomeScreenGridItem(null, 0, ROW_COUNT - 1, 0, ROW_COUNT - 1, defaultDialerPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null)
|
||||||
homeScreenGridItems.add(dialerIcon)
|
homeScreenGridItems.add(dialerIcon)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -615,7 +612,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, 1, ROW_COUNT - 1, defaultSMSMessengerPackage, title, ITEM_TYPE_ICON, "", -1, "", "", null)
|
HomeScreenGridItem(null, 1, ROW_COUNT - 1, 1, ROW_COUNT - 1, defaultSMSMessengerPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null)
|
||||||
homeScreenGridItems.add(SMSMessengerIcon)
|
homeScreenGridItems.add(SMSMessengerIcon)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -627,7 +624,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName
|
val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName
|
||||||
appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply {
|
appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply {
|
||||||
val browserIcon =
|
val browserIcon =
|
||||||
HomeScreenGridItem(null, 2, ROW_COUNT - 1, 2, ROW_COUNT - 1, defaultBrowserPackage, title, ITEM_TYPE_ICON, "", -1, "", "", null)
|
HomeScreenGridItem(null, 2, ROW_COUNT - 1, 2, ROW_COUNT - 1, defaultBrowserPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null)
|
||||||
homeScreenGridItems.add(browserIcon)
|
homeScreenGridItems.add(browserIcon)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -638,7 +635,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, 3, ROW_COUNT - 1, storePackage, title, ITEM_TYPE_ICON, "", -1, "", "", null)
|
val storeIcon = HomeScreenGridItem(null, 3, ROW_COUNT - 1, 3, ROW_COUNT - 1, storePackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null)
|
||||||
homeScreenGridItems.add(storeIcon)
|
homeScreenGridItems.add(storeIcon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -650,7 +647,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, 4, ROW_COUNT - 1, defaultCameraPackage, title, ITEM_TYPE_ICON, "", -1, "", "", null)
|
val cameraIcon = HomeScreenGridItem(null, 4, ROW_COUNT - 1, 4, ROW_COUNT - 1, defaultCameraPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null)
|
||||||
homeScreenGridItems.add(cameraIcon)
|
homeScreenGridItems.add(cameraIcon)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -13,7 +13,7 @@ import com.simplemobiletools.launcher.interfaces.HomeScreenGridItemsDao
|
|||||||
import com.simplemobiletools.launcher.models.AppLauncher
|
import com.simplemobiletools.launcher.models.AppLauncher
|
||||||
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
||||||
|
|
||||||
@Database(entities = [AppLauncher::class, HomeScreenGridItem::class], version = 2)
|
@Database(entities = [AppLauncher::class, HomeScreenGridItem::class], version = 3)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class AppsDatabase : RoomDatabase() {
|
abstract class AppsDatabase : RoomDatabase() {
|
||||||
|
|
||||||
@ -30,6 +30,7 @@ abstract class AppsDatabase : RoomDatabase() {
|
|||||||
if (db == null) {
|
if (db == null) {
|
||||||
db = Room.databaseBuilder(context.applicationContext, AppsDatabase::class.java, "apps.db")
|
db = Room.databaseBuilder(context.applicationContext, AppsDatabase::class.java, "apps.db")
|
||||||
.addMigrations(MIGRATION_1_2)
|
.addMigrations(MIGRATION_1_2)
|
||||||
|
.addMigrations(MIGRATION_2_3)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,5 +45,12 @@ abstract class AppsDatabase : RoomDatabase() {
|
|||||||
database.execSQL("ALTER TABLE home_screen_grid_items ADD COLUMN icon BLOB")
|
database.execSQL("ALTER TABLE home_screen_grid_items ADD COLUMN icon BLOB")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val MIGRATION_2_3 = object : Migration(2, 3) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE apps ADD COLUMN activity_name TEXT default '' NOT NULL")
|
||||||
|
database.execSQL("ALTER TABLE home_screen_grid_items ADD COLUMN activity_name TEXT default '' NOT NULL")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.simplemobiletools.launcher.extensions
|
package com.simplemobiletools.launcher.extensions
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
|
import android.content.ComponentName
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
@ -9,16 +11,22 @@ import com.simplemobiletools.launcher.activities.SettingsActivity
|
|||||||
import com.simplemobiletools.launcher.helpers.UNINSTALL_APP_REQUEST_CODE
|
import com.simplemobiletools.launcher.helpers.UNINSTALL_APP_REQUEST_CODE
|
||||||
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
import com.simplemobiletools.launcher.models.HomeScreenGridItem
|
||||||
|
|
||||||
fun Activity.launchApp(packageName: String) {
|
fun Activity.launchApp(packageName: String, activityName: String) {
|
||||||
// if this is true, launch the app settings
|
// if this is true, launch the app settings
|
||||||
if (packageName == this.packageName) {
|
if (packageName == this.packageName) {
|
||||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
|
|
||||||
try {
|
try {
|
||||||
startActivity(launchIntent)
|
Intent(Intent.ACTION_MAIN).apply {
|
||||||
|
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
`package` = packageName
|
||||||
|
component = ComponentName.unflattenFromString("$packageName/$activityName")
|
||||||
|
startActivity(this)
|
||||||
|
}
|
||||||
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
showErrorToast(e)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||||||
val currAdapter = all_apps_grid.adapter
|
val currAdapter = all_apps_grid.adapter
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
LaunchersAdapter(activity!!, launchers, this) {
|
LaunchersAdapter(activity!!, launchers, this) {
|
||||||
activity?.launchApp((it as AppLauncher).packageName)
|
activity?.launchApp((it as AppLauncher).packageName, it.activityName)
|
||||||
}.apply {
|
}.apply {
|
||||||
all_apps_grid.adapter = this
|
all_apps_grid.adapter = this
|
||||||
}
|
}
|
||||||
@ -151,7 +151,23 @@ 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 =
|
val gridItem =
|
||||||
HomeScreenGridItem(null, -1, -1, -1, -1, appLauncher.packageName, appLauncher.title, ITEM_TYPE_ICON, "", -1, "", "", null, appLauncher.drawable)
|
HomeScreenGridItem(
|
||||||
|
null,
|
||||||
|
-1,
|
||||||
|
-1,
|
||||||
|
-1,
|
||||||
|
-1,
|
||||||
|
appLauncher.packageName,
|
||||||
|
appLauncher.activityName,
|
||||||
|
appLauncher.title,
|
||||||
|
ITEM_TYPE_ICON,
|
||||||
|
"",
|
||||||
|
-1,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
appLauncher.drawable
|
||||||
|
)
|
||||||
activity?.showHomeIconMenu(x, y, gridItem, true)
|
activity?.showHomeIconMenu(x, y, gridItem, true)
|
||||||
ignoreTouches = true
|
ignoreTouches = true
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,14 @@ data class AppLauncher(
|
|||||||
@PrimaryKey(autoGenerate = true) var id: Long?,
|
@PrimaryKey(autoGenerate = true) var id: Long?,
|
||||||
@ColumnInfo(name = "title") var title: String,
|
@ColumnInfo(name = "title") var title: String,
|
||||||
@ColumnInfo(name = "package_name") var packageName: String,
|
@ColumnInfo(name = "package_name") var packageName: String,
|
||||||
|
@ColumnInfo(name = "activity_name") var activityName: String, // some apps create multiple icons, this is needed at clicking them
|
||||||
@ColumnInfo(name = "order") var order: Int,
|
@ColumnInfo(name = "order") var order: Int,
|
||||||
@ColumnInfo(name = "thumbnail_color") var thumbnailColor: Int,
|
@ColumnInfo(name = "thumbnail_color") var thumbnailColor: Int,
|
||||||
|
|
||||||
@Ignore var drawable: Drawable?
|
@Ignore var drawable: Drawable?
|
||||||
) : Comparable<AppLauncher> {
|
) : Comparable<AppLauncher> {
|
||||||
|
|
||||||
constructor() : this(null, "", "", 0, 0, null)
|
constructor() : this(null, "", "", "", 0, 0, null)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var sorting = 0
|
var sorting = 0
|
||||||
|
@ -16,6 +16,7 @@ data class HomeScreenGridItem(
|
|||||||
@ColumnInfo(name = "right") var right: Int,
|
@ColumnInfo(name = "right") var right: Int,
|
||||||
@ColumnInfo(name = "bottom") var bottom: Int,
|
@ColumnInfo(name = "bottom") var bottom: Int,
|
||||||
@ColumnInfo(name = "package_name") var packageName: String,
|
@ColumnInfo(name = "package_name") var packageName: String,
|
||||||
|
@ColumnInfo(name = "activity_name") var activityName: String, // needed at apps that create multiple icons at install, not just the launcher
|
||||||
@ColumnInfo(name = "title") var title: String,
|
@ColumnInfo(name = "title") var title: String,
|
||||||
@ColumnInfo(name = "type") var type: Int,
|
@ColumnInfo(name = "type") var type: Int,
|
||||||
@ColumnInfo(name = "class_name") var className: String,
|
@ColumnInfo(name = "class_name") var className: String,
|
||||||
@ -30,7 +31,7 @@ data class HomeScreenGridItem(
|
|||||||
@Ignore var widthCells: Int = 1,
|
@Ignore var widthCells: Int = 1,
|
||||||
@Ignore var heightCells: Int = 1
|
@Ignore var heightCells: Int = 1
|
||||||
) {
|
) {
|
||||||
constructor() : this(null, -1, -1, -1, -1, "", "", ITEM_TYPE_ICON, "", -1, "", "", null, 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) {
|
fun getWidthInCells() = if (right == -1 || left == -1) {
|
||||||
widthCells
|
widthCells
|
||||||
|
@ -278,6 +278,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
|||||||
xIndex,
|
xIndex,
|
||||||
yIndex,
|
yIndex,
|
||||||
draggedItem!!.packageName,
|
draggedItem!!.packageName,
|
||||||
|
draggedItem!!.activityName,
|
||||||
draggedItem!!.title,
|
draggedItem!!.title,
|
||||||
draggedItem!!.type,
|
draggedItem!!.type,
|
||||||
"",
|
"",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user