Android Question On Camera2

rossati

Active Member
Licensed User
Longtime User
Hi
I am not able to restore the background color of previous panel after open and close a camera.
In nuce below the functions that create a light gray background with an image:
B4X:
Sub createPanel()
            pnl.Initialize("")           
            pnl.Color = Colors.LightGray
            addButton("btnAnamnesis","Anammnesis",0)
            btnTakePicture = addButton("btnCamera","Take Picture",1)
            ...
            pnl.SetBackgroundImage(LoadBitmapResize(File.DirAssets, "bigGaleno.png", 100%x, 100%y, True)).Gravity = Gravity.CENTER
            Activity.AddView(pnl,0,0,100%x,100%y)
        formData.Text = editData2(data,": ",Chr(10))
End Sub
Here the functions that activate the camera:
B4X:
Sub btnCamera_Click
    Activity.LoadLayout("camera")
    pnl.RemoveView
    camEx.Initialize(cameraPanel)
    OpenCamera(frontCamera)
End Sub
At last closing the camera:
B4X:
Sub btnExitPicture_Click
    camEx.Stop
    cameraPanel.RemoveView
    createPanel
End Sub
The panel is recreated with buttons and image but the background is black.
I have also attempted with visibility on/off, SendToBack/brìngToFront and activity.inalidate.


Thanks
John Rossati
 

rossati

Active Member
Licensed User
Longtime User
Thank Erel
The camer panel is into layout: Activity.LoadLayout("camera").
If I impose the color before the image, it is no longer visible; I include the two images, the white one is at the start off app, the black image is after closing the camera and removing the camera panel itself.
 

Attachments

  • GalenoBlack.jpg
    GalenoBlack.jpg
    60.7 KB · Views: 219
  • GalenoWhite.jpg
    GalenoWhite.jpg
    62.5 KB · Views: 219
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
As Erel said, Line #3 in createPanel will do nothing since later in line#7 you are setting again the background when loading a picture (since it is a png, the background will be transparent where the pic is transparent)

That's why, the 'LightGray' that you are seeing when the program starts, is not the pnl background color but the Activity background Color, which is initially set to that value (probably because of the targetSDK default theme or the specific theme that has been chosen in the manifest).

Later, when you load the camera layout to the activity: it does 2 things
  1. Loads a panel with its content
  2. Changes the Activity color to black :eek:
Finally, when you remove the camerapanel to create your pnl again, step 2) is not restored, so you are seeing again the Activity Background, BUT this time modified by the camera layout (even if you removed the panel)

There are several ways to solve it :)
  • Load a picture to pnl, that has a solid background
  • (Cleaner) Change the layout in the designer, so that the container Activity Drawable, instead of being a drawable with black color, will be a BitmapDrawable with no specified file (it will do nothing and keep the existing background)
 
Upvote 0

rossati

Active Member
Licensed User
Longtime User
Tanks JordiCP
Thanks your explanation has been helpful to me to solve the problem (with the Cleaner suggestion) and it has helped me to know better the Android environment.
 
Upvote 0
Top