Hi I need a floating bubble on top of my activity and I decided to use a service for that. Everything works well except that in Android 4.xx devices the imageView is not being animated. I have added listeners to the animation and the animation is run (it starts, repeats... and also the values change) but the imageView does not move. It works perfectly well on Android 5.x devices but not 4.x. Anybody has any idea why?
Here is the code:
public class SellFloatingBubbleService extends Service {
private WindowManager windowManager;
private ImageView imageView;
@Override
public void onCreate() {
super.onCreate();
imageView = new ImageView(this);
imageView.setImageResource(R.drawable.tabbar_tooltip_v3);
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT,
LayoutParams.TYPE_PHONE,
LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
layoutParams.y = (int) TypedValue.applyDimension(TypedValue
.COMPLEX_UNIT_PX, getResources().getDimensionPixelOffset(R.dimen
.sell_button_height), getResources().getDisplayMetrics());
windowManager.addView(imageView, layoutParams);
imageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
stopSelf();
return true;
}
});
/**
* When these animations will end they will revert and then play endlessly.
*/
AnimatorSet bouncer = new AnimatorSet();
ObjectAnimator animX = ObjectAnimator.ofFloat(imageView, "scaleX", 1f, 0.8f);
animX.setRepeatMode(ValueAnimator.REVERSE);
animX.setRepeatMode(-1);
ObjectAnimator animY = ObjectAnimator.ofFloat(imageView, "scaleY", 1f, 0.8f);
animY.setRepeatMode(ValueAnimator.REVERSE);
animY.setRepeatCount(-1);
bouncer.playTogether(animX, animY);
bouncer.setDuration(1000);
bouncer.setInterpolator(new AccelerateDecelerateInterpolator());
bouncer.start();
}
@Override
public void onDestroy() {
imageView.setVisibility(View.GONE);
windowManager.removeView(imageView);
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
I have tried the same animation on another view, not in a service and it works. I also tried replacing ObjectAnimator by the old animations and the problem is still the same.
Is there something wrong about the code?