Introduction to how to create and play an android boot Animation

Source: Internet
Author: User
Introduction to how to create and play an android boot Animation

Everyone wants to have a gorgeous and beautiful boot animation, which makes people feel comfortable. How does Android achieve it? How to Create a boot animation? Here we unveil the mystery of Android boot animation.

1. Create an animation for the on/off Server 1.1

System/Media/bootanimation.zip. to modify the boot animation, modify the compression file bootanimation. If the package does not exist, use the native resources, its path in system/framework/framework-res.apk/assets/images(android-logo-mask.png, android-logo-shine.png), but ugly, more common is "android ". Therefore, you need to customize your own on/off animation in the system/Media/directory to put bootanimation.zipand shutanimation.zip. Here we take the boot animation as an example. The shutdown animation works the same way as the boot animation.

1.2 bootanimation.zip file structure

Bootanimation mainly containsDesc.txtAnd n folders. The folder contains the image resources of the boot animation. Decs.txt is used to instruct the system to execute the boot animation.

The following is the description of the notebook:

320 480 12p 1 0 folder1p 0 0 folder2

320 480 indicates the screen resolution. 12 indicates 12 frames per second. In short, 12 indicates playing 12 images in one second;
P 1 0 Part1:P is play. 1 indicates playing once, and 0 indicates unlimited. 0 indicates that the number of frames at the stage interval is 0. Folder1 means that this command is for the folder folder1;
P 0 0 Part2:The first 0 indicates loop playback, and the second 0 indicates the same as the second command above. Folder2 is the second folder.
The summary rules are as follows:
Command 1: [Screen Resolution] [playback frequency]
Command 2: [p] [playback times] [number of frames at intervals] [Folder]
N commands: Same as above
1.3 compressed packages

Package the used folderfolder with decs.txt in ZIP format. It must be a zip file, not a RAR file, and the compression mode is "Storage. Change the name to bootanimation.zip, and then push the prepared zip package to the/system/media directory.

Note:: Bootanimation cannot be too large. Generally, it is better not to exceed 3 M.

1.4 view animations

 Enter the following command in the terminal:

ADB shell ---> Cd/system/bin ---> bootanimation or bootanimation shut

This allows you to view custom animations without restarting.

1.5 The Hard-condition mobile phone must have the root permission. Otherwise, the created image resources cannot be pushed to the/system/Media Directory. In addition, the bootanimaiton command may not have the permission, therefore, to customize your mobile phone, you must have the root permission. Of course, you can use different methods based on your interests. 2. Playback principles

The above prepare boot resource has been prepared, so how does Android Play the video. First, Android uses a dedicated
Native service for playing (/system/bin/bootanimation), including the implementation of the boot ringtone is also implemented using this service.

2.1 start bootanimation

The Android system defines many services in init. Rc. For specific definition formats, refer to "android init language" in Android platform developer's guide ". The service defined in init. RC will be created by the INIT process, and the defined service contains bootanimation.

Each service must be in/init. RC definition. when the Android system is started, the init daemon will parse the init. RC and start the property service. The property "CTL. start and CTL. stop is used to start and stop the service. Once you receive a request to set the "Ctrl. Start" attribute, the property service uses this attribute value as the service name to locate the service and start the service. The startup result of this service will be placed in the "init. SVC. <service name>" attribute.

service bootanim /system/bin/bootanimation    user graphics    group graphics system audio qcom_oncrpc    disabled    oneshot

Defines a bootanim service, corresponding to the execution of/system/bin/bootanimation

Disabled indicates that the INIT process is created but not immediately;

Oneshot indicates that the service is only executed once;

2.2 boot animation call

We can see from the above that the call of bootanimation is the same as that of the Palace Museum CLT. start and CTL. when the system kernel is started up and Android is started, the boot animation will be started

Why is it called in the readytorun method of surfaceflinger. cpp? Please review the boot process.

status_t SurfaceFlinger::readyToRun() {    // start boot animation service    property_set("ctl.start", "bootanim");//   }

After Android is started, disable the boot animation.

void SurfaceFlinger::bootFinished() {    //stop bootanim service    property_set("ctl.stop", "bootanim");}

2.3 location of the bootanimation source code analysis code:/frameworks/base/cmds/bootanimation. It mainly contains the following three files:

BootAnimation_main.cppBootAnimation.hbootAnimation.cpp

2.3.1 bootanimation_main.cpp

This file is the main entry file;

int main(int argc, char** argv){#if defined(HAVE_PTHREADS)    setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY);#endif    char value[PROPERTY_VALUE_MAX];    property_get("debug.sf.nobootanimation", value, "0");    int noBootAnimation = atoi(value);    LOGI_IF(noBootAnimation,  "boot animation disabled");    if (!noBootAnimation) {        sp<ProcessState> proc(ProcessState::self());        ProcessState::self()->startThreadPool();        // create the boot animation object        bool setBoot = true;bool setRotated = false;bool sePaly = true;if(argc > 1){           if(!strcmp(argv[1],"shut"))   setBoot = false;}if(argc > 2){if(!strcmp(argv[2],"nomp3"))   sePaly = false;}if(argc > 3){if(!strcmp(argv[3],"rotate"))   setRotated = true;}char volume[PROPERTY_VALUE_MAX];        property_get("persist.sys.mute.state", volume, "-1");    int nVolume = -1;nVolume = atoi(volume);if(nVolume == 0 || nVolume == 1 ){sePaly = false;}        sp<BootAnimation> boot = new BootAnimation(setBoot,sePaly,setRotated);        IPCThreadState::self()->joinThreadPool();    }    return 0;}

The main function is to determine whether to play the boot or shutdown animation/ringtone based on the input parameters, and start bootanimation;

2.3.2 bootanimation. cpp

Bootanimation. cpp is integrated with the thread. When it is created, readytorun ()-> threadloop () is called ().

Status_tbootanimation: readytorun (){............... Omitted ........................... Mandroidanimation = false; If (bbootorshutdown) {status_t err = mzip. Open ("/data/local/bootanimation.zip"); If (Err! = No_error) {err = mzip. Open ("/system/Media/bootanimation.zip"); If (Err! = No_error) {mandroidanimation = true ;}} else {If (! Bshutrotate) {status_terr = mzip. Open ("/data/local/shutanimation.zip"); If (Err! = No_error) {err = mzip. Open ("/system/Media/shutanimation.zip"); If (Err! = No_error) {mandroidanimation = true ;}}} return no_error ;}

Readytorun () method to determine whether/system/Media/bootanimation.zip(shutanimaion.zip) exists. If so, set mandroidanimation to false. This variable determines whether Android () or movie () is called in threadloop () to play the animation.

Boolbootanimation: threadloop () {...... omitted ...... if (! Bbootorshutdown) {psoundfilename = "/data/local/shutaudioaudio"; pbackupsoundfilename = "/system/Media/shutaudioaudio";} else {psoundfilename = "/data/local/bootaudioaudio "; pbackupsoundfilename = "/system/Media/bootaudio.mp3";} If (mandroidanimation) r = Android () ;}else {r = movie ();}}

The threadloop () method calls Android ()/movie () based on the mandroidanimation variable. If the system/Media/shutanimation.zip/movie file is used, the animation is played based on the configuration in the TXT file. Otherwise, Android is called to play back the Native Resources.

3. Summary

I think this is not the focus of this article on how to draw image resources. If you are interested, you can continue to explore it.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.