-- Chargement des modules
-local widget = require( "widget" )
-local json = require("json")
-local sqlite3 = require ("sqlite3")
-local mime = require("mime")
+local widget = require( "widget" )
+local json = require( "json" )
+local sqlite3 = require( "sqlite3" )
+local mime = require( "mime" )
+
+local photo = require( "lib.PrisePhoto" )
-- Instanciation de l'objet
local photoName = ""
local photoT = "Pas de photo."
local prioriteT = 0
-local categorieT = "Pas de catégorie."
-local typeT = "Pas de type."
-local adresseT = "Pas d'adresse."
-local descriptionT = "Pas de description."
+local categorieT = "Pas de catégorie"
+local typeT = "Pas de type"
+local adresseT = "Pas d'adresse"
+local descriptionT = "Pas de description"
local coordT = "0,0" -- lat,long
local mail = ""
local isEnvoyerActive = false
local isAccueilActive = false
+-- Tous les 1 mètre, événement GPS
+
+system.setLocationThreshold( 1 )
+
+-- Constante de marge
+
+local m = (.5/10)*VW
+
+-- Désactiver ou réactiver les objets à travers des booléens
-- désactiver les objets
local function disableObjects()
end
--- Tous les 1 m, GPS event
-
-system.setLocationThreshold( 1 )
-
--- Constante de marge
+-- -- Décorons le ticket
-local m = (.5/10)*VW
-
--- Initialisation du fond
+-- Initialisation du fond du ticket
local function initFond()
local bg = display.newRect( CX, CY, VW, VH)
-
bg:setFillColor( 240/255, 238/255, 221/255, 1 )
-
ticket:insert( bg )
ticket.bg = bg
end
--- Initialisation de la décoration du ticket (cercles)
-
-local function initCircles()
-
- local circle1 = {}
- local circle2 = {}
-
- for i = 0, 11 do
-
- circle1[i] = display.newCircle( 0, 0, 8 )
- circle1[i]:setFillColor( 0, 0, 0 )
- circle1[i].x = (VW/10)*i
- circle1[i].y = SY - 3
- ticket:insert( circle1[i] )
-
- circle2[i] = display.newCircle( 0, 0, 8 )
- circle2[i]:setFillColor( 0, 0, 0 )
- circle2[i].x = (VW/10)*i
- circle2[i].y = VH + 3
- ticket:insert( circle2[i] )
-
- end
-
-end
-
-- Initialisation des bordures du ticket
local function initBorders()
+ -- bordure du haut
local border1 = display.newRect( 0, 0, VW, 40 )
border1:setFillColor( 146/255, 114/255, 79/255 )
-
border1.anchorX = 0
border1.anchorY = 0
-
border1.x = SX
border1.y = SY
-
- local topTitle = display.newText( "T i c k e t d ' U t i l i t é P u b l i q u e", 0, 0, "Dosis-Book", 14 )
- topTitle:setFillColor( 1, 1, 1 )
-
- topTitle.anchorY = 0
-
- topTitle.height = 40
-
- topTitle.x = CX
- topTitle.y = SY - topTitle.height
+ ticket:insert( border1 )
+ ticket.border1 = border1
+ -- bordure du bas
local border2 = display.newRect( 0, 0, VW, 40 )
border2:setFillColor( 146/255, 114/255, 79/255 )
-
border2.anchorX = 0
border2.anchorY = 0
-
border2.x = SX
border2.y = VH - border2.height
+ ticket:insert( border2 )
+ ticket.border2 = border2
- local boutonRetour = display.newRect( 0, 0, 60, 40 )
- boutonRetour.alpha = .01
-
- boutonRetour.anchorX = 0
-
- boutonRetour.x = SX - boutonRetour.width
- boutonRetour.y = border2.y + border2.height/2
-
- function boutonRetour:touch( event )
-
- if event.phase == "began" and isAccueilActive then
-
- if ticket.map then
+ -- fonction de retour à l'accueil
+ local function onAccueil( event )
- ticket.map.x = CX + VW*2
-
- end
+ if isAccueilActive then
+ ticket.map.x = CX + VW*2
Runtime:dispatchEvent{ name = "MenuEvent", type = "accueilSlideRight" }
end
end
- local labelRetour = display.newText( "< Accueil", 0, 0, "Dosis-Book", 14 )
+ -- bouton pour retourner à l'accueil
+ local boutonRetour = widget.newButton
+ {
+ shape = "rect",
+ width = 60,
+ height = 40,
+ font = "Dosis-Book",
+ fontSize = 14,
+ fillColor = { default = { 0, 0, 0, .1 }, over = { 0, 0, 0, .08 } },
+ label = "< Accueil",
+ labelColor = { default = { 1, 1, 1, 1 }, over = { 1, 1, 1, 1 } },
+ onRelease = onAccueil,
+ }
+ boutonRetour.alpha = 1
+ boutonRetour.anchorX = 0
+ boutonRetour.x = VW + boutonRetour.width
+ boutonRetour.y = border2.y + border2.height/2
+ ticket:insert( boutonRetour )
+ ticket.boutonRetour = boutonRetour
- labelRetour.x = boutonRetour.x
- labelRetour.y = boutonRetour.y
+ isAccueilActive = true
- local labelObligatoire = display.newText( "*Obligatoires", 0, 0, "Dosis-Book", 14 )
- labelObligatoire:setFillColor( 0, 0, 0, 1 )
+end
- labelObligatoire.anchorX = 0
+-- Initialisation des cercles de décoration
- labelObligatoire.x = VW - labelObligatoire.width - 5
- labelObligatoire.y = border2.y + border2.height/2
+local function initCircles()
- -- insertions
+ local circle1 = {}
+ local circle2 = {}
- ticket:insert( boutonRetour )
- ticket.boutonRetour = boutonRetour
+ for i = 0, 11 do
+
+ -- cercles du haut
+ circle1[i] = display.newCircle( 0, 0, 8 )
+ circle1[i]:setFillColor( 0, 0, 0 )
+ circle1[i].x = (VW/10)*i
+ circle1[i].y = SY - 3
+ ticket:insert( circle1[i] )
- isAccueilActive = true
+ -- cercles du bas
+ circle2[i] = display.newCircle( 0, 0, 8 )
+ circle2[i]:setFillColor( 0, 0, 0 )
+ circle2[i].x = (VW/10)*i
+ circle2[i].y = VH + 3
+ ticket:insert( circle2[i] )
- ticket:insert( border1 )
- ticket.border1 = border1
+ end
- ticket:insert( topTitle )
- ticket.topTitle = topTitle
+end
- ticket:insert( border2 )
- ticket.border2 = border2
+-- Initialisation des labels sur les bordures
- ticket:insert( boutonRetour )
- ticket.boutonRetour = boutonRetour
+local function initLabels()
- ticket:insert( labelRetour )
- ticket.labelRetour = labelRetour
+ -- titre du ticket
+ local topTitle = display.newText( "T i c k e t d ' U t i l i t é P u b l i q u e", 0, 0, "Dosis-Book", 14 )
+ topTitle:setFillColor( 1, 1, 1 )
+ topTitle.anchorY = 0
+ topTitle.height = 40
+ topTitle.x = CX
+ topTitle.y = SY - topTitle.height
+ ticket:insert( topTitle )
+ ticket.topTitle = topTitle
+ -- label d'indication des informations obligatoires à renseigner
+ local labelObligatoire = display.newText( "*Obligatoires", 0, 0, "Dosis-Book", 14 )
+ labelObligatoire:setFillColor( 0, 0, 0, 1 )
+ labelObligatoire.anchorX = 0
+ labelObligatoire.x = SX + 5
+ labelObligatoire.y = ticket.border2.y + ticket.border2.height/2
ticket:insert( labelObligatoire )
ticket.labelObligatoire = labelObligatoire
end
--- Initialisation du bouton prise de photo
+-- Initialisation du bouton photo
local function initPhoto()
- local boutonPhoto = display.newRect( 0, 0, 70, 70 )
- boutonPhoto:setFillColor( 253/255, 105/255, 0, .5 )
-
- boutonPhoto.strokeWidth = 0
- boutonPhoto:setStrokeColor( 0, 0, 0, .7 )
-
+ local boutonPhoto = PrisePhoto:new()
+ ticket:insert( boutonPhoto )
+ ticket.boutonPhoto = boutonPhoto
boutonPhoto.anchorX = 0
boutonPhoto.anchorY = 0
-
boutonPhoto.x = SX - boutonPhoto.width
boutonPhoto.y = SY + 60
- ticket:insert( boutonPhoto )
- ticket.boutonPhoto = boutonPhoto
-
- isPhotoActive = true
-
local icon = display.newImage( "photoIcon.png", 0, 0 )
-
icon.x = SX - 80
- icon.y = SY + boutonPhoto.height/2 + 60
-
+ icon.y = boutonPhoto.y + 35
icon.width = 42
icon.height = 32
-
icon.alpha = .4
-
ticket:insert( icon )
ticket.icon = icon
- photo = display.newRect( 0, 0, 80, 80 )
-
- photo.alpha = 0
-
- ticket:insert( photo )
-
- -- gestion de la prise de photo
- function boutonPhoto:touch( event )
-
- if event.phase == "began" and isPhotoActive then
-
- print("photo")
- -- on fait une photo
- local function onComplete( event )
-
- local newPhoto = event.target
-
- -- si la prise de photo n'est pas annulée
- if newPhoto ~= nil then
- -- Une photo a été prise
-
- isPhotoTaken = true
-
- -- sauvegarder l'anciennce photo
- display.save( newPhoto, { filename = "photo.jpg", baseDir = system.TemporaryDirectory } )
-
- -- masquer l'ancienne photo
- local clear = display.newRect( 0, 0, boutonPhoto.width, boutonPhoto.height )
- clear:setFillColor( 0, 0, 0 )
-
- clear.anchorX = 0
- clear.anchorY = 0
-
- clear.x = boutonPhoto.x
- clear.y = boutonPhoto.y
-
- ticket:insert( clear )
-
- -- nouvelle photo
- photo = newPhoto
-
- photo.anchorX = 0
- photo.anchorY = 0
-
- photo.x = boutonPhoto.x
- photo.y = boutonPhoto.y
-
- photo.width = boutonPhoto.width
- photo.height = boutonPhoto.height
-
- photo.alpha = 1
-
- ticket:insert( photo )
-
- end
-
- end
-
- if media.hasSource( media.Camera ) then
-
- --photo = nil
-
- media.capturePhoto( { listener = onComplete } )
-
- else
-
- native.showAlert( "Hum.", "Cet appareil n'a pas d'appareil photo.", { "OK" } )
-
- end
-
- end
-
- end
-
- photoT = system.pathForFile( "photo.jpg", system.TemporaryDirectory )
-
end
-- Initialisation des boutons de priorité du ticket
local labelBg = display.newRect( 0, 0, (3.5/16)*VW, (.8/16)*VH )
labelBg.alpha = 0
-
labelBg.x = SX + (7.4/16)*VW
labelBg.y = ticket.boutonPhoto.y + labelBg.height/2
-
ticket:insert( labelBg )
local labelBg2 = display.newRect( 0, 0, (5/16)*VW, (.8/16)*VH )
labelBg2.alpha = 0
-
labelBg2.anchorX = 1
-
labelBg2.x = SX + VW - 20--SX + (12.7/16)*VW
labelBg2.y = ticket.boutonPhoto.y + labelBg2.height/2
-
ticket:insert( labelBg2 )
-- labels de priorité
local label = display.newText( "Choisissez une priorité :", 0, 0, "Dosis-Book", 20 )
label:setFillColor( 0, 0, 0, .9 )
-
label.x = SX + (10.5/16)*VW
label.y = labelBg.y
-
ticket:insert( label )
local label2 = display.newText( "", 0, 0, "Dosis-Bold", 20 )
label2:setFillColor( 255/255, 101/255, 83/255 )
-
label2.x = labelBg2.x - labelBg2.width/2
label2.y = labelBg2.y
-
label2.align = "center"
-
ticket:insert( label2 )
-- bouton de priorité faible
local prioriteL = display.newCircle( 0, 0, 16 )
prioriteL:setFillColor( .2, .8, .4, .9 )
-
prioriteL.anchorX = 0
prioriteL.anchorY = 0
-
prioriteL.strokeWidth = 0
prioriteL:setStrokeColor( .2, .8, .4, .5 )
-
prioriteL.x = SX + (6.5/16)*VW
prioriteL.y = SY - prioriteL.height
if event.phase == "began" and isPriorityActive then
--- ticket.bg:setFillColor( 0/255, 180/255, 80/255, .9 )
-
label.text = "Ticket : "
label.x = SX + (7.6/16)*VW
label2.text = "Commun"
--- label2.x = SX + (12.7/16)*VW
label2:setFillColor( .1, .7, .3, 1 )
labelBg.alpha = .5
prioriteT = 0
priorite64 = mime.b64( prioriteT )
- print(prioriteT)
- print(priorite64)
end
-- bouton de priorité moyenne
local prioriteM = display.newCircle( 0, 0, 16 )
prioriteM:setFillColor( 1, .9, .3, .9 )
-
prioriteM.anchorX = 0
prioriteM.anchorY = 0
-
prioriteM.strokeWidth = 0
prioriteM:setStrokeColor( 1, .9, .3, .5 )
-
prioriteM.x = SX + (9.5/16)*VW
prioriteM.y = SY - prioriteM.height*2
if event.phase == "began" and isPriorityActive then
--- ticket.bg:setFillColor( 241/255, 196/255, 15/255, .9 )
-
label.text = "Ticket : "
label.x = SX + (7.6/16)*VW
label2.text = "Important"
--- label2.size = 21
--- label2.x = SX + (12.7/16)*VW
label2:setFillColor( 1, 194/255, 0, 1 )
labelBg.alpha = .5
prioriteT = 1
priorite64 = mime.b64( prioriteT )
- print(prioriteT)
- print(priorite64)
end
-- bouton de priorité forte
local prioriteH = display.newCircle( 0, 0, 16 )
prioriteH:setFillColor( 1, 0, 0, .9 )
-
prioriteH.anchorX = 0
prioriteH.anchorY = 0
-
prioriteH.strokeWidth = 0
prioriteH:setStrokeColor( 1, 0, 0, .5 )
-
prioriteH.x = SX + (12.5/16)*VW
prioriteH.y = SY - prioriteH.height*3
if event.phase == "began" and isPriorityActive then
- --ticket.bg:setFillColor( 231/255, 76/255, 60/255, .8 )
-
label.text = "Ticket : "
label.x = SX + (7.6/16)*VW
label2.text = "Urgent"
label2:setFillColor( 1, 0, 0, 1 )
--- label2.x = SX + (12.7/16)*VW
labelBg.alpha = .5
labelBg2.alpha = .5
prioriteT = 2
priorite64 = mime.b64( prioriteT )
- print(prioriteT)
- print(priorite64)
end
end
--- prioriteL:addEventListener( "touch", prioriteL )
--- prioriteM:addEventListener( "touch", prioriteM )
--- prioriteH:addEventListener( "touch", prioriteH )
-
ticket:insert( prioriteL )
ticket:insert( prioriteM )
ticket:insert( prioriteH )
ticket.prioriteM = prioriteM
ticket.prioriteH = prioriteH
+ -- les boutons de priorités sont initialisés donc actifs
isPriorityActive = true
end
local function initType()
local boutonType = display.newRect( 0, 0, VW, 55 )
-
boutonType:setFillColor( 1, 1, 1, .7 )
-
boutonType.anchorX = 0
boutonType.anchorY = 0
-
boutonType.x = SX
boutonType.y = SY + 150
ticket:insert( boutonType )
ticket.boutonType = boutonType
- isTypeActive = true
-
-- label initial du bouton type de problème
local labelType = display.newText( "*Quel est le problème ?", 0, 0, "Dosis-Medium", 26 )
-
labelType:setFillColor( 0, 0, 0 )
-
labelType.height = 50
-
labelType.anchorY = 0
-
labelType.x = CX
labelType.y = boutonType.y
-
ticket:insert( labelType )
ticket.labelType = labelType
local categorie = display.newText( "", 0, 0, "Dosis-Book", 16 )
-
categorie:setFillColor( 0, 0, 0, 1 )
-
categorie.height = 50
-
categorie.x = CX
categorie.y = boutonType.y + .25*boutonType.height
-
ticket:insert( categorie )
ticket.categorie = categorie
-- texte qui affiche le type de problème sur le bouton
local textType = display.newText( "", 0, 0, "Dosis-Bold", 22 )
-
textType:setFillColor( 0, 0, 0, 0 )
-
textType.height = 50
-
textType.x = CX
textType.y = boutonType.y + .7*boutonType.height
-
ticket:insert( textType )
ticket.textType = textType
+ -- le bouton de type est initialisé donc actif
+ isTypeActive = true
+
end
--- fin type
-- Initialisation de la carte Google Maps
local function initMap()
- --- A SUPPRIMER
- ---
-
+ -- repère pour le placement de la map
local placeholder = display.newRect( 0, 0, VW, 100 )
placeholder:setFillColor( 0, 0, 0, .5 )
-
placeholder.anchorY = 0
-
placeholder.x = CX
placeholder.y = ticket.boutonType.y + ticket.boutonType.height
-
ticket:insert( placeholder )
ticket.placeholder = placeholder
-
- ---
- --- A SUPPRIMER
-- carte pour le positionnement gps
local map = native.newMapView( 0, 0, VW, 100 )
-
- local function goToAddress( address )
-
- map:requestLocation( address, resultHandler )
-
- end
-
map.anchorY = 0
-
map.x = CX
map.y = ticket.boutonType.y + ticket.boutonType.height
-- pour la lisibilité de l'adresse
local adresseBg = display.newRect( 0, 0, VW - 40, 40 )
-
adresseBg:setFillColor( 1, 1, 1, .7 )
-
adresseBg.anchorX = 0
adresseBg.anchorY = 0
-
adresseBg.x = SX
-
ticket:insert( adresseBg )
ticket.adresseBg = adresseBg
- isAddressActive = true
-
-- adresse de la localisation
local labelAdresse = display.newText( "*Adresse", 0, 0, adresseBg.width, (1/16)*VH, "Dosis-Book", 18 )
-
labelAdresse:setFillColor( 0, 0, 0 )
-
labelAdresse.anchorX = 0
-
labelAdresse.x = SX + 10
-
ticket:insert( labelAdresse )
ticket.labelAdresse = labelAdresse
+ -- le bouton dynamique d'adresse est initialisé donc actif
+ isAddressActive = true
+
+ -- gestion de l'entrée manuelle de l'adresse
local function adresseListener( event )
if event.phase == "submitted" or event.phase == "ended" then
if event.target.text == "" or event.target.text == " " or event.target.text == " " then
labelAdresse.text = "*Veuillez vous localiser ou entrer une adresse."
- adresseT = "Pas d'adresse."
+ adresseT = "Pas d'adresse"
else
- if #event.target.text > 27 then
+ if #event.target.text > 29 then
- labelAdresse.text = event.target.text:sub(1,27).."..."
+ labelAdresse.text = event.target.text:sub(1,29).."..."
else labelAdresse.text = event.target.text
adresseT = event.target.text
- -- on met à les données relatives à la position (adresse entrée au clavier)
+ -- on met à jour les données relatives à la position (adresse entrée au clavier)
-- on supprime tous les marqueurs déjà présents à chaque activation
map:removeAllMarkers()
local function mapLocationHandler( event )
- -- handle mapLocation event here
+
if event.isError then
- print( "Error: " .. event.errorMessage )
+
native.showAlert( "Erreur !", ""..event.errorMessage, { "OK" } )
+
else
+
coordT = ""..event.latitude..","..event.longitude
-- on centre la map sur la position
- map:setCenter( location.latitude, location.longitude, true )
+ map:setCenter( event.latitude, event.longitude, true )
-- on place le marqueur
- map:addMarker( location.latitude, location.longitude )
+ map:addMarker( event.latitude, event.longitude )
+
end
+
end
-- on récupère les coordonnées de l'adresse entrée au clavier
- map:requestLocation( adresseT, mapLocationHandler )
+ -- et on met la map à jour
+ map:requestLocation( ""..adresseT, mapLocationHandler )
-- l'adresse est écrite
isAddressWritten = true
end
+ -- champ (caché) où l'on insère l'adresse au clavier
local adresseManuelle = native.newTextField( 0, 0, VW, 40 )
-
adresseManuelle.size = 18
adresseManuelle.align = "center"
-
adresseManuelle.x = CX
adresseManuelle.y = SY - adresseManuelle.height
-
adresseManuelle:addEventListener( "userInput", adresseListener )
-
ticket:insert( adresseManuelle )
ticket.adresseManuelle = adresseManuelle
-- label simulant un bouton valider pour l'adresse ou la description (plus tard dans le code)
local labelValider = display.newText( "Valider", 0, 0, "Dosis-Book", 26 )
labelValider:setFillColor( 1, 1, 1 )
-
labelValider.x = CX
labelValider.y = SY - 80
-
ticket:insert( labelValider )
ticket.labelValider = labelValider
+ -- déclenche l'affichage du champ caché pour permettre la saisie de l'adresse au clavier
function adresseBg:touch( event )
if event.phase == "began" and isAddressActive then
-- lorsqu'on édite l'adresse, on désactive les autres objets
disableObjects()
+ -- on indique qu'on est en train d'éditer l'adresse
editAdresse = true
-- on place l'écran grisé devant les objets désactivés
-- bouton pour localiser
local boutonLocaliser = display.newRect( 0, 0, 40, 40 )
boutonLocaliser:setFillColor( 253/255, 105/255, 0, .5 )
-
boutonLocaliser.anchorX = 0
boutonLocaliser.anchorY = 0
-
boutonLocaliser.x = SX + VW - boutonLocaliser.width
-
boutonLocaliser.alpha = 1
- print(VH/VW)
- print("VH : "..VH)
- print("VW : "..VW)
-
--- 480x320 : iphone : réduire un peu la map
--- 512x320 : problème
-
-- la map est plus ou moins haute selon la hauteur de l'écran
-
- -- pour les écrans en hauteur (smartphones)
if( VH/VW >= 1.7 ) then
-
placeholder.height = 180
map.height = 160
-
elseif( VH/VW < 1.7 and VH/VW > 1.5 ) then
-
placeholder.height = 120
map.height = 120
-
end
-
if ( VH == 512 and VW == 320 ) then
-
placeholder.height = 140
map.height = 140
-
elseif ( VH == 480 and VW == 320 ) then
-
placeholder.height = 100
map.height = 100
-
end
- -- on positionne la barre d'adresse en dessous de la map
- -- en fonction de sa hauteur qui dépend de celle de l'écran
+ -- on positionne la barre d'adresse sous la map
+ -- en fonction de sa hauteur qui dépend de celle de l'écran
adresseBg.y = ticket.placeholder.y + ticket.placeholder.height
labelAdresse.y = ticket.placeholder.y + ticket.placeholder.height + ticket.adresseBg.height/2
boutonLocaliser.y = ticket.placeholder.y + ticket.placeholder.height
-- icone localiser
local iconGps = display.newImage( "gpsIcon.png", 0, 0 )
-
iconGps.x = boutonLocaliser.x + boutonLocaliser.width/2
iconGps.y = boutonLocaliser.y + boutonLocaliser.width/2
-
iconGps.width = 26
iconGps.height = 26
-
iconGps.alpha = .4
-- fonction d'action du bouton de localiser
if event.phase == "began" and isLocaliserActive then
- print("OK!!!!!")
- labelAdresse.text = "Entré dans la fonction"
+ labelAdresse.text = "Recherche de votre position ."
-- on supprime tous les marqueurs déjà présents à chaque activation
map:removeAllMarkers()
-- on place le marqueur
map:addMarker( location.latitude, location.longitude )
+ -- on récupère les coordonnées pour l'envoi plus tard
coordT = ""..location.latitude..","..location.longitude
local function mapAddressHandler( event )
- labelAdresse.text = "Entré dans la fonction"
- -- handle mapAddress event here
+
+ labelAdresse.text = "Recherche de votre position .."
+
if event.isError then
print( "mapView Error: " .. event.errorMessage )
labelAdresse.text = "Event.isError"
else
- labelAdresse.text = "Normalement ça écrit l'adresse"
+ labelAdresse.text = "Recherche de votre position ..."
print( "The specified location is in: " .. event.city .. ", " .. event.country )
number = event.streetDetail
street = event.street
-- on stocke l'adresse
adresseT = k
+ -- on tronque l'adresse pour éviter qu'elle prenne toute la place
if #k > 34 then
labelAdresse.text = k:sub(1,34).."..."
timer.performWithDelay( 1000, localize )
end
--- fin map
+-- Fin de la map et de tous ses composants
-- Initialisation de la description du problème
if isBlank( event.target.text ) then
- descriptionT = "Pas de description."
+ descriptionT = "Pas de description"
ticket.textDescr.text = "Pas de description."
else
-- description du problème dans une TextBox
local description = native.newTextBox( 0, 0, 190, 100 )
-
description.x = CX
description.y = SY - description.height
-
description.font = native.newFont( "Dosis-Book", 16 )
description.placeholder = "Description du problème."
-
description.isEditable = true
description.hasBackground = true
-
description:addEventListener( "userInput", inputListener )
-
ticket.description = description
- -- bouton pour éditer la description
local z = ticket.adresseBg.y + ticket.adresseBg.height
-
+
+ -- bouton pour éditer la description
local descr = display.newRect( 0, 0, VW - ( ticket.border2.y - z ) + 4, ticket.border2.y - z - 40 )
descr:setFillColor( 1, 1, 1, .7 )
-
descr.anchorX = 0
descr.anchorY = 0
-
descr.x = SX - descr.width
descr.y = z + 20
local textDescr = display.newText( "Description", 0, 0, descr.width - 10, descr.height - 5, "Dosis-Book", 18 )
textDescr:setFillColor( 0, 0, 0 )
-
textDescr.anchorX = 0
textDescr.anchorY = 0
-
textDescr.x = SX - textDescr.width
textDescr.y = descr.y + 5
+ -- filtre gris lors de l'édition de l'adresse ou de la description
local block = display.newRect( 0, 0, VW, VH )
block:setFillColor( 0, 0, 0, .6 )
-
block.x = CX
block.y = CY - 2*VH
-
ticket:insert( block )
ticket.block = block
ticket.textDescr = textDescr
end
--- fin description
-- Initialisation du nombre de tickets restants
end
local function envoiCallback( event )
-
-if ( event.isError ) then
- print("Network error!")
- native.showAlert( "Erreur réseau.", "Veuillez vérifier votre connexion internet." )
- else
- print("RESPONSE:" .. event.response)
- local data = json.decode(event.response)
-
- if (data.result == 200) then
- print("Le ticket a bien été envoyé. Le client est débité d'un crédit sur son nombre de tickets restants (auto en php)")
-
- elseif (data.result == 400) then
+ if ( event.isError ) then
+ print("Network error!")
+ native.showAlert( "Erreur réseau.", "Veuillez vérifier votre connexion internet." )
+ else
+ print("RESPONSE:" .. event.response)
+ local data = json.decode(event.response)
+ if (data.result == 200) then
+ print("Le ticket a bien été envoyé. Le client est débité d'un crédit sur son nombre de tickets restants (auto en php)")
+ elseif (data.result == 400) then
print ("Plus de ticket restant.")
-
- elseif (data.result == 403) then
+ elseif (data.result == 403) then
print ("Une erreur mysql est survenue.")
-
end
end
print("T : "..prioriteT)
print("64 : "..priorite64)
- local url = "http://tup.url.ph/app/uploadTicket.php?mail="..mime.b64(mail).."&objet="..categorie64.."&type="..type64.."&priorite="..priorite64.."&adresse="..adresse64.."&description="..description64.."&img="..photoName.."&coord="..coord64
+ local url = "http://tup.url.ph/app/uploadTicket.php?mail="..mime.b64(mail).."&objet="..categorie64.."&type="..type64.."&priorite="..priorite64.."&adresse="..adresse64.."&description="..description64.."&img="..photoName.."&coord="..coord64
network.request( url, "GET", envoiCallback )
end
local function uploadListener( event )
- if ( event.isError ) then
-
- print( "Network Error." )
-
- -- This is likely a time out or server being down. In other words,
- -- It was unable to communicate with the web server. Now if the
- -- connection to the web server worked, but the request is bad, this
- -- will be false and you need to look at event.status and event.response
- -- to see why the web server failed to do what you want.
-
- else
-
- if ( event.phase == "began" ) then
- print( "Upload started" )
- elseif ( event.phase == "progress" ) then
- print( "Uploading... bytes transferred ", event.bytesTransferred )
- elseif ( event.phase == "ended" ) then
- print( "Upload ended..." )
- print( "Status:", event.status )
- print( "Response:", event.response )
- photoName = event.response
-
- print("Upload de l'image terminé, on envoit les informations du ticket")
-
- sendAll()
- end
- end
+ if ( event.isError ) then
+ print( "Network Error." )
+ else
+
+ if ( event.phase == "began" ) then
+ print( "Upload started" )
+ elseif ( event.phase == "progress" ) then
+ print( "Uploading... bytes transferred ", event.bytesTransferred )
+ elseif ( event.phase == "ended" ) then
+ print( "Upload ended..." )
+ print( "Status:", event.status )
+ print( "Response:", event.response )
+ photoName = event.response
+
+ print("Upload de l'image terminé, on envoit les informations du ticket")
+ sendAll()
+ end
+ end
end
local function uploadImage()
+-- -- on récupère la photo pour l'envoyer au serveur plus tard
+-- photoT = system.pathForFile( "photo.jpg", system.TemporaryDirectory )
+
local url = "http://tup.url.ph/uploadImage.php"
local method = "PUT"
transition.to( ticket.prioriteM, { time = 900, y = SY + 95, transition = easing.outBounce } )
transition.to( ticket.prioriteH, { time = 1000, y = SY + 95, transition = easing.outBounce } )
transition.to( ticket.boutonPhoto, { time = 550, x = SX + 20, transition = easing.outQuad } )
- transition.to( ticket.icon, { time = 550, x = SX + ticket.boutonPhoto.width/2 + 20, transition = easing.outQuad } )
+ transition.to( ticket.icon, { time = 650, x = SX + ticket.boutonPhoto.width/2, transition = easing.outQuad } )
transition.to( ticket.map, { time = 700, x = CX, transition = easing.outExpo } )
transition.to( ticket.placeholder, { time = 700, x = CX, transition = easing.outExpo } )
transition.to( ticket.boutonLocaliser, { time = 500, x = SX + VW - ticket.boutonLocaliser.width, transition = easing.outExpo } )
transition.to( ticket.descr, { time = 500, x = SX - 4, transition = easing.outExpo } )
transition.to( ticket.textDescr, { time = 550, x = SX + 10, transition = easing.outQuad } )
- transition.to( ticket.boutonRetour, { time = 550, x = ticket.border2.x, transition = easing.outQuad } )
- transition.to( ticket.labelRetour, { time = 650, x = SX + ticket.boutonRetour.width/2, transition = easing.outQuad } )
-
+ transition.to( ticket.boutonRetour, { time = 750, x = VW - ticket.boutonRetour.width, transition = easing.outQuad } )
+
local k = SY + VH - ticket.border2.height
local l = SY + ticket.adresseBg.y + ticket.adresseBg.height
local z = VW - ( k - l )/2
end
+-- Gestion du bouton retour physique (Android)
+
+local function onKeyEvent( event )
+
+ if (event.keyName == "back") and (system.getInfo("platformName") == "Android") then
+
+ if isAddressActive then
+
+
+
+ elseif isDescriptionActive then
+
+
+
+ elseif isAccueilActive then
+
+
+
+ end
+
+ end
+
+ -- si la touche ou le bouton n'est pas "back", on l'ignore
+ return false
+
+end
+
function enableBoutonRetour()
ticket.boutonRetour:addEventListener( "touch", boutonRetour )
function ticket:enableListeners()
- ticket.boutonPhoto:addEventListener( "touch", boutonPhoto )
+-- ticket.boutonPhoto:addEventListener( "touch", boutonPhoto )
ticket.prioriteL:addEventListener( "touch", prioriteL )
ticket.prioriteM:addEventListener( "touch", prioriteM )
ticket.prioriteH:addEventListener( "touch", prioriteH )
ticket.block:addEventListener( "touch", block )
ticket.boutonEnvoyer:addEventListener( "touch", boutonEnvoyer )
- ticket:addEventListener( "key", onKeyEvent )
Runtime:addEventListener( "MenuEvent", changeType )
-
+ Runtime:addEventListener( "key", onKeyEvent )
+
-- on active le bouton retour un peu après pour éviter des conflits de chargement
timer.performWithDelay( 500, enableBoutonRetour )
function ticket:disableListeners()
- ticket.boutonPhoto:removeEventListener( "touch", boutonPhoto )
+-- ticket.boutonPhoto:removeEventListener( "touch", boutonPhoto )
ticket.prioriteL:removeEventListener( "touch", prioriteL )
ticket.prioriteM:removeEventListener( "touch", prioriteM )
ticket.prioriteH:removeEventListener( "touch", prioriteH )
ticket.boutonRetour:removeEventListener( "touch", boutonRetour )
Runtime:removeEventListener( "MenuEvent", changeType )
+ Runtime:removeEventListener( "key", onKeyEvent )
end
initFond()
initBorders()
+ initLabels()
initPhoto()
initPriorite()
initType()
init()
ticket:enableListeners()
---ticket.map.isHitTestable = false
return ticket