) Android principle, one of the series of dynamic wallpapers

Source: Internet
Author: User

Source: LinuxCommunityAuthor: droidpioneer

Livewallpaper, a dynamic wallpaper, is a 3D feature of Android. Users can choose to attach dynamic wallpaper on the desktop to rotate the desktop background of their mobile phones.

Compared with static desktop wallpapers, dynamic wallpapers can display a variety of dynamic backgrounds. Unlike traditional mobile phone systems that use GIF as a dynamic background, Android dynamic wallpapers are not GIF images, it is a standard Android Application.Program, That is, APK. Since it is an application, of course, it means that it is born with a function not available in GIF images-it can interact with users, moreover, dynamic background changes are not limited to the loop playback of fixed images as GIF images.

It should be noted that the standard Android system can set dynamic GIF images as wallpaper, but it cannot dynamically run GIF images. That is to say, if you use GIF images as wallpaper, you can only see one static image. You cannot see the dynamic effect of GIF images on the desktop as on many other system hosts. This limitation is a major defect of Android, which is related to the design defect of the android wallpaper framework. Of course, since you can load a variety of types of mobile Android dynamic wallpapers with interactive effects, a little pity about GIF images is acceptable.

Android built-in dynamic wallpaper is implemented based on renderscript. renderscript is a type of C language that Google uses for Android. Its structure is similar to that of C, it encapsulates the standard API of OpenGL and can load the renderscript file to run it at runtime. That is to say, if you want to develop a new dynamic wallpaper Based on renderscript, you should have a certain understanding of common OpenGL APIs. In addition, Google's current development materials for renderscript are not perfect, and the renderscript has not been inherited into ADT in the public release SDK. In other words, if you want to use renderscript to develop new dynamic wallpapers, you must download the completeSource codeCompile the entire framework and then write new applications in your own Linux compiling environment. Because renderscript calls the OpenGL interface, your developed application must be able to run on a real machine, and your machine must support 3D, that is, OpenGL. If you find that some manufacturers' mobile phone desktops do not have a portal to load dynamic wallpaper, you do not need to say that the mobile phone does not support 3D at all, this is important for those who want to buy a real machine to learn how to develop andoid.

Google has built a certain number of dynamic wallpapers in various Android versions released.CodeThere are a few differences, but the name, effect, and number of dynamic wallpapers are basically the same. Next, let's take a look at the location of the dynamic wallpaper code. We open Google Android Source Code address: http://android.git.kernel.org/

We can see that the android built-in dynamic wallpaper are in the packages/wallpapers/directory, through the GIT clone method (see "android source code download-use git clone to download a single directory", http://www.linuxidc.com/Linux/2011-07/38953.htm) quickly download the android built-in dynamic wallpaper code for each Android version of each subdirectory. Among them, the basic and musicvisualization directories contain multiple dynamic wallpapers with the same code framework. The magicsmoke directory only contains one dynamic wallpaper of magic smoke, the livepicker directory contains the code of the dynamic wallpaper selection list, that is, the implementation code of the list of all dynamic wallpapers in the system that appears when you choose to add dynamic wallpaper on the desktop.

So what is the essence of dynamic wallpaper? As mentioned above, it is an APK, but it is a special APK. Open the androidmanifest. xml file of magicsomke:

 <  Span   Style  = "Font-size: 16px ;"  > <  Manifest        Xmlns: Android  = "Http://schemas.android.com/apk/res/android"        Package = "Com. Android. magicsmoke"  >        <  Original-Package   Android: Name  = "Com. Android. magicsmoke"   />        <  Uses-feature   Android: Name  = "Android. Software. live_wallpaper"   />        <  Uses-Permission   Android: Name  = "Android. Permission. set_wallpaper_component"   />        < Uses-Permission   Android: Name  = "Android. Permission. bind_wallpaper"   />        <  Application            Android: Label  = "@ String/wallpapers"            Android: icon  = "@ Drawable/ic_launcher_wallpaper"  >            <  Service                Android: Label  = "@ String/wallpaper_magicsmoke"                Android: Name  = "Magicsmoke"                Android: Permission = "Android. Permission. bind_wallpaper"  >                <  Intent-Filter  >                    <  Action   Android: Name  = "Android. Service. wallpaper. wallpaperservice"   />                </  Intent-Filter  >                <  Meta-data   Android: Name = "Android. Service. Wallpaper"   Android: Resource = "@ XML/magicsmoke"   />            </  Service  >            <  Activity                Android: Name  = "Com. Android. magicsmoke. magicsmokeselector"                Android: Theme  = "@ Style/preview"                Android: exported  = "True"  >            </  Activity  >        </  Application >    </  Manifest  >    </  Span  >   

I have already guessed that the android dynamic wallpaper is essentially a "service", which can be loaded by the launcher on the main interface. So how can launcher identify this APK with dynamic wallpaper service? The intent-filter action of the above androidmanifest. xml file leaks the following:

 
<Action Android: Name= "Android. Service. wallpaper. wallpaperservice" />

Yes. The system officially uses the APK action to load it into the livepicker list as a dynamic wallpaper. You can select your favorite dynamic wallpaper in the livepicker list, then, the dynamic wallpaper is displayed behind the launcher.

it should be pointed out that although the android dynamic wallpaper seems to be displayed in the launcher background, it is only an illusion that the dynamic wallpaper and launcher are completely different processes, however, the launcher and the dynamic wallpaper process can communicate with each other through the wallpapermanager in the framework. When a user slides the launcher desktop and clicks the screen, some dynamic wallpapers can interact with each other, in fact, this process completes communication. If you use the code to set the background of the launcher to non-transparent, such as using an opaque image or color as the background, then you will not see any dynamic wallpaper effect. Of course, in this case, you won't see the static wallpaper either.

Related Article

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.