mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Add option to uninstall or launch apps, Improve layout
This commit is contained in:
parent
7e57d6208b
commit
f1dbaf928d
5 changed files with 128 additions and 13 deletions
|
@ -3,6 +3,8 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.finnmglas.launcher">
|
||||
|
||||
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
@ -10,6 +12,7 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity android:name=".MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
tools:ignore="LockedOrientationActivity">
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -20,6 +20,18 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
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
|
||||
android:id="@+id/scrollView3"
|
||||
android:layout_width="0dp"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
android:id="@+id/sub_head_1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Actions"
|
||||
android:text="Applications"
|
||||
android:textColor="#999"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
@ -177,15 +177,29 @@
|
|||
|
||||
</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
|
||||
android:id="@+id/buttonsdanger"
|
||||
android:id="@+id/buttons"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/actionschooser"
|
||||
app:layout_constraintVertical_bias="0.48000002">
|
||||
app:layout_constraintVertical_bias="0.19999999">
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
|
@ -196,23 +210,49 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:alpha=".3"
|
||||
android:onClick="resetSettingsClick"
|
||||
android:text="Reset" />
|
||||
android:onClick="setLauncher"
|
||||
android:text="Select Launcher" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:alpha=".3"
|
||||
android:onClick="setLauncher"
|
||||
android:text="Choose Launcher" />
|
||||
android:onClick="resetSettingsClick"
|
||||
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
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="backHome"
|
||||
android:text="Back Home" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
|
|
Loading…
Add table
Reference in a new issue