Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------------------------------------------------
- --
- -- main.lua
- --
- -----------------------------------------------------------------------------------------
- -- Your code here
- local composer = require("composer");
- local widget = require("widget");
- local json = require("json");
- http = require("socket.http")
- local appodeal = require( "plugin.appodeal" )
- composer.removeScene('scenes.menu')
- local scene = composer.newScene();
- local function adListener( event )
- if ( event.phase == "init" ) then -- Successful initialization
- print( event.isError )
- elseif ( event.phase == "failed" ) then -- The ad failed to load
- print( event.type )
- print( event.isError )
- print( event.response )
- end
- end
- appodeal.init( adListener, { appKey="37d4629e7cae2fa7f2147e6bf1f19bfa96fead0abc25a6e3", testMode = true } )
- local jsonRawData = http.request("http://ezmarketing.ru/fitness1/test.json")
- local jsonData = json.decode(jsonRawData)
- -- print(jsonData[1].name)
- -- print(jsonData[1].description)
- -- print(jsonData[1].img)
- function saveSettings(t, filename)
- local path = system.pathForFile(filename, system.ResourceDirectory);
- local file = io.open(path, "w");
- if (file) then
- local contents = json.encode(t);
- file:write(contents);
- io.close(file);
- return true
- else
- return false
- end
- end
- saveSettings(jsonData, "settings.json");
- settings = jsonData
- function scene:show(event)
- local sceneGroup = self.view;
- -- создаём группу для ввода веса
- local contentGroup = display.newGroup();
- local function scrollListener(event)
- local phase = event.phase
- local direction = event.direction
- -- если долистает до конца - дойдет до лимита
- if event.limitReached then
- if "up" == direction then
- print("Reached Top Limit")
- elseif "down" == direction then
- print("Reached Bottom Limit")
- end
- end
- return true
- end
- -- создаем скролвью
- local scrollView = widget.newScrollView
- {
- left = 0,
- top = 0,
- width = display.contentWidth,
- height = display.contentHeight,
- topPadding = 50,
- bottomPadding = 50,
- horizontalScrollDisabled = true,
- verticalScrollDisabled = false,
- listener = scrollListener,
- }
- -- local contentGroup = display.newGroup()
- -- -- рисую первую карточку
- -- local backgrRect = display.newRect(contentGroup, 0, 5, display.contentWidth, 110 ):setFillColor(0.4)
- -- local textTitle = "dfdsf"
- -- local textTitleObject = display.newText(contentGroup, textTitle, 110, -20, 300, 50, "Helvetica", 20)
- -- local textDescr = "dfdsf sf df we fwef wefwefwef wef we fwe we wef we we few we we wef wef wef we fwe fwe fwe fwej wjef wej fiwoej fiowej fiwej fowiej foiwje fiowje foiwjef oiwej iofwej fiowje iofjweio fjweio fjwoiej fwioej owiejf oiwej oiwej fiowejf iowejf iofewj fiowjefo ifjweio jfweio jiowej iowefj fiowej oifwejf oifwejio ffjweofi jfweo jwoej eoiwjf oiwje iowjeo ifjwefio jfweoi jewoifj fwoefjf wio"
- -- local textDecsrObject = display.newText(contentGroup, textDescr, 60, 25, 200, 50, "Helvetica", 14)
- -- local imageContent = display.newImageRect(contentGroup, "img/img1.jpg", 100, 100);
- -- imageContent.x = -display.contentWidth/3
- -- imageContent.y = 5
- -- -- lotsOfTextObject:setTextColor(0)
- -- contentGroup.x = display.contentCenterX
- -- scrollView:insert(contentGroup)
- for i = 1,5 do
- local function networkListener( event, urlOfImage )
- if ( event.isError ) then
- print( "Network error - download failed: ", event.response )
- elseif ( event.phase == "began" ) then
- print( "Progress Phase: began" )
- elseif ( event.phase == "ended" ) then
- print( "Displaying response image file" )
- -- myImage = display.newImage( event.response.filename, event.response.baseDirectory, 60, 40 )
- imageContent = display.newImageRect(contentGroup, event.response.filename,event.response.baseDirectory, 100, 100);
- imageContent.x = -display.contentWidth/3
- imageContent.y = 5+(110+10)*(i-1)
- contentGroup.x = display.contentCenterX
- -- contentGroup.y = (110+10)*(i-1)
- scrollView:insert(contentGroup)
- end
- end
- local contentGroup = display.newGroup()
- local backgrRect = display.newRect(contentGroup, 0, 5, display.contentWidth, 110 ):setFillColor(0.4)
- local textTitle = jsonData[i].name
- local textTitleObject = display.newText(contentGroup, textTitle, 110, -20, 300, 50, "Helvetica", 20)
- local textDescr = jsonData[i].description
- local textDecsrObject = display.newText(contentGroup, textDescr, 60, 25, 200, 50, "Helvetica", 14)
- local params = {}
- params.progress = true
- local urlOfImage = jsonData[i].img
- -- local urlOfImage = "http://docs.coronalabs.com/images/simulator/image-mask-base2.png"
- print(urlOfImage)
- print("check")
- contentGroup.x = display.contentCenterX
- contentGroup.y = (110+10)*(i-1)
- scrollView:insert(contentGroup)
- params =
- {
- }
- params[i] = urlOfImage
- print("Param"..i,"=",params[i])
- network.download(
- urlOfImage,
- "GET",
- networkListener,
- params,
- i..".jpg",
- system.DocumentsDirectory
- )
- -- local imageContent = display.newImageRect(contentGroup, "img/img1.jpg", 100, 100);
- -- imageContent.x = -display.contentWidth/3
- -- imageContent.y = 5
- local options =
- {
- effect = "fade",
- time = 400,
- params = {
- iCount = i,
- textT = textTitle,
- descrD = textDescr
- }
- }
- contentGroup:addEventListener("touch",
- function(event)
- -- composer.showOverlay("scenes.activity")
- -- composer.gotoScene("scenes.activity", options)
- -- Initialize the Appodeal plugin
- appodeal.show("interstitial")
- print("hello")
- end
- );
- end
- end
- function scene:hide( event )
- local sceneGroup = self.view
- -- Called prior to the removal of scene's view ("sceneGroup").
- -- Insert code here to clean up the scene.
- -- Example: remove display objects, save state, etc.
- end
- -- Called when a key event has been received
- local function onKeyEvent( event )
- -- Print which key was pressed down/up
- local message = "Key '" .. event.keyName .. "' was pressed " .. event.phase
- print( message )
- -- If the "back" key was pressed on Android, prevent it from backing out of the app
- if ( event.keyName == "back" ) then
- if ( system.getInfo("platform") == "android" ) then
- gotoScene("scenes.activity")
- end
- end
- -- IMPORTANT! Return false to indicate that this app is NOT overriding the received key
- -- This lets the operating system execute its default handling of the key
- return false
- end
- -- Add the key event listener
- Runtime:addEventListener( "key", onKeyEvent )
- scene:addEventListener("show", scene)
- scene:addEventListener("hide", scene)
- return scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement