Last active
November 16, 2016 04:40
-
-
Save CapnSpellcheck/af9e4cb1945bc6b282cabf387ace91f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 letstwinkle.com.twinkle.widget | |
import android.graphics.Bitmap | |
import android.view.View | |
import android.view.animation.* | |
import com.nostra13.universalimageloader.core.assist.LoadedFrom | |
import com.nostra13.universalimageloader.core.display.CircleBitmapDisplayer | |
import com.nostra13.universalimageloader.core.imageaware.ImageAware | |
/** | |
* Displays image with "fade in" animation | |
* Can display bitmap cropped by a circle. This implementation works only with ImageViews wrapped | |
* in ImageViewAware. | |
* Although this class supports the border from CircleBitmapDisplayer, I don't recommend using border | |
* because it draws inside the image, cutting out even more of the image. | |
*/ | |
open class FadeInCircleBitmapDisplayer(strokeColor: Int?, strokeWidth: Float, val duration: Int) | |
: CircleBitmapDisplayer(strokeColor, strokeWidth) { | |
constructor(strokeColor: Int?, duration: Int) : this(strokeColor, 0f, duration) | |
constructor(duration: Int) : this(null, duration) | |
override fun display(bitmap: Bitmap, imageAware: ImageAware, loadedFrom: LoadedFrom) { | |
super.display(bitmap, imageAware, loadedFrom) | |
animate(imageAware.wrappedView, duration) | |
} | |
/** | |
* Animates [ImageView] with "fade-in" effect | |
* @param imageView [ImageView] which display image in | |
* * | |
* @param durationMillis The length of the animation in milliseconds | |
*/ | |
private fun animate(imageView: View?, durationMillis: Int) { | |
if (imageView != null) { | |
val fadeImage = AlphaAnimation(0f, 1f) | |
fadeImage.duration = durationMillis.toLong() | |
fadeImage.interpolator = LinearInterpolator() | |
imageView.startAnimation(fadeImage) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment