mirror of
https://github.com/jrpie/Launcher.git
synced 2025-04-19 10:20:51 +02:00
Add a new activity_choose activity
This commit is contained in:
parent
2327b028ff
commit
7fd2e9c733
5 changed files with 108 additions and 73 deletions
66
app/src/main/java/com/finnmglas/launcher/ChooseActivity.kt
Normal file
66
app/src/main/java/com/finnmglas/launcher/ChooseActivity.kt
Normal file
|
@ -0,0 +1,66 @@
|
|||
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.WindowManager
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import kotlinx.android.synthetic.main.activity_choose.*
|
||||
|
||||
|
||||
class ChooseActivity : AppCompatActivity() {
|
||||
|
||||
private fun listApps() {
|
||||
val mainIntent = Intent(Intent.ACTION_MAIN, null)
|
||||
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
|
||||
val pm = packageManager
|
||||
val apps = pm.getInstalledApplications(0)
|
||||
|
||||
val installedApps: MutableList<ApplicationInfo> = ArrayList()
|
||||
|
||||
// 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
|
||||
pm.getLaunchIntentForPackage(app.packageName)
|
||||
|
||||
// creating TextView programmatically
|
||||
val tvdynamic = TextView(this)
|
||||
tvdynamic.textSize = 20f
|
||||
tvdynamic.text = app.loadLabel(pm).toString()
|
||||
tvdynamic.setTextColor(Color.parseColor("#cccccc"));
|
||||
|
||||
tvdynamic.setOnClickListener { startActivity(pm.getLaunchIntentForPackage(app.packageName)) }
|
||||
|
||||
apps_list.addView(tvdynamic)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n") // I do not care
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
||||
setContentView(R.layout.activity_choose)
|
||||
listApps()
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import android.view.KeyEvent
|
|||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.MotionEventCompat
|
||||
|
@ -48,22 +49,6 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun listApps() {
|
||||
val mainIntent = Intent(Intent.ACTION_MAIN, null)
|
||||
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
|
||||
val pm = packageManager
|
||||
val packages =
|
||||
pm.getInstalledApplications(PackageManager.GET_META_DATA)
|
||||
|
||||
for (packageInfo in packages) {
|
||||
//packageInfo.packageName
|
||||
//packageInfo.sourceDir
|
||||
pm.getLaunchIntentForPackage(packageInfo.packageName)
|
||||
startActivity(pm.getLaunchIntentForPackage(packageInfo.packageName))
|
||||
}
|
||||
}
|
||||
|
||||
fun launchInstagram(v: View){ launchApp("com.instagram.android") }
|
||||
fun launchWhatsapp(v: View){ launchApp("com.whatsapp") }
|
||||
|
||||
|
@ -125,7 +110,8 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
}
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
//listApps() // crashes
|
||||
val intent = Intent(this, ChooseActivity::class.java);
|
||||
startActivity(intent)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue