Let the user change theme, Add animation, preference

This commit is contained in:
Finn M Glas 2020-05-23 00:28:15 +02:00
parent a56cec7f9e
commit 8a6dd32360
No known key found for this signature in database
GPG key ID: 25037A2E81AB459C
6 changed files with 65 additions and 3 deletions

View file

@ -25,6 +25,13 @@ class ChooseActivity : AppCompatActivity() {
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
setTheme(
when (getSavedTheme(this)) {
"dark" -> R.style.darkTheme
"finn" -> R.style.finnmglasTheme
else -> R.style.finnmglasTheme
}
)
setContentView(R.layout.activity_choose)
// As older APIs somehow do not recognize the xml defined onClick

View file

@ -31,6 +31,13 @@ class FirstStartupActivity : AppCompatActivity(){
)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
setTheme(
when (getSavedTheme(this)) {
"dark" -> R.style.darkTheme
"finn" -> R.style.finnmglasTheme
else -> R.style.finnmglasTheme
}
)
setContentView(R.layout.activity_firststartup)
hintText.blink() // animate

View file

@ -124,6 +124,22 @@ fun openNewTabWindow(urls: String, context : Context) {
/** Settings related functions */
fun getSavedTheme(context : Context) : String {
val sharedPref = context.getSharedPreferences(
context.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
return sharedPref.getString("theme", "finnmglas").toString()
}
fun saveTheme(context : Context, themeName : String) {
val sharedPref = context.getSharedPreferences(
context.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
val editor: SharedPreferences.Editor = sharedPref.edit()
editor.putString("theme", themeName)
editor.apply()
}
fun openAppSettings(pkg :String, context:Context){
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.parse("package:$pkg")

View file

@ -17,6 +17,8 @@ import kotlin.math.abs
class MainActivity : AppCompatActivity(),
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
private var currentTheme = "" // keep track of theme changes
/** Variables for this activity */
private lateinit var mDetector: GestureDetectorCompat
@ -45,6 +47,14 @@ class MainActivity : AppCompatActivity(),
)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
currentTheme = getSavedTheme(this)
setTheme(
when (currentTheme) {
"dark" -> R.style.darkTheme
"finn" -> R.style.finnmglasTheme
else -> R.style.finnmglasTheme
}
)
setContentView(R.layout.activity_main)
// Start by showing the settings icon
@ -78,6 +88,8 @@ class MainActivity : AppCompatActivity(),
override fun onResume() {
super.onResume()
if (currentTheme != getSavedTheme(this)) recreate()
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())

View file

@ -22,6 +22,15 @@ class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(
when (getSavedTheme(this)) {
"dark" -> R.style.darkTheme
"finn" -> R.style.finnmglasTheme
else -> R.style.finnmglasTheme
}
)
setContentView(R.layout.activity_settings)
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
@ -178,14 +187,18 @@ class SettingsActivity : AppCompatActivity() {
/** Theme - related */
fun chooseDarkTheme(view: View) {
saveTheme(this, "dark")
recreate()
}
fun chooseFinnTheme(view: View) {
saveTheme(this, "finn")
recreate()
}
fun chooseCustomTheme(view: View) {
Toast.makeText(this, "[not implemented yet]", Toast.LENGTH_SHORT)
.show()
}
}
}

View file

@ -13,6 +13,7 @@
<item name="colorButtonNormal">@color/finnmglasTheme_accent_color</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowAnimationStyle">@style/WindowFadeTransition</item>
</style>
<!-- A dark efficiency theme -->
@ -27,10 +28,16 @@
<item name="colorButtonNormal">@color/darkTheme_accent_color</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowAnimationStyle">@style/WindowFadeTransition</item>
</style>
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColor">#000000</item>
</style>
<!-- Set the fade in animation on all activities by default -->
<style name="WindowFadeTransition">
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
</style>
</resources>