Skip to content

Instantly share code, notes, and snippets.

@fredericpierron
Created November 4, 2012 23:44
Show Gist options
  • Save fredericpierron/4014386 to your computer and use it in GitHub Desktop.
Save fredericpierron/4014386 to your computer and use it in GitHub Desktop.
The module itself
local navGene = {}
local storyboard = require ("storyboard")
local widget = require ("widget")
local dataBase = require ("dataBase")
local ui_news, ui_now, ui_yellow, ui_news_over, ui_now_over, ui_yellow_over
navGene.createNavGene = function()
local path = "ui_footer/"
local imgNews = "news_out.png"
local imgNow = "now_out.png"
local imgYellow = "yellow_out.png"
local imgNews_over = "news_over.png"
local imgNow_over = "now_over.png"
local imgYellow_over = "yellow_over.png"
-- NEWS en 1er rang
ui_news_over = display.newImageRect(path..imgNews_over,109,47,true);
ui_news_over:setReferencePoint ( display.TopLeftReferencePoint );
ui_news_over.x = 0
hauteur = display.viewableContentHeight + ui_news_over.height
ui_news_over.y = hauteur;
ui_news_over.name = "news"
ui_news_over.statut = false
ui_news = display.newImageRect(path..imgNews,109,47,true);
ui_news:setReferencePoint ( display.TopLeftReferencePoint );
ui_news.x = 0
hauteur = display.viewableContentHeight + ui_news.height
ui_news.y = hauteur
ui_news.name = "news"
ui_news.statut = false
-- NOW > passe en 2eme rang
ui_now = display.newImageRect(path..imgNow,100,47,true);
ui_now:setReferencePoint ( display.TopLeftReferencePoint );
ui_now.x = ui_news.width
hauteur = display.viewableContentHeight + ui_now.height
ui_now.y = hauteur;
ui_now.name = "now"
ui_now.statut = false
ui_now_over = display.newImageRect(path..imgNow_over,100,47,true);
ui_now_over:setReferencePoint ( display.TopLeftReferencePoint );
ui_now_over.x = ui_news.width
hauteur = display.viewableContentHeight + ui_now_over.height
ui_now_over.y = hauteur;
ui_now_over.name = "now"
ui_now_over.statut = false
-- YELLOW > 3eme rang
ui_yellow_over = display.newImageRect(path..imgYellow_over,111,47,true);
ui_yellow_over:setReferencePoint ( display.TopLeftReferencePoint );
ui_yellow_over.x = ui_now_over.width + ui_news_over.width
hauteur = display.viewableContentHeight + ui_yellow_over.height
ui_yellow_over.y = hauteur;
ui_yellow_over.name = "yellow"
ui_yellow_over.statut = false
ui_yellow = display.newImageRect(path..imgYellow,111,47,true);
ui_yellow:setReferencePoint ( display.TopLeftReferencePoint );
ui_yellow.x = ui_now.width + ui_news.width
hauteur = display.viewableContentHeight + ui_yellow.height
ui_yellow.y = hauteur;
ui_yellow.name = "yellow"
ui_yellow.statut = false
return ui_news, ui_now, ui_yellow, ui_news_over, ui_now_over, ui_yellow_over
end
navGene.addEventTo = function(bouton)
local function navControler(event)
navGene.manageDirection(event)
end
bouton:addEventListener("touch", navControler)
end
local ui_interview, ui_trends, ui_interview_over, ui_trends_over
navGene.createNavNews = function()
local path = "uiNews/"
local hauteur
ui_interview = display.newImageRect(path.."ui_interview_out.png",161,47,true);
ui_interview:setReferencePoint ( display.TopLeftReferencePoint );
ui_interview.x = 0
hauteur = display.viewableContentHeight + (ui_news.height + ui_interview.height)
ui_interview.y = hauteur
ui_interview.name = "interview"
ui_trends = display.newImageRect(path.."ui_trends_out.png",159,47,true);
ui_trends:setReferencePoint ( display.TopLeftReferencePoint );
ui_trends.x = ui_interview.width
hauteur = display.viewableContentHeight + (ui_news.height + ui_trends.height)
ui_trends.y = hauteur
ui_trends.name = "trends"
ui_interview_over = display.newImageRect(path.."ui_interview_over.png",161,47,true);
ui_interview_over:setReferencePoint ( display.TopLeftReferencePoint );
ui_interview_over.x = 0
hauteur = display.viewableContentHeight + (ui_news.height + ui_interview.height)
ui_interview_over.y = hauteur
ui_interview_over.name = "interview"
ui_trends_over = display.newImageRect(path.."ui_trends_over.png",159,47,true);
ui_trends_over:setReferencePoint ( display.TopLeftReferencePoint );
ui_trends_over.x = ui_interview.width
hauteur = display.viewableContentHeight + (ui_news.height + ui_trends.height)
ui_trends_over.y = hauteur
ui_trends_over.name = "trends"
return ui_interview, ui_trends, ui_interview_over, ui_trends_over
end
local ui_cities, ui_suggest, ui_cities_over, ui_suggest_over
navGene.createNavNow = function()
local path = "uiNow/"
local hauteur
ui_cities = display.newImageRect(path.."ui_cities_out.png",161,47,true);
ui_cities:setReferencePoint ( display.TopLeftReferencePoint );
ui_cities.x = 0
hauteur = display.viewableContentHeight + (ui_news.height + ui_cities.height)
ui_cities.y = hauteur
ui_cities.name = "cities"
-- ui_suggest_out_bis.png = cartouche vierge
ui_suggest = display.newImageRect(path.."ui_suggest_out.png",159,47,true);
ui_suggest:setReferencePoint ( display.TopLeftReferencePoint );
ui_suggest.x = ui_cities.width
hauteur = display.viewableContentHeight + (ui_news.height + ui_suggest.height)
ui_suggest.y = hauteur
ui_suggest.name = "suggest"
ui_cities_over = display.newImageRect(path.."ui_cities_over.png",161,47,true);
ui_cities_over:setReferencePoint ( display.TopLeftReferencePoint );
ui_cities_over.x = 0
hauteur = display.viewableContentHeight + (ui_news.height + ui_cities_over.height)
ui_cities_over.y = hauteur
ui_cities_over.name = "cities"
--over
ui_suggest_over = display.newImageRect(path.."ui_suggest_over.png",159,47,true);
ui_suggest_over:setReferencePoint ( display.TopLeftReferencePoint );
ui_suggest_over.x = ui_cities_over.width
hauteur = display.viewableContentHeight + (ui_news.height + ui_suggest_over.height)
ui_suggest_over.y = hauteur
ui_suggest_over.name = "suggest"
return ui_cities, ui_suggest, ui_cities_over, ui_suggest_over
end
local ui_back, ui_logo, ui_share
navGene.createBlackHeader = function()
ui_back = display.newImageRect("uiHeader/back.png",135,35,true);
ui_back:setReferencePoint ( display.TopLeftReferencePoint );
ui_back.x = 0
hauteur = ui_back.height * -1
ui_back.y = hauteur;
ui_back.name = "back"
ui_logo = display.newImageRect("uiHeader/logoblack.png",50,35,true);
ui_logo:setReferencePoint ( display.TopLeftReferencePoint );
ui_logo.x = ui_back.width
hauteur = ui_back.height * -1
ui_logo.y = hauteur;
ui_logo.name = "logoblack"
ui_share = display.newImageRect("uiHeader/share.png",135,35,true);
ui_share:setReferencePoint ( display.TopLeftReferencePoint );
ui_share.x = ui_back.width + ui_logo.width
hauteur = ui_back.height * -1
ui_share.y = hauteur;
ui_share.name = "share"
return ui_back, ui_logo, ui_share
end
local ui_spirit, ui_season, ui_wines, ui_spirit_over, ui_season_over, ui_wines_over
navGene.createNavYellow = function ()
path = "uiYellow/"
local hauteur
ui_spirit = display.newImageRect(path.."ui_spirit_out.png",86,47,true);
ui_spirit:setReferencePoint ( display.TopLeftReferencePoint );
ui_spirit.x = 0
hauteur = display.viewableContentHeight + (ui_now.height + ui_spirit.height)
ui_spirit.y = hauteur
ui_spirit.name = "airstream01"
ui_season = display.newImageRect(path.."ui_season_out.png",146,47,true);
ui_season:setReferencePoint ( display.TopLeftReferencePoint );
ui_season.x = ui_spirit.width
hauteur = display.viewableContentHeight + (ui_now.height+ui_season.height)
ui_season.y = hauteur
ui_season.name = "season"
ui_wines = display.newImageRect(path.."ui_wines_out.png",88,47,true);
ui_wines:setReferencePoint ( display.TopLeftReferencePoint );
ui_wines.x = ui_spirit.width + ui_season.width
hauteur = display.viewableContentHeight + (ui_now.height+ui_wines.height)
ui_wines.y = hauteur
ui_wines.name = "wines"
ui_spirit_over = display.newImageRect(path.."ui_spirit_over.png",86,47,true);
ui_spirit_over:setReferencePoint ( display.TopLeftReferencePoint );
ui_spirit_over.x = 0
hauteur = display.viewableContentHeight + (ui_now.height + ui_spirit_over.height)
ui_spirit_over.y = hauteur
ui_spirit_over.name = "airstream01"
ui_season_over = display.newImageRect(path.."ui_season_over.png",146,47,true);
ui_season_over:setReferencePoint ( display.TopLeftReferencePoint );
ui_season_over.x = ui_spirit.width
hauteur = display.viewableContentHeight + (ui_now.height+ui_season.height)
ui_season_over.y = hauteur
ui_season_over.name = "season"
ui_wines_over = display.newImageRect(path.."ui_wines_over.png",88,47,true);
ui_wines_over:setReferencePoint ( display.TopLeftReferencePoint );
ui_wines_over.x = ui_spirit_over.width + ui_season_over.width
hauteur = display.viewableContentHeight + (ui_now.height+ui_wines.height)
ui_wines_over.y = hauteur
ui_wines_over.name = "wines"
return ui_spirit, ui_season, ui_wines, ui_spirit_over, ui_season_over, ui_wines_over
end
navGene.changeStatut = function(rubrique, sousRubrique, statut)
if rubrique == "news" then
navGene.exe_transition(ui_news_over, statut, 0)
navGene.exe_transition(ui_now, statut, 0)
navGene.exe_transition(ui_yellow, statut, 0)
if sousRubrique == "none" then
navGene.exe_transition(ui_interview, statut, ui_interview.height)
navGene.exe_transition(ui_trends, statut, ui_trends.height)
elseif sousRubrique == "interview" then
navGene.exe_transition(ui_interview_over, statut, ui_interview.height)
navGene.exe_transition(ui_trends, statut, ui_trends.height)
elseif sousRubrique == "trends" then
navGene.exe_transition(ui_interview, statut, ui_interview.height)
navGene.exe_transition(ui_trends_over, statut, ui_trends.height)
end
elseif rubrique == "now" then
navGene.exe_transition(ui_news, statut, 0)
navGene.exe_transition(ui_now_over, statut, 0)
navGene.exe_transition(ui_yellow, statut, 0)
if sousRubrique == "none" then
navGene.exe_transition(ui_cities, statut, ui_cities.height)
navGene.exe_transition(ui_suggest, statut, ui_suggest.height)
elseif sousRubrique == "cities" then
navGene.exe_transition(ui_cities_over, statut, ui_cities.height)
navGene.exe_transition(ui_suggest, statut, ui_suggest.height)
elseif sousRubrique == "suggest" then
navGene.exe_transition(ui_cities, statut, ui_cities.height)
navGene.exe_transition(ui_suggest_over, statut, ui_suggest_over.height)
end
elseif rubrique == "yellow" then
navGene.exe_transition(ui_news, statut, 0)
navGene.exe_transition(ui_now, statut, 0)
navGene.exe_transition(ui_yellow_over, statut, 0)
if sousRubrique == "none" then
navGene.exe_transition(ui_spirit, statut, ui_spirit.height)
navGene.exe_transition(ui_season, statut, ui_season.height)
navGene.exe_transition(ui_wines, statut, ui_wines.height)
elseif sousRubrique == "spirit" then
navGene.exe_transition(ui_spirit_over, statut, ui_spirit.height)
navGene.exe_transition(ui_season, statut, ui_season.height)
navGene.exe_transition(ui_wines, statut, ui_wines.height)
elseif sousRubrique == "season" then
navGene.exe_transition(ui_spirit, statut, ui_spirit.height)
navGene.exe_transition(ui_season_over, statut, ui_season.height)
navGene.exe_transition(ui_wines, statut, ui_wines.height)
elseif sousRubrique == "wines" then
navGene.exe_transition(ui_spirit, statut, ui_spirit.height)
navGene.exe_transition(ui_season, statut, ui_season.height)
navGene.exe_transition(ui_wines_over, statut, ui_wines.height)
end
end
--statut = (not statut)
navGene.exe_transition(ui_back, statut, 0)
navGene.exe_transition(ui_logo, statut, 0)
navGene.exe_transition(ui_share, statut, 0)
end
navGene.exe_transition = function(rub, nav_visible, hauteur)
if nav_visible == true then
facteur = -1
else
facteur = 1
end
if rub == ui_back or rub == ui_logo or rub == ui_share then
if nav_visible == true then
formule = 0
else
formule = rub.height * -1
end
else
formule = display.viewableContentHeight + ((rub.height+hauteur)*facteur)
end
transition.to( rub,{ time = 500, y = formule, transition = easing.inOutQuad })
end
navGene.manageDirection = function (event)
local direction = "slideLeft"
local scene = event.target.name
local current_scene_name
local previous_scene_name
current_scene_name = storyboard.getCurrentSceneName()
previous_scene_name = storyboard.getPrevious()
print("_________________________")
print("current_scene: " .. current_scene_name)
print("previous_scene: ".. previous_scene_name)
if (event.phase == "began" or event.phase == "touch") then
if scene == "back" then
-- PARTIE NOW
if current_scene_name == "cities_articles" then
scene = "cities_themes"
elseif current_scene_name == "cities_themes" then
scene = "cities2"
elseif current_scene_name == "cities2" then
scene = "cities"
elseif current_scene_name == "cities" then
scene = "accueil"
-- PARTIE NEWS
elseif current_scene_name == "news" then
scene = "accueil"
elseif current_scene_name == "news_articles" and previous_scene_name == "news" then
scene = "news"
elseif current_scene_name == "news_articles" and previous_scene_name == "interview" then
scene = "interview"
elseif current_scene_name == "interview" then
scene = "news"
elseif current_scene_name == "trends_articles" and previous_scene_name == "news" then
scene = "news"
elseif current_scene_name == "trends_articles" and previous_scene_name == "trends" then
scene = "trends"
elseif current_scene_name == "trends" then
scene = "news"
-- PARTIE YELLOW
elseif current_scene_name == "yellow" then
scene = 'accueil'
elseif current_scene_name == "wines" then
scene = "yellow"
elseif current_scene_name == "wines_articles" then
scene = "wines"
elseif current_scene_name == "spirit" then
scene = "yellow"
elseif current_scene_name == "season" then
scene = "accueil"
elseif current_scene_name == "season_articles" then
scene = "season"
elseif current_scene_name == "surfOnWeb" then
scene = "accueil"
elseif current_scene_name == "share" then
scene = "accueil"
elseif current_scene_name == "shareTweeter" then
scene = "accueil"
-- PARTIE AIRSTREAM
elseif current_scene_name == "airstream01" then
scene = "yellow"
elseif current_scene_name == "airstream02" then
scene = "airstream01"
elseif current_scene_name == "airstream03" then
scene = "airstream02"
elseif current_scene_name == "loader" then
scene = "accueil"
else
scene = "accueil"
end
storyboard.gotoScene(scene, direction, 500)
<<<<<<< HEAD
elseif scene == "now" then
scene = "cities"
storyboard.gotoScene(scene,direction,500)
elseif scene == "logoblack" then
scene = "accueil"
storyboard.gotoScene(scene,direction,500)
else
-- si ce n'est pas un back on va à la scene
if scene ~= current_scene_name then
local opt =
{
effect = "slideLeft",
time = 500
}
print("autre cas:"..scene)
storyboard.gotoScene(scene, opt)
=======
else
if scene == "now" then
scene = "cities"
elseif scene == "logoblack" then
scene = "accueil"
end
print("scene : "..scene)
print("current: ".. current_scene_name)
print("previous: ".. previous_scene_name)
if scene ~= current_scene_name then
storyboard.gotoScene(scene, direction, 500)
>>>>>>> Version 1.3.5
end
end
return true
end
-- fin de la fonction
end
local ville, textVille, scrollView
local boutonRubrique = {}
navGene.screenNow = function(myNomVille, myIdVille, myPaysVille, myCodeVille)
local path = "uiNow/"
--[[print("naveGene/nomville : "..myNomVille)
--print("naveGene/idVille : "..myIdVille)
--print("naveGene/PaysVille : "..myPaysVille)
--print("naveGene/codeVille : "..myCodeVille)]]
--[[
liste les fonts
local sysFonts = native.getFontNames()
for k,v in pairs(sysFonts) do --print(v) end
]]
-- creation d'une scrollview
local function scrollViewListener( event )
local s = event.target -- reference to scrollView object
if event.type == "beganScroll" then
--print( "beganScroll event type" )
elseif event.type == "endedScroll" then
--print ( s.x )
--print( "endedScroll event type" )
elseif event.type == "movingToTopLimit" then
--print( "movingToTopLimit event type" )
elseif event.type == "movingToBottomLimit" then
--print( "movingToBottomLimit event type" )
elseif event.type == "movingToLeftLimit" then
--print( "movingToLeftLimit event type" )
elseif event.type == "movingToRightLimit" then
--print( "movingToRightLimit event type" )
end
end
-- Create a new ScrollView widget:
local rubriques = {} -- liste des contenus
local h = 0 -- h = hauteur des contenus
local hText = 0 -- hauteur des box de contenus
local textTheme = {} -- texte box des themes
local textNbNews = {} -- nombre de news dans chaque theme
local ovalNbNews = {}
--local boutonRubrique = {}
local tabTheme = {}
local scrollView = widget.newScrollView {
left = 0,
top = 206,
width = 320,
height = 184,
scrollWidth = 320,
maskFile= path.."ui_mask_320x184.png",
--listener = scrollViewListener
}
local onButtonEvent = function(event)
if event.phase == "moved" then
local dx = math.abs( event.x - event.xStart )
local dy = math.abs( event.y - event.yStart )
-- le doigt se déplace de plus de 5 pixels
if dx > 5 or dy > 5 then
scrollView:takeFocus ( event )
end
elseif event.phase == "release" then
-- charge la liste des news concernant un thème
myNomTheme = tostring(tabTheme[event.target.id])
local options =
{
effect = "slideLeft",
time = 500,
params = { nomVille = myNomVille, idVille = myIdVille, idTheme = event.target.id, paysVille = myPaysVille, nomTheme = myNomTheme, codeVille = myCodeVille }
}
storyboard.params = { nomVille = myNomVille, idVille = myIdVille, idTheme = event.target.id, paysVille = myPaysVille, nomTheme = myNomTheme, codeVille = myCodeVille }
storyboard.gotoScene( "cities_themes", options )
end
return true
end
-- select toutes les infos qui ont pour ville le nom de la ville order by theme
local sqlPath = system.pathForFile ( "now.db", system.CachesDirectory)
local db_now_cities = sqlite3.open ( sqlPath )
--Handle the applicationExit event to close the db
local function onSystemEvent( event )
if( event.type == "applicationExit" ) then
if db_now_cities:isopen() then
db_now_cities:close()
end
end
end
--setup the system listener to catch applicationExit
Runtime:addEventListener( "system", onSystemEvent )
local sql = [[
SELECT rubriques.nom as "rubrique", rubriques.id_rubrique as "idRubrique", COUNT( evenements.id_rubrique) as "nombre"
FROM evenements, rubriques WHERE evenements.id_ville = "]]..tostring(myCodeVille)..[["
AND evenements.id_rubrique = rubriques.id_rubrique
GROUP BY rubriques.nom
]]
--print ( sql )
local path = "uiNow/"
local i = 0
for row in db_now_cities:nrows(sql) do
boutonRubrique[i] = widget.newButton{
id = row.idRubrique,
left = 0,
top = h,
label = "",
--default = path.."ui_liste_blanche.png",
default = path.."ui_fond_filet_fleche.png",
over = path.."ui_liste_orange.png",
font = "HelveticaNeue-Light",
defaultColor = {250,157,67,255},
overColor = {250, 157, 67, 255},
cornerRadius = 0,
strokeWidth = 0,
fontSize = 18,
width = 320,
height = 40,
onEvent = onButtonEvent
}
-- affiche du theme
textTheme[i] = display.newText("", 0, hText, "HelveticaNeue-Light", 18 )
textTheme[i]:setTextColor(83, 71, 65)
textTheme[i].text = row.rubrique
textTheme[i]:setReferencePoint ( display.TopLeftReferencePoint)
textTheme[i].x = 25
textTheme[i].y = h + 10
textTheme[i]:setReferencePoint ( display.TopLeftReferencePoint)
-- affiche nombre de news dans le theme
textNbNews[i] = display.newText("",20, hText, "HelveticaNeue-Light", 18 )
textNbNews[i].x = 277
textNbNews[i].y = h + 20
textNbNews[i]:setTextColor(83, 71, 65)
textNbNews[i].text = "("..row.nombre..")"
h = h + 40
scrollView:insert ( boutonRubrique[i] )
scrollView:insert ( textNbNews[i] )
scrollView:insert ( textTheme[i] )
tabTheme[row.idRubrique] = row.rubrique
i= i +1
end
db_now_cities:close()
-- insertion de l'espace d'affichage de la ville
ville = display.newImageRect(path.."ui_fond_ville2.png",320, 35, true)
ville:setReferencePoint ( display.TopLeftReferencePoint )
ville.x = 0
ville.y = 175
-- affiche du textbox de la ville
textVille = display.newText(tostring(myNomVille), 25, 175, "HelveticaNeue-UltraLight", 24)
textVille:setReferencePoint ( display.TopLeftReferencePoint )
textVille:setTextColor(250, 157, 67, 255)
textVille.align = "left"
textVille.text = tostring(myNomVille)
textVille.x = 25
textVille.y = 175
textVille:setReferencePoint( display.TopLeftReferencePoint )
return ville, textVille, scrollView
end
-- /// Gestion de la liste des articles ///
navGene.screenNowListeEvents = function (myNomVille, myIdVille, myIdTheme, myPaysVille, myThemeName, myCodeVille)
local path = "uiNow/"
local tabGPS={}
-- creation d'une scrollview : pas d'interaction nécessaire
local function scrollViewListener( event )
local s = event.target -- reference to scrollView2 object
if event.type == "beganScroll" then
--print( "beganScroll event type" )
elseif event.type == "endedScroll" then
--print ( s.x )
--print( "endedScroll event type" )
elseif event.type == "movingToTopLimit" then
--print( "movingToTopLimit event type" )
elseif event.type == "movingToBottomLimit" then
--print( "movingToBottomLimit event type" )
elseif event.type == "movingToLeftLimit" then
--print( "movingToLeftLimit event type" )
elseif event.type == "movingToRightLimit" then
--print( "movingToRightLimit event type" )
end
end
-- Create a new ScrollView widget:
local articles = {} -- liste des articles
local h = 0 -- h = hauteur des articles
local hText = 0 -- hauteur des box de contenus
local textArticle = {} -- texte box des themes
local imgArticle -- image de l'article
local boutonArticle = {}
local myVignette = {}
local scrollView2 = widget.newScrollView {
left = 0,
top = 206,
width = 320,
height = 184,
scrollWidth = 320,
maskFile = path.."ui_mask_320x184.png",
--listener = scrollViewListener
}
local onButtonEvent = function(event)
if event.phase == "moved" then
local dx = math.abs( event.x - event.xStart )
local dy = math.abs( event.y - event.yStart )
-- le doigt se déplace de plus de 5 pixels
if dx > 5 or dy > 5 then
scrollView2:takeFocus ( event )
end
elseif event.phase == "release" then
--print ( "BOUTON CLIQUE : "..event.target.id )
-- charge la liste des news concernant un thème
local options =
{
effect = "slideLeft",
time = 500,
params = {
nomVille = tostring(myNomVille),
idVille = tostring(idVille),
idArticle = tostring(event.target.id),
nomTheme = tostring(myThemeName),
paysVille = tostring(myPaysVille),
codeVille = storyboard.params.codeVille
}
}
storyboard.params = {
nomVille = myNomVille,
idVille = myIdVille,
idTheme = myIdTheme,
paysVille = myPaysVille,
nomTheme = tostring(myThemeName),
codeVille = myCodeVille,
idArticle = tostring(event.target.id)
}
storyboard.gotoScene( "cities_articles", options )
end
return true
end
-- select toutes les infos qui ont pour ville le nom de la ville order by theme
local sqlPath = system.pathForFile ( "now.db", system.CachesDirectory)
local db_now_cities = sqlite3.open ( sqlPath )
--Handle the applicationExit event to close the db
local function onSystemEvent( event )
if( event.type == "applicationExit" ) then
if db_now_cities:isopen() then
db_now_cities:close()
end
end
end
--setup the system listener to catch applicationExit
Runtime:addEventListener( "system", onSystemEvent )
local sql = [[
SELECT evenements.id_evenement as "idEvenement", evenements.nom as "titre", evenements.image as "vignette", rubriques.nom as "nomTheme", evenements.GPS as "myGPS"
FROM evenements, rubriques
WHERE evenements.id_ville = ']]..myCodeVille..[[' and evenements.id_rubrique = ]]..myIdTheme..[[ GROUP BY evenements.id_evenement
]]
--print("sql de navegene.screenListeEvent:"..sql)
local path = "uiNow/"
local i = 0
for row in db_now_cities:nrows(sql) do
tabGPS[i+1] = row.myGPS
--print ("ScreenNow DONNEES GPS : "..tostring(tabGPS))
boutonArticle[i] = widget.newButton{
id = row.idEvenement,
left = 0,
top = h,
label = "",
--default = path.."ui_liste_blanche.png",
default = path.."ui_fond_filet_fleche_liste.png",
over = path.."ui_fond_filet_fleche_orange.png",
font = "HelveticaNeue-Light",
defaultColor = {255,255,255,255},
overColor = {250, 157, 67, 255},
cornerRadius = 0,
strokeWidth = 0,
fontSize = 18,
width = 320,
height = 61,
onEvent = onButtonEvent
}
--print("screenlisteEvent Titre de la base : "..row.titre)
-- coupe de la chaine si plus de 22 caractères
local lg = tostring(row.titre)
local x = string.len(lg)
if x > 22 then
lg = string.sub(lg, 1, 22)
local c = string.sub(lg, string.len(lg), -1)
while c ~= " " do
local y = string.len(lg) -1
lg = string.sub(lg, 1, y)
c = string.sub(lg, string.len(lg), -1)
end
lg = string.sub(lg, 1, string.len(lg)-1)
lg = lg.."..."
end
-- affiche du theme
textArticle[i] = display.newText(" ", 0, hText, "HelveticaNeue-Light", 18 )
textArticle[i]:setTextColor(83, 71, 65)
textArticle[i].text = lg
textArticle[i]:setReferencePoint ( display.TopLeftReferencePoint)
textArticle[i].x = 85
textArticle[i].y = h + 20
-- reconstruction du nom de la miniVignette à afficher
local vignette = row.vignette
local miniVignette
if vignette == "NULL" then
miniVignette = "greyVignetteMini.jpg"
else
local l = vignette:len()
local nomVignette = vignette:sub(1, l-4)
local vignetteExtension = vignette:sub(l-3,l)
miniVignette = "img_now/"..nomVignette.."Mini"..vignetteExtension
end
--myVignette[i] = display.newImageRect("greyVignetteMini.jpg",system.ResourceDirectory, 80,50)
myVignette[i] = display.newImageRect(miniVignette,system.CachesDirectory, 80,50)
myVignette[i]:setReferencePoint (display.TopLeftReferencePoint )
myVignette[i].x = 4
myVignette[i].y = h + 4
h = h + 61
scrollView2:insert ( boutonArticle[i] )
scrollView2:insert ( myVignette[i] )
scrollView2:insert ( textArticle[i] )
i= i +1
end
db_now_cities:close()
-- insertion de l'espace d'affichage de la news
local ville = display.newImageRect(path.."ui_fond_ville2.png",320, 35, true)
ville:setReferencePoint ( display.TopLeftReferencePoint )
ville.x = 0
ville.y = 175
-- affiche du textbox de la news
local textVille = display.newText(tostring(myNomVille), 25, 175, "HelveticaNeue-UltraLight", 24)
textVille:setReferencePoint ( display.TopLeftReferencePoint )
textVille:setTextColor(250, 157, 67, 255)
textVille.align = "left"
textVille.text = tostring(myNomVille)
textVille.x = 14
textVille.y = 175
textVille:setReferencePoint( display.TopLeftReferencePoint )
local textTheme = display.newText(tostring(myThemeName), 180, 175, "HelveticaNeue-UltraLight", 18)
textTheme:setReferencePoint ( display.TopLeftReferencePoint )
textTheme:setTextColor(83, 71, 65)
textTheme.align = "right"
textTheme.text = tostring(myThemeName)
textTheme.x = 160
--textTheme.width = 160
textTheme.y = 180
textTheme:setReferencePoint ( display.TopRightReferencePoint )
textTheme.x = 310
return ville, textVille, textTheme, scrollView2, tabGPS
end
-- FIN DU MODULE
return navGene
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment