mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Clean up code in the Settings Activity
Extract all strings to the resource files (helpful for translations in the future), Move and simplify functions.
This commit is contained in:
parent
9e3cac35ae
commit
b8d1880fbc
4 changed files with 118 additions and 92 deletions
|
@ -8,6 +8,7 @@ import android.content.Intent
|
|||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.widget.Toast
|
||||
|
||||
|
@ -70,6 +71,15 @@ fun launchApp(packageName: String, context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
fun openNewTabWindow(urls: String, context : Context) {
|
||||
val uris = Uri.parse(urls)
|
||||
val intents = Intent(Intent.ACTION_VIEW, uris)
|
||||
val b = Bundle()
|
||||
b.putBoolean("new_window", true)
|
||||
intents.putExtras(b)
|
||||
context.startActivity(intents)
|
||||
}
|
||||
|
||||
/** Settings related functions */
|
||||
|
||||
fun openAppSettings(pkg :String, context:Context){
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.finnmglas.launcher
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlertDialog
|
||||
import android.content.*
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
|
@ -16,6 +14,17 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
//TODO Make Settings scrollable as soon as more are added
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
|
||||
/** Activity Lifecycle functions */
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
||||
setContentView(R.layout.activity_settings)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if(requestCode == 5000)
|
||||
{
|
||||
|
@ -37,6 +46,7 @@ class SettingsActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
/** onClick functions for Settings */
|
||||
fun chooseDownApp(view: View) {chooseApp("downApp")}
|
||||
fun chooseUpApp(view: View) {chooseApp("upApp")}
|
||||
fun chooseLeftApp(view: View) {chooseApp("leftApp")}
|
||||
|
@ -63,26 +73,9 @@ class SettingsActivity : AppCompatActivity() {
|
|||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun openNewTabWindow(urls: String, context : Context) {
|
||||
val uris = Uri.parse(urls)
|
||||
val intents = Intent(Intent.ACTION_VIEW, uris)
|
||||
val b = Bundle()
|
||||
b.putBoolean("new_window", true)
|
||||
intents.putExtras(b)
|
||||
context.startActivity(intents)
|
||||
}
|
||||
|
||||
fun openFinnWebsite(view: View) {
|
||||
openNewTabWindow("https://www.finnmglas.com/", this)
|
||||
}
|
||||
|
||||
fun openGithubRepo(view: View) {
|
||||
openNewTabWindow("https://github.com/finnmglas/Launcher#en", this)
|
||||
}
|
||||
|
||||
fun backHome(view: View) {
|
||||
finish()
|
||||
}
|
||||
fun openFinnWebsite(view: View) { openNewTabWindow("https://www.finnmglas.com/", this) }
|
||||
fun openGithubRepo(view: View) { openNewTabWindow("https://github.com/finnmglas/Launcher#en", this) }
|
||||
fun backHome(view: View) { finish() }
|
||||
|
||||
fun setLauncher(view: View) {
|
||||
// on newer sdk: choose launcher
|
||||
|
@ -124,14 +117,4 @@ class SettingsActivity : AppCompatActivity() {
|
|||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show()
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n") // I do not care
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
||||
setContentView(R.layout.activity_settings)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
android:id="@+id/heading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Settings"
|
||||
android:text="@string/settings_title"
|
||||
android:textColor="#cccccc"
|
||||
android:textSize="36sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
@ -24,7 +24,7 @@
|
|||
android:id="@+id/sub_head_1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Applications"
|
||||
android:text="@string/settings_sub_title1"
|
||||
android:textColor="#999"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
@ -54,7 +54,9 @@
|
|||
android:id="@+id/text_up"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Swipe Up"
|
||||
android:paddingLeft="10sp"
|
||||
android:paddingRight="10sp"
|
||||
android:text="@string/settings_choose_up"
|
||||
android:textColor="#ccc"
|
||||
android:textSize="24sp" />
|
||||
|
||||
|
@ -64,7 +66,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:alpha=".8"
|
||||
android:onClick="chooseUpApp"
|
||||
android:text="Choose App" />
|
||||
android:text="@string/settings_choose_btn" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
|
@ -75,7 +77,9 @@
|
|||
android:id="@+id/text_down"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Swipe Down"
|
||||
android:paddingLeft="10sp"
|
||||
android:paddingRight="10sp"
|
||||
android:text="@string/settings_choose_down"
|
||||
android:textColor="#ccc"
|
||||
android:textSize="24sp" />
|
||||
|
||||
|
@ -85,7 +89,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:alpha=".8"
|
||||
android:onClick="chooseDownApp"
|
||||
android:text="Choose App" />
|
||||
android:text="@string/settings_choose_btn" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
|
@ -97,7 +101,9 @@
|
|||
android:id="@+id/text_left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Swipe Left"
|
||||
android:paddingLeft="10sp"
|
||||
android:paddingRight="10sp"
|
||||
android:text="@string/settings_choose_left"
|
||||
android:textColor="#ccc"
|
||||
android:textSize="24sp" />
|
||||
|
||||
|
@ -107,7 +113,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:alpha=".8"
|
||||
android:onClick="chooseLeftApp"
|
||||
android:text="Choose App" />
|
||||
android:text="@string/settings_choose_btn" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
|
@ -118,7 +124,9 @@
|
|||
android:id="@+id/text_right"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Swipe Right"
|
||||
android:paddingLeft="10sp"
|
||||
android:paddingRight="10sp"
|
||||
android:text="@string/settings_choose_right"
|
||||
android:textColor="#ccc"
|
||||
android:textSize="24sp" />
|
||||
|
||||
|
@ -128,7 +136,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:alpha=".8"
|
||||
android:onClick="chooseRightApp"
|
||||
android:text="Choose App" />
|
||||
android:text="@string/settings_choose_btn" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
|
@ -140,7 +148,9 @@
|
|||
android:id="@+id/text_vol_up"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Volume Up"
|
||||
android:paddingLeft="10sp"
|
||||
android:paddingRight="10sp"
|
||||
android:text="@string/settings_choose_vol_up"
|
||||
android:textColor="#ccc"
|
||||
android:textSize="24sp" />
|
||||
|
||||
|
@ -150,7 +160,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:alpha=".8"
|
||||
android:onClick="chooseVolumeUpApp"
|
||||
android:text="Choose App" />
|
||||
android:text="@string/settings_choose_btn" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
|
@ -161,7 +171,9 @@
|
|||
android:id="@+id/text_vol_down"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Volume Down "
|
||||
android:paddingLeft="10sp"
|
||||
android:paddingRight="10sp"
|
||||
android:text="@string/settings_choose_vol_down"
|
||||
android:textColor="#ccc"
|
||||
android:textSize="24sp" />
|
||||
|
||||
|
@ -171,7 +183,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:alpha=".8"
|
||||
android:onClick="chooseVolumeDownApp"
|
||||
android:text="Choose App" />
|
||||
android:text="@string/settings_choose_btn" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
|
@ -181,7 +193,7 @@
|
|||
android:id="@+id/sub_head_2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Actions"
|
||||
android:text="@string/settings_sub_title2"
|
||||
android:textColor="#999"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/buttons"
|
||||
|
@ -193,7 +205,7 @@
|
|||
|
||||
<TableLayout
|
||||
android:id="@+id/buttons"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
@ -207,18 +219,20 @@
|
|||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
style="@style/Widget.AppCompat.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:alpha=".3"
|
||||
android:onClick="setLauncher"
|
||||
android:text="Select Launcher" />
|
||||
android:text="@string/settings_select_launcher" />
|
||||
|
||||
<Button
|
||||
style="@style/Widget.AppCompat.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:alpha=".3"
|
||||
android:onClick="resetSettingsClick"
|
||||
android:text="Reset Settings" />
|
||||
android:text="@string/settings_reset" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
|
@ -228,18 +242,20 @@
|
|||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
style="@style/Widget.AppCompat.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:alpha=".3"
|
||||
android:onClick="chooseLaunchApp"
|
||||
android:text="Launch Apps" />
|
||||
android:text="@string/settings_launch" />
|
||||
|
||||
<Button
|
||||
style="@style/Widget.AppCompat.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:alpha=".3"
|
||||
android:onClick="chooseUninstallApp"
|
||||
android:text="Uninstall Apps" />
|
||||
android:text="@string/settings_uninstall" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
|
@ -252,30 +268,25 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="backHome"
|
||||
android:text="Back Home" />
|
||||
android:text="@string/settings_home" />
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
|
||||
<TableLayout
|
||||
android:id="@+id/about_footer"
|
||||
android:layout_width="0dp"
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
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.9">
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.95">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="By "
|
||||
android:text="@string/settings_footer_by"
|
||||
android:textColor="#999"
|
||||
android:textSize="18sp" />
|
||||
|
||||
|
@ -283,16 +294,18 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="openFinnWebsite"
|
||||
android:text="Finn M Glas"
|
||||
android:text=" Finn M Glas"
|
||||
android:textColor="?attr/colorAccent"
|
||||
android:textSize="18sp" />
|
||||
android:textSize="18sp"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=" | "
|
||||
android:textColor="#999"
|
||||
android:textSize="18sp" />
|
||||
android:textSize="18sp"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -300,9 +313,8 @@
|
|||
android:onClick="openGithubRepo"
|
||||
android:text="Open Source"
|
||||
android:textColor="?attr/colorAccent"
|
||||
android:textSize="18sp" />
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
android:textSize="18sp"
|
||||
tools:ignore="HardcodedText" />
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -3,6 +3,27 @@
|
|||
<string name="app_name">Launcher</string>
|
||||
<string name="preference_file_key">V3RYR4ND0MK3YCR4P</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings_title">Settings</string>
|
||||
<string name="settings_sub_title1">Applications</string>
|
||||
<string name="settings_sub_title2">Actions</string>
|
||||
|
||||
<string name="settings_choose_up">Swipe Up</string>
|
||||
<string name="settings_choose_down">Swipe Down</string>
|
||||
<string name="settings_choose_left">Swipe Left</string>
|
||||
<string name="settings_choose_right">Swipe Right</string>
|
||||
<string name="settings_choose_vol_up">Volume Up</string>
|
||||
<string name="settings_choose_vol_down">Volume Down</string>
|
||||
<string name="settings_choose_btn">Choose App</string>
|
||||
|
||||
<string name="settings_select_launcher">Select Launcher</string>
|
||||
<string name="settings_reset">Reset Settings</string>
|
||||
<string name="settings_launch">Launch Apps</string>
|
||||
<string name="settings_uninstall">Uninstall Apps</string>
|
||||
<string name="settings_home">Back Home</string>
|
||||
|
||||
<string name="settings_footer_by">By</string>
|
||||
|
||||
<!-- Errors, Exceptions (Alerts, Toasts ...) -->
|
||||
<string name="none_found">None found</string>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue