Skip to content

Instantly share code, notes, and snippets.

@CapnSpellcheck
Last active November 16, 2016 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CapnSpellcheck/af9e4cb1945bc6b282cabf387ace91f8 to your computer and use it in GitHub Desktop.
Save CapnSpellcheck/af9e4cb1945bc6b282cabf387ace91f8 to your computer and use it in GitHub Desktop.
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