I'm using DraweeHolder in my custom view to display image. When I want to update the image with a new resource, I create a new DraweeController, then setController to the DraweeHolder.
What I'm trying to implement is the crossfading effect between the previous and new image. For fade in/out, I setAlpha to the drawable recursively.
void handleTransition(DraweeHolder draweeHolder, long startingTime) {
Drawable drawable = draweeHolder.getTopLevelDrawable().mutate();
int duration = 2000;
long currTime = System.currentTimeMillis();
int diff = (int) (currTime - startingTime);
int toAlpha = Math.max(0, 255 - (255 * diff / duration));
drawable.setAlpha(toAlpha);
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
Log.d(TAG, "onDraw()");
super.onDraw(canvas);
synchronized (this) {
handleTransition(draweeHolder, mCurrentTransStartTime);
}
}
It seems working fine, except that onDraw will be called too many times. However, I have no idea how can we have two images appear at the same time (crossfade) in this DraweeHolder. Even setting high/low resolution image for DraweeHolder doesn't give the option of crossfading.