From 832369da43f8d1a92ec1a1c06cfb0e139305db48 Mon Sep 17 00:00:00 2001 From: Kevin Schmid Date: Mon, 10 Jan 2022 22:11:07 +0100 Subject: [PATCH 1/3] removed local.properties from tracking, introduced gitignore with android studio stuff --- .gitignore | 30 ++++++++++++++++++++++++++++++ local.properties | 10 ---------- 2 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 .gitignore delete mode 100644 local.properties diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..95814ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Log/OS Files +*.log + +# Android Studio generated files and folders +captures/ +.externalNativeBuild/ +.cxx/ +*.apk +output.json + +# IntelliJ +*.iml +.idea/ + +# Keystore files +*.jks +*.keystore + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Android Profiling +*.hprof \ No newline at end of file diff --git a/local.properties b/local.properties deleted file mode 100644 index da02c60..0000000 --- a/local.properties +++ /dev/null @@ -1,10 +0,0 @@ -## This file is automatically generated by Android Studio. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file should *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -sdk.dir=/Users/hugh/Library/Android/sdk \ No newline at end of file From ff307027d7ecdeba71095131926fbfca1108e957 Mon Sep 17 00:00:00 2001 From: Kevin Schmid Date: Mon, 10 Jan 2022 22:11:59 +0100 Subject: [PATCH 2/3] updated gradle patch version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9784795..b41e580 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { } } dependencies { - classpath "com.android.tools.build:gradle:7.0.2" + classpath 'com.android.tools.build:gradle:7.0.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31" // NOTE: Do not place your application dependencies here; they belong From 8037e404527574fae30c24add71f4d960907dd02 Mon Sep 17 00:00:00 2001 From: Kevin Schmid Date: Mon, 10 Jan 2022 22:13:04 +0100 Subject: [PATCH 3/3] introduced the capability to display sideloaded apks like f-droid --- .../com/hugegreenbug/launchy/AppManager.kt | 47 +++++++++---------- .../java/com/hugegreenbug/launchy/Model.kt | 4 +- .../launchy/db/adapter/FavoriteAdapter.kt | 10 ++-- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/hugegreenbug/launchy/AppManager.kt b/app/src/main/java/com/hugegreenbug/launchy/AppManager.kt index 4a38ebf..308b3e0 100644 --- a/app/src/main/java/com/hugegreenbug/launchy/AppManager.kt +++ b/app/src/main/java/com/hugegreenbug/launchy/AppManager.kt @@ -3,7 +3,8 @@ package com.hugegreenbug.launchy import android.annotation.SuppressLint import android.content.Context import android.content.Intent -import android.content.pm.ComponentInfo +import android.content.pm.ApplicationInfo +import android.content.pm.PackageItemInfo import android.content.pm.PackageManager.MATCH_ALL import android.graphics.drawable.Drawable import android.util.ArrayMap @@ -17,38 +18,34 @@ class AppManager(private val context: Context) { fun getLaunchableApps(): List { val intent = Intent(Intent.ACTION_MAIN, null) intent.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER) - var list = packageManager.queryIntentActivities(intent, MATCH_ALL) - .map { it.activityInfo } - .map { App(it.packageName, it.loadLabel(packageManager).toString(), it, false) } - val listIter = list.iterator() - while (listIter.hasNext()) { - val app = listIter.next() - val drawable = getAppIcon(app.componentInfo) - if (drawable == null) { - list = list.filterIndexed { _, element -> - element.packageName != app.packageName - } - } - } + + val list = ( getAppsThroughPackages() + getAppsThroughIntent(intent) ) + .distinctBy { it.packageName } + .sortedBy { it.label } return list } + private fun getAppsThroughIntent(intent: Intent) = + packageManager.queryIntentActivities(intent, MATCH_ALL) + .map { it.activityInfo } + .map { App(it.packageName, it.loadLabel(packageManager).toString(), it, false) } + + private fun getAppsThroughPackages() = packageManager.getInstalledPackages(0) + .filter { (it.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0 } + .map { it.applicationInfo } + .map { App(it.packageName, it.loadLabel(packageManager).toString(), it, false) } + fun startApp(app: App) { - val intent = packageManager.getLeanbackLaunchIntentForPackage(app.packageName) + val intent = packageManager.getLeanbackLaunchIntentForPackage(app.packageName) ?: + packageManager.getLaunchIntentForPackage(app.packageName) context.startActivity(intent) } - fun getAppIcon(componentInfo: ComponentInfo): Drawable? - = appIconCache[componentInfo.packageName] ?: loadAppIcon(componentInfo) - - private fun loadAppIcon(componentInfo: ComponentInfo): Drawable? { - return try { - val drawable = componentInfo.loadBanner(packageManager) ?: return null + fun getAppIcon(info: PackageItemInfo): Drawable + = appIconCache[info.packageName] ?: loadAppIcon(info) - drawable - } catch (e: SecurityException) { - null - } + private fun loadAppIcon(info: PackageItemInfo): Drawable { + return info.loadBanner(packageManager) ?: info.loadIcon(packageManager) } } \ No newline at end of file diff --git a/app/src/main/java/com/hugegreenbug/launchy/Model.kt b/app/src/main/java/com/hugegreenbug/launchy/Model.kt index 89f16a5..fabc5d0 100644 --- a/app/src/main/java/com/hugegreenbug/launchy/Model.kt +++ b/app/src/main/java/com/hugegreenbug/launchy/Model.kt @@ -1,8 +1,8 @@ package com.hugegreenbug.launchy -import android.content.pm.ComponentInfo +import android.content.pm.PackageItemInfo import android.graphics.Bitmap data class App(val packageName: String, val label: String, - val componentInfo: ComponentInfo, var favorite: Boolean) + val packageItemInfo: PackageItemInfo, var favorite: Boolean) data class Unsplash(val author: String, val url: String, val thumb: Bitmap, val name: String) diff --git a/app/src/main/java/com/hugegreenbug/launchy/db/adapter/FavoriteAdapter.kt b/app/src/main/java/com/hugegreenbug/launchy/db/adapter/FavoriteAdapter.kt index 9d9e005..98ac5d7 100644 --- a/app/src/main/java/com/hugegreenbug/launchy/db/adapter/FavoriteAdapter.kt +++ b/app/src/main/java/com/hugegreenbug/launchy/db/adapter/FavoriteAdapter.kt @@ -44,12 +44,10 @@ class FavoriteAdapter(private val appManager: AppManager, private var list: List return@setOnClickListener } - val banner = appManager.getAppIcon(app.componentInfo) - if (banner != null) { - val bannerBmap = BitmapUtils.toBitmap(banner) - val roundedBanner = getRoundedCornerBitmap(bannerBmap) - ivIcon.setImageBitmap(roundedBanner) - } + val banner = appManager.getAppIcon(app.packageItemInfo) + val bannerBmap = BitmapUtils.toBitmap(banner) + val roundedBanner = getRoundedCornerBitmap(bannerBmap) + ivIcon.setImageBitmap(roundedBanner) if (app.favorite) { ivFav.visibility = View.VISIBLE } else {