#Region Project Attributes
#ApplicationLabel: ImageCapture
#VersionCode: 1
#VersionName: landscape
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim gfilename As String
Dim Timer1 As Timer
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim camera1 As AdvancedCamera
Dim Panel1 As Panel
Dim i As Int = 0
Dim ScreenTimeout As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("Menu")
If IsPaused(imgcap) = True Then
' StartServiceAt("imgcap",DateTime.Now + 10*1000,True)
StartService("imgcap")
End If
End Sub
Sub Activity_Resume
SetShowWhenLocked
ScreenTimeout = GetScreenTimeout
Log("ScreenTimeout: " & ScreenTimeout)
SetScreenTimeout(60000)
' WakeState.KeepAlive(False)
Dim r As Reflector
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindow")
r.RunMethod2("addFlags", 6815872, "java.lang.int")
Dim p As Phone
' Dim Value As Float : Value = 0
' p.SetScreenBrightness(Value/255)
p.SetScreenBrightness(0.001)
Timer1.Initialize("Timer1",1000)
Timer1.Enabled=True
Timer1_Tick
End Sub
Sub SetShowWhenLocked
Dim r As Reflector
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindow")
r.RunMethod2("addFlags", 6815872, "java.lang.int")
End Sub
Sub Timer1_Tick
i = i + 1
Log(i)
If i=2 Then
camera1.Initialize(Panel1, "Camera1")
Else If i=4 Then
camera1.StartPreview
Else If i=10 Then
camera1 .TakePicture
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
SetScreenTimeout(ScreenTimeout)
StartServiceAt("imgcap",DateTime.Now + 30 * 1000,True)
End Sub
Sub Camera1_PictureTaken (Data() As Byte)
camera1.StartPreview
Dim out As OutputStream
DateTime.DateFormat="yyyyMMddHHmmss"
gfilename = DateTime.Date(DateTime.Now)
out = File.OpenOutput(File.DirRootExternal & "/weatall", gfilename & ".jpg", False)
out.WriteBytes(Data, 0, Data.Length)
out.Close
Log("Image saved: " & gfilename)
Log("image saved.")
Timer1.Enabled=False
Dim p As Phone
p.SetScreenBrightness(200)
SetScreenTimeout(ScreenTimeout)
StartService("imgcap")
' Dim i As Intent
' i.Initialize(i.ACTION_MAIN, "")
' i.AddCategory("android.intent.category.HOME")
' i.Flags = 0x10000000
' StartActivity(i)
Activity.Finish
End Sub
Sub Panel1_Touch (Action As Int, X As Float, Y As Float)
StartServiceAt("imgcap",DateTime.Now + 30 * 1000,True)
Activity.Finish
End Sub
Sub SetScreenTimeout(Timeout As Int)
Dim jo As JavaObject
Return jo.InitializeStatic("android.provider.Settings.System") _
.RunMethod("putInt", Array As Object(GetContext.RunMethod("getContentResolver", Null) _
, "screen_off_timeout", Timeout))
Return Timeout
End Sub
'Return the timeout measured in milliseconds
Sub GetScreenTimeout As Int
Dim jo As JavaObject
Return jo.InitializeStatic("android.provider.Settings.System") _
.RunMethod("getInt", Array As Object(GetContext.RunMethod("getContentResolver", Null) _
, "screen_off_timeout"))
End Sub
Sub GetContext As JavaObject
Return GetBA.GetField("context")
End Sub
Sub GetBA As JavaObject
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetFieldJO("processBA")
End Sub