Add option to uninstall or launch apps, Improve layout

This commit is contained in:
Finn M Glas 2020-05-16 07:32:32 +02:00
parent 7e57d6208b
commit f1dbaf928d
5 changed files with 128 additions and 13 deletions

View file

@ -1,18 +1,23 @@
package com.finnmglas.launcher
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_choose.*
class ChooseActivity : AppCompatActivity() {
val UNINSTALL_REQUEST_CODE = 1
fun backHome(view: View) {
finish()
}
@ -30,6 +35,15 @@ class ChooseActivity : AppCompatActivity() {
val action = bundle!!.getString("action") // why choose an app
val forApp = bundle.getString("forApp") // which app we choose
if (action == "launch")
heading.text = "Launch Apps"
else if (action == "pick") {
heading.text = "Choose App"
subheading.text = forApp
}
else if (action == "uninstall")
heading.text = "Uninstall Apps"
/* Build Layout */
// TODO: Make this more efficient, faster, generate the list before
@ -54,8 +68,7 @@ class ChooseActivity : AppCompatActivity() {
tvdynamic.text = app.loadLabel(pm).toString()
tvdynamic.setTextColor(Color.parseColor("#cccccc"))
//TODO Add delete app option
if (action == "run"){
if (action == "launch"){
tvdynamic.setOnClickListener { startActivity(pm.getLaunchIntentForPackage(app.packageName)) }
}
else if (action == "pick"){
@ -70,7 +83,40 @@ class ChooseActivity : AppCompatActivity() {
finish()
}
}
else if (action == "uninstall"){
tvdynamic.setOnClickListener {
val intent = Intent(Intent.ACTION_UNINSTALL_PACKAGE)
intent.data = Uri.parse("package:" + app.packageName)
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
startActivityForResult(intent, UNINSTALL_REQUEST_CODE)
}
}
apps_list.addView(tvdynamic)
}
}
override fun onActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent?
) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == UNINSTALL_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
Toast.makeText(
this,
"Removed the selected application",
Toast.LENGTH_LONG
).show()
finish()
} else if (resultCode == Activity.RESULT_FIRST_USER) {
Toast.makeText(
this,
"Can't remove this app",
Toast.LENGTH_LONG
).show()
finish()
}
}
}
}

View file

@ -17,6 +17,8 @@ import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
//TODO Make Settings scrollable as soon as more are added
class SettingsActivity : AppCompatActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if(requestCode == 5000)
@ -48,11 +50,23 @@ class SettingsActivity : AppCompatActivity() {
fun chooseApp(forAction :String) {
val intent = Intent(this, ChooseActivity::class.java)
intent.putExtra("action", "pick") // why choose an app
intent.putExtra("forApp", forAction) // which app we choose
intent.putExtra("action", "pick")
intent.putExtra("forApp", forAction) // for which action we choose the app
startActivityForResult(intent, 5000)
}
fun chooseUninstallApp(view: View) {
val intent = Intent(this, ChooseActivity::class.java)
intent.putExtra("action", "uninstall")
startActivity(intent)
}
fun chooseLaunchApp(view: View) {
val intent = Intent(this, ChooseActivity::class.java)
intent.putExtra("action", "launch")
startActivity(intent)
}
fun openNewTabWindow(urls: String, context : Context) {
val uris = Uri.parse(urls)
val intents = Intent(Intent.ACTION_VIEW, uris)