Skip to content

Instantly share code, notes, and snippets.

@akaita
Created March 27, 2018 00:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akaita/39220d9f3a1cec308a498c6ba5a86279 to your computer and use it in GitHub Desktop.
Save akaita/39220d9f3a1cec308a498c6ba5a86279 to your computer and use it in GitHub Desktop.
MorphView example
package com.akaita.android.morphview.example.kotlin
/**
* Created by mikel on 26/03/2018.
*/
import android.content.Context
import android.support.graphics.drawable.AnimatedVectorDrawableCompat
import android.util.AttributeSet
class FavoriteToSendMorphView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : android.support.v7.widget.AppCompatImageView(context, attrs, defStyleAttr) {
private var sendToFavorite: AnimatedVectorDrawableCompat? = null
private var favoriteToSend: AnimatedVectorDrawableCompat? = null
private var showingFavorite: Boolean = false
init {
showingFavorite = true
favoriteToSend = AnimatedVectorDrawableCompat.create(context, R.drawable.avd_favorite_to_send)
sendToFavorite = AnimatedVectorDrawableCompat.create(context, R.drawable.avd_send_to_favorite)
setImageDrawable(favoriteToSend)
}
fun showFavorite() {
if (!showingFavorite) {
morph()
}
}
fun showSend() {
if (showingFavorite) {
morph()
}
}
fun morph() {
val drawable = if (showingFavorite) favoriteToSend else sendToFavorite
setImageDrawable(drawable)
drawable?.start()
showingFavorite = !showingFavorite
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment