mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Automatically select default apps
This commit is contained in:
parent
50350139e4
commit
63bc9a619a
4 changed files with 167 additions and 40 deletions
|
@ -54,6 +54,7 @@ class ChooseActivity : AppCompatActivity() {
|
|||
tvdynamic.text = app.loadLabel(pm).toString()
|
||||
tvdynamic.setTextColor(Color.parseColor("#cccccc"))
|
||||
|
||||
//TODO Add delete app option
|
||||
if (action == "run"){
|
||||
tvdynamic.setOnClickListener { startActivity(pm.getLaunchIntentForPackage(app.packageName)) }
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ package com.finnmglas.launcher
|
|||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.SharedPreferences.Editor
|
||||
import android.os.Bundle
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.*
|
||||
|
@ -25,11 +23,13 @@ var leftApp = ""
|
|||
var volumeUpApp = ""
|
||||
var volumeDownApp = ""
|
||||
|
||||
var calendarApp = ""
|
||||
var clockApp = ""
|
||||
|
||||
class MainActivity : AppCompatActivity(),
|
||||
GestureDetector.OnGestureListener,
|
||||
GestureDetector.OnDoubleTapListener {
|
||||
|
||||
|
||||
private lateinit var mDetector: GestureDetectorCompat
|
||||
|
||||
// get device dimensions
|
||||
|
@ -42,34 +42,27 @@ GestureDetector.OnDoubleTapListener {
|
|||
return intent
|
||||
}
|
||||
|
||||
private fun launchApp(packageName: String, fallback: String = "") {
|
||||
private fun launchApp(packageName: String) {
|
||||
val intent1 = getIntent(packageName)
|
||||
|
||||
if (intent1 != null) {
|
||||
applicationContext.startActivity(intent1)
|
||||
overridePendingTransition(0, 0)
|
||||
} else {
|
||||
val intent2 = getIntent(fallback)
|
||||
|
||||
if (intent2 != null) {
|
||||
applicationContext.startActivity(intent2)
|
||||
overridePendingTransition(0, 0)
|
||||
} else {
|
||||
Toast.makeText(
|
||||
this,
|
||||
"Package '$packageName' not found. Change your Settings.",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
Toast.makeText(
|
||||
this,
|
||||
"Open settings to choose an app for this action",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun launchCalendar(v: View) {
|
||||
launchApp("com.google.android.calendar", "com.samsung.android.calendar")
|
||||
launchApp(calendarApp)
|
||||
}
|
||||
|
||||
fun launchClock(v: View) {
|
||||
launchApp("com.sec.android.app.clockpackage")
|
||||
launchApp(clockApp)
|
||||
}
|
||||
|
||||
fun launchUpApp() {
|
||||
|
@ -115,12 +108,11 @@ GestureDetector.OnDoubleTapListener {
|
|||
|
||||
// First Startup
|
||||
if (!sharedPref.getBoolean("startedBefore", false))
|
||||
resetSettings(sharedPref)
|
||||
initSettings(sharedPref, this)
|
||||
|
||||
loadSettings(sharedPref)
|
||||
|
||||
// Flags
|
||||
|
||||
window.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||
|
|
|
@ -1,20 +1,158 @@
|
|||
package com.finnmglas.launcher
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
|
||||
fun resetSettings(sharedPref : SharedPreferences){
|
||||
|
||||
fun isInstalled(uri: String, context: Context): Boolean {
|
||||
val pm: PackageManager = context.packageManager
|
||||
try {
|
||||
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES)
|
||||
return true
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun initSettings(sharedPref : SharedPreferences, context: Context){
|
||||
val editor: SharedPreferences.Editor = sharedPref.edit()
|
||||
|
||||
// Set Defaults
|
||||
editor.putString("action_upApp", "org.mozilla.firefox")
|
||||
editor.putString("action_downApp", "com.samsung.android.app.galaxyfinder")
|
||||
editor.putString("action_rightApp", "com.samsung.android.email.provider")
|
||||
editor.putString("action_leftApp", "com.google.android.calendar")
|
||||
editor.putString("action_volumeUpApp", "com.whatsapp")
|
||||
editor.putString("action_volumeDownApp", "com.sec.android.app.popupcalculator")
|
||||
|
||||
editor.putBoolean("startedBefore", true) // never run this again
|
||||
editor.apply()
|
||||
|
||||
resetSettings(sharedPref, context)
|
||||
}
|
||||
|
||||
// Some magical default settings are set here ^^
|
||||
fun resetSettings(sharedPref : SharedPreferences, context: Context){
|
||||
val editor: SharedPreferences.Editor = sharedPref.edit()
|
||||
|
||||
|
||||
/* upApp -> Browser */
|
||||
|
||||
// #1 -> Firefox
|
||||
if(isInstalled("org.mozilla.firefox", context))
|
||||
editor.putString("action_upApp", "org.mozilla.firefox")
|
||||
|
||||
// #2 -> Chrome
|
||||
else if(isInstalled("com.android.chrome", context))
|
||||
editor.putString("action_upApp", "com.android.chrome")
|
||||
|
||||
// #3 -> Samsung Internet
|
||||
else if(isInstalled("com.sec.android.app.sbrowser", context))
|
||||
editor.putString("action_upApp", "com.sec.android.app.sbrowser")
|
||||
|
||||
else
|
||||
editor.putString("action_upApp", "")
|
||||
|
||||
|
||||
/* downApp -> Search Apps */
|
||||
|
||||
// #1 -> Galaxyfinder -> newer Devices
|
||||
if(isInstalled("com.samsung.android.app.galaxyfinder", context))
|
||||
editor.putString("action_downApp", "com.samsung.android.app.galaxyfinder")
|
||||
|
||||
// #2 -> Speechsearch -> older Devices
|
||||
else if(isInstalled("com.prometheusinteractive.voice_launcher", context))
|
||||
editor.putString("action_downApp", "com.prometheusinteractive.voice_launcher")
|
||||
|
||||
else
|
||||
editor.putString("action_downApp", "")
|
||||
|
||||
|
||||
/* rightApp -> Mail */
|
||||
|
||||
// #1 -> Web DE Mail -> people having it installed likely want it first
|
||||
if(isInstalled("de.web.mobile.android.mail", context))
|
||||
editor.putString("action_rightApp", "de.web.mobile.android.mail")
|
||||
|
||||
// #2 -> Samsung Mail
|
||||
else if(isInstalled("com.samsung.android.email.provider", context))
|
||||
editor.putString("action_rightApp", "com.samsung.android.email.provider")
|
||||
|
||||
// #3 -> Google Mail
|
||||
else if(isInstalled("com.google.android.gm", context))
|
||||
editor.putString("action_rightApp", "com.google.android.gm")
|
||||
|
||||
else
|
||||
editor.putString("action_rightApp", "")
|
||||
|
||||
|
||||
/* leftApp, calendarApp -> Calendar */
|
||||
|
||||
// #1 -> Google Calendar
|
||||
if(isInstalled("com.google.android.calendar", context)){
|
||||
editor.putString("action_leftApp", "com.google.android.calendar")
|
||||
editor.putString("action_calendarApp", "com.google.android.calendar")
|
||||
}
|
||||
|
||||
// #2 -> Samsung Calendar
|
||||
else if(isInstalled("com.samsung.android.calendar", context)){
|
||||
editor.putString("action_leftApp", "com.samsung.android.calendar")
|
||||
editor.putString("action_calendarApp", "com.samsung.android.calendar")
|
||||
}
|
||||
|
||||
else
|
||||
editor.putString("action_leftApp", "")
|
||||
|
||||
|
||||
/* volumeUpApp -> Messenger */
|
||||
|
||||
// #1 -> Whatsapp
|
||||
if(isInstalled("com.whatsapp", context))
|
||||
editor.putString("action_volumeUpApp", "com.whatsapp")
|
||||
|
||||
// #2 -> FB Messenger
|
||||
else if(isInstalled("com.facebook.orca", context))
|
||||
editor.putString("action_volumeUpApp", "com.facebook.orca")
|
||||
|
||||
// #3 -> Viber
|
||||
else if(isInstalled("com.viber.voip", context))
|
||||
editor.putString("action_volumeUpApp", "com.viber.voip")
|
||||
|
||||
// #4 -> Skype
|
||||
else if(isInstalled("com.skype.raider", context))
|
||||
editor.putString("action_volumeUpApp", "com.skype.raider")
|
||||
|
||||
// #5 -> Snapchat
|
||||
else if(isInstalled("com.snapchat.android", context))
|
||||
editor.putString("action_volumeUpApp", "com.snapchat.android")
|
||||
|
||||
// #6 -> Instagram
|
||||
else if(isInstalled("com.instagram.android", context))
|
||||
editor.putString("action_volumeUpApp", "com.instagram.android")
|
||||
|
||||
// #7 -> SMS
|
||||
else if(isInstalled("com.samsung.android.messaging", context))
|
||||
editor.putString("action_volumeUpApp", "com.samsung.android.messaging")
|
||||
|
||||
else
|
||||
editor.putString("action_volumeUpApp", "")
|
||||
|
||||
|
||||
/* volumeDownApp -> Util */
|
||||
|
||||
// #1 -> Github App
|
||||
if(isInstalled("com.github.android", context))
|
||||
editor.putString("action_volumeDownApp", "com.github.android")
|
||||
|
||||
// #2 -> Soundbrenner App
|
||||
else if(isInstalled("com.soundbrenner.pulse", context))
|
||||
editor.putString("action_volumeDownApp", "com.soundbrenner.pulse")
|
||||
|
||||
// #3 -> Calculator
|
||||
else if(isInstalled("com.sec.android.app.popupcalculator", context))
|
||||
editor.putString("action_volumeDownApp", "com.sec.android.app.popupcalculator")
|
||||
|
||||
else
|
||||
editor.putString("action_volumeDownApp", "")
|
||||
|
||||
/* clockApp default */
|
||||
editor.putString("action_clockApp", "com.sec.android.app.clockpackage")
|
||||
|
||||
editor.apply()
|
||||
|
||||
// TODO showInfo()
|
||||
}
|
||||
|
||||
fun loadSettings(sharedPref : SharedPreferences){
|
||||
|
@ -24,4 +162,7 @@ fun loadSettings(sharedPref : SharedPreferences){
|
|||
leftApp = sharedPref.getString("action_leftApp", "").toString()
|
||||
volumeUpApp = sharedPref.getString("action_volumeUpApp", "").toString()
|
||||
volumeDownApp = sharedPref.getString("action_volumeDownApp", "").toString()
|
||||
|
||||
calendarApp = sharedPref.getString("action_calendarApp", "").toString()
|
||||
clockApp = sharedPref.getString("action_clockApp", "").toString()
|
||||
}
|
|
@ -28,14 +28,7 @@ class SettingsActivity : AppCompatActivity() {
|
|||
editor.putString("action_$forApp", value.toString())
|
||||
editor.apply()
|
||||
|
||||
// Update running App
|
||||
if (forApp == "downApp") downApp = value.toString()
|
||||
else if (forApp == "upApp") upApp = value.toString()
|
||||
else if (forApp == "leftApp") leftApp = value.toString()
|
||||
else if (forApp == "rightApp") rightApp = value.toString()
|
||||
else if (forApp == "volumeDownApp") volumeDownApp = value.toString()
|
||||
else if (forApp == "volumeUpApp") volumeUpApp = value.toString()
|
||||
|
||||
loadSettings(sharedPref)
|
||||
}
|
||||
else {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
|
@ -70,7 +63,7 @@ class SettingsActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
fun openGithubRepo(view: View) {
|
||||
openNewTabWindow("https://github.com/finnmglas/Launcher", this)
|
||||
openNewTabWindow("https://github.com/finnmglas/Launcher#en", this)
|
||||
}
|
||||
|
||||
fun backHome(view: View) {
|
||||
|
@ -84,7 +77,7 @@ class SettingsActivity : AppCompatActivity() {
|
|||
.setMessage("This will discard all your App Choices. Sure you want to continue?")
|
||||
.setPositiveButton(android.R.string.yes,
|
||||
DialogInterface.OnClickListener { dialog, which ->
|
||||
resetSettings(this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE))
|
||||
resetSettings(this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE), this)
|
||||
finish()
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
|
|
Loading…
Add table
Reference in a new issue