I am trying to get a TextView to invert the background and text colors at an interval specified by a variable called "interval" (integer value representing milliseconds).
Currently, I am using an ObjectAnimator for each property, then using an AnimatorSet object to play them together. This works; however, I'm not sure how to get rid of all of the transitional colors. I don't need a smooth transition, just a hard flashing. I tried using setFrameDelay(interval) to accomplish this, but that's not working.
I had tried doing it with a separate thread/runnable, but I kept running into issues where I needed to stop the thread before performing another action. I could not get the new action to reliably wait for the thread to stop, so I would end up with weird background and text overlays when the timing wasn't just right. Using the Android's Animation framework seemed better suited for easy starting and stopping.
Here's the code I'm working with:
ObjectAnimator backgroundColorValueAnimator = ObjectAnimator.ofInt(
textView,
"backgroundColor",
Color.BLACK,
Color.parseColor(globalSettings.color)
);
ObjectAnimator textColorValueAnimator = ObjectAnimator.ofInt(
textView,
"textColor",
Color.parseColor(globalSettings.color),
Color.BLACK
);
backgroundColorValueAnimator.setFrameDelay(interval);
textColorValueAnimator.setFrameDelay(interval);
backgroundColorValueAnimator.setRepeatCount(ObjectAnimator.INFINITE);
backgroundColorValueAnimator.setRepeatMode(ObjectAnimator.RESTART);
textColorValueAnimator.setRepeatCount(ObjectAnimator.INFINITE);
textColorValueAnimator.setRepeatMode(ObjectAnimator.RESTART);
globalSettings.invertBackground = new AnimatorSet();
globalSettings.invertBackground.play(backgroundColorValueAnimator).with(textColorValueAnimator);
globalSettings.invertBackground.setDuration(interval);
globalSettings.invertBackground.start();
Any help would be greatly appreciated.