I have done some research and found that it's possible to have a progress bar in the expanded statusbar area but I am still not sure about whether the animation icon is possible or not. I have tried the answer of this question: Animation in Notification bar Custom View. However, the icon is not animated. If it's not possible, could you point me to any documentation that confirms that? Thanks in advance.
-
I don't know how to do this right off, but an example of an application that does this is Podkicker. When you're downloading a file for offline listening, it is animated. Do these help? http://stackoverflow.com/questions/9216616/animation-in-status-bar-in-android http://stackoverflow.com/questions/4688052/animation-in-notification-bar-cutsom-view – Jim Sep 07 '12 at 20:31
-
I am checking Podkicker. Anyway, the SO question you referred is different from what I want. That question is actually about animation on ImageView. – patrick Sep 07 '12 at 20:37
-
@Jim I checked out Podkicker. It's not same as what I want. My requirement is an animation icon in the expanded statusbar area (which displays when a user pull down the notification bar). Thanks, anyway. – patrick Sep 07 '12 at 20:54
-
That's interesting because I linked two questions one titled "Animation in status bar in Android" and the other "Animation in Notification bar Cutsom View". Maybe it's time I tried to do it myself :-) – Jim Sep 07 '12 at 21:05
-
And the video linked in the "Animation in Notification bar Cutsom View" shows what I think you are talking about. – Jim Sep 07 '12 at 21:07
-
I've tried the second answer of http://stackoverflow.com/questions/4688052/animation-in-notification-bar-cutsom-view but it's not animated. – patrick Sep 07 '12 at 21:13
1 Answers
The video in your referenced question (which I admit I didn't see was the same as one of the links I gave) clearly shows an animated icon there. At about 0:35. http://www.youtube.com/watch?v=yNcs-sS2nFU&t=0m32s (this link jumps to that part). The arrow has a little black line move down through it repeatedly. Seems like animation to me. Is that what you want?
Regardless, what Android version is that on? Maybe it's something custom from T-Mobile, I don't know, it's just some video on YouTube.
You can create a custom view for the notification, for example: http://www.roman10.net/android-custom-notification-with-progress-bar/ You might be able to use a similar idea with an animation drawable (same SO question again) where Roman10's got the default android image.
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.noti);
contentView.setImageViewResource(... your animated resource ...);
Edit
So in the end RemoteViews doesn't support animation in the image resource as far as I can tell. But I figured out a way to work around that and it is possibly expensive, but I haven't profiled it to see how the CPU usage is.
I started with the code at roman10 (link above) and made a couple of modifications.
yinyangAnim.xml + animation frame .png files
<?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/yinyang0" android:duration="150" />
<item android:drawable="@drawable/yinyang1" android:duration="150" />
<item android:drawable="@drawable/yinyang2" android:duration="150" />
<item android:drawable="@drawable/yinyang3" android:duration="150" />
<item android:drawable="@drawable/yinyang4" android:duration="150" />
<item android:drawable="@drawable/yinyang5" android:duration="150" />
</animation-list>
Add another thread creation to the start button click:
new Thread(new Runnable() {
public void run() {
int frameIndex = 0;
mRun = true;
while (mRun) {
++frameIndex;
SystemClock.sleep(100);
BitmapDrawable frame = (BitmapDrawable) yinyangAnimation.getFrame(frameIndex);
noti.contentView.setImageViewBitmap(R.id.status_icon, frame.getBitmap());
nm.notify(STATUS_BAR_NOTIFICATION, noti);
if (frameIndex >= yinyangAnimation.getNumberOfFrames()-1) {
frameIndex = 0;
}
}
}
}).start();
Add to ProgressBarNotificationActivity.onCreate()
ImageView yinyang = new ImageView(this);
yinyang.setBackgroundResource(R.drawable.yinyang_anim);
yinyangAnimation = (AnimationDrawable) yinyang.getBackground();
And the private variable of course: private AnimationDrawable yinyangAnimation;
Pressing the start button in the app and viewing the notification shows the spinning yin-yang for me. I got the yin-yang at loadinfo.net and split it using ImageMagick command line (ubuntu).
-
Thanks for the answer. The icon on the video is really animated. However, I followed your answer but still can't get it working. I forked the project you referred and added the animation part as you suggested. My code is at https://github.com/pt2121/roman10-android-tutorial/tree/master/ProgressBarNotification My animation code works fine on ImageView but not on the RemoteViews (StatusBar). Not sure what I missed. – patrick Sep 08 '12 at 22:48
-
I've also tried this answer of http://stackoverflow.com/questions/4688052/animation-in-notification-bar-cutsom-view. I cannot get it working. If the code works for you, is it possible to share your example project? Appreciated. – patrick Sep 08 '12 at 22:57
-
It works. Thanks. Although I think it's expensive because notification is repeatedly sent, I accepted your answer. – patrick Sep 10 '12 at 20:38
-