Programatically setting screen to fullscreen or not

MDEnt

Member
Licensed User
Longtime User
I currently have the IDE set to fullscreen, but I'm wondering what the correct syntax would be to set fullscreen or not for an activity in code instead.

Thanks.
 

hasanaydin52

Member
Licensed User
Longtime User
Programatically setting screen to fullscreen is possible

Hello,

You can do it with calling RunMethod.

B4X:
Sub FullScreen(active As Boolean,ActivityName As String)
      Dim obj1 As Reflector

      obj1.Target = obj1.GetMostCurrent(ActivityName)
      obj1.Target = obj1.RunMethod("getWindow")

      'remove previous parameters
      obj1.RunMethod2("clearFlags",1024,"java.lang.int")
      obj1.RunMethod2("clearFlags",2048,"java.lang.int")

      'add new parameter
      If active Then
         obj1.RunMethod2("addFlags",1024,"java.lang.int")  'FLAG_FULLSCREEN
        Else
         obj1.RunMethod2("addFlags",2048,"java.lang.int")  'FLAG_FORCE_NOT_FULLSCREEN
      End If
End Sub


.
.
.
'Calling within main activity

FullScreen(True,"Main")
'  or
FullScreen(False,"Main")
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi hasanaydin52,

I tryed your code but unfortunately it sets full screen but doesn't go back.
The code below does.
B4X:
Sub FullScreen(Active As Boolean, ActivityName As String)
    Dim obj1 As Reflector
    Dim i As Int

    i = 1024  'FLAG_FULLSCREEN
    obj1.Target = obj1.GetMostCurrent(ActivityName)
    obj1.Target = obj1.RunMethod("getWindow")
    If Active Then
        obj1.RunMethod2("addFlags",i,"java.lang.int")
    Else
        obj1.RunMethod2("clearFlags",i,"java.lang.int")
    End If
End Sub
Best regards.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi NJDude,
In the original code the two lines below weren't in.
B4X:
obj1.RunMethod2("clearFlags",1024,"java.lang.int")
obj1.RunMethod2("clearFlags",2048,"java.lang.int")
I think that hasanaydin52 has added them afterwards.

I agree with you that the Title bar should also be removed, I have shortly looked at it but not yet found how to do it.

Best regards.
 
Last edited:
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
You might have to create a separate Activity with it's layout to no Title and Fullscreen and open it.

You'd need to persist the original views (I'd create a class for that) or use StateManager.

I know it might well look ungainly but if Android doesn't allow it we need to kludge it I guess.

regards, Ricky
 
Last edited:
Upvote 0

Gargoyle

Member
Licensed User
Longtime User
Having a problem...

Using the FullScreen() is working, however how do I redraw/re-initialize the activity to now use the new height?

Regardless of the setting, the activity is still at the previous size, unless I rotate the screen and have the activity recreated (and then rotate it back).

Is there a simple way to do the re-initialize/re-create?

Thanks.
 
Upvote 0

Gargoyle

Member
Licensed User
Longtime User
You may check if 100%x and 100%y change their values after you perform the FullScreen.

If so, you can always use Activity.ReRunDesignerScript("somescript", 100%x, 100%y).

But you should tell us if you are using layouts or creating views from code.

Creating the view by code.

If I use the RemoveViewAt(), and repopulate, it (Activity) still isn't resized to altered screenheight.

The 100%y isn't changing on FullScreen(), unless I rotate tablet to re-Create
 
Upvote 0

Gargoyle

Member
Licensed User
Longtime User
I've even tried using a service to restart the activity, after closing it with Activity.Finish, but a ToastMessage, just shows the same Height (even though bar disappears).
 

Attachments

  • FullScreenTest.zip
    6.4 KB · Views: 357
Upvote 0

Gargoyle

Member
Licensed User
Longtime User
ARRGGGHHHH!.

I realised that FullScreen option wasn't On in IDE->Project->Activity Properties

Even when ticked, and titlebar is off, regardless of FullScreen() the Activity.Height reports the same result (the whole display size).

Now, is there anyway to get the DisplayedHeight?
(Or should I start a new thread)
 
Upvote 0

Gargoyle

Member
Licensed User
Longtime User
Activity.Height (or 100%y) should return the actual available height (similar to WinForms ClientSize).

@Erel, It does, but if calling the FullScreen() function, the Activity's size doesn't change, unless the Activity is reset by re-orientating device and then back.

Using example, (my tablet's dimensions in [], display height is 1024)
Press Display Height, it shows the Activity height and the device screen height. [984]

Press the Toggle FullScreen, the Activity is then fullscreen, but isn't using all of it (black border exists, not changed to white). Press the Display Height to confirm. [still 984]

Now if you rotate device so it changes orientation, then back again, the activity is reset, and the Display Height will confirm full height. [1024]

Now if you 'Toggle FullScreen' again, Display Height, should be the lower sized height but stays at full size. [1024]

Now click the Reset Activity, which should reset it correctly, but doesn't as Display Heights will confirm.

I thought the way I'm resetting the activity would work - but doesn't.

So is there any other way of resetting the Activity, so it uses the correct re-sized height after a FullScreen(), without having the user re-orientating the device.
 

Attachments

  • FullScreenTest.zip
    6.6 KB · Views: 334
Upvote 0

Gargoyle

Member
Licensed User
Longtime User
The problem is that the Activity.Height value is only measured once when the activity is created. Maybe you can use two activities. One full screen and one not.
One last question here then (I know it should be in a new thread, but it is related :)), is there a proper way of restarting/resetting the Activity, so it recreates. (Obviously the way I'm doing it in that last test isn't enough.)
 
Upvote 0

Gargoyle

Member
Licensed User
Longtime User
Found one solution, I'm changing the rotation programmatically, to a set rotation, but normally I'd do it away from usual orientation, then back.
It's hardly noticable on my tablet.
Edit Test from a Portrait orientation, or alter the 6, and 7 in the SetScreenOrientation calls.

Edit: Changes to Testfile, Uses Phone library.
B4X:
Sub Process_Globals
   'Add this next line
   Dim fs_RESET As Boolean
End Sub

Sub Globals
   'Add this next line
   Dim phn As Phone
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Add these to top of Sub
   If fs_RESET = True Then
      phn.SetScreenOrientation(7)
      fs_RESET = False
   End If
End Sub

Sub but3_Click
   'Add these two lines, and comment out the other two
   fs_RESET = True
   phn.SetScreenOrientation(6)
'   StartService("FSToggle")
'   Activity.Finish
End Sub
 
Last edited:
Upvote 0

Gargoyle

Member
Licensed User
Longtime User
You can try to call Activity.Finish followed by CallSubDelayed("", ...) (or StartActivity). It should destroy the activity and then create it again.

Tried that :), never seemed to work, just quit out and didn't re-start.

I'll try it again after a few other niggles are addressed.
 
Upvote 0
Top