Tutorial details

[TUT] DayDreams are as easy as counting sheep | App Code for Sale | Preview

[TUT] DayDreams are as easy as counting sheep | Android Tutorial

How to work with DayDreams

Overview PAGE TOP

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:

http-__makeagif.com_media_5-27-2013_JGNIPc.gif

(much smoother on a device, this is a GIF representation)

To create a DayDream we need to:

  • Create a DayDream activity to display our daydream
  • Update our Manifest to inform the system we can dream
  • Create a custom view that will perform something cool in our daydream

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.

Reference PAGE TOP

http://blog.blundell-apps.com/tut-daydreams-are-as-easy-as-counting-sheep/

0 Comments Leave a comment

Please login in order to leave a comment.

Newest first
!

Sign-in to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.