Created
March 27, 2018 00:04
-
-
Save akaita/39220d9f3a1cec308a498c6ba5a86279 to your computer and use it in GitHub Desktop.
MorphView example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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