DayDreaming is simple, if you have written an application with an Activity i.e everybody! You should be able to implement a simple daydream with little extra effort.
We are going to run through creating one and it will look something like this at the end:
(much smoother on a device, this is a GIF representation)
To create a DayDream we need to:
Ok here we go..
First we’ll create the DayDreamActivity, now technically it is not an Activity but a Service and in that idea we have to extend Service, but if you think of it as an Activity to display content with a lifecycle, I think it is a better concept.
In the DayDreamActivity we set a content view, this is the layout that will be shown if your day dream is being used. We also declare that we can handle user touch events, we don’t want the status bar shown when our day dream is shown and they can dim the screen.
DayDreamActivity.java:
+ expand source
After your create your DayDream, you need to declare it in your AndroidManifest like any other service:
AndroidManifest.xml
+ expand source
That’s it, that would get you a basic daydream. However it doesn’t really do anything, so below I’m going to show you how to create a custom ImageView that will rotate any image you give it. For this example it is a spinning cloud daydream! We use a TimeAnimator to give us a callback on every frame for the system drawing. When we get this callback we change the Y rotation of the ImageView. You could do whatever you wanted for your daydream this is just one example.
SpinningImageView.java
+ expand source
Then you use your custom view in the layout for the DayDreamActivity and you are done.
dream_main.xml
+ expand source
Take a look at the GitRepo for the source. DayDream Source Here
Inspired by the Google IO 2013 Talk Androids Do DayDream, I would highly recommend you watch it.
Enjoy! and ask any questions you like.
http://blog.blundell-apps.com/tut-daydreams-are-as-easy-as-counting-sheep/
Please login in order to leave a comment.