Added customizable animation speed and some xml comments

This commit is contained in:
ottoptj 2024-08-10 21:59:27 +03:00
commit 54960318b3
7 changed files with 94 additions and 42 deletions

View file

@ -15,12 +15,12 @@ class Animations (context: Context) {
private val sharedPreferenceManager = SharedPreferenceManager(context) private val sharedPreferenceManager = SharedPreferenceManager(context)
fun fadeViewIn(view: View, duration: Long = 100) { fun fadeViewIn(view: View) {
view.fadeIn(duration) view.fadeIn()
} }
fun fadeViewOut(view: View, duration: Long = 100) { fun fadeViewOut(view: View) {
view.fadeOut(duration) view.fadeOut()
} }
fun showHome(homeView: View, appView: View) { fun showHome(homeView: View, appView: View) {
appView.slideOutToBottom() appView.slideOutToBottom()
@ -32,7 +32,7 @@ class Animations (context: Context) {
homeView.fadeOut() homeView.fadeOut()
} }
fun backgroundIn(activity: Activity, duration: Long = 100) { fun backgroundIn(activity: Activity) {
val originalColor = sharedPreferenceManager.getBgColor() val originalColor = sharedPreferenceManager.getBgColor()
val newColor: Int = if (originalColor == Color.parseColor("#00000000")) { val newColor: Int = if (originalColor == Color.parseColor("#00000000")) {
@ -48,12 +48,13 @@ class Animations (context: Context) {
backgroundColorAnimator.addUpdateListener { animator -> backgroundColorAnimator.addUpdateListener { animator ->
colorDrawable.color = animator.animatedValue as Int colorDrawable.color = animator.animatedValue as Int
} }
val duration = sharedPreferenceManager.getAnimationSpeed()
backgroundColorAnimator.duration = duration backgroundColorAnimator.duration = duration
backgroundColorAnimator.start() backgroundColorAnimator.start()
} }
fun backgroundOut(activity: Activity, duration: Long = 100) { fun backgroundOut(activity: Activity) {
val newColor = sharedPreferenceManager.getBgColor() val newColor = sharedPreferenceManager.getBgColor()
val originalColor: Int = if (newColor == Color.parseColor("#00000000")) { val originalColor: Int = if (newColor == Color.parseColor("#00000000")) {
@ -69,16 +70,19 @@ class Animations (context: Context) {
backgroundColorAnimator.addUpdateListener { animator -> backgroundColorAnimator.addUpdateListener { animator ->
colorDrawable.color = animator.animatedValue as Int colorDrawable.color = animator.animatedValue as Int
} }
val duration = sharedPreferenceManager.getAnimationSpeed()
backgroundColorAnimator.duration = duration backgroundColorAnimator.duration = duration
backgroundColorAnimator.start() backgroundColorAnimator.start()
} }
private fun View.slideInFromBottom(duration: Long = 100) { private fun View.slideInFromBottom() {
if (visibility != View.VISIBLE) { if (visibility != View.VISIBLE) {
translationY = height.toFloat()/5 translationY = height.toFloat()/5
scaleY = 1.2f scaleY = 1.2f
alpha = 0f alpha = 0f
visibility = View.VISIBLE visibility = View.VISIBLE
val duration = sharedPreferenceManager.getAnimationSpeed()
animate() animate()
.translationY(0f) .translationY(0f)
.scaleY(1f) .scaleY(1f)
@ -88,13 +92,15 @@ class Animations (context: Context) {
} }
} }
private fun View.slideOutToBottom(duration: Long = 50) { private fun View.slideOutToBottom() {
if (visibility == View.VISIBLE) { if (visibility == View.VISIBLE) {
val duration = sharedPreferenceManager.getAnimationSpeed()
animate() animate()
.translationY(height.toFloat() / 5) .translationY(height.toFloat() / 5)
.scaleY(1.2f) .scaleY(1.2f)
.alpha(0f) .alpha(0f)
.setDuration(duration) .setDuration(duration/2)
.setListener(object : AnimatorListenerAdapter() { .setListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) { override fun onAnimationEnd(animation: Animator) {
visibility = View.INVISIBLE visibility = View.INVISIBLE
@ -103,29 +109,36 @@ class Animations (context: Context) {
} }
} }
private fun View.fadeIn(duration: Long = 100) { private fun View.fadeIn() {
if (visibility != View.VISIBLE) { if (visibility != View.VISIBLE) {
alpha = 0f alpha = 0f
translationY = -height.toFloat()/100 translationY = -height.toFloat()/100
visibility = View.VISIBLE visibility = View.VISIBLE
val duration = sharedPreferenceManager.getAnimationSpeed()
animate() animate()
.alpha(1f) .alpha(1f)
.translationY(0f) .translationY(0f)
.setDuration(duration) .setDuration(duration)
.setListener(null) .setListener(null)
} }
} }
private fun View.fadeOut(duration: Long = 50) { private fun View.fadeOut() {
if (visibility == View.VISIBLE) { if (visibility == View.VISIBLE) {
val duration = sharedPreferenceManager.getAnimationSpeed()
animate() animate()
.alpha(0f) .alpha(0f)
.translationY(-height.toFloat()/100) .translationY(-height.toFloat()/100)
.setDuration(duration) .setDuration(duration/2)
.setListener(object : AnimatorListenerAdapter() { .setListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) { override fun onAnimationEnd(animation: Animator) {
visibility = View.GONE visibility = View.GONE
} }
})} })
}
} }
} }

View file

@ -48,7 +48,7 @@ class AppActionMenu {
) )
} }
animations.fadeViewOut(actionMenu, 100) animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE textView.visibility = View.VISIBLE
} }
@ -58,7 +58,7 @@ class AppActionMenu {
intent.putExtra(Intent.EXTRA_USER, userHandle) intent.putExtra(Intent.EXTRA_USER, userHandle)
activity.startActivity(intent) activity.startActivity(intent)
animations.fadeViewOut(actionMenu, 100) animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE textView.visibility = View.VISIBLE
} }
@ -66,7 +66,7 @@ class AppActionMenu {
actionMenu.findViewById<TextView>(R.id.rename).setOnClickListener { actionMenu.findViewById<TextView>(R.id.rename).setOnClickListener {
textView.visibility = View.INVISIBLE textView.visibility = View.INVISIBLE
animations.fadeViewIn(editLayout) animations.fadeViewIn(editLayout)
animations.fadeViewOut(actionMenu, 100) animations.fadeViewOut(actionMenu)
val editText = editLayout.findViewById<EditText>(R.id.appNameEdit) val editText = editLayout.findViewById<EditText>(R.id.appNameEdit)
val resetButton = editLayout.findViewById<AppCompatButton>(R.id.reset) val resetButton = editLayout.findViewById<AppCompatButton>(R.id.reset)
@ -86,7 +86,7 @@ class AppActionMenu {
if (bottom - top > oldBottom - oldTop) { if (bottom - top > oldBottom - oldTop) {
editLayout.clearFocus() editLayout.clearFocus()
animations.fadeViewOut(editLayout, 100) animations.fadeViewOut(editLayout)
textView.visibility = View.VISIBLE textView.visibility = View.VISIBLE
searchView.visibility = View.VISIBLE searchView.visibility = View.VISIBLE
} }
@ -138,7 +138,7 @@ class AppActionMenu {
} }
actionMenu.findViewById<TextView>(R.id.close).setOnClickListener { actionMenu.findViewById<TextView>(R.id.close).setOnClickListener {
animations.fadeViewOut(actionMenu, 100) animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE textView.visibility = View.VISIBLE
} }
} }

View file

@ -370,6 +370,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
closeKeyboard() closeKeyboard()
animations.showHome(binding.homeView, binding.appView) animations.showHome(binding.homeView, binding.appView)
animations.backgroundOut(this@MainActivity) animations.backgroundOut(this@MainActivity)
val animSpeed = sharedPreferenceManager.getAnimationSpeed()
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
handler.postDelayed({ handler.postDelayed({
try { try {
@ -378,7 +379,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
catch (_: UninitializedPropertyAccessException) { catch (_: UninitializedPropertyAccessException) {
} }
}, 100) }, animSpeed)
handler.postDelayed({ handler.postDelayed({
lifecycleScope.launch { lifecycleScope.launch {
refreshAppMenu() refreshAppMenu()
@ -391,7 +393,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
catch (_: UninitializedPropertyAccessException) { catch (_: UninitializedPropertyAccessException) {
} }
}}, 150) }}, animSpeed + 50)
} }

View file

@ -161,4 +161,12 @@ class SharedPreferenceManager (context: Context) {
fun isBatteryEnabled(): Boolean { fun isBatteryEnabled(): Boolean {
return preferences.getBoolean("battery_enabled", false) return preferences.getBoolean("battery_enabled", false)
} }
fun getAnimationSpeed(): Long {
val animSpeed = preferences.getString("animationSpeed", "200")?.toLong()
if (animSpeed != null) {
return animSpeed
}
return 200
}
} }

View file

@ -1,17 +1,6 @@
<resources> <resources>
<string-array name="shortcut_options"> <!--General UI-->
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
</string-array>
<string-array name="bg_options"> <string-array name="bg_options">
<item>Transparent</item> <item>Transparent</item>
<item>Black</item> <item>Black</item>
@ -36,6 +25,35 @@
<item>#FF0C0C0C</item> <item>#FF0C0C0C</item>
</string-array> </string-array>
<string-array name="animation_options">
<item>0.25x</item>
<item>0.5x</item>
<item>1x</item>
<item>2x</item>
<item>4x</item>
</string-array>
<string-array name="animation_values">
<item>800</item>
<item>400</item>
<item>200</item>
<item>100</item>
<item>50</item>
</string-array>
<!--Home and App Menu-->
<string-array name="shortcut_options">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
</string-array>
<string-array name="h_alignment_options"> <string-array name="h_alignment_options">
<item>Left</item> <item>Left</item>
<item>Center</item> <item>Center</item>
@ -60,6 +78,7 @@
<item>large</item> <item>large</item>
</string-array> </string-array>
<!--Weather-->
<string-array name="temp_units"> <string-array name="temp_units">
<item>°C</item> <item>°C</item>
<item>°F</item> <item>°F</item>

View file

@ -5,12 +5,14 @@
<string name="shortcut_default">App</string> <string name="shortcut_default">App</string>
<!--App Menu Titles-->
<string name="select_an_app">Select an app</string> <string name="select_an_app">Select an app</string>
<string name="unhide_an_app">Unhide an app</string> <string name="unhide_an_app">Unhide an app</string>
<string name="find_your_city">Find your city</string> <string name="find_your_city">Find your city</string>
<string name="search">Search…</string> <string name="search">Search…</string>
<!--Action Menu Items-->
<string name="reset">Reset</string> <string name="reset">Reset</string>
<string name="info">Info</string> <string name="info">Info</string>
<string name="uninstall">Uninstall</string> <string name="uninstall">Uninstall</string>
@ -18,6 +20,7 @@
<string name="hide">Hide</string> <string name="hide">Hide</string>
<string name="close">Close</string> <string name="close">Close</string>
<!--About Page Items-->
<string name="app_icon">App Icon</string> <string name="app_icon">App Icon</string>
<string name="creditName">By Otto Petäjä</string> <string name="creditName">By Otto Petäjä</string>
<string name="source_code">Source Code</string> <string name="source_code">Source Code</string>
@ -28,19 +31,17 @@
<string name="liberapay">Liberapay</string> <string name="liberapay">Liberapay</string>
<string name="weather_data_credit">Weather data by Open-Meteo.com\n(CC BY 4.0)</string> <string name="weather_data_credit">Weather data by Open-Meteo.com\n(CC BY 4.0)</string>
<!--About page links-->
<string name="my_website_link"><![CDATA[by <a href="https://ottop.eu">Otto Petäjä</a>]]></string> <string name="my_website_link"><![CDATA[by <a href="https://ottop.eu">Otto Petäjä</a>]]></string>
<string name="codeberg_link"><![CDATA[<a href="https://codeberg.org/ottoptj/yamlauncher">Codeberg</a>]]></string> <string name="codeberg_link"><![CDATA[<a href="https://codeberg.org/ottoptj/yamlauncher">Codeberg</a>]]></string>
<string name="github_link"><![CDATA[<a href="https://github.com">GitHub</a>]]></string> <string name="github_link"><![CDATA[<a href="https://github.com">GitHub</a>]]></string>
<string name="libera_link"><![CDATA[<a href="https://github.com">Liberapay</a><br>(recurring)]]></string> <string name="libera_link"><![CDATA[<a href="https://github.com">Liberapay</a><br>(recurring)]]></string>
<string name="stripe_link"><![CDATA[<a href="https://codeberg.org/ottoptj/yamlauncher">Stripe</a><br>(one-time)]]></string> <string name="stripe_link"><![CDATA[<a href="https://codeberg.org/ottoptj/yamlauncher">Stripe</a><br>(one-time)]]></string>
<string name="weather_link"><![CDATA[Weather data by <a href="https://open-meteo.com/">Open-Meteo.com</a><br>(<a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>)]]></string> <string name="weather_link"><![CDATA[Weather data by <a href="https://open-meteo.com/">Open-Meteo.com</a><br>(<a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>)]]></string>
<!--Location Selector Items-->
<string name="location_link"><![CDATA[Location data by <a href="https://open-meteo.com/">Open-Meteo.com</a> (<a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>)]]></string> <string name="location_link"><![CDATA[Location data by <a href="https://open-meteo.com/">Open-Meteo.com</a> (<a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>)]]></string>
<string name="region_text">%1$s%2$s</string> <string name="region_text">%1$s%2$s</string>
<string name="accessibility_service_description">The permission is required for double tap to work for locking the screen.\n\nIt is only needed if you want to use the double tap to lock screen feature in YAM Launcher.</string> <string name="accessibility_service_description">The permission is required for double tap to work for locking the screen.\n\nIt is only needed if you want to use the double tap to lock screen feature in YAM Launcher.</string>
</resources> </resources>

View file

@ -30,6 +30,15 @@
android:defaultValue="false" android:defaultValue="false"
android:title="Show Status Bar" android:title="Show Status Bar"
app:key="barVisibility" /> app:key="barVisibility" />
<ListPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:defaultValue="200"
app:entries="@array/animation_options"
app:entryValues="@array/animation_values"
app:key="animationSpeed"
app:title="Animation Speed"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:layout_width="wrap_content" android:layout_width="wrap_content"