Advertisement
reshetnikoff

Strange

Jul 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.04 KB | None | 0 0
  1. -----------------------------------------------------------------------------------------
  2. --
  3. -- main.lua
  4. --
  5. -----------------------------------------------------------------------------------------
  6.  
  7. -- Your code here
  8.  
  9. local composer = require("composer");
  10. local widget = require("widget");
  11. local json = require("json");
  12. http = require("socket.http")
  13. local appodeal = require( "plugin.appodeal" )
  14.  
  15. composer.removeScene('scenes.menu')
  16.  
  17. local scene = composer.newScene();
  18.  
  19. local function adListener( event )
  20.  
  21.     if ( event.phase == "init" ) then  -- Successful initialization
  22.        
  23.         print( event.isError )
  24.     elseif ( event.phase == "failed" ) then  -- The ad failed to load
  25.         print( event.type )
  26.         print( event.isError )
  27.         print( event.response )
  28.     end
  29. end
  30.  
  31.  
  32. appodeal.init( adListener, { appKey="37d4629e7cae2fa7f2147e6bf1f19bfa96fead0abc25a6e3", testMode = true } )  
  33.  
  34.  
  35.  
  36. local jsonRawData = http.request("http://ezmarketing.ru/fitness1/test.json")
  37.  
  38. local jsonData = json.decode(jsonRawData)
  39. -- print(jsonData[1].name)
  40. -- print(jsonData[1].description)
  41. -- print(jsonData[1].img)
  42.  
  43.  
  44. function saveSettings(t, filename)
  45.     local path = system.pathForFile(filename, system.ResourceDirectory);
  46.     local file = io.open(path, "w");
  47.     if (file) then
  48.         local contents = json.encode(t);
  49.         file:write(contents);
  50.         io.close(file);
  51.         return true
  52.     else
  53.         return false
  54.     end
  55. end
  56.  
  57. saveSettings(jsonData, "settings.json");
  58.  
  59.  
  60. settings = jsonData
  61.  
  62.  
  63.  
  64. function scene:show(event)
  65.     local sceneGroup = self.view;
  66.  
  67.     -- создаём группу для ввода веса
  68.     local contentGroup = display.newGroup();
  69.  
  70.  
  71.     local function scrollListener(event)
  72.         local phase = event.phase
  73.         local direction = event.direction
  74.  
  75.         -- если долистает до конца - дойдет до лимита
  76.         if event.limitReached then
  77.             if "up" == direction then
  78.                 print("Reached Top Limit")
  79.             elseif "down" == direction then
  80.                 print("Reached Bottom Limit")
  81.             end
  82.         end
  83.  
  84.         return true
  85.     end
  86.  
  87.     -- создаем скролвью
  88.     local scrollView = widget.newScrollView
  89.         {
  90.             left = 0,
  91.             top = 0,
  92.             width = display.contentWidth,
  93.             height = display.contentHeight,
  94.             topPadding = 50,
  95.             bottomPadding = 50,
  96.             horizontalScrollDisabled = true,
  97.             verticalScrollDisabled = false,
  98.             listener = scrollListener,
  99.         }
  100.  
  101.  
  102.     -- local contentGroup = display.newGroup()
  103.     -- -- рисую первую карточку
  104.     -- local backgrRect = display.newRect(contentGroup, 0, 5, display.contentWidth, 110 ):setFillColor(0.4)
  105.  
  106.     -- local textTitle = "dfdsf"
  107.     -- local textTitleObject = display.newText(contentGroup, textTitle, 110, -20, 300, 50, "Helvetica", 20)
  108.  
  109.     -- 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"
  110.     -- local textDecsrObject = display.newText(contentGroup, textDescr, 60, 25, 200, 50, "Helvetica", 14)
  111.  
  112.     -- local imageContent = display.newImageRect(contentGroup, "img/img1.jpg", 100, 100);
  113.     -- imageContent.x = -display.contentWidth/3
  114.     -- imageContent.y = 5
  115.  
  116.     -- -- lotsOfTextObject:setTextColor(0)
  117.     -- contentGroup.x = display.contentCenterX
  118.     -- scrollView:insert(contentGroup)
  119.  
  120.  
  121.    
  122.  
  123.    
  124.  
  125.      
  126.         for i = 1,5 do
  127.  
  128.  
  129.             local function networkListener( event, urlOfImage )
  130.                 if ( event.isError ) then
  131.                     print( "Network error - download failed: ", event.response )
  132.                 elseif ( event.phase == "began" ) then
  133.                     print( "Progress Phase: began" )
  134.                 elseif ( event.phase == "ended" ) then
  135.                     print( "Displaying response image file" )
  136.                     -- myImage = display.newImage( event.response.filename, event.response.baseDirectory, 60, 40 )
  137.                        
  138.                     imageContent = display.newImageRect(contentGroup, event.response.filename,event.response.baseDirectory, 100, 100);
  139.                     imageContent.x = -display.contentWidth/3
  140.                     imageContent.y = 5+(110+10)*(i-1)
  141.  
  142.                     contentGroup.x = display.contentCenterX
  143.                     -- contentGroup.y = (110+10)*(i-1)
  144.                     scrollView:insert(contentGroup)
  145.  
  146.                
  147.  
  148.                 end
  149.             end
  150.  
  151.  
  152.             local contentGroup = display.newGroup()
  153.            
  154.             local backgrRect = display.newRect(contentGroup, 0, 5, display.contentWidth, 110 ):setFillColor(0.4)
  155.  
  156.             local textTitle = jsonData[i].name
  157.             local textTitleObject = display.newText(contentGroup, textTitle, 110, -20, 300, 50, "Helvetica", 20)
  158.  
  159.             local textDescr = jsonData[i].description
  160.             local textDecsrObject = display.newText(contentGroup, textDescr, 60, 25, 200, 50, "Helvetica", 14)
  161.            
  162.  
  163.  
  164.            
  165.  
  166.             local params = {}
  167.             params.progress = true
  168.             local urlOfImage = jsonData[i].img
  169.  
  170.             -- local urlOfImage = "http://docs.coronalabs.com/images/simulator/image-mask-base2.png"
  171.  
  172.             print(urlOfImage)
  173.             print("check")
  174.  
  175.             contentGroup.x = display.contentCenterX
  176.             contentGroup.y = (110+10)*(i-1)
  177.             scrollView:insert(contentGroup)
  178.  
  179.  
  180.  
  181.             params =
  182.             {
  183.             }
  184.  
  185.             params[i] = urlOfImage
  186.             print("Param"..i,"=",params[i])
  187.  
  188.             network.download(
  189.                 urlOfImage,
  190.                 "GET",
  191.                 networkListener,
  192.                 params,
  193.                 i..".jpg",
  194.                 system.DocumentsDirectory
  195.             )
  196.  
  197.  
  198.                 -- local imageContent = display.newImageRect(contentGroup, "img/img1.jpg", 100, 100);
  199.                 -- imageContent.x = -display.contentWidth/3
  200.                 -- imageContent.y = 5
  201.  
  202.  
  203.            
  204.  
  205.  
  206.            
  207.  
  208.             local options =
  209.             {
  210.                 effect = "fade",
  211.                 time = 400,
  212.                 params = {
  213.                     iCount = i,
  214.                     textT = textTitle,
  215.                     descrD = textDescr
  216.                 }
  217.             }
  218.  
  219.  
  220.  
  221.  
  222.             contentGroup:addEventListener("touch",  
  223.             function(event)
  224.                 -- composer.showOverlay("scenes.activity")
  225.                 -- composer.gotoScene("scenes.activity", options)
  226.  
  227.                 -- Initialize the Appodeal plugin
  228.                
  229.                 appodeal.show("interstitial")
  230.                 print("hello")
  231.             end
  232.             );
  233.            
  234.  
  235.            
  236.         end
  237.  
  238.  
  239.  
  240.  
  241. end
  242.  
  243.  
  244. function scene:hide( event )
  245.  
  246.     local sceneGroup = self.view
  247.  
  248.     -- Called prior to the removal of scene's view ("sceneGroup").
  249.     -- Insert code here to clean up the scene.
  250.     -- Example: remove display objects, save state, etc.
  251. end
  252.  
  253.  
  254.  
  255.  
  256.  
  257. -- Called when a key event has been received
  258. local function onKeyEvent( event )
  259.  
  260.     -- Print which key was pressed down/up
  261.     local message = "Key '" .. event.keyName .. "' was pressed " .. event.phase
  262.     print( message )
  263.  
  264.     -- If the "back" key was pressed on Android, prevent it from backing out of the app
  265.     if ( event.keyName == "back" ) then
  266.         if ( system.getInfo("platform") == "android" ) then
  267.             gotoScene("scenes.activity")
  268.         end
  269.     end
  270.  
  271.     -- IMPORTANT! Return false to indicate that this app is NOT overriding the received key
  272.     -- This lets the operating system execute its default handling of the key
  273.     return false
  274. end
  275.  
  276.  
  277. -- Add the key event listener
  278. Runtime:addEventListener( "key", onKeyEvent )
  279.  
  280.  
  281.  
  282. scene:addEventListener("show", scene)
  283. scene:addEventListener("hide", scene)
  284.  
  285.  
  286. return scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement