Android Question Help With Battery Widget

Darren Llewellyn

Member
Licensed User
Longtime User
I have been working on a battery widget, the software compiles fine and the widget shows up in the list but when I put it on the screen all I get is a white block

the code in the service module is this
B4X:
#Region  Service Attributes
    #StartAtBoot: true
#End Region
 
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all module
    Dim RV As RemoteViews
   
    Dim PhneEvents As PhoneEvents
End Sub
Sub Globals
    Dim BatLvl As Int
    Dim lblLvl As Label
    Dim imgLvl As ImageView
    imgLvl.Initialize("")
    lblLvl.Initialize ("")
    Dim pnlwidget As Panel
    pnlwidget.Initialize ("")
    imgLvl.Bitmap = LoadBitmap(File.DirAssets, "geekbatloadbg.gif")
End Sub
 
Sub Service_Create
    RV = ConfigureHomeWidget("l1","RV",5,"geekBat",True)
   
End Sub
 
Sub Service_Start (StartingIntent As Intent)
    If RV.HandleWidgetEvents(StartingIntent) Then Return
    PhneEvents.Initialize("phneevents")
End Sub
 
Sub Service_Destroy
 
End Sub
Sub rv_RequestUpdate
    'PhneEvnts_BatteryChanged
    RV.UpdateWidget
End Sub
Sub rv_Disabled
    StopService("")
End Sub
Sub PhneEvnts_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
Dim BatLvl As Int
Dim lblLvl As Label
Dim imgLvl As ImageView
    lblLvl.Initialize ("")
    BatLvl = Level
    lblLvl.Text  = Level
    imgLvl.Initialize ("")
    If Plugged = True Then
        imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatblubg.gif")
    Else
        If BatLvl >50 Then
            imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatbatlvlgrn.gif")
        Else If BatLvl > 25 Then
            imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatbatlvlylo.gif")
        Else If BatLvl > 15 Then
            imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatbatlvlorg.gif")
        Else If BatLvl > 0 Then
            imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatbatlvlred.gif")
        Else
            'Do Nothing
        End If
    End If
       
End Sub

I have checked the tutorials and found no joy there.

also any help on how to get it to be a 1X1 panel would be helpful as well

thanks in advance for any help
 

Attachments

  • Widget.png
    Widget.png
    33.1 KB · Views: 177
  • batWidget.zip
    31.8 KB · Views: 176

Darren Llewellyn

Member
Licensed User
Longtime User
B4X:
#Region  Service Attributes
    #StartAtBoot: true
#End Region
 
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all module
    Dim RV As RemoteViews
   
    Dim PhneEvents As PhoneEvents
End Sub
 
 
Sub Service_Create
    RV = ConfigureHomeWidget("l1","RV",5,"geekBat",True)
   
End Sub
 
Sub Service_Start (StartingIntent As Intent)
    If RV.HandleWidgetEvents(StartingIntent) Then Return
    PhneEvents.Initialize("phneevents")
End Sub
 
Sub Service_Destroy
 
End Sub
Sub rv_RequestUpdate
    'PhneEvnts_BatteryChanged
    RV.UpdateWidget
End Sub
Sub rv_Disabled
    StopService("")
End Sub
Sub PhneEvnts_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
Dim BatLvl As Int
Dim lblLvl As Label
Dim imgLvl As ImageView
    lblLvl.Initialize ("")
    BatLvl = Level
    lblLvl.Text  = Level
    imgLvl.Initialize ("")
    imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatbatlvlgrn.gif")
    If Plugged = True Then
        imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatblubg.gif")
    Else
        If BatLvl >50 Then
            imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatbatlvlgrn.gif")
        Else If BatLvl > 25 Then
            imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatbatlvlylo.gif")
        Else If BatLvl > 15 Then
            imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatbatlvlorg.gif")
        Else If BatLvl > 0 Then
            imgLvl.Bitmap = LoadBitmap(File.DirAssets,"geekbatbatlvlred.gif")
        Else
            'Do Nothing
        End If
    End If
       
End Sub

B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: GeekBat
    #VersionCode: 1
    #VersionName: 1.1
    #CanInstallToExternalStorage: True
#End Region
 
'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
 
End Sub
 
Sub Globals
 
End Sub
 
Sub Activity_Create(FirstTime As Boolean)
    Activity.Finish
End Sub
 
Sub Activity_Resume
 
End Sub
 
Sub Activity_Pause (UserClosed As Boolean)
 
End Sub
here is the updated file with none missing
 

Attachments

  • batWidget.zip
    189.3 KB · Views: 198
Upvote 0
Top