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

@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.finnmglas.launcher"> package="com.finnmglas.launcher">
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
@ -10,6 +12,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".MainActivity" <activity android:name=".MainActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"> tools:ignore="LockedOrientationActivity">

View file

@ -1,18 +1,23 @@
package com.finnmglas.launcher package com.finnmglas.launcher
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
import android.widget.TextView import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_choose.* import kotlinx.android.synthetic.main.activity_choose.*
class ChooseActivity : AppCompatActivity() { class ChooseActivity : AppCompatActivity() {
val UNINSTALL_REQUEST_CODE = 1
fun backHome(view: View) { fun backHome(view: View) {
finish() finish()
} }
@ -30,6 +35,15 @@ class ChooseActivity : AppCompatActivity() {
val action = bundle!!.getString("action") // why choose an app val action = bundle!!.getString("action") // why choose an app
val forApp = bundle.getString("forApp") // which app we choose 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 */ /* Build Layout */
// TODO: Make this more efficient, faster, generate the list before // TODO: Make this more efficient, faster, generate the list before
@ -54,8 +68,7 @@ class ChooseActivity : AppCompatActivity() {
tvdynamic.text = app.loadLabel(pm).toString() tvdynamic.text = app.loadLabel(pm).toString()
tvdynamic.setTextColor(Color.parseColor("#cccccc")) tvdynamic.setTextColor(Color.parseColor("#cccccc"))
//TODO Add delete app option if (action == "launch"){
if (action == "run"){
tvdynamic.setOnClickListener { startActivity(pm.getLaunchIntentForPackage(app.packageName)) } tvdynamic.setOnClickListener { startActivity(pm.getLaunchIntentForPackage(app.packageName)) }
} }
else if (action == "pick"){ else if (action == "pick"){
@ -70,7 +83,40 @@ class ChooseActivity : AppCompatActivity() {
finish() 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) 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 import androidx.appcompat.app.AppCompatActivity
//TODO Make Settings scrollable as soon as more are added
class SettingsActivity : AppCompatActivity() { class SettingsActivity : AppCompatActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if(requestCode == 5000) if(requestCode == 5000)
@ -48,11 +50,23 @@ class SettingsActivity : AppCompatActivity() {
fun chooseApp(forAction :String) { fun chooseApp(forAction :String) {
val intent = Intent(this, ChooseActivity::class.java) val intent = Intent(this, ChooseActivity::class.java)
intent.putExtra("action", "pick") // why choose an app intent.putExtra("action", "pick")
intent.putExtra("forApp", forAction) // which app we choose intent.putExtra("forApp", forAction) // for which action we choose the app
startActivityForResult(intent, 5000) 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) { fun openNewTabWindow(urls: String, context : Context) {
val uris = Uri.parse(urls) val uris = Uri.parse(urls)
val intents = Intent(Intent.ACTION_VIEW, uris) val intents = Intent(Intent.ACTION_VIEW, uris)

View file

@ -20,6 +20,18 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.100000024" /> app:layout_constraintVertical_bias="0.100000024" />
<TextView
android:id="@+id/subheading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#999999"
android:textSize="14sp"
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.17000002" />
<ScrollView <ScrollView
android:id="@+id/scrollView3" android:id="@+id/scrollView3"
android:layout_width="0dp" android:layout_width="0dp"

View file

@ -24,7 +24,7 @@
android:id="@+id/sub_head_1" android:id="@+id/sub_head_1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Actions" android:text="Applications"
android:textColor="#999" android:textColor="#999"
android:textSize="18sp" android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
@ -177,15 +177,29 @@
</TableLayout> </TableLayout>
<TextView
android:id="@+id/sub_head_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Actions"
android:textColor="#999"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="@id/buttons"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/actionschooser"
app:layout_constraintVertical_bias="0.65999997" />
<TableLayout <TableLayout
android:id="@+id/buttonsdanger" android:id="@+id/buttons"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/actionschooser" app:layout_constraintTop_toBottomOf="@+id/actionschooser"
app:layout_constraintVertical_bias="0.48000002"> app:layout_constraintVertical_bias="0.19999999">
<TableRow <TableRow
android:layout_width="match_parent" android:layout_width="match_parent"
@ -196,23 +210,49 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:alpha=".3" android:alpha=".3"
android:onClick="resetSettingsClick" android:onClick="setLauncher"
android:text="Reset" /> android:text="Select Launcher" />
<Button <Button
android:id="@+id/button2"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:alpha=".3" android:alpha=".3"
android:onClick="setLauncher" android:onClick="resetSettingsClick"
android:text="Choose Launcher" /> android:text="Reset Settings" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha=".3"
android:onClick="chooseLaunchApp"
android:text="Launch Apps" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha=".3"
android:onClick="chooseUninstallApp"
android:text="Uninstall Apps" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button <Button
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:onClick="backHome" android:onClick="backHome"
android:text="Back Home" /> android:text="Back Home" />
</TableRow> </TableRow>
</TableLayout> </TableLayout>