mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Implement theme-choosing using a Spinner
This commit is contained in:
parent
badbba535b
commit
70114fc9d3
3 changed files with 77 additions and 73 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.finnmglas.launcher.settings.launcher
|
package com.finnmglas.launcher.settings.launcher
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
@ -100,7 +101,6 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
||||||
.putInt(PREF_VIBRANT, vibrantColor)
|
.putInt(PREF_VIBRANT, vibrantColor)
|
||||||
.apply()
|
.apply()
|
||||||
|
|
||||||
saveTheme("custom")
|
|
||||||
intendedSettingsPause = true
|
intendedSettingsPause = true
|
||||||
activity!!.recreate()
|
activity!!.recreate()
|
||||||
}
|
}
|
||||||
|
@ -109,36 +109,36 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun applyTheme() {
|
override fun applyTheme() {
|
||||||
// Hide 'select' button for the selected theme or allow customisation
|
|
||||||
when (getSavedTheme(context!!)) {
|
|
||||||
"dark" -> settings_theme_dark_button_select.visibility = View.INVISIBLE
|
|
||||||
"finn" -> settings_theme_finn_button_select.visibility = View.INVISIBLE
|
|
||||||
"custom" ->
|
|
||||||
settings_theme_custom_button_select.text = getString(R.string.settings_select_image)
|
|
||||||
}
|
|
||||||
|
|
||||||
setSwitchColor(settings_launcher_switch_screen_timeout, vibrantColor)
|
setSwitchColor(settings_launcher_switch_screen_timeout, vibrantColor)
|
||||||
|
|
||||||
settings_launcher_container.setBackgroundColor(dominantColor)
|
settings_launcher_container.setBackgroundColor(dominantColor)
|
||||||
setButtonColor(settings_theme_finn_button_select, vibrantColor)
|
|
||||||
setButtonColor(settings_theme_dark_button_select, vibrantColor)
|
|
||||||
setButtonColor(settings_theme_custom_button_select, vibrantColor)
|
setButtonColor(settings_theme_custom_button_select, vibrantColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setOnClicks() {
|
override fun setOnClicks() {
|
||||||
// Theme changing buttons
|
|
||||||
settings_theme_dark_button_select.setOnClickListener {
|
|
||||||
resetToDarkTheme(activity!!)
|
|
||||||
}
|
|
||||||
settings_theme_finn_button_select.setOnClickListener {
|
|
||||||
resetToDefaultTheme(activity!!)
|
|
||||||
}
|
|
||||||
settings_theme_custom_button_select.setOnClickListener {
|
settings_theme_custom_button_select.setOnClickListener {
|
||||||
|
resetToCustomTheme(activity!!)
|
||||||
|
}
|
||||||
|
settings_launcher_switch_screen_timeout.setOnClickListener { // Toggle screen timeout
|
||||||
|
launcherPreferences.edit()
|
||||||
|
.putBoolean(PREF_SCREEN_TIMEOUT_DISABLED,
|
||||||
|
!launcherPreferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false))
|
||||||
|
.apply()
|
||||||
|
|
||||||
|
setWindowFlags(activity!!.window)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resetToCustomTheme(context: Activity) {
|
||||||
intendedSettingsPause = true
|
intendedSettingsPause = true
|
||||||
|
saveTheme("custom") // TODO: Fix the bug this creates (displays custom theme without chosen img)
|
||||||
|
|
||||||
// Request permission (on newer APIs)
|
// Request permission (on newer APIs)
|
||||||
if (Build.VERSION.SDK_INT >= 23) {
|
if (Build.VERSION.SDK_INT >= 23) {
|
||||||
when {
|
when {
|
||||||
ContextCompat.checkSelfPermission(context!!,
|
ContextCompat.checkSelfPermission(context,
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
|
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
|
||||||
-> letUserPickImage(true)
|
-> letUserPickImage(true)
|
||||||
shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
|
@ -151,15 +151,6 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
||||||
}
|
}
|
||||||
else letUserPickImage()
|
else letUserPickImage()
|
||||||
}
|
}
|
||||||
settings_launcher_switch_screen_timeout.setOnClickListener { // Toggle screen timeout
|
|
||||||
launcherPreferences.edit()
|
|
||||||
.putBoolean(PREF_SCREEN_TIMEOUT_DISABLED,
|
|
||||||
!launcherPreferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false))
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
setWindowFlags(activity!!.window)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun adjustLayout() {
|
override fun adjustLayout() {
|
||||||
// visually load settings
|
// visually load settings
|
||||||
|
@ -187,5 +178,36 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load values into the theme spinner
|
||||||
|
val staticThemeAdapter = ArrayAdapter.createFromResource(
|
||||||
|
activity!!, R.array.settings_themes,
|
||||||
|
android.R.layout.simple_spinner_item )
|
||||||
|
|
||||||
|
staticThemeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||||
|
settings_launcher_theme_spinner.adapter = staticThemeAdapter
|
||||||
|
|
||||||
|
var themeInt = when (getSavedTheme(activity!!)) {
|
||||||
|
"finn" -> 0
|
||||||
|
"dark" -> 1
|
||||||
|
"custom" -> 2
|
||||||
|
else -> 0
|
||||||
|
};
|
||||||
|
|
||||||
|
settings_launcher_theme_spinner.setSelection(themeInt)
|
||||||
|
|
||||||
|
settings_launcher_theme_spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
|
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
|
||||||
|
when (position) {
|
||||||
|
0 -> if (getSavedTheme(activity!!) != "finn") resetToDefaultTheme(activity!!)
|
||||||
|
1 -> if (getSavedTheme(activity!!) != "dark") resetToDarkTheme(activity!!)
|
||||||
|
2 -> if (getSavedTheme(activity!!) != "custom") resetToCustomTheme(activity!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -85,10 +85,24 @@
|
||||||
android:id="@+id/settings_launcher_theme_spinner"
|
android:id="@+id/settings_launcher_theme_spinner"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:entries="@array/settings_launcher_time_formats"
|
android:entries="@array/settings_themes"
|
||||||
android:spinnerMode="dropdown" />
|
android:spinnerMode="dropdown" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16sp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/settings_theme_custom_button_select"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Choose a wallpaper"
|
||||||
|
android:textAllCaps="false" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/settings_launcher_section_options"
|
android:id="@+id/settings_launcher_section_options"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -141,43 +155,4 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
|
||||||
android:id="@+id/settings_theme_dark"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:cardCornerRadius="8dp"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/settings_launcher_switch_screen_timeout"
|
|
||||||
tools:layout_editor_absoluteX="32dp">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/settings_theme_dark_button_select"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Dark"
|
|
||||||
android:textAllCaps="false"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/settings_theme_finn_button_select" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/settings_theme_finn_button_select"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Default"
|
|
||||||
android:textAllCaps="false"
|
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/settings_theme_custom_button_select"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Wallpaper"
|
|
||||||
android:textAllCaps="false"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -48,6 +48,13 @@
|
||||||
<string name="settings_select_theme">Select</string>
|
<string name="settings_select_theme">Select</string>
|
||||||
<string name="settings_select_image">Change Image</string>
|
<string name="settings_select_image">Change Image</string>
|
||||||
<string name="settings_theme_examples">Examples</string>
|
<string name="settings_theme_examples">Examples</string>
|
||||||
|
|
||||||
|
<string-array name="settings_themes">
|
||||||
|
<item>Default</item>
|
||||||
|
<item>Dark</item>
|
||||||
|
<item>Custom</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string name="settings_launcher_disable_timeout">Keep screen on</string>
|
<string name="settings_launcher_disable_timeout">Keep screen on</string>
|
||||||
<string name="settings_launcher_time_format">Date format</string>
|
<string name="settings_launcher_time_format">Date format</string>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue