Android Question Newbie question, button on top of panel can't be displayed

Elton Leung

Member
Licensed User
Longtime User
Just bought the Enterprise version yesterday and start using it last night. Immediately I have a feeling that every penny is worth it.

I am downloaded a copy of CCTV sample client (https://www.b4x.com/android/forum/threads/android-based-closed-circuit-tv-cctv-example.23601/) and start changing the code to suite my need, e.g. starting from the front camera. Everything is working ok. One thing that I don’t quite understand is how layout work.

From the CCTV client layout, there are three buttons. I deleted one and moved the other two to the bottom of the screen.

But when I run the code, I got a big camera preview panel but NOT the buttons. See screen grab:
Screenshot_2015-09-19-19-24-09.png

What I need to do is to press the invisible button to switch to the back camera then I can see the buttons.
Screenshot_2015-09-19-17-43-02.png

And of cause, when I switch back to the front, the buttons are there too.
From the Visual Designer, Script – General, I notice the background panel was resized by the script but not sized by the Properties screen, so I added the two lines in red but it doesn’t help.

'All variants script
AutoScaleAll'uncomment to scale all views based on the device physical size.
Panel1.SetLeftAndRight(0, 100%x)
Panel1.SetTopAndBottom(0, 100%y)
btnChangeCamera.Visible = True
btnTakePicture.Visible = True


I understand it is probably a stupid mistake that I made but I can’t found the solution from the Beginner’s guide. Please help. Thanks.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
If you get the buttons shown correctly and in the right position for both the front and the rear camera views but not the preview then it sounds like you've not loaded the buttons on the preview screen. We need to see more code to know where you have gone wrong.
 
Upvote 0

Elton Leung

Member
Licensed User
Longtime User
If you get the buttons shown correctly and in the right position for both the front and the rear camera views but not the preview then it sounds like you've not loaded the buttons on the preview screen. We need to see more code to know where you have gone wrong.


Sorry, may be I didn't make my question clear enough. The WYSIWYG preview screen is correct with two buttons. The first photo that I attached is how the app is looks like when it started (with the front camera) and there is NO button visible. The second photo is after I pressed the invisible cam switch button, the cam changed to the back camera and the two buttons appeared. Strange!
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
Like RandomCoder said, post your code or attach the project (File->Export as ZIP). Then it's easier to help you...
 
Upvote 0

Elton Leung

Member
Licensed User
Longtime User
Here is my code, basically just a simplified version of the CCTV sample client (without the communication part)

B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: False
    #ApplicationLabel: Camera Elton mod
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
    Private frontCamera As Boolean = True
'    Public ServerIp As String = "192.168.1.101"
'    Public ServerPort As Int = 17178
    Private IntervalMs As Int = 10000
    Private lastPreviewSaved As Long
End Sub

Sub Globals
    Private Panel1 As Panel
    Private camEx As CameraExClass
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    'StartService(Communicator)
End Sub

Sub Activity_Resume
    InitializeCamera
End Sub

Private Sub InitializeCamera
    camEx.Initialize(Panel1, frontCamera, Me, "Camera1")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    camEx.Release
End Sub

Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camEx.StartPreview
        Log("Supported sizes:")
        For Each size As CameraSize In camEx.GetSupportedPicturesSizes
            Log(size.Width & "x" & size.Height)
        Next
        camEx.SetJpegQuality(90)
        camEx.SetPictureSize(1280,720)
        Log(camEx.GetSupportedFlashModes)
        camEx.CommitParameters
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub

Sub btnTakePicture_Click
    camEx.TakePicture
    ToastMessageShow("Manual save", True)
End Sub

Sub Camera1_Preview (PreviewPic() As Byte)
    If DateTime.Now > lastPreviewSaved + IntervalMs Then
'        Dim jpeg() As Byte = camEx.PreviewImageToJpeg(PreviewPic, 70)
        camEx.TakePicture
        ToastMessageShow("Picture auto saved", True)
        lastPreviewSaved = DateTime.Now
'        CallSubDelayed2(Communicator, "Send", jpeg)
    End If
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
    camEx.SavePictureToFile(Data, File.DirRootExternal, "1.jpg")
    camEx.StartPreview
End Sub



Sub ChangeCamera_Click
    camEx.Release
    frontCamera = Not(frontCamera)
    InitializeCamera
End Sub
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
It would be better to upload your project as I can't tell what is wrong from looking at your sample code above. Although I'm surprised that the button click events work at all as there doesn't seem to be any button declarations. Whilst using the designer there is no need to initialise the Buttons but they still need to be declared.
This won't fox your problem though. I suggest using file export as zip to save your project and then upload here and we'll be able to provide the answer.
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
I can see your trouble now and it's not an easy one to fix because it seems to be linked to how the camera preview works, but that doesn't explain why switching the camera causes the buttons to be displayed and for them to continue to work correctly after switching back to the main camera. Very strange!!
I tried forcing the buttons to the front, invalidating them which should cause them to redraw, and also invalidated the whole activity but could not get the Buttons to display on first starting the App. In the end I have had to use two separate Panels. One of the Buttons and one for the camera. It now works the way you intended. ;)
 

Attachments

  • CameraMod1.zip
    10 KB · Views: 223
Upvote 0
Top