B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Activity
Version=6.8
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: False
	
#End Region
Sub Process_Globals
	Private frontCamera As Boolean = False
	Dim ruta As String
	Dim g As GPS
	Dim foto_g () As Byte
	Dim foto_g1 () As Byte
	Dim foto_g2 () As Byte
	Dim foto_g3 () As Byte
	Dim foto_g4 () As Byte
	Dim existe_gestion As String


End Sub

Sub Globals
	Private Panel1 As Panel
	Private camEx As CameraExClass
	Dim btnTakePicture As Button
'	Dim skmt As SQL
	Dim c As Cursor
	Dim cuenta As String
	Dim lat_gps As String
	Dim lon_gps As String

	Private Panel2 As Panel
	Private b_guardar As Button
	Private i_foto As ImageView
	Dim contador As String
	Private LA_TIPO As Label
	Dim tgl As Toggle
End Sub

Sub Activity_Create(FirstTime As Boolean)
	If(FirstTime) Then
		g.Initialize("GPS")
	End If
	Activity.LoadLayout("foto")
'	If File.ExternalWritable Then
'		ruta = File.DirDefaultExternal
'	Else
'		ruta = File.DirInternal
'	End If
	
'	If File.Exists(ruta, "kmt.db") = False Then
'		File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
'	End If
	
'	skmt.Initialize(ruta,"kmt.db", True)
	c=Starter.skmt.execQuery("select cuenta from cuentaa")
	c.Position = 0
	cuenta = c.GetString("CUENTA")
		
End Sub

Sub Activity_Resume
	i_foto.Visible = False
	tgl.Initialize

'	tgl.TurnGPSOn
'	If g.GPSEnabled=False Then
'		ToastMessageShow("Habilitar el GPS", True)
'		StartActivity(g.LocationSettingsIntent)
'	Else
		g.Start(0,0)
'	End If
	InitializeCamera
	'lon_gps = "-99:52:38,682"
	'lat_gps = "16:51:38,022"
	contador = 1
End Sub

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

Sub Activity_Pause (UserClosed As Boolean)
	camEx.Release
End Sub
Sub GPS_LocationChanged (Location1 As Location)

	lat_gps=Location1.ConvertToSeconds(Location1.Latitude)
	lon_gps=Location1.ConvertToSeconds(Location1.Longitude)
	'btnTakePicture.Enabled = True
	's.ExecNonQuery2("INSERT INTO  HIST_GPS (HGDATE,HGLAT, HGLON) VALUES(?,?,?) ", Array As Object (sDate & sTime, lat_gps, lon_gps))
End Sub

Sub Camera1_Ready (Success As Boolean)
	If Success Then
		camEx.SetJpegQuality(90)
		camEx.CommitParameters
		camEx.StartPreview
		Log(camEx.GetPreviewSize)
	Else
		ToastMessageShow("Cannot open camera.", True)
	End If
End Sub

Sub btnTakePicture_Click
	Dim ps As CameraSize
	ps.Width =640
	ps.Height =480
	camEx.SetPictureSize(ps.Width, ps.Height)
	'ToastMessageShow(ps.Width & "x" & ps.Height, False)
	camEx.CommitParameters
	camEx.TakePicture
End Sub

Sub btnFocus_Click
	camEx.FocusAndTakePicture
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
	Dim filename As String = "1.jpg"
	Dim dir As String = File.DirRootExternal
	
	camEx.SavePictureToFile(Data, dir, filename)
	camEx.StartPreview 'restart preview
	i_foto.Visible = True

	i_foto.Bitmap = LoadBitmap(File.DirRootExternal, "1.jpg")
	Dim ins As InputStream
	Dim bmp As Bitmap
	Dim jpeg() As Byte
	Dim InputStream1 As InputStream
	InputStream1 = File.OpenInput(File.DirRootExternal, "1.jpg")
	Dim OutputStream1 As OutputStream
	OutputStream1.InitializeToBytesArray(500)
	File.Copy2(InputStream1, OutputStream1)
	foto_g = OutputStream1.ToBytesArray
	
End Sub

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

Sub btnEffect_Click
	Dim effects As List = camEx.GetSupportedColorEffects
	If effects.IsInitialized = False Then
		ToastMessageShow("Effects not supported.", False)
		Return
	End If
	Dim effect As String = effects.Get((effects.IndexOf(camEx.GetColorEffect) + 1) Mod effects.Size)
	camEx.SetColorEffect(effect)
	ToastMessageShow(effect, False)
	camEx.CommitParameters
End Sub

Sub btnFlash_Click
	Dim f() As Float = camEx.GetFocusDistances
	Log(f(0) & ", " & f(1) & ", " & f(2))
	Dim flashModes As List = camEx.GetSupportedFlashModes
	If flashModes.IsInitialized = False Then
		ToastMessageShow("Flash not supported.", False)
		Return
	End If
	Dim flash As String = flashModes.Get((flashModes.IndexOf(camEx.GetFlashMode) + 1) Mod flashModes.Size)
	camEx.SetFlashMode(flash)
	ToastMessageShow(flash, False)
	camEx.CommitParameters
End Sub
Sub btnPictureSize_Click
	Dim pictureSizes() As CameraSize = camEx.GetSupportedPicturesSizes
	Dim current As CameraSize = camEx.GetPictureSize
	For i = 0 To pictureSizes.Length - 1
		If pictureSizes(i).Width = current.Width And pictureSizes(i).Height = current.Height Then Exit
	Next
	Dim ps As CameraSize = pictureSizes((i + 1) Mod pictureSizes.Length)
	camEx.SetPictureSize(ps.Width, ps.Height)
	ToastMessageShow(ps.Width & "x" & ps.Height & i, False)
	camEx.CommitParameters
End Sub
Sub Activity_KeyPress (key As Int) As Boolean
	' BACK key pressed
	If key=KeyCodes.KEYCODE_BACK Then
		' I want to capture the key here so I return True
		StartActivity(seleccion)
		'Return True
	End If
	' Returning False signals the system to handle the key
	Return False
End Sub


Sub b_guardar_Click
	Dim sDate,sTime As String

		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
		starter.skmt.execNonQuery2("UPDATE kmt_info set CAT_CL_NUM_SERIEFISICO = ?, CAT_CL_LONG = ?, CAT_CL_LAT =?, CAT_CL_FOTO =? where CAT_CL_CODIGO In (select cuenta from cuentaa)", Array As Object("OK", lon_gps, lat_gps, foto_g))

		'send a broadcast intent to the media scanner to force it to scan the saved file.
		'Dim Phone As Phone
		'Dim i As Intent
		'i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
		'	"file://" & File.Combine(dir, filename))
		'Phone.SendBroadcastIntent(i)
		'ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
		StartActivity(fila)
	
End Sub