Tuesday, March 18, 2014

DayDream feature of Android 4.2+

Dreams are new features of Android 4.2+ version. They are interactive screensavers launched when a charging device is idle, or docked in a desk dock. Dreams provide another modality for apps to express themselves, tailored for an exhibition/lean-back experience.

We can develope a dream for Daydream by simply implementing a subclass of DreamService. The DreamService APIs are much more similar to those of Activity

For developing your own daydream feature, we have to create One java class that extends DreamService and make entry in AndroidManifest.xml file about Dream service.

Step 1:
Create a simple Android project from your IDE.

Step 2:

 package com.sign.mydaydream;  
 import android.service.dreams.DreamService;   
 import android.widget.TextView;  
 public class MyDayDreamService extends DreamService {  
   public void onAttachedToWindow() {  
        * Allow user to touch while dreaming to make it interactive.  
        * Hide the notification bar to run it in full screen.  
     * You can either give any layout id to display as daydream or   
           * build UI for daydream by yourself.  
     TextView tView = new TextView(this);  
     tView.setText("Hello DayDream by Sanket Shah!");  
     tView.setTextColor(Color.rgb(144, 225, 220));  
     // Setting a view for daydream screen  

Now, the second step is to make entry in AndroidManifest.xml file.

Step 3:

     android:label="My Day Dream" >
        android:name="android.service.dreams.DreamService" />
        android:name="android.intent.category.DEFAULT" />

That's it! Now install your application on your Android device.
You can find your daydream under Settings -> Display -> DayDream menu.

You can also provide setting for your daydream for let user customize the dream like changing font color, screen brightness, etc. For providing setting button beside your daydream you need to add metadata tag to your AndroidManifest.xml file where we declare the daydream service in Step 3.

Note: While creating the daydream simply create a Activity for developing UI. This way you can easily test your daydream UI during development.

No comments:

Post a Comment