Android Question ( closed ) Position widget to the device screen?

anOparator

Active Member
Licensed User
Longtime User
Can a widget be given a position Absolute to the device screen?
So that when I swipe Left or Right between 3 different home screens, the widget is visible on all 3 screens.

I am able to display a variable, 'Starter.lstNmbr', in the Logs or in a 7-second Toast but would like to display it on a Widget or or even on the Notification Bar so that it is visible on all 3 screens.

What I've found so far involves the position of the widget View within it's parent Panel, not widget position relative to the device screen.
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
I don't know of any widget that can stay persistent/visible across home screens. You might need to have the user place three separate widgets (one on each screen and at the same location on each screen).

I also don't think there is a way to tell which homepage the user is viewing, so you'll need to update all the widgets at once.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
I don't know of any widget that can stay persistent/visible across home screens. You might need to have the user place three separate widgets (one on each screen and at the same location on each screen).

I also don't think there is a way to tell which homepage the user is viewing, so you'll need to update all the widgets at once.
Thanks, maybe that's the template, swipe to different homepage, remove/update the widget. (looking up remove widget now)
edit:
just remembered that the user has to manually place widget on screen (end user burnouts), also there's no way to know how many screens a user has.
This is for tracking item numbers in a List of images used when changing wallpaper. Can the Notification Bar be used?)
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
This is for tracking item numbers in a List of images used when changing wallpaper. Can the Notification Bar be used?)

Can you explain in more detail your application because it sounds like your app runs when a user is trying to select a background/wallpaper for their homescreen.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
When launched 2 buttons show:
btnPickPicture
btnStart

btnPickPicture uses MultiPhotoPicker to create List of pics.
Once started, a Sticky Service calls a 'changePicture' and 'SetWallPaper' sub every 3 hours to change the wallpaper.
B4X:
 Sub changePicture
   If Starter.picNmbr = Starter.lstGlbl.Size - 1 Then
       Starter.picNmbr = 0
       Log("                lstGlbl.Size maxed")
   Else
       Starter.picNmbr = Starter.picNmbr + 1
       Log("                lstGlbl.Size    NOT maxed")
   End If
   SetWallPaper(LoadBitmap(Starter.daPaf, Starter.lstGlbl.Get(Starter.picNmbr))) ' change wallpaper
End Sub
B4X:
 Sub SetWallPaper(Bmp As Bitmap)
   Dim nuNum = Starter.picNmbr -1 As String
     clrMe
   Dim r As Reflector
   r.Target = r.RunStaticMethod("android.app.WallpaperManager", "getInstance", _
      Array As Object(r.GetContext), Array As String("android.content.Context"))
   r.RunMethod4("setBitmap", Array As Object(Bmp), Array As String("android.graphics.Bitmap"))
   Log("picture name  = " & Starter.lstGlbl.Get(Starter.picNmbr))
   ShowToastAt(15, 15, "was " & nuNum  & " now " & Starter.picNmbr, True)
   End Sub
Since some pics might be too large for the screen I want to know the pic # that needs a smaller pixel size.
I'm at 300 pics now, will set a maximum possible entered later.
No UI when running.

Thanks for helping me think.
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I'm still a little confused on the issue, but is the problem that you know how to get the button position relative to the panel its in, but you want to get the position relative to the Host Activity (screen) that a button is?

If so, you can simply do this:

B4X:
AbsoluteLeft = Button.left + Panel.Left
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
Am stepping thru a List, a variable has the current lstPosition #.
How to constantly show that number on the device screen when the Home screen is swiped left or right.
Am now looking into using the Notification Bar and Drawer. (notifications are new to me).
It is a wallpaper app, incremented by a Service, no UI views visible once started.
thanks.
edit: Notification wont work, don't want to start an activity or service unless they can show a variable on the screen, I just want easy access to a variable.
 
Last edited:
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
I knew it could be done, it's called a GIF overlay.
see the video in Post #9 here.
The little I've managed to change so far:
android:targetSdkVersion="26"
added text to lblMain
made text visible for "b As Button" and "b2 As Button"

In addition to why the "Reflection" and "Animation" library not being used, I get lost @ the following error.
Has anyone worked with this demo OR are there more recent Overlay posts that I haven't found because once I get the overlay on the screen I can plug in the variable content.

B4X:
 *** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (oservice) Create ***
Error occurred on line: 86 (oService)
java.lang.RuntimeException: Cannot change properties after call to SetInfo. Initialize the notification again.
   at anywheresoftware.b4a.objects.NotificationWrapper.getND(NotificationWrapper.java:92)
   at anywheresoftware.b4a.objects.NotificationWrapper.setIcon(NotificationWrapper.java:168)
   at com.twouchapps.example.chatheads.oservice._service_create(oservice.java:558)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
   at com.twouchapps.example.chatheads.oservice.onCreate(oservice.java:67)
   at android.app.ActivityThread.handleCreateService(ActivityThread.java:3212)
   at android.app.ActivityThread.-wrap5(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6165)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
** Service (oservice) Start **
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I get lost @ the following error
for which you should create a new thread as it is not related to the question in this thread.

SetInfo must be the last command used before you show the notification.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
Closing thread, widget is not what I can use.
 
Upvote 0
Top