mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Make preferences persistent
This commit is contained in:
parent
2893437b14
commit
5a2ff95c15
3 changed files with 51 additions and 8 deletions
|
@ -16,13 +16,13 @@ import java.util.*
|
||||||
import kotlin.concurrent.fixedRateTimer
|
import kotlin.concurrent.fixedRateTimer
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
// App Launch Actions
|
||||||
var upApp = "org.mozilla.firefox"
|
var upApp = ""
|
||||||
var downApp = "com.samsung.android.app.galaxyfinder"
|
var downApp = ""
|
||||||
var rightApp = "com.samsung.android.email.provider"
|
var rightApp = ""
|
||||||
var leftApp = "com.google.android.calendar"
|
var leftApp = ""
|
||||||
var volumeUpApp = "com.whatsapp"
|
var volumeUpApp = ""
|
||||||
var volumeDownApp = "com.sec.android.app.popupcalculator"
|
var volumeDownApp = ""
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity(),
|
class MainActivity : AppCompatActivity(),
|
||||||
GestureDetector.OnGestureListener,
|
GestureDetector.OnGestureListener,
|
||||||
|
@ -38,7 +38,7 @@ GestureDetector.OnDoubleTapListener {
|
||||||
val pm = applicationContext.packageManager
|
val pm = applicationContext.packageManager
|
||||||
val intent: Intent? = pm.getLaunchIntentForPackage(packageName)
|
val intent: Intent? = pm.getLaunchIntentForPackage(packageName)
|
||||||
intent?.addCategory(Intent.CATEGORY_LAUNCHER)
|
intent?.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
return intent;
|
return intent
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchApp(packageName: String, fallback: String = "") {
|
private fun launchApp(packageName: String, fallback: String = "") {
|
||||||
|
@ -108,6 +108,36 @@ GestureDetector.OnDoubleTapListener {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
// Preferences
|
||||||
|
val sharedPref = this.getSharedPreferences(
|
||||||
|
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
// First Startup
|
||||||
|
if (!sharedPref.getBoolean("startedBefore", false)){
|
||||||
|
val editor: 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()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load settings
|
||||||
|
upApp = sharedPref.getString("action_upApp", "").toString()
|
||||||
|
downApp = sharedPref.getString("action_downApp", "").toString()
|
||||||
|
rightApp = sharedPref.getString("action_rightApp", "").toString()
|
||||||
|
leftApp = sharedPref.getString("action_leftApp", "").toString()
|
||||||
|
volumeUpApp = sharedPref.getString("action_volumeUpApp", "").toString()
|
||||||
|
volumeDownApp = sharedPref.getString("action_volumeDownApp", "").toString()
|
||||||
|
|
||||||
|
// Flags
|
||||||
|
|
||||||
window.setFlags(
|
window.setFlags(
|
||||||
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.finnmglas.launcher
|
package com.finnmglas.launcher
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.pm.ResolveInfo
|
import android.content.pm.ResolveInfo
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
@ -28,12 +30,22 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
val value = data?.getStringExtra("value")
|
val value = data?.getStringExtra("value")
|
||||||
val forApp = data?.getStringExtra("forApp") ?: return
|
val forApp = data?.getStringExtra("forApp") ?: return
|
||||||
|
|
||||||
|
// Save the new App to Preferences
|
||||||
|
val sharedPref = this.getSharedPreferences(
|
||||||
|
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
val editor :SharedPreferences.Editor = sharedPref.edit()
|
||||||
|
editor.putString("action_$forApp", value.toString())
|
||||||
|
editor.apply()
|
||||||
|
|
||||||
|
// Update running App
|
||||||
if (forApp == "downApp") downApp = value.toString()
|
if (forApp == "downApp") downApp = value.toString()
|
||||||
else if (forApp == "upApp") upApp = value.toString()
|
else if (forApp == "upApp") upApp = value.toString()
|
||||||
else if (forApp == "leftApp") leftApp = value.toString()
|
else if (forApp == "leftApp") leftApp = value.toString()
|
||||||
else if (forApp == "rightApp") rightApp = value.toString()
|
else if (forApp == "rightApp") rightApp = value.toString()
|
||||||
else if (forApp == "volumeDownApp") volumeDownApp = value.toString()
|
else if (forApp == "volumeDownApp") volumeDownApp = value.toString()
|
||||||
else if (forApp == "volumeUpApp") volumeUpApp = value.toString()
|
else if (forApp == "volumeUpApp") volumeUpApp = value.toString()
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Launcher</string>
|
<string name="app_name">Launcher</string>
|
||||||
|
<string name ="preference_file_key">V3RYR4ND0MK3YCR4P</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Reference in a new issue