My app has a not that frequent operation that is executed on the UI threads and takes long time (up to 3 secs). I want to display an animated 'wait' indications during that time. For example, a rotating spinner. No need to display the actual progress, just a fix speed animation.
I created a custom dialog that pops up during the long operation and it has this layout
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Problem is that it does not spin. How do I make it spin, even if the UI thread is busy?
I tried to create a chain on events to increment it but I get only two events, probably because the UI thread is busy.
// In the custom dialog class. mProgressBar is the ProgressBar in the layout.
// Called externally once when the dialog is shown
public void tick() {
mProgressBar.incrementProgressBy(10);
mProgressBar.postDelayed(new Runnable() {
@Override
public void run() {
// Not a recursion since it's done in a future event.
tick();
}
}, 100);
}
What is a simple way to achieve this animation? Will a frame by frame animation be easier to do?