mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Improve app choosing layout, sort launchable apps
This commit is contained in:
parent
ea0e094c5c
commit
50ed720925
2 changed files with 43 additions and 28 deletions
|
@ -2,9 +2,9 @@ package com.finnmglas.launcher
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -13,6 +13,10 @@ import kotlinx.android.synthetic.main.activity_choose.*
|
|||
|
||||
class ChooseActivity : AppCompatActivity() {
|
||||
|
||||
fun backHome(view: View) {
|
||||
finish()
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n") // I do not care
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -26,38 +30,27 @@ class ChooseActivity : AppCompatActivity() {
|
|||
val action = bundle!!.getString("action") // why choose an app
|
||||
val forApp = bundle.getString("forApp") // which app we choose
|
||||
|
||||
// Build Layout
|
||||
/* Build Layout */
|
||||
|
||||
// TODO: Make this more efficient, faster, generate the list before
|
||||
|
||||
val mainIntent = Intent(Intent.ACTION_MAIN, null)
|
||||
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
|
||||
val pm = packageManager
|
||||
val apps = pm.getInstalledApplications(0)
|
||||
val i = Intent(Intent.ACTION_MAIN)
|
||||
i.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
val apps = pm.queryIntentActivities(i, 0)
|
||||
|
||||
val installedApps: MutableList<ApplicationInfo> = ArrayList()
|
||||
apps.sortBy { it.activityInfo.loadLabel(pm).toString() }
|
||||
|
||||
// list
|
||||
for (app in apps) {
|
||||
|
||||
if (app.flags and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP != 0) {
|
||||
//checks for flags; if flagged, check if updated system app
|
||||
installedApps.add(app)
|
||||
} else if (app.flags and ApplicationInfo.FLAG_SYSTEM != 0) {
|
||||
//it's a system app, not interested
|
||||
} else {
|
||||
//in this case, it should be a user-installed app
|
||||
installedApps.add(app)
|
||||
}
|
||||
}
|
||||
|
||||
// ui
|
||||
for (app in installedApps) {
|
||||
//packageInfo.sourceDir
|
||||
for (resolveInfo in apps) {
|
||||
val app = resolveInfo.activityInfo
|
||||
pm.getLaunchIntentForPackage(app.packageName)
|
||||
|
||||
// creating TextView programmatically
|
||||
val tvdynamic = TextView(this)
|
||||
tvdynamic.textSize = 20f
|
||||
tvdynamic.textSize = 24f
|
||||
tvdynamic.text = app.loadLabel(pm).toString()
|
||||
tvdynamic.setTextColor(Color.parseColor("#cccccc"))
|
||||
|
||||
|
@ -66,7 +59,6 @@ class ChooseActivity : AppCompatActivity() {
|
|||
}
|
||||
else if (action == "pick"){
|
||||
tvdynamic.setOnClickListener {
|
||||
|
||||
val returnIntent = Intent()
|
||||
returnIntent.putExtra("value", app.packageName)
|
||||
returnIntent.putExtra("forApp", forApp)
|
||||
|
@ -74,11 +66,9 @@ class ChooseActivity : AppCompatActivity() {
|
|||
5000,
|
||||
returnIntent
|
||||
)
|
||||
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
apps_list.addView(tvdynamic)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,19 +7,33 @@
|
|||
android:background="?attr/colorPrimaryDark"
|
||||
tools:context=".ChooseActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/heading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Choose App"
|
||||
android:textColor="#cccccc"
|
||||
android:textSize="36sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.100000024" />
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView3"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginTop="86dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginBottom="128dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
app:layout_constraintTop_toTopOf="@id/heading">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/apps_list"
|
||||
|
@ -28,4 +42,15 @@
|
|||
android:orientation="vertical" />
|
||||
</ScrollView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="backHome"
|
||||
android:text="Back to Settings"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/scrollView3" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Add table
Reference in a new issue