Hi, I am new to APK and I have been building an application to record my miles usage for work, I have been having some trouble understanding where some of my code breaks.
I am using apk as an application tool and not a gaming tool at this moment.
I have a few things I noted that I have some difficulty understanding (see code and screenshot about details):
When I click on a botton, another button's code is triggered.
GPS values takes a while to change from 0 to an actual value(this happens when google maps has not been opened yet).
Images get flipped to the left(tested on Samsung S3).
Like I said, I am new to this and I am definitely breaking a few things here, this app will help me to learn APK Basic, any pointers is appreciated.
Code:
main.agc:
#include "functions.agc"
// Project: EasyTravelLog
// Created: 2015-08-19
global Gd_ScreenWidth = 720
global Gd_ScreenHight = 1280
global Gb_HasGPS = 0
global Gim_FontImage = 0
global Gb_ShowSysVars = 0
global Gs_platform$ = ""
global Gs_startwritepath$ = ""
global Gs_newwritepath$ = ""
global Gb_ImageEmpty = 1
global Gb_ReadingEmpty = 0
global Gim_CaptureImage = 0
global Gsp_CaptureSprite = 101
global Gd_CaptureKM$ = ""
global Gb_GetText = 0
global Gb_GetImage = 0
global iTextLine_001 = 1001
global iTextLine_002 = 1002
global iTextLine_003 = 1003
global iTextLine_004 = 1004
global iTextLine_005 = 1005
global iTextLine_006 = 1006
global iTextLine_007 = 1007
global iTextLine_008 = 1008
global iTextLine_009 = 1009
global iTextLine_010 = 1010
global iTextLine_011 = 1011
global iTextLine_012 = 1012
global btn_Exit = 6
global btn_Save = 7
global btn_GetImage = 8
global btn_Upload = 9
global btn_Clear = 10
global txt_GetKM = 12
SetWindowTitle("EasyTravelLog")
SetWindowSize(1024, 768, 0)
SetVirtualResolution(Gd_ScreenWidth, Gd_ScreenHight)
SetOrientationAllowed(1, 0, 0, 0)
//SetBorderColor(255,255,255)
SetBorderColor(1,1,1)
SetClearColor(255,255,255)
SetPrintColor(0,0,0)
Gs_platform$ = GetDeviceName()
Gs_startwritepath$ = GetWritePath()
SetFolder("")
Gs_newwritepath$ = GetWritePath()
if GetGPSSensorExists() = 1
Gb_HasGPS = 1
StartGPSTracking()
else
Gb_HasGPS = 0
endif
LoadBackground()
Gs_newwritepath$ = GetWritePath()
AddControls()
if GetFileExists("/media/Images/Fonts/ObliviousFont.png") = 1
if GetFileExists("/media/Images/Fonts/ObliviousFont subimages.txt") = 1
Gim_FontImage = LoadImage("/media/Images/Fonts/ObliviousFont.png")
SetTextDefaultFontImage(Gim_FontImage)
endif
endif
PrintTextInit()
do
Gd_CaptureKM$ = GetEditBoxText(txt_GetKM)
PrintSysVars()
PrintTextReset()
//PrintTextSet("test 1",1)
if Gb_ImageEmpty = 1
PrintTextSet("Get Image",2)
else
PrintTextSet("Get New Image",2)
endif
//if Gd_CaptureKM# = 0.0
PrintTextSet("Get KM",5)
//else
// PrintTextSet("Get KM",5)
// PrintTextSet(" (" + str(Gd_CaptureKM#,2) + ")",6)
//endif
if GetVirtualButtonPressed(btn_Exit) = 1
if Gb_HasGPS = 1
StopGPSTracking()
Gb_HasGPS = 0
endif
exit
endif
if GetVirtualButtonPressed(btn_Save) = 1
if Gb_ImageEmpty = 1
Message("Please capture an image first")
else
if Gd_CaptureKM$ = "" or val(Gd_CaptureKM$) = 0
Message("Please enter the KM first")
else
SetFolder("/")
SetFolder("media")
MakeFolder("Data")
SetFolder("Data")
s_ImageName$ = GetDateTimeNow()
SaveImage(Gim_CaptureImage,"Capture_" + s_ImageName$ + ".png")
fileID = OpenToWrite("Data.txt", 1)
WriteLine(fileID, "")
WriteLine(fileID, "<Entry>")
WriteLine(fileID, " <ID>" + s_ImageName$ + "</ID>")
WriteLine(fileID, " <Km>" + Gd_CaptureKM$ + "</Km>")
WriteLine(fileID, " <Latitude>" + str(GetRawGPSLatitude()) + "</Latitude>")
WriteLine(fileID, " <Longitude>" + str(GetRawGPSLongitude()) + "</Longitude>")
WriteLine(fileID, " <Image>Capture_" + s_ImageName$ + ".png</Image>")
WriteLine(fileID, "</Entry>")
CloseFile(fileID)
DeleteSprite(Gsp_CaptureSprite)
SetEditBoxText(txt_GetKM,"")
Gb_ImageEmpty = 1
Gb_GetImage = 0
Message("Saved")
endif
endif
endif
if GetVirtualButtonPressed(btn_GetImage) = 1
Gb_ImageEmpty = 1
Gb_GetImage = 1
DeleteSprite(Gsp_CaptureSprite)
if GetCameraExists() = 1
if ShowImageCaptureScreen() = 1
while IsCapturingImage() = 1
endwhile
Gim_CaptureImage = GetCapturedImage()
if not Gim_CaptureImage = 0
CreateSprite(Gsp_CaptureSprite, Gim_CaptureImage)
SetSpriteSize(Gsp_CaptureSprite,700,400)
SetSpritePosition(Gsp_CaptureSprite,10,190)
Gb_ImageEmpty = 0
else
Gb_ImageEmpty = 1
Gb_GetImage = 0
endif
endif
else
Message("This Device has no Camera")
Gb_ImageEmpty = 0
endif
Gb_GetImage = 0
endif
Sync()
loop
if Gb_HasGPS = 1
StopGPSTracking()
endif
functions.agc:
function GetDateTimeNow()
Date$=GetCurrentDate()
//Print (Date$)
Time$=GetCurrentTime()
//Print (Time$)
ConCat$ = Mid(Date$,1,4) + Mid(Date$,6,2) + Mid(Date$,9,2) + Mid(Time$,1,2) + Mid(Time$,4,2) + Mid(Time$,7,2)
//Print (ConCat$)
endfunction ConCat$
function GetDateNow()
Date$=GetCurrentDate()
//Print (Date$)
ConCat$ = Mid(Date$,1,4) + Mid(Date$,6,2) + Mid(Date$,9,2)
//Print (ConCat$)
endfunction ConCat$
function GetTimeNow()
Time$=GetCurrentTime()
//Print (Time$)
ConCat$ = Mid(Time$,1,2) + Mid(Time$,4,2) + Mid(Time$,7,2)
//Print (ConCat$)
endfunction ConCat$
function LoadBackground()
BackImage = LoadImage("/media/Images/Logos/company.png")
BackSprite = CreateSprite(BackImage)
BackPOSx = (Gd_ScreenWidth / 2) - (GetSpriteWidth(BackSprite) / 2)
BackPOSy = (Gd_ScreenHight / 2) - (GetSpriteHeight(BackSprite) / 2)
SetSpritePosition(BackSprite,BackPOSx,600)
endfunction
function PrintSysVars()
if GetRawKeyState(119) = 1
Print(Gs_startwritepath$)
Print(Gs_newwritepath$)
Print("Platform: " + Gs_platform$ + " KM: " + Gd_CaptureKM$)
if Gb_HasGPS = 1
Print("Has GPS: " + str(Gb_HasGPS))
Print("Latitude: " + str(GetRawGPSLatitude()))
Print("Longitude: " + str(GetRawGPSLongitude()))
Print("Altitude: " + str(GetRawGPSAltitude()))
endif
Print(ScreenFPS())
endif
endfunction
function PrintTextInit()
//iTextLine_001 = 1001
//DeleteText(iTextLine_001)
CreateText(iTextLine_001, "Line 001 Testing")
//SetTextString(iTextLine_001, "a brand new string")
SetTextPosition(iTextLine_001, 0, 0)
SetTextSize(iTextLine_001, 40)
SetTextColor(iTextLine_001, 0, 0, 0, 255)
SetTextVisible(iTextLine_001, 1)
//iTextLine_002 = 1002
//DeleteText(iTextLine_002)
CreateText(iTextLine_002, "Line 002 Testing")
//SetTextString(iTextLine_002, "a brand new string")
SetTextPosition(iTextLine_002, 0, 35)
SetTextSize(iTextLine_002, 40)
SetTextColor(iTextLine_002, 0, 0, 0, 255)
SetTextVisible(iTextLine_002, 1)
//iTextLine_003 = 1003
//DeleteText(iTextLine_003)
CreateText(iTextLine_003, "Line 003 Testing")
//SetTextString(iTextLine_003, "a brand new string")
SetTextPosition(iTextLine_003, 0, 70)
SetTextSize(iTextLine_003, 40)
SetTextColor(iTextLine_003, 0, 0, 0, 255)
SetTextVisible(iTextLine_003, 1)
//iTextLine_004 = 1004
//DeleteText(iTextLine_004)
CreateText(iTextLine_004, "Line 004 Testing")
//SetTextString(iTextLine_004, "a brand new string")
SetTextPosition(iTextLine_004, 0, 105)
SetTextSize(iTextLine_004, 40)
SetTextColor(iTextLine_004, 0, 0, 0, 255)
SetTextVisible(iTextLine_004, 1)
//iTextLine_005 = 1005
//DeleteText(iTextLine_005)
CreateText(iTextLine_005, "Line 005 Testing")
//SetTextString(iTextLine_005, "a brand new string")
SetTextPosition(iTextLine_005, 0, 140)
SetTextSize(iTextLine_005, 40)
SetTextColor(iTextLine_005, 0, 0, 0, 255)
SetTextVisible(iTextLine_005, 1)
//iTextLine_006 = 1006
//DeleteText(iTextLine_006)
CreateText(iTextLine_006, "Line 006 Testing")
//SetTextString(iTextLine_006, "a brand new string")
SetTextPosition(iTextLine_006, 0, 175)
SetTextSize(iTextLine_006, 40)
SetTextColor(iTextLine_006, 0, 0, 0, 255)
SetTextVisible(iTextLine_006, 1)
//iTextLine_007 = 1007
//DeleteText(iTextLine_007)
CreateText(iTextLine_007, "Line 007 Testing")
//SetTextString(iTextLine_007, "a brand new string")
SetTextPosition(iTextLine_007, 0, 210)
SetTextSize(iTextLine_007, 40)
SetTextColor(iTextLine_007, 0, 0, 0, 255)
SetTextVisible(iTextLine_007, 1)
//iTextLine_008 = 1008
//DeleteText(iTextLine_008)
CreateText(iTextLine_008, "Line 008 Testing")
//SetTextString(iTextLine_008, "a brand new string")
SetTextPosition(iTextLine_008, 0, 245)
SetTextSize(iTextLine_008, 40)
SetTextColor(iTextLine_008, 0, 0, 0, 255)
SetTextVisible(iTextLine_008, 1)
//iTextLine_009 = 1009
//DeleteText(iTextLine_009)
CreateText(iTextLine_009, "Line 009 Testing")
//SetTextString(iTextLine_009, "a brand new string")
SetTextPosition(iTextLine_009, 0, 280)
SetTextSize(iTextLine_009, 40)
SetTextColor(iTextLine_009, 0, 0, 0, 255)
SetTextVisible(iTextLine_009, 1)
//iTextLine_010 = 1010
//DeleteText(iTextLine_010)
CreateText(iTextLine_010, "Line 010 Testing")
//SetTextString(iTextLine_010, "a brand new string")
SetTextPosition(iTextLine_010, 0, 315)
SetTextSize(iTextLine_010, 40)
SetTextColor(iTextLine_010, 0, 0, 0, 255)
SetTextVisible(iTextLine_010, 1)
//iTextLine_011 = 1011
//DeleteText(iTextLine_011)
CreateText(iTextLine_011, "Line 011 Testing")
//SetTextString(iTextLine_011, "a brand new string")
SetTextPosition(iTextLine_011, 0, 350)
SetTextSize(iTextLine_011, 40)
SetTextColor(iTextLine_011, 0, 0, 0, 255)
SetTextVisible(iTextLine_011, 1)
//iTextLine_012 = 1012
//DeleteText(iTextLine_012)
CreateText(iTextLine_012, "Line 012 Testing")
//SetTextString(iTextLine_012, "a brand new string")
SetTextPosition(iTextLine_012, 0, 385)
SetTextSize(iTextLine_012, 40)
SetTextColor(iTextLine_012, 0, 0, 0, 255)
SetTextVisible(iTextLine_012, 1)
endfunction
function PrintTextReset()
SetTextString(iTextLine_001, "")
SetTextVisible(iTextLine_001,0)
SetTextString(iTextLine_002, "")
SetTextVisible(iTextLine_002,0)
SetTextString(iTextLine_003, "")
SetTextVisible(iTextLine_003,0)
SetTextString(iTextLine_004, "")
SetTextVisible(iTextLine_004,0)
SetTextString(iTextLine_005, "")
SetTextVisible(iTextLine_005,0)
SetTextString(iTextLine_006, "")
SetTextVisible(iTextLine_006,0)
SetTextString(iTextLine_007, "")
SetTextVisible(iTextLine_007,0)
SetTextString(iTextLine_008, "")
SetTextVisible(iTextLine_008,0)
SetTextString(iTextLine_009, "")
SetTextVisible(iTextLine_009,0)
SetTextString(iTextLine_010, "")
SetTextVisible(iTextLine_010,0)
SetTextString(iTextLine_011, "")
SetTextVisible(iTextLine_011,0)
SetTextString(iTextLine_012, "")
SetTextVisible(iTextLine_012,0)
endfunction
function PrintTextSet(s_Text$,i_TextLine)
if i_TextLine = 1
SetTextString(iTextLine_001, s_Text$)
SetTextVisible(iTextLine_001,1)
endif
if i_TextLine = 2
SetTextString(iTextLine_002, s_Text$)
SetTextVisible(iTextLine_002,1)
endif
if i_TextLine = 3
SetTextString(iTextLine_003, s_Text$)
SetTextVisible(iTextLine_003,1)
endif
if i_TextLine = 4
SetTextString(iTextLine_004, s_Text$)
SetTextVisible(iTextLine_004,1)
endif
if i_TextLine = 5
SetTextString(iTextLine_005, s_Text$)
SetTextVisible(iTextLine_005,1)
endif
if i_TextLine = 6
SetTextString(iTextLine_006, s_Text$)
SetTextVisible(iTextLine_006,1)
endif
if i_TextLine = 7
SetTextString(iTextLine_007, s_Text$)
SetTextVisible(iTextLine_007,1)
endif
if i_TextLine = 8
SetTextString(iTextLine_008, s_Text$)
SetTextVisible(iTextLine_008,1)
endif
if i_TextLine = 9
SetTextString(iTextLine_009, s_Text$)
SetTextVisible(iTextLine_009,1)
endif
if i_TextLine = 10
SetTextString(iTextLine_010, s_Text$)
SetTextVisible(iTextLine_010,1)
endif
if i_TextLine = 11
SetTextString(iTextLine_011, s_Text$)
SetTextVisible(iTextLine_011,1)
endif
if i_TextLine = 12
SetTextString(iTextLine_012, s_Text$)
SetTextVisible(iTextLine_012,1)
endif
endfunction
function PrintTextDestroy()
DeleteText(iTextLine_001)
DeleteText(iTextLine_002)
DeleteText(iTextLine_003)
DeleteText(iTextLine_004)
DeleteText(iTextLine_005)
DeleteText(iTextLine_006)
DeleteText(iTextLine_007)
DeleteText(iTextLine_008)
DeleteText(iTextLine_009)
DeleteText(iTextLine_010)
DeleteText(iTextLine_011)
DeleteText(iTextLine_012)
endfunction
function AddControls()
AddButtons()
AddEditBoxes()
endfunction
function AddButtons()
temp_ImageUp = LoadImage("/media/Images/UI/button_up.png")
temp_ImageDown = LoadImage("/media/Images/UI/button_down.png")
temp_ImageUpWide = LoadImage("/media/Images/UI/button_up_widenew.png")
temp_ImageDownWide = LoadImage("/media/Images/UI/button_down_wide.png")
//btn_Exit
AddVirtualButton(btn_Exit, 175, 1210, 350)
SetVirtualButtonText(btn_Exit, "Exit")
SetVirtualButtonAlpha(btn_Exit, 255)
SetVirtualButtonImageUp(btn_Exit,temp_ImageUp)
SetVirtualButtonImageDown(btn_Exit,temp_ImageDown)
//btn_Save
AddVirtualButton(btn_Save, 545, 1210, 350)
SetVirtualButtonText(btn_Save, "Save")
SetVirtualButtonAlpha(btn_Save, 255)
SetVirtualButtonImageUp(btn_Save,temp_ImageUp)
SetVirtualButtonImageDown(btn_Save,temp_ImageDown)
//btn_GetImage
AddVirtualButton(btn_GetImage, 550, 51, 350)
SetVirtualButtonText(btn_GetImage, "")
SetVirtualButtonAlpha(btn_GetImage, 255)
SetVirtualButtonImageUp(btn_GetImage,temp_ImageUp)
SetVirtualButtonImageDown(btn_GetImage,temp_ImageDown)
SetVirtualButtonSize(btn_GetImage,200)
//btn_Upload
AddVirtualButton(btn_Upload, 620, 1100, 200)
SetVirtualButtonText(btn_Upload, "Post")
SetVirtualButtonAlpha(btn_Upload, 255)
SetVirtualButtonImageUp(btn_Upload,temp_ImageUp)
SetVirtualButtonImageDown(btn_Upload,temp_ImageDown)
//btn_Clear
AddVirtualButton(btn_Clear, 100, 1100, 200)
SetVirtualButtonText(btn_Clear, "Clear")
SetVirtualButtonAlpha(btn_Clear, 255)
SetVirtualButtonImageUp(btn_Clear,temp_ImageUp)
SetVirtualButtonImageDown(btn_Clear,temp_ImageDown)
endfunction
function AddEditBoxes()
temp_Image = LoadImage("/media/Images/UI/button_up.png")
//txt_GetKM
CreateEditBox(txt_GetKM)
//SetEditBoxBorderColor(txt_GetKM,0,0,0,255)
//SetEditBoxBorderSize(txt_GetKM,5)
SetEditBoxSize(txt_GetKM,425,40)
SetEditBoxPosition(txt_GetKM,220,140)
//SetEditBoxBackgroundColor(txt_GetKM,79,0,0,255)
SetEditBoxBackgroundImage(txt_GetKM,temp_Image)
SetEditBoxTextColor(txt_GetKM,0,0,0)
SetEditBoxTextSize(txt_GetKM,65)
endfunction