AnimatedVectorDrawable.start() зависает на некоторых устройствах
Всем привет. Столкнулся с проблемой:
1. У меня есть класс Activty в котором устанавливается фон (векторная анимация):
private void showSplashScreenAnimation() {
AnimatedVectorDrawable animationBackground = (AnimatedVectorDrawable) getDrawable(R.drawable.splash_screen_anim);
getWindow().setBackgroundDrawable(new CenterCropDrawable(animationBackground));
animationBackground.start();
}
new CenterCropDrawable(animationBackground) - используется для установки scaleType = CenterCrop (для Drawable);
- Соответственно сам класс CenterCropDrawable:
public class CenterCropDrawable extends Drawable {
@NonNull
private final Drawable target;
public CenterCropDrawable(@NonNull Drawable target) {
this.target = target;
}
@Override
public void setBounds(@NonNull Rect bounds) {
super.setBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
}
@Override
public void setBounds(int left, int top, int right, int bottom) {
final RectF sourceRect = new RectF(0, 0, target.getIntrinsicWidth(), target.getIntrinsicHeight());
final RectF screenRect = new RectF(left, top, right, bottom);
final Matrix matrix = new Matrix();
matrix.setRectToRect(screenRect, sourceRect, Matrix.ScaleToFit.CENTER);
final Matrix inverse = new Matrix();
matrix.invert(inverse);
inverse.mapRect(sourceRect);
target.setBounds(Math.round(sourceRect.left), Math.round(sourceRect.top),
Math.round(sourceRect.right), Math.round(sourceRect.bottom));
super.setBounds(left, top, right, bottom);
}
@Override
public void draw(@NonNull Canvas canvas) {
canvas.save();
canvas.clipRect(getBounds());
target.draw(canvas);
canvas.restore();
}
@Override
public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {
target.setAlpha(alpha);
}
@Override
public void setColorFilter(@Nullable ColorFilter colorFilter) {
target.setColorFilter(colorFilter);
}
@Override
public int getOpacity() {
return target.getOpacity();
}
}
Суть проблемы: такой код позволяет установить scaleType для Drawable и воспроизвести векторную анимацию. Это работает на большом количестве старых/новых устройств, но обнаружил проблему, что у некоторых пользователей анимация не воспроизводиться (девайс был новый API 29). Она зависает на старте воспроизведения. Если изменить код:
c
getWindow().setBackgroundDrawable(new CenterCropDrawable(animationBackground));
на
getWindow().setBackgroundDrawable(animationBackground);
то анимация на этих устройствах начинает воспроизводиться. В чем может быть проблема?
defaultConfig{
minSDKVersion 21
}
Буду благодарен за любую помощь!