mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Add option to reset settings and to go to homescreen
This commit is contained in:
parent
6cb06b3095
commit
ea0e094c5c
4 changed files with 83 additions and 37 deletions
|
@ -3,6 +3,7 @@ package com.finnmglas.launcher
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.content.SharedPreferences.Editor
|
import android.content.SharedPreferences.Editor
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
|
@ -113,28 +114,10 @@ GestureDetector.OnDoubleTapListener {
|
||||||
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
||||||
|
|
||||||
// First Startup
|
// First Startup
|
||||||
if (!sharedPref.getBoolean("startedBefore", false)){
|
if (!sharedPref.getBoolean("startedBefore", false))
|
||||||
val editor: Editor = sharedPref.edit()
|
resetSettings(sharedPref)
|
||||||
|
|
||||||
// Set Defaults
|
loadSettings(sharedPref)
|
||||||
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
|
// Flags
|
||||||
|
|
||||||
|
|
27
app/src/main/java/com/finnmglas/launcher/Settings.kt
Normal file
27
app/src/main/java/com/finnmglas/launcher/Settings.kt
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package com.finnmglas.launcher
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
|
||||||
|
fun resetSettings(sharedPref : SharedPreferences){
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadSettings(sharedPref : SharedPreferences){
|
||||||
|
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()
|
||||||
|
}
|
|
@ -1,29 +1,16 @@
|
||||||
package com.finnmglas.launcher
|
package com.finnmglas.launcher
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.content.pm.ResolveInfo
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.Html
|
|
||||||
import android.util.DisplayMetrics
|
|
||||||
import android.view.KeyEvent
|
|
||||||
import android.view.MotionEvent
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.TextView
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.MotionEventCompat
|
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
|
||||||
import kotlinx.android.synthetic.main.activity_settings.*
|
|
||||||
import kotlin.math.abs
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
import kotlin.concurrent.fixedRateTimer
|
|
||||||
|
|
||||||
|
|
||||||
class SettingsActivity : AppCompatActivity() {
|
class SettingsActivity : AppCompatActivity() {
|
||||||
|
@ -86,6 +73,25 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
openNewTabWindow("https://github.com/finnmglas/Launcher", this)
|
openNewTabWindow("https://github.com/finnmglas/Launcher", this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun backHome(view: View) {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show a dialog prompting for confirmation
|
||||||
|
fun resetSettingsClick(view: View) {
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle("Reset Settings")
|
||||||
|
.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))
|
||||||
|
finish()
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.no, null)
|
||||||
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n") // I do not care
|
@SuppressLint("SetTextI18n") // I do not care
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
|
@ -171,10 +171,40 @@
|
||||||
|
|
||||||
</TableLayout>
|
</TableLayout>
|
||||||
|
|
||||||
|
<TableLayout
|
||||||
|
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">
|
||||||
|
|
||||||
enter image description here
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="resetSettingsClick"
|
||||||
|
android:text="Reset" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button3"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="backHome"
|
||||||
|
android:text="Back Home" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
</TableLayout>
|
||||||
|
|
||||||
<TableLayout
|
<TableLayout
|
||||||
|
android:id="@+id/about_footer"
|
||||||
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"
|
||||||
|
|
Loading…
Add table
Reference in a new issue