Poroblem wil live wallpaper

tazlikesrobots

Member
Licensed User
Longtime User
Created a live wallpaper based on a code example by Vasper (http://www.b4x.com/forum/basic4android-updates-questions/13745-animation-technique.html) and everything compiles OK, but I cannot get it to work on the phone.

Basically I can load the wallpaper, but all the screen says is Loading live wallpaper and will not do anything else.

BTW I am a complete :sign0104: so my programming skills are very basic at best, so feel free to let me know if there is a better way to do this!

Here is my code

B4X:
'code adapted from post by Vasper- http://www.b4x.com/forum/basic4android-updates-questions/13745-animation-technique.html

Sub Process_Globals
    Dim lwm As LWManager
    Dim x, y, vx, vy As Int
    Dim initialized As Boolean: initialized = False
    Dim boxSize As Int
    Dim FlakeBitmap(8) As Bitmap
    Dim Bgnd As Bitmap
    Dim prevRect As Rect
    Dim prevRectOffSet As Rect
    Dim Degrees As Int
    Dim snowflakes As List
    Dim snowflakesX As List
    Dim snowflakesY As List
    Dim snowflakesVX As List
    Dim snowflakesVY As List
    Dim snowflakesPrev As List
    Dim snowflakesPrevOffset As List
    Dim snowflakesDegrees As List
    Dim snowflakesBoxSize As List
    Dim rndFlake As Int
    Dim fullInfoBM As Bitmap
    Dim maxSnow As Int
    maxSnow = 20
    snowflakes.Initialize
    snowflakesX.Initialize
    snowflakesY.Initialize
    snowflakesVX.Initialize
    snowflakesVY.Initialize
    snowflakesPrev.Initialize
    snowflakesPrevOffset.Initialize
    snowflakesDegrees.Initialize
    snowflakesBoxSize.Initialize
End Sub

Sub Service_Create
    lwm.Initialize("lwm", True)
    lwm.StartTicking(80) 
    vx = 1dip
    vy = 4dip
    boxSize = 16dip
    FlakeBitmap(1).Initialize(File.DirAssets, "blue.png")
    FlakeBitmap(2).Initialize(File.DirAssets, "green.png")
    FlakeBitmap(3).Initialize(File.DirAssets, "orange.png")
    FlakeBitmap(4).Initialize(File.DirAssets, "purple.png")
    FlakeBitmap(5).Initialize(File.DirAssets, "red.png")
    FlakeBitmap(6).Initialize(File.DirAssets, "white.png")
    FlakeBitmap(7).Initialize(File.DirAssets, "yellow.png")
    Bgnd.Initialize(File.DirAssets, "bkg.png")
    rndFlake = Rnd(1,8)
End Sub

Sub addNewSnowFlake(ax As Int,ay As Int,avx As Int, Engine As LWEngine)
    snowflakes.Add(Rnd(1,8))
    snowflakesX.Add(ax)
    snowflakesY.Add(ay)
    snowflakesVX.Add(avx)
    snowflakesVY.Add(Rnd(1,8))
    snowflakesBoxSize.Add(Rnd(12,32))
    Dim prevRect1 As Rect
    Dim prevRectOffset1 As Rect
    prevRect1.Initialize(0,0,0,0)
    snowflakesPrev.Add(prevRect1)
    prevRectOffset1.Initialize(0,0,0,0)
    snowflakesPrevOffset.Add(prevRectOffset1)    
    snowflakesDegrees.Add(0)
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub


Sub Service_Destroy

End Sub

Sub lwm_SizeChanged (Engine As LWEngine)
    DrawBackground (Engine)
End Sub
Sub DrawBackground (Engine As LWEngine)
    FullRefresh(Engine)
End Sub

Sub FullRefresh (Engine As LWEngine)
    Dim aRectOffSet As Rect
    Dim aRect As Rect
    aRectOffSet.Initialize(0 + Engine.CurrentOffsetX,0,Engine.ScreenWidth + Engine.CurrentOffsetX,Engine.ScreenHeight)
    aRect.Initialize(0,0,Engine.ScreenWidth,Engine.ScreenHeight)
    Engine.Canvas.DrawBitmap(Bgnd,aRectOffSet,aRect)
    Engine.RefreshAll
End Sub

Sub lwm_OffsetChanged (Engine As LWEngine)
    FullRefresh(Engine)
End Sub

Sub lwm_VisibilityChanged (Engine As LWEngine, Visible As Boolean)
    If Visible Then
        DrawBackground (Engine)
    End If
End Sub

Sub AnimateSnowFlakes(Engine As LWEngine)
    Dim i As Int
    If Not (fullInfoBM.IsInitialized) Then
        fullInfoBM.InitializeMutable(Engine.ScreenWidth,Engine.ScreenHeight)
    End If
    Dim aCNV As Canvas
    aCNV.Initialize2(fullInfoBM)
    Dim aRectOffSet As Rect
    Dim aRect As Rect
    aRectOffSet.Initialize(0 + Engine.CurrentOffsetX,0,Engine.ScreenWidth + Engine.CurrentOffsetX,Engine.ScreenHeight)
    aRect.Initialize(0,0,Engine.ScreenWidth,Engine.ScreenHeight)    
    aCNV.DrawBitmap(Bgnd,aRectOffSet,aRect)
    i = 0
    Do While i<snowflakes.Size
        Dim nwRndFlake As Int
        Dim nwX As Int
        Dim nwY As Int
        Dim nwVX As Int
        Dim nwVY As Int
        Dim nwPrevRect As Rect
        Dim nwPrevRectOffset As Rect
        Dim nwDegrees As Int
        Dim nwBoxSize As Int
        nwRndFlake = snowflakes.Get(i)
        nwX = snowflakesX.Get(i)
        nwY = snowflakesY.Get(i)
        nwVX = snowflakesVX.Get(i)
        nwVY = snowflakesVY.Get(i)
        nwPrevRect = snowflakesPrev.Get(i)
        nwPrevRectOffset = snowflakesPrevOffset.Get(i)
        nwDegrees = snowflakesDegrees.Get(i)
        nwBoxSize = snowflakesBoxSize.Get(i)
        If nwX > Engine.ScreenWidth Then
            nwX = 1dip
        Else If nwX < nwBoxSize Then
            nwX = nwBoxSize + 2dip
        End If
        If nwY  + nwBoxSize > Engine.ScreenHeight Then
            snowflakes.RemoveAt(i)
            snowflakesX.RemoveAt(i)
            snowflakesY.RemoveAt(i)
            snowflakesVX.RemoveAt(i)
            snowflakesVY.RemoveAt(i)
            snowflakesPrev.RemoveAt(i)
            snowflakesPrevOffset.RemoveAt(i)
            snowflakesDegrees.RemoveAt(i)
            snowflakesBoxSize.RemoveAt(i)
        Else
            nwX = nwX + nwVX
            nwY = nwY + nwVY    
            Engine.Rect.Top = nwY
            Engine.Rect.Left = nwX
            Engine.Rect.Bottom = nwY + nwBoxSize
            Engine.Rect.Right = nwX + nwBoxSize            
            nwDegrees = (nwDegrees + 10) Mod 360
            nwPrevRect.Left = Engine.Rect.Left - 2dip
            nwPrevRect.Top = Engine.Rect.Top - vy
            nwPrevRect.Right = Engine.Rect.Right + 2dip
            nwPrevRect.Bottom = Engine.Rect.Bottom
            nwPrevRectOffset.Left = Engine.Rect.Left + Engine.CurrentOffsetX - 2dip
            nwPrevRectOffset.Top = Engine.Rect.Top - vy
            nwPrevRectOffset.Right = Engine.Rect.Right + Engine.CurrentOffsetX + 2dip
            nwPrevRectOffset.Bottom = Engine.Rect.Bottom
            aCNV.DrawBitmapRotated(FlakeBitmap(nwRndFlake), Null, Engine.Rect, nwDegrees)
            snowflakesX.Set(i,nwX)
            snowflakesY.Set(i,nwY)
            snowflakesDegrees.Set(i,nwDegrees)
            Dim selDirection As Int
            selDirection = Rnd(1,10)
            If selDirection == 2 Then
                nwVX = -1 * Abs(nwVX)
            End If
            If selDirection == 8 Then
                nwVX = Abs(nwVX)
            End If            
            snowflakesVX.Set(i,nwVX)
            i = i + 1
        End If            
    Loop
    Engine.Canvas.DrawBitmap(fullInfoBM,aRect,aRect)
    Engine.RefreshAll    
End Sub

Sub lwm_Tick (Engine As LWEngine)
    
    If snowflakes.Size<maxSnow Then
        addNewSnowFlake(Rnd(20dip,Engine.ScreenWidth-60dip),0,vx, Engine)
    End If
    AnimateSnowFlakes(Engine)
End Sub
Sub lwm_Touch (Engine As LWEngine, Action As Int, tx As Float, ty As Float)
    rndFlake = Rnd(1,8)
    addNewSnowFlake(Round(tx),Round(ty),vx, Engine)
End Sub

Wallpaper xml file
<?xml version="1.0" encoding="utf-8"?>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
android:thumbnail="@drawable/icon"
/>


AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="rasofware.wdwlw.wallpaper"
android:versionCode="1"
android:versionName=""
android:installLocation="internalOnly">

<uses-sdk android:minSdkVersion="7" />
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:icon="@drawable/icon"
android:label="wdw Ballons">
<activity
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTop"
android:name=".main"
android:label="wdw-livewallpaper"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
<service
android:label="WDW ballons"
android:name="anywheresoftware.b4a.objects.WallpaperInternalService"
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/wallpaper" />
</service>
<receiver android:name=".wallpaperservice$wallpaperservice_BR">
</receiver>
</application>
</manifest>
 
Last edited:
Top