Skip to content

Commit

Permalink
feat: Use launcehr apps to retrieve installed apps
Browse files Browse the repository at this point in the history
  • Loading branch information
axel358 committed Jan 23, 2024
1 parent 54b77ee commit da87fca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AppChooserPreference(private val context: Context, attrs: AttributeSet?) :
override fun onClick() {
val dialog = MaterialAlertDialogBuilder(context)
dialog.setTitle(R.string.choose_app)
val apps = AppUtils.getInstalledApps(context.packageManager)
val apps = AppUtils.getInstalledApps(context)
dialog.setAdapter(AppAdapter(context, apps)) { _, position ->
val app = apps[position]
sharedPreferences!!.edit().putString(key, app.packageName).apply()
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/cu/axel/smartdock/services/DockService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On
"113" -> isModifierPressed = event.isCtrlPressed
"3" -> isModifierPressed = event.isMetaPressed
}

if (event.action == KeyEvent.ACTION_UP && isModifierPressed) {
if (event.keyCode == KeyEvent.KEYCODE_L && sharedPreferences.getBoolean("enable_lock_desktop", true))
lockScreen()
Expand Down Expand Up @@ -1427,7 +1428,7 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On

internal inner class UpdateAppMenuTask : AsyncTask<Void?, Void?, ArrayList<App>>() {
override fun doInBackground(p1: Array<Void?>): ArrayList<App> {
return AppUtils.getInstalledApps(packageManager)
return AppUtils.getInstalledApps(context)
}

override fun onPostExecute(result: ArrayList<App>) {
Expand Down
23 changes: 14 additions & 9 deletions app/src/main/java/cu/axel/smartdock/utils/AppUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import android.app.usage.UsageStatsManager
import android.content.Context
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.LauncherActivityInfo
import android.content.pm.LauncherApps
import android.content.pm.PackageManager
import android.graphics.Rect
import android.graphics.drawable.Drawable
Expand All @@ -22,26 +24,28 @@ import java.io.FileNotFoundException
import java.io.FileReader
import java.io.FileWriter
import java.io.IOException
import android.os.Process

object AppUtils {
const val PINNED_LIST = "pinned.lst"
const val DOCK_PINNED_LIST = "dock_pinned.lst"
const val DESKTOP_LIST = "desktop.lst"
var currentApp = ""
fun getInstalledApps(packageManager: PackageManager): ArrayList<App> {
fun getInstalledApps(context: Context): ArrayList<App> {
val apps = ArrayList<App>()
val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_LAUNCHER)
val appsInfo = packageManager.queryIntentActivities(intent, 0)
val launcherApps = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val appsInfo: List<LauncherActivityInfo> =
launcherApps.getActivityList(null, Process.myUserHandle())
.sortedWith(compareBy { it.label.toString() })

//TODO: Filter Google App
for (appInfo in appsInfo) {
val label = appInfo.activityInfo.loadLabel(packageManager).toString()
val icon = appInfo.activityInfo.loadIcon(packageManager)
val packageName = appInfo.activityInfo.packageName
val label = appInfo.label.toString()
val icon = appInfo.getIcon(0)
val packageName = appInfo.componentName.packageName
apps.add(App(label, packageName, icon))
}
apps.sortWith { app: App, app2: App -> app.name.compareTo(app2.name, ignoreCase = true) }

return apps
}

Expand Down Expand Up @@ -312,7 +316,8 @@ object AppUtils {
}

fun resizeTask(context: Context, mode: String, taskId: Int, dockHeight: Int, secondary: Boolean) {
if (taskId < 0) return
if (taskId < 0)
return
val bounds = makeLaunchBounds(context, mode, dockHeight, secondary)
DeviceUtils.runAsRoot("am task resize " + taskId + " " + bounds.left + " " + bounds.top + " " + bounds.right
+ " " + bounds.bottom)
Expand Down

0 comments on commit da87fca

Please sign in to comment.