LiveWallpaper Library

Highwinder

Active Member
Licensed User
Longtime User
LWP Tips/General Info

As the main culprit who goaded Erel into producing the LWP library, I feel a responsibility to chime in and spill the beans by offering some helpful information to the folks who are struggling with creating LWPs and need to know some general basics.

First things first:

Just to have said it, an animated GIF is still a GIF - that means nothing beyond the crappy 256 color limitations of the GIF format. Any app you create with GIFs being used for graphics will be limited to 256 colors. This means potentially grainy graphics - and there's nothing you'd be able to do about it. Also, the GIF format does not produce tiny file sizes, they can be VERY large, and push your app into huge bloatware territory that will have potential customers shunning it. Ever downloaded an animated GIF from the web? Notice how huge the file sizes are. Just so you know.

If you want high quality LWPs, you're going to be using JPG images only (or PNG if you need an alpha channel, but PNGs can get huge too so beware). And yes, you're probably going to be looping them in a list array using a timer unless you want to engage in some pretty complex animation programming using Java, which I'm not sure B4A is up to. I do know that Erel has clarified that you will not be using B4A to do OpenGL programming for LWPs (if you're into OpenGL programming on any accomplished level, there's a good chance that your programming skills are beyond the level of the average VB jockey who's using B4A for their chosen development platform).

All of my animations are series of export images that I create in other 2D and 3D animation software (like Flash, ToonBoom, 3DS MAX, etc). I use these products as "cheaters" to create profesional graphic content that allows me to fake high quality 3D in my apps. The tradeoff is that I'm basically making inefficient movies and looping them as LWPs instead of creating truly efficient, complex Java OpenGL animations. Oh well, the world of entertainment is nothing but a well-orchestrated universe of shortcuts, corner-cutting and lowest-common-denominator fakery. Welcome to Hollywood and the wonderful world of bloatware.

You'll probably want to use a frame rate of at least 24/second (30fps preferable for smooth motion) or it's gonna be an annoyingly jerky slideshow (unless you WANT or NEED it to be a slideshow). This is controlled using the tick value of the Live Wallpaper service. Want 30fps for a smooth animation? 1000/30 = 33, so that means a new image gets cycled with a tick value of 33. A frame rate of 24 fps means cycling a new image with a tick set to 42. And whatever animation software you use to create the series of images will need to be set at the same frame rate that you use in your LWP. Remember that.

Also know that cycling images puts a load on the processor the same way playing a movie does. Same exact thing, zero difference. As such, you will notice that this puts a bit of a performance lag on the phone when you're sliding home screens left and right. This does NOT happen when any app is launched, however, as the LWP then hibernates. This lag is not severe, but noticeable compared to non-movie, efficient, complex LWPs. No particular reason I mention this other than an FYI factoid for the sake of it.

LWP developers who write the really super high-class, complex, real Java-animated LWPs (the ones that use true 3D graphics, loads of animation code, perform beautifully smooth, and put virtually no load on the phone) criticize these types of LWPs mostly for marketing purposes, but they are correct - the type of LWP I describe above is in fact a "looping movie" that puts a recognizable (but not severe) load on the processor and battery.

If you plan on cycling images to animate your LWPs like so many of us do, fair warning: the more resolution, color and movement in your images, the bigger the files are and the more "processing bandwidth" they use. Keep your loops short enough to keep the APK file size down - live wallpapers are generally considered hideous bloatware if they exceed 9 megabytes. You can go over 10mb with just a few seconds of animated image looping! No matter what, your finished LWP should be under 10mb, and under 5mb if you're wise and took the time to find your "magic combination. All the best ones out there are very small (usually 2-5mb). You'll have to find the magic combination of frame rate, image quality, and resolution on your own to see how it works for your app. And each app can be different. When my LWPs end up being about 2-3mb, I kick the image quality or resolution up to get it up to about 5mb just for quality's sake, but only when it makes sense to do so. Good judgment is called for with these things.

As for a previous comment about the "instability" of using list arrays for animating LWPs, I strongly disagree. Every single one of my LWPs are solid as a rock using that method, and a few of my LWPs include multiple list arrays nearly 2,000 images in size (the size of the list arrays themselves, not actual image count). Read that again. If your LWP is unstable, you've done something wrong.

No, list array-driven LWPs are not perfect performance-wise, but close enough to not have anybody in my world complaining one bit - I have not heard of any instabilities or crashes from any of my customers. The only thing any of my LWPs might suffer from is if I make the mistake of choosing boring subject material or create crappy-looking graphics content.

Sorry for the epic novel, but somebody out there is gonna be happy about this. And that definitely would have included me last year. :)
 
Last edited:

walterf25

Expert
Licensed User
Longtime User
Great advice

Hey there thanks for your feedback and experience regarding LWP, i have been trying to create nice looking LWP as far as graphics go, but have not had much success, i lack knowledge of image creation using any type of software out there, i'm in the process of learning though. That being said, do you have any links to any of the LWP you have created I'd like to check them out and compare the quality of the images to mine, i need to set a standard that i can follow for the images i create. Again thanks for your input!

Regards,
Walter
 

Highwinder

Active Member
Licensed User
Longtime User
Hey there thanks for your feedback and experience regarding LWP, i have been trying to create nice looking LWP as far as graphics go, but have not had much success, i lack knowledge of image creation using any type of software out there, i'm in the process of learning though. That being said, do you have any links to any of the LWP you have created I'd like to check them out and compare the quality of the images to mine, i need to set a standard that i can follow for the images i create. Again thanks for your input!

Regards,
Walter

Sure, here's one of my quickie "down and dirty" LWPs. I created the animation for this one in Flash. It's not much, as this was my very first LWP I ever released. Even though it's got a few fun bells and whistles, don't expect much in the graphics department. This one really was more about writing a good solid LWP framework that I could regurgitate rather quickly when I cranked out new animations.

Graphics: To make animations for your live wallpapers, you MUST get the hang of at least one software product that allows you to create animated graphics. All of such programs have some type of learning curve, sometimes fairly steep (at least at the beginning). I personally think products such as Anime Studio Pro and Flash are the easiest out of all of them to learn, and both allow you to animate raster graphics (photos). But it will only suffice if 2D graphics/motion are good enough for your apps. I quickly outgrew 2D and have bravely/foolishly dove into the bottomless pit of pro-level 3D animation, which will immediately start eating up your entire life just to learn the basics and produce anything that can be considered "non-crap". Still deciding if this was a wise decision or not, but frankly, my software requires it.


BTW: "Faith is the substance of things hoped for, the evidence of things not seen." 15 years. :)
 
Last edited:

NeoTechni

Well-Known Member
Licensed User
Longtime User
A few things I did for my LWPs is let the user select the framerate, AND the top and bottom borders of the screen.

That way they can decide how much power they want to sacrifice for smoothness, and how big the top/bottom borders are of whatever launcher they use.

Anyone have code to bring up the LWP selector window?
 

walterf25

Expert
Licensed User
Longtime User
Here's how i do it

Code to launch the wallpaper chooser

B4X:
Sub button1_click
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_MAIN, "")
Intent1.SetComponent("com.android.wallpaper.livepicker/.LiveWallpaperListActivity")
StartActivity(Intent1)
End Sub

the above code works for android devices with 2.2 versions

and this one below works with android devices with 4.0.4

B4X:
Sub button1_click
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_MAIN, "")
Intent1.SetComponent("com.android.wallpaper.livepicker/.LiveWallpaperActivity")'this will work for android 4.0.4
StartActivity(Intent1)
End Sub

hope this helps, i actually display an activity when a user installs my wallpapers with three buttons where they can be taken directly to the wallpaper picker, or check out more of my live wallpapers, or exit.

below is a screenshot of the transparent activity, one thing i also implement is that i do not show the live wallpaper icon in the app tray that way is not as easy for users to uninstall!

transparent activity.jpg

to prevent the app icon to show up in the app tray, you need to add this code to your manifest file

B4X:
AddReplacement(<category android:name="android.intent.category.LAUNCHER" />,)


AddApplicationText(<activity
    android:label="Beautiful Lake Live WallPaper HD"
    android:name=".main"
    android:exported="true"
   android:theme="@style/Theme.Transparent">
   
    <intent-filter>
       <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.INFO" />
    </intent-filter>
</activity>)
 
Last edited:

NeoTechni

Well-Known Member
Licensed User
Longtime User
Thank you.

So the second one only works on Android 4.04 and higher, the other from 2.2 and higher? Or 2.2 and lower/4.04 and lower?

If it's first one from 2.2 to 4.04, then second one from 4.04 and up, then I've made code to autodetect

B4X:
Sub APIlevel As Int 
   Dim r As Reflector
   Return r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
End Sub
Sub LWPselector 
   Dim Intent1 As Intent
   Intent1.Initialize(Intent1.ACTION_MAIN, "")
   If APIlevel<15 Then
      Intent1.SetComponent("com.android.wallpaper.livepicker/.LiveWallpaperListActivity")
   Else
      Intent1.SetComponent("com.android.wallpaper.livepicker/.LiveWallpaperActivity")'this will work for android 4.0.4
   End If
   StartActivity(Intent1)
End Sub
 

walterf25

Expert
Licensed User
Longtime User
Nice code

Thanks Neo, and i haven't actually with many versions, the only two phones i have with me are v2.2, and 4.0.4, so i'm not really sure up to what version the first code works, or from what version to what version the second code will work, but thanks for your code.

Cheers,
Walter
 

melamoud

Active Member
Licensed User
Longtime User
looks cool,

is there a way to get the nimap of the current wallpaper, the one I'm about to clear ?

thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code (requires Reflection library):
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim bg As Object
   bg = GetWallpaperBackground
   Activity.Background = bg
End Sub

Sub GetWallpaperBackground As Object
   Dim r As Reflector
   r.Target = r.RunStaticMethod("android.app.WallpaperManager", "getInstance", _
      Array As Object(r.GetContext), Array As String("android.content.Context"))
   Dim bg As Object
   bg = r.RunMethod("getDrawable")
   Return bg
End Sub
GetWallpaperBackground returns a drawable object.
 

melamoud

Active Member
Licensed User
Longtime User
thanks, now how do I create a Bitmap based on that object ?

what I'm trying to do is get the wallpaper add something to it, and put it back

thanks
 

rikky1966

Member
Licensed User
Longtime User
Hey everyone,

Releasing a new library that took me about approx. 1 hour to make.
With this library you are able to create/specify your own (live) wallpaper from your app.
So you can:

- remove the current wallpaper
- get information about the current wallpaper
- get the desired height and width.
- Setting the x- and y offset.
- specify a new wallpaper from a bitmap or a stream
- and a little bit more functions.

and so you can create your own dynamical wallpaper.

B4X:
Dim lw As LiveWallpaper
Dim btmp As Bitmap
lw.Initialize
btmp.Initialize(File.DirAssets,"rs2.png")

lw.clearWallpaper

Msgbox(lw.WallpaperInfo,"Information")
Msgbox(lw.DesiredMinimumHeight,lw.DesiredMinimumWidth)
lw.WallpaperBitmap(btmp)

Cheers,

XverhelstX
where is the download link?
 
Top