Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
'Dim out As OutputStream
End Sub
Sub Globals
Dim camera1 As Camera
Dim btnTakePicture As Button
Dim came_from As Object
Dim backSub As String
Dim pnlCameraImage As Panel
Dim btnOK As Button
Dim btnTakeNew As Button
Dim pnlControls As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("layCamera_takephoto")
End Sub
Sub Activity_Resume
initializeCamera
End Sub
Sub Activity_Pause (UserClosed As Boolean)
camera1.Release
End Sub
Sub Activity_KeyUp (KeyCode As Int) As Boolean
If(KeyCode = KeyCodes.KEYCODE_DPAD_CENTER) Then
TakePicture
End If
End Sub
Sub selector(sourcePlace As Object)
came_from = sourcePlace
'initializeCamera
End Sub
Sub initializeCamera()
Activity.Invalidate
Try
' camera1.Release
Catch
End Try
Try
camera1.Initialize(pnlCameraImage, "Camera1")
Catch
End Try
hideControlsPanel
End Sub
Sub getBack()
If(backSub = "") Then
CallSubDelayed(came_from, "getBackWithPicture")
Else
CallSubDelayed(came_from, backSub)
End If
End Sub
Sub Camera1_Ready (Success As Boolean)
If Success Then
StartRecording
'btnTakePicture.Enabled = True
Else
ToastMessageShow("Cannot open camera.", True)
End If
End Sub
Sub Camera1_PictureTaken (Data() As Byte)
'camera1.StartPreview
Dim out As OutputStream
out = File.OpenOutput(File.DirRootExternal, "temp.jpg", False)
out.WriteBytes(Data, 0, Data.Length)
out.Close
ToastMessageShow("Image saved: " & File.Combine(File.DirDefaultExternal, "temp.jpg"), True)
Dim img As ImageView
img.Initialize("img")
img.Bitmap = LoadBitmap(File.DirRootExternal, "temp.jpg")
pnlCameraImage.AddView(img, 0, 0, 100%x, 100%y) ' add a snapshot to the panel.
showControlsPanel ' show the buttons btnOK and btnTakeNew
End Sub
Sub TakePicture()
camera1.TakePicture ' take the picture
StopRecording ' stop recording. I think this is handled internally but not sure.
End Sub
' starts the previous of images
Sub StartRecording()
pnlControls.Visible = False ' hide the btnOK and btnTakeNew controls
camera1.StartPreview
End Sub
Sub StopRecording()
camera1.StopPreview
End Sub
Sub showControlsPanel()
pnlControls.Visible = True
End Sub
Sub hideControlsPanel()
pnlControls.Visible = False
End Sub
Sub btnTakeNew_Click()
zCommon.clearPanel(pnlCameraImage) ' clear the snapshot
StartRecording ' start new previews
End Sub
Sub btnOK_Click
getBack ' we like the result, go back to the calling Activity
End Sub
Sub pnlCameraImage_Click
If(pnlControls.Visible = True) Then ' this will disable picture taking if the controls menu is visible. It is time for decision, not new picture taking.
Return True
End If
TakePicture
End Sub