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

View file

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

View file

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

View file

@ -161,4 +161,12 @@ class SharedPreferenceManager (context: Context) {
fun isBatteryEnabled(): Boolean {
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>
<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>
<!--General UI-->
<string-array name="bg_options">
<item>Transparent</item>
<item>Black</item>
@ -36,6 +25,35 @@
<item>#FF0C0C0C</item>
</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">
<item>Left</item>
<item>Center</item>
@ -60,6 +78,7 @@
<item>large</item>
</string-array>
<!--Weather-->
<string-array name="temp_units">
<item>°C</item>
<item>°F</item>

View file

@ -5,12 +5,14 @@
<string name="shortcut_default">App</string>
<!--App Menu Titles-->
<string name="select_an_app">Select an app</string>
<string name="unhide_an_app">Unhide an app</string>
<string name="find_your_city">Find your city</string>
<string name="search">Search…</string>
<!--Action Menu Items-->
<string name="reset">Reset</string>
<string name="info">Info</string>
<string name="uninstall">Uninstall</string>
@ -18,6 +20,7 @@
<string name="hide">Hide</string>
<string name="close">Close</string>
<!--About Page Items-->
<string name="app_icon">App Icon</string>
<string name="creditName">By Otto Petäjä</string>
<string name="source_code">Source Code</string>
@ -28,19 +31,17 @@
<string name="liberapay">Liberapay</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="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="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="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="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>
</resources>

View file

@ -30,6 +30,15 @@
android:defaultValue="false"
android:title="Show Status Bar"
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
android:layout_width="wrap_content"