Исправление запуска анимации иконок
This commit is contained in:
1 parent
54818ff6cc
commit
48e4493d09
3 files changed
+28
-5
No files matched your search
@@ -1,16 +1,29 @@
|
||||
package com.example.helponizer
|
||||
|
||||
import android.graphics.drawable.AnimatedVectorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.View
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import java.util.WeakHashMap
|
||||
|
||||
object IconAnimator {
|
||||
private val animatables = WeakHashMap<MaterialButton, Drawable>()
|
||||
|
||||
fun setup(button: MaterialButton, @DrawableRes resId: Int) {
|
||||
val drawable = AnimatedVectorDrawableCompat.create(button.context, resId)
|
||||
button.icon = drawable
|
||||
if (drawable != null) {
|
||||
animatables[button] = drawable
|
||||
}
|
||||
}
|
||||
|
||||
fun start(view: View) {
|
||||
val icon = (view as? MaterialButton)?.icon ?: return
|
||||
when (icon) {
|
||||
is AnimatedVectorDrawableCompat -> icon.start()
|
||||
is AnimatedVectorDrawable -> icon.start()
|
||||
val drawable = animatables[view as? MaterialButton] ?: return
|
||||
when (drawable) {
|
||||
is AnimatedVectorDrawableCompat -> drawable.start()
|
||||
is AnimatedVectorDrawable -> drawable.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,12 @@ class MainActivity : AppCompatActivity() {
|
||||
insets
|
||||
}
|
||||
|
||||
IconAnimator.setup(findViewById(R.id.buttonSchedule), R.drawable.avd_calendar)
|
||||
IconAnimator.setup(findViewById(R.id.buttonTips), R.drawable.avd_bulb)
|
||||
IconAnimator.setup(findViewById(R.id.buttonAbout), R.drawable.avd_info)
|
||||
IconAnimator.setup(findViewById(R.id.buttonSettings), R.drawable.avd_settings)
|
||||
IconAnimator.setup(findViewById(R.id.buttonParty), R.drawable.avd_party)
|
||||
|
||||
findViewById<View>(R.id.buttonSchedule).setOnClickListener {
|
||||
IconAnimator.start(it)
|
||||
startActivity(Intent(this, Raspisanie::class.java))
|
||||
|
||||
@@ -57,6 +57,9 @@ class Settings : AppCompatActivity() {
|
||||
prefs.getInt("shet", 0) == 1
|
||||
)
|
||||
updateNotificationButton()
|
||||
IconAnimator.setup(findViewById(R.id.buttonSound), R.drawable.avd_sound)
|
||||
IconAnimator.setup(findViewById(R.id.buttonTextUp), R.drawable.avd_text_up)
|
||||
IconAnimator.setup(findViewById(R.id.buttonTextDown), R.drawable.avd_text_down)
|
||||
|
||||
findViewById<View>(R.id.buttonSound).setOnClickListener {
|
||||
IconAnimator.start(it)
|
||||
@@ -110,7 +113,8 @@ class Settings : AppCompatActivity() {
|
||||
if (notificationsEnabled) R.string.settings_notification_on
|
||||
else R.string.settings_notification_off
|
||||
)
|
||||
button.setIconResource(
|
||||
IconAnimator.setup(
|
||||
button,
|
||||
if (notificationsEnabled) R.drawable.avd_notification_ringing
|
||||
else R.drawable.avd_notification
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user