mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-02-01 09:56:47 +01:00
list all installed apps at the Add launcher dialog
This commit is contained in:
parent
12d4997d94
commit
69645885f3
@ -25,7 +25,7 @@ class MyCursorAdapter(cxt: Context, dataCursor: Cursor, val itemClick: (AppLaunc
|
|||||||
val name = cursor.getString(cursor.getColumnIndex(DbHelper.NAME))
|
val name = cursor.getString(cursor.getColumnIndex(DbHelper.NAME))
|
||||||
val pkgName = cursor.getString(cursor.getColumnIndex(DbHelper.PKG_NAME))
|
val pkgName = cursor.getString(cursor.getColumnIndex(DbHelper.PKG_NAME))
|
||||||
val icon = cursor.getInt(cursor.getColumnIndex(DbHelper.ICON_ID))
|
val icon = cursor.getInt(cursor.getColumnIndex(DbHelper.ICON_ID))
|
||||||
val launcher = AppLauncher(name, icon, pkgName)
|
val launcher = AppLauncher(name, pkgName, icon, null)
|
||||||
holder.bindView(context, launcher)
|
holder.bindView(context, launcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ class MyCursorAdapter(cxt: Context, dataCursor: Cursor, val itemClick: (AppLaunc
|
|||||||
fun bindView(context: Context, launcher: AppLauncher) {
|
fun bindView(context: Context, launcher: AppLauncher) {
|
||||||
with(launcher) {
|
with(launcher) {
|
||||||
itemView.launcher_label.text = launcher.name
|
itemView.launcher_label.text = launcher.name
|
||||||
itemView.launcher_icon.setImageDrawable(context.resources.getDrawable(launcher.icon))
|
itemView.launcher_icon.setImageDrawable(context.resources.getDrawable(launcher.iconId))
|
||||||
itemView.setOnClickListener { itemClick(this) }
|
itemView.setOnClickListener { itemClick(this) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.simplemobiletools.applauncher.adapters
|
||||||
|
|
||||||
|
import android.support.v7.widget.RecyclerView
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.simplemobiletools.applauncher.R
|
||||||
|
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||||
|
import kotlinx.android.synthetic.main.app_launcher_item.view.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class RecyclerAdapter(val launchers: ArrayList<AppLauncher>, val itemClick: (AppLauncher) -> Unit) :
|
||||||
|
RecyclerView.Adapter<RecyclerAdapter.ViewHolder>() {
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
holder.bindView(launchers[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||||
|
val view = LayoutInflater.from(parent?.context).inflate(R.layout.app_launcher_item, parent, false)
|
||||||
|
return ViewHolder(view, itemClick)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int {
|
||||||
|
return launchers.count()
|
||||||
|
}
|
||||||
|
|
||||||
|
class ViewHolder(view: View, val itemClick: (AppLauncher) -> Unit) : RecyclerView.ViewHolder(view) {
|
||||||
|
fun bindView(launcher: AppLauncher) {
|
||||||
|
with(launcher) {
|
||||||
|
itemView.launcher_label.text = launcher.name
|
||||||
|
itemView.launcher_icon.setImageDrawable(launcher.drawable)
|
||||||
|
itemView.setOnClickListener { itemClick(this) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,27 @@
|
|||||||
package com.simplemobiletools.applauncher.dialogs
|
package com.simplemobiletools.applauncher.dialogs
|
||||||
|
|
||||||
import android.app.AlertDialog
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.app.DialogFragment
|
import android.app.DialogFragment
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.support.v7.app.AlertDialog
|
||||||
|
import android.view.View
|
||||||
import com.simplemobiletools.applauncher.R
|
import com.simplemobiletools.applauncher.R
|
||||||
|
import com.simplemobiletools.applauncher.adapters.RecyclerAdapter
|
||||||
|
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||||
|
import kotlinx.android.synthetic.main.launcher_picker.view.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class AddAppDialog() : DialogFragment() {
|
class AddAppDialog() : DialogFragment() {
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val builder = AlertDialog.Builder(activity)
|
val builder = AlertDialog.Builder(activity)
|
||||||
builder.setTitle(R.string.add_apps)
|
builder.setTitle(R.string.add_apps)
|
||||||
|
|
||||||
|
val recyclerView = View.inflate(activity, R.layout.launcher_picker, null)
|
||||||
|
fillGrid(recyclerView)
|
||||||
|
builder.setView(recyclerView)
|
||||||
|
|
||||||
builder.setPositiveButton(android.R.string.ok, { dialogInterface, i ->
|
builder.setPositiveButton(android.R.string.ok, { dialogInterface, i ->
|
||||||
|
|
||||||
})
|
})
|
||||||
@ -17,4 +29,21 @@ class AddAppDialog() : DialogFragment() {
|
|||||||
builder.setNegativeButton(android.R.string.cancel, null)
|
builder.setNegativeButton(android.R.string.cancel, null)
|
||||||
return builder.create()
|
return builder.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fillGrid(recyclerView: View) {
|
||||||
|
val apps = ArrayList<AppLauncher>()
|
||||||
|
val packageManager = activity.packageManager
|
||||||
|
val intent = Intent(Intent.ACTION_MAIN, null)
|
||||||
|
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
||||||
|
for (info in list) {
|
||||||
|
val componentInfo = info.activityInfo.applicationInfo
|
||||||
|
apps.add(AppLauncher(componentInfo.loadLabel(packageManager).toString(), componentInfo.packageName, 0, componentInfo.loadIcon(packageManager)))
|
||||||
|
}
|
||||||
|
|
||||||
|
apps.sortBy { it.name }
|
||||||
|
recyclerView.launchers_holder.adapter = RecyclerAdapter(apps) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
package com.simplemobiletools.applauncher.models
|
package com.simplemobiletools.applauncher.models
|
||||||
|
|
||||||
data class AppLauncher(val name: String, val icon: Int, val pkgName: String)
|
import android.graphics.drawable.Drawable
|
||||||
|
|
||||||
|
data class AppLauncher(val name: String, val pkgName: String, val iconId: Int, val drawable: Drawable?)
|
||||||
|
11
app/src/main/res/layout/launcher_picker.xml
Normal file
11
app/src/main/res/layout/launcher_picker.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/launchers_holder"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
||||||
|
app:spanCount="@integer/columns"/>
|
Loading…
x
Reference in New Issue
Block a user