How to make a count down timer in Notification's view?
Asked Answered
D

1

9

I figured out how to make custom views using RemoteViews class. I also know how to use Chronometer and ProgressBar inside of RemoteViews.

But how to make a count down View, almost exactly the same as Chronometer but with the difference that it will be counting down instead of up?

I tried to copy the source of Chronometer class and modify it so it will fit my needs, but there are annotations like @android.view.RemotableViewMethod, which i can not import to my project. Unfortunately, without annotations it is not working, because RemoteViews is using them to pass values.

My second idea was to extend the Chronometer class and override proper methods, but they are private.

Any ideas, is it possible? (And extra question, because I'm not sure: If the method is annotated and I override this method, is the annotation inherited?)

Dolf answered 6/12, 2011 at 16:53 Comment(0)
Y
4

I don't believe you're going to be able to use a custom class directly with RemoteViews even if it's derived from one of the supported classes (annotations are not inherited). You could try using a TextView, counting down in a Service with a reference to the RemoteViews object and updating from there.

Yawl answered 6/12, 2011 at 19:1 Comment(3)
Wouldn't it be resource consuming? Anyway, how to tell if the View is currently viewed or not?Dolf
It's certainly not cheap, I just can't think of another way to handle this really. If this is going to be more than just a test app and you try this approach, you'll definitely want to look at trying to find situations where you can pause this work (e.g. when the screen is off). I don't believe there's a good way to see if that view in the notification tray is visible either.Yawl
Yepp, there is no way doing it in elegant and effective way. I gave up this feature. Let this question be a time-saver for the others who want to do the same. Beware!Dolf

© 2022 - 2024 — McMap. All rights reserved.