Dynamic wallpaper for Android principles

Source: Internet
Author: User

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, that is, APK. Since it is an application, of course, it means that there is a function inherent in GIF images that is not available-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 supports setting dynamic GIF images as static wallpapers, but it cannot dynamically run GIF images. That is to say, if you use a GIF image as a static wallpaper, you can only see one static image. You cannot see the dynamic effect of the GIF image on the desktop as many other systems do. 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 cannot develop in eclipse Based on ADT or SDK. Instead, you should download the complete source code and compile 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 each Android version released. The dynamic Wallpaper Code of each version is slightly different, however, 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/


As you can see, the built-in dynamic wallpaper of Android is in the packages/wallpapers/directory, through git
Clone method (see blog post "Download Android source code-use git
Clone to achieve a single directory download ", http://blog.csdn.net/droidpioneer/article/details/6612026) quickly download each sub-directory of each Android version of Android built-in dynamic wallpaper code. 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:

<? XML version = "1.0" encoding = "UTF-8"?> <! --/***** Copyright 2008, the android open source project ***** licensed under the Apache license, version 2.0 (the "License "); ** you may not use this file except T in compliance with the license. ** you may obtain a copy of the license at ***** http://www.apache.org/licenses/license-2.0###** unless required by applicable law or agreed to in writing, software ** distributed under the license is distributed on an "as is" basis, ** without warranties or conditions of any kind, either express or implied. ** see the license for the specific language governing permissions and ** limitations under the license. */--> <manifest xmlns: Android = "The 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>

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 noted 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.