Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display indeterminate progressbar in Status bar on Android

I am trying to display an animated graphic identical to the indeterminate progress bar (not the horizontal one, but the circular one) in the status bar while my on-going notification is alive.

I tried to find the resource ID corresponding to the indeterminate progress bar, but found that it is animated via code.

I tried setting the icon ID in my Notification instance to an animated GIF, but only the first frame of the GIF is displayed in the Status bar.

If I set the icon ID to android.R.drawable.progress_indeterminate_horizontal, the graphic animates perfectly. So, my question is- how is the animation achieved in this case? Through iconLevel? How can I set an animated icon without requiring to animate it periodically myself?

like image 212
Akshay Avatar asked Apr 13 '11 08:04

Akshay


People also ask

What is indeterminate ProgressBar?

Indeterminate ProgressBars are a useful tool for communicating to our users that an operation is in progress when we cannot predict how long it is likely to take.

How do you make an indeterminate ProgressBar?

ProgressBar bar = new android. widget. ProgressBar(context); bar. setIndeterminate(true);

How do I stop indeterminate ProgressBar?

How do I stop indeterminate progress bar? An indeterminate progress bar animates constantly. You can stop the animation and clear the progress bar by making the progress bar determinate and setting the current value to the minimum.

How do I show progress notifications on android?

To display a determinate progress bar, add the bar to your notification by calling setProgress(max, progress, false) and then issue the notification. The third argument is a boolean that indicates whether the progress bar is indeterminate (true) or determinate (false).


2 Answers

I found my answer. The requirement is to create an animation list (say saved as my_spinner.xml), with various images of the spinner rotated by different angles from 0 to 360.

<?xml version="1.0" encoding="utf-8"?>
<animation-list
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/spinner_0"
        android:duration="200" />
    <item android:drawable="@drawable/spinner_60"
        android:duration="200" />
    <item android:drawable="@drawable/spinner_120"
        android:duration="200" />
    <item android:drawable="@drawable/spinner_180"
        android:duration="200" />
    <item android:drawable="@drawable/spinner_240"
        android:duration="200" />
    <item android:drawable="@drawable/spinner_360"
        android:duration="200" />
</animation-list>

And set my_spinner.xml as the icon ID when the notification is created.

Notification n = new Notification(R.drawable.my_spinner, null, 0);
like image 137
Akshay Avatar answered Sep 30 '22 18:09

Akshay


You can display the progress bar in the title by requesting proper windows feature and setting bar visibility:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    //any code here
    setProgressBarIndeterminateVisibility(true);

However, it will appear in the title, not in status bar.

like image 34
ernazm Avatar answered Sep 30 '22 17:09

ernazm