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

Discussion in 'Android Questions' started by Elton Leung, Sep 19, 2015.

  1. Elton Leung

    Elton Leung Member Licensed 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 (http://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:
    [​IMG]
    What I need to do is to press the invisible button to switch to the back camera then I can see the buttons.
    [​IMG]
    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.
     
  2. RandomCoder

    RandomCoder Well-Known Member Licensed 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.
     
  3. Elton Leung

    Elton Leung Member Licensed User


    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!
     
  4. eurojam

    eurojam Well-Known Member Licensed User

    Like RandomCoder said, post your code or attach the project (File->Export as ZIP). Then it's easier to help you...
     
  5. Elton Leung

    Elton Leung Member Licensed User

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

    Code:
    #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
     
  6. RandomCoder

    RandomCoder Well-Known Member Licensed 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.
     
  7. Elton Leung

    Elton Leung Member Licensed User

    alright here is the zipped code
     

    Attached Files:

  8. RandomCoder

    RandomCoder Well-Known Member Licensed 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. ;)
     

    Attached Files:

  9. Elton Leung

    Elton Leung Member Licensed User

    thank you !
     
    RandomCoder likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice